Skip to content

Commit

Permalink
fix(@embark/ens): fix registerSubDomain in tests and add test
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
jrainville authored and iurimatias committed Jan 29, 2020
1 parent 3f58376 commit 3ceac53
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
30 changes: 24 additions & 6 deletions dapps/tests/app/test/embarkJS_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,26 @@ config({
});

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

const rootName = await EmbarkJS.Names.lookup(rootAddress);
assert.strictEqual(rootName, 'test.eth');
const rootAddress = await EmbarkJS.Names.resolve('test.eth');
assert.strictEqual(rootAddress, web3.eth.defaultAccount);

const rootName = await EmbarkJS.Names.lookup(rootAddress);
assert.strictEqual(rootName, 'test.eth');

const subRegisterAddr = await EmbarkJS.Names.resolve('subdomain.test.eth');
assert.strictEqual(subRegisterAddr, registerAddr);

done();
} catch (e) {
done(e);
}
});
});

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

it('should have access to Blockchain functions', async function() {
const contract = new EmbarkJS.Blockchain.Contract({abi: SimpleStorage.options.jsonInterface, address: SimpleStorage.options.address, web3: web3});
const contract = new EmbarkJS.Blockchain.Contract({
abi: SimpleStorage.options.jsonInterface,
address: SimpleStorage.options.address,
web3: web3
});
const result = await contract.methods.get().call();
assert.strictEqual(parseInt(result, 10), 100);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/embarkjs/ens/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ __embarkENS.web3 = new Web3();
__embarkENS.setProvider = function(config) {
const ERROR_MESSAGE = 'ENS is not available in this chain';
this.registration = config.registration;
this.env = config.env;
this.ready = false;
this.dappAutoEnable = config.dappAutoEnable;

Expand All @@ -231,6 +230,7 @@ __embarkENS.setProvider = function(config) {
const accounts = await this.web3.eth.getAccounts();
this.web3.eth.defaultAccount = accounts[0];
const id = await this.web3.eth.net.getId();
this.isKnownNetwork = !!this.registryAddresses[id];
const registryAddress = this.registryAddresses[id] || config.registryAddress;
this._isAvailable = true;
this.ens = new this.web3.eth.Contract(config.registryAbi, registryAddress);
Expand Down Expand Up @@ -345,7 +345,7 @@ __embarkENS.registerSubDomain = function (name, address, callback) {
return callback(defaultAccountNotSetError);
}

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

0 comments on commit 3ceac53

Please sign in to comment.