Skip to content

Commit 3ceac53

Browse files
jrainvilleiurimatias
authored andcommitted
fix(@embark/ens): fix registerSubDomain in tests and add test
registerSubDomain didn't work in tests because it used the old way of checking the env, which is checking the `this.env` string, but in tests, we use the `test` env. So instead, we now check if it is a known network using the network ID (like we do for other place)
1 parent 3f58376 commit 3ceac53

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

dapps/tests/app/test/embarkJS_spec.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,26 @@ config({
2020
});
2121

2222
describe("EmbarkJS functions", function() {
23-
it('should have access to ENS functions and registered test.eth', async function() {
24-
const rootAddress = await EmbarkJS.Names.resolve('test.eth');
25-
assert.strictEqual(rootAddress, web3.eth.defaultAccount);
23+
it('should have access to ENS functions (register, lookup and resolve)', function(done) {
24+
const registerAddr = web3.utils.toChecksumAddress('0x1a2f3b98e434c02363f3dac3174af93c1d690914');
25+
EmbarkJS.Names.registerSubDomain('subdomain', registerAddr, async (err) => {
26+
try {
27+
assert.strictEqual(err, null);
2628

27-
const rootName = await EmbarkJS.Names.lookup(rootAddress);
28-
assert.strictEqual(rootName, 'test.eth');
29+
const rootAddress = await EmbarkJS.Names.resolve('test.eth');
30+
assert.strictEqual(rootAddress, web3.eth.defaultAccount);
31+
32+
const rootName = await EmbarkJS.Names.lookup(rootAddress);
33+
assert.strictEqual(rootName, 'test.eth');
34+
35+
const subRegisterAddr = await EmbarkJS.Names.resolve('subdomain.test.eth');
36+
assert.strictEqual(subRegisterAddr, registerAddr);
37+
38+
done();
39+
} catch (e) {
40+
done(e);
41+
}
42+
});
2943
});
3044

3145
it('should have access to Storage functions', async function() {
@@ -35,7 +49,11 @@ describe("EmbarkJS functions", function() {
3549
});
3650

3751
it('should have access to Blockchain functions', async function() {
38-
const contract = new EmbarkJS.Blockchain.Contract({abi: SimpleStorage.options.jsonInterface, address: SimpleStorage.options.address, web3: web3});
52+
const contract = new EmbarkJS.Blockchain.Contract({
53+
abi: SimpleStorage.options.jsonInterface,
54+
address: SimpleStorage.options.address,
55+
web3: web3
56+
});
3957
const result = await contract.methods.get().call();
4058
assert.strictEqual(parseInt(result, 10), 100);
4159
});

packages/embarkjs/ens/src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ __embarkENS.web3 = new Web3();
207207
__embarkENS.setProvider = function(config) {
208208
const ERROR_MESSAGE = 'ENS is not available in this chain';
209209
this.registration = config.registration;
210-
this.env = config.env;
211210
this.ready = false;
212211
this.dappAutoEnable = config.dappAutoEnable;
213212

@@ -231,6 +230,7 @@ __embarkENS.setProvider = function(config) {
231230
const accounts = await this.web3.eth.getAccounts();
232231
this.web3.eth.defaultAccount = accounts[0];
233232
const id = await this.web3.eth.net.getId();
233+
this.isKnownNetwork = !!this.registryAddresses[id];
234234
const registryAddress = this.registryAddresses[id] || config.registryAddress;
235235
this._isAvailable = true;
236236
this.ens = new this.web3.eth.Contract(config.registryAbi, registryAddress);
@@ -345,7 +345,7 @@ __embarkENS.registerSubDomain = function (name, address, callback) {
345345
return callback(defaultAccountNotSetError);
346346
}
347347

348-
if (this.env !== 'development' && this.env !== 'privatenet') {
348+
if (this.isKnownNetwork) {
349349
return callback('Sub-domain registration is only available in development or privatenet mode');
350350
}
351351
if (!this.registration || !this.registration.rootDomain) {

0 commit comments

Comments
 (0)