From 985358b0880c810d2d7440e80188892f954ec90a Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 18 Oct 2018 10:59:12 -0400 Subject: [PATCH] fix web3 being reseted every test and fix ens failing on web3 reset --- lib/modules/ens/index.js | 4 ++++ lib/modules/tests/test.js | 3 ++- test_apps/test_app/test/interface_spec.js | 2 +- test_apps/test_app/test/token_spec.js | 9 ++++++++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/modules/ens/index.js b/lib/modules/ens/index.js index 79552d6c..5be206aa 100644 --- a/lib/modules/ens/index.js +++ b/lib/modules/ens/index.js @@ -77,6 +77,9 @@ class ENS { this.registerConsoleCommands(); } + reset() { + this.configured = false; + } registerConsoleCommands() { this.embark.registerConsoleCommand((cmd, _options) => { @@ -106,6 +109,7 @@ class ENS { registerEvents() { this.embark.registerActionForEvent("deploy:beforeAll", this.configureContractsAndRegister.bind(this)); + this.events.setCommandHandler('blockchain:reset', this.reset.bind(this)); this.events.setCommandHandler("storage:ens:associate", this.associateStorageToEns.bind(this)); } diff --git a/lib/modules/tests/test.js b/lib/modules/tests/test.js index df30700b..161162c0 100644 --- a/lib/modules/tests/test.js +++ b/lib/modules/tests/test.js @@ -128,7 +128,8 @@ class Test { return callback(__("contracts config error: unknown deployment type %s", type)); } - if (accounts || port !== this.simOptions.port || type !== this.simOptions.type || host !== this.simOptions.host) { + if (accounts || (port && port !== this.simOptions.port) || (type && type !== this.simOptions.type) || + (host && host !== this.simOptions.host)) { resetServices = true; } diff --git a/test_apps/test_app/test/interface_spec.js b/test_apps/test_app/test/interface_spec.js index f546c2a8..ab9e51ce 100644 --- a/test_apps/test_app/test/interface_spec.js +++ b/test_apps/test_app/test/interface_spec.js @@ -16,7 +16,7 @@ contract("AnotherStorageWithInterface", function() { it("sets an empty address because ERC20 is an interface", async function() { let result = await AnotherStorage.methods.simpleStorageAddress().call(); - assert.equal(result.toString(), '0x0000000000000000000000000000000000000000'); + assert.strictEqual(result.toString(), '0x0000000000000000000000000000000000000000'); }); }); diff --git a/test_apps/test_app/test/token_spec.js b/test_apps/test_app/test/token_spec.js index 85fd4e6b..8ac8b07f 100644 --- a/test_apps/test_app/test/token_spec.js +++ b/test_apps/test_app/test/token_spec.js @@ -1,4 +1,4 @@ -/*global describe, config, it*/ +/*global describe, config, it, web3*/ const assert = require('assert'); const Token = require('Embark/contracts/Token'); const MyToken = require('Embark/contracts/MyToken'); @@ -85,4 +85,11 @@ describe("Token", function () { it("should not deploy if deployIf returns false", function() { assert.ok(!SomeContract.options.address); }); + + it("should set the ens attr to the address of embark.eth", async function() { + let result = await Test.methods.ens().call(); + // Testing that it is an address as we don't really know the address + assert.strictEqual(web3.utils.isAddress(result), true); + assert.notStrictEqual(result, '0x0000000000000000000000000000000000000000'); + }); });