2018-05-14 02:34:31 +00:00
|
|
|
const utils = require('../utils/testUtils.js');
|
2018-09-05 06:52:30 +00:00
|
|
|
const ENSRegistry = require('Embark/contracts/ENSRegistry');
|
2018-05-14 02:34:31 +00:00
|
|
|
const web3Utils = require('web3-utils');
|
|
|
|
const namehash = require('eth-ens-namehash');
|
2018-05-15 18:50:01 +00:00
|
|
|
|
2018-09-05 06:52:30 +00:00
|
|
|
config({
|
|
|
|
contracts: {
|
|
|
|
"ENSRegistry": { },
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-05-14 02:34:31 +00:00
|
|
|
contract('ENS', function () {
|
2018-05-16 22:14:39 +00:00
|
|
|
this.timeout(0);
|
2018-05-14 02:34:31 +00:00
|
|
|
let accountsArr;
|
|
|
|
|
|
|
|
before(function(done) {
|
2018-09-05 06:52:30 +00:00
|
|
|
web3.eth.getAccounts().then(function (res) {
|
|
|
|
accountsArr = res;
|
|
|
|
done();
|
2018-05-14 02:34:31 +00:00
|
|
|
});
|
2018-09-05 06:52:30 +00:00
|
|
|
});
|
2018-05-14 02:34:31 +00:00
|
|
|
|
|
|
|
it('should allow ownership transfers', async () => {
|
2018-09-05 06:52:30 +00:00
|
|
|
let result = await ENSRegistry.methods.setOwner(utils.zeroBytes32, accountsArr[1]).send({from: accountsArr[0]});
|
|
|
|
assert.equal(await ENSRegistry.methods.owner(utils.zeroBytes32).call(), accountsArr[1])
|
2018-05-14 20:58:42 +00:00
|
|
|
assert.equal(result.events.Transfer.returnValues.node, utils.zeroBytes32);
|
2018-05-14 02:34:31 +00:00
|
|
|
assert.equal(result.events.Transfer.returnValues.owner, accountsArr[1]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should prohibit transfers by non-owners', async () => {
|
|
|
|
try {
|
2018-09-05 06:52:30 +00:00
|
|
|
await ENSRegistry.methods.setOwner(utils.zeroBytes32, accountsArr[2]).send({from: accountsArr[0]});
|
2018-05-14 02:34:31 +00:00
|
|
|
} catch (error) {
|
|
|
|
return utils.ensureException(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.fail('transfer did not fail');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow setting resolvers', async () => {
|
2018-09-05 06:52:30 +00:00
|
|
|
let result = await ENSRegistry.methods.setResolver(utils.zeroBytes32, accountsArr[3]).send({from: accountsArr[1]});
|
2018-05-14 02:34:31 +00:00
|
|
|
let args = result.events.NewResolver.returnValues;
|
2018-05-14 20:58:42 +00:00
|
|
|
assert.equal(args.node, utils.zeroBytes32);
|
2018-05-14 02:34:31 +00:00
|
|
|
assert.equal(args.resolver, accountsArr[3]);
|
2018-09-05 06:52:30 +00:00
|
|
|
assert.equal(await ENSRegistry.methods.resolver(utils.zeroBytes32).call(), accountsArr[3]);
|
2018-05-14 02:34:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should prevent setting resolvers by non-owners', async () => {
|
|
|
|
try {
|
2018-09-05 06:52:30 +00:00
|
|
|
await ENSRegistry.methods.setResolver(utils.zeroBytes32, accountsArr[4]).send({from: accountsArr[0]});
|
2018-05-14 02:34:31 +00:00
|
|
|
} catch (error) {
|
|
|
|
return utils.ensureException(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.fail('setting resolver did not fail');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow setting the TTL', async () => {
|
2018-09-05 06:52:30 +00:00
|
|
|
let result = await ENSRegistry.methods.setTTL(utils.zeroBytes32, 3600).send({from: accountsArr[1]});
|
|
|
|
assert.equal(await ENSRegistry.methods.ttl(utils.zeroBytes32).call(), 3600);
|
2018-05-14 02:34:31 +00:00
|
|
|
let args = result.events.NewTTL.returnValues;
|
2018-05-14 20:58:42 +00:00
|
|
|
assert.equal(args.node, utils.zeroBytes32);
|
2018-05-14 02:34:31 +00:00
|
|
|
assert.equal(args.ttl, 3600);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should prevent setting the TTL by non-owners', async () => {
|
|
|
|
try {
|
2018-09-05 06:52:30 +00:00
|
|
|
await ENSRegistry.methods.setTTL(utils.zeroBytes32, 1200).send({from: accountsArr[0]});
|
2018-05-14 02:34:31 +00:00
|
|
|
} catch (error) {
|
|
|
|
return utils.ensureException(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.fail('setting resolver did not fail');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow the creation of subnodes', async () => {
|
2018-09-05 06:52:30 +00:00
|
|
|
let result = await ENSRegistry.methods.setSubnodeOwner(utils.zeroBytes32, web3Utils.sha3('eth'), accountsArr[2]).send({from: accountsArr[1]});
|
|
|
|
assert.equal(await ENSRegistry.methods.owner(namehash.hash('eth')).call(), accountsArr[2]);
|
2018-05-14 02:34:31 +00:00
|
|
|
let args = result.events.NewOwner.returnValues;
|
2018-05-14 20:58:42 +00:00
|
|
|
assert.equal(args.node, utils.zeroBytes32);
|
2018-05-14 02:34:31 +00:00
|
|
|
assert.equal(args.label, web3Utils.sha3('eth'));
|
|
|
|
assert.equal(args.owner, accountsArr[2]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should prohibit subnode creation by non-owners', async () => {
|
|
|
|
try {
|
2018-09-05 06:52:30 +00:00
|
|
|
await ENSRegistry.methods.setSubnodeOwner(utils.zeroBytes32, web3Utils.sha3('eth'), accountsArr[3]).send({from: accountsArr[0]});
|
2018-05-14 02:34:31 +00:00
|
|
|
} catch (error) {
|
|
|
|
return utils.ensureException(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.fail('setting resolver did not fail');
|
|
|
|
});
|
|
|
|
});
|