Skip to content

Commit

Permalink
Merge pull request #21 from ensdomains/upgrade/truffle
Browse files Browse the repository at this point in the history
upgrade/truffle
  • Loading branch information
Dean Eigenmann authored Feb 21, 2019
2 parents d84eb2f + ca2f155 commit f08ebad
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 145 deletions.
5 changes: 3 additions & 2 deletions migrations/2_deploy_contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ module.exports = function(deployer, network) {
return;
}

await deployer.deploy([[ENSRegistry], [DummyDNSSEC]]);
await deployer.deploy(ENSRegistry);
await deployer.deploy(DummyDNSSEC);

const ens = await ENSRegistry.deployed();
const dnssec = await DummyDNSSEC.deployed();

await deployer.deploy(DNSRegistrar, dnssec.address, ens.address);
const registrar = await DNSRegistrar.deployed();

await ens.setSubnodeOwner(0, "0x" + sha3(tld), registrar.address);
await ens.setSubnodeOwner("0x0", "0x" + sha3(tld), registrar.address);
});
};
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions test/Helpers/Utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const packet = require('dns-packet');

function isException(error) {
let strError = error.toString();
return strError.includes('invalid opcode') || strError.includes('invalid JUMP') || strError.includes('revert');
}

function ensureException(error) {
assert(isException(error), error.toString());
}

function hexEncodeName(name){
return '0x' + packet.name.encode(name).toString('hex');
}

function hexEncodeTXT(keys){
return '0x' + packet.answer.encode(keys).toString('hex');
}

module.exports = {
zeroAddress: '0x0000000000000000000000000000000000000000',
ensureException: ensureException,
hexEncodeTXT: hexEncodeTXT,
hexEncodeName: hexEncodeName
};
112 changes: 112 additions & 0 deletions test/TestDNSRegistrar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
const ENSRegistry = artifacts.require('./ENSRegistry.sol');
const DummyDNSSEC = artifacts.require('./DummyDNSSEC.sol');
const DNSRegistrarContract = artifacts.require('./DNSRegistrar.sol');
const namehash = require('eth-ens-namehash');
const sha3 = require('js-sha3').keccak_256;
const utils = require('./Helpers/Utils')

contract('DNSRegistrar', function(accounts) {
var registrar = null;
var ens = null;
var dnssec = null;
var tld = 'test';
var now = Math.round(new Date().getTime() / 1000);

beforeEach(async function() {
ens = await ENSRegistry.new();
dnssec = await DummyDNSSEC.new();
registrar = await DNSRegistrarContract.new(
dnssec.address,
ens.address
);

await ens.setSubnodeOwner('0x0', '0x' + sha3(tld), registrar.address);
});

it('allows the owner of a DNS name to claim it in ENS', async function() {
assert.equal(await registrar.oracle(), dnssec.address);
assert.equal(await registrar.ens(), ens.address);

var proof = utils.hexEncodeTXT({
name: '_ens.foo.test',
type: 'TXT',
class: 'IN',
ttl: 3600,
data: ['a=' + accounts[0]]
});

await dnssec.setData(
16,
utils.hexEncodeName('_ens.foo.test'),
now,
now,
proof
);

await registrar.claim(utils.hexEncodeName('foo.test'), proof);

assert.equal(await ens.owner(namehash.hash('foo.test')), accounts[0]);
});

it('allows anyone to zero out an obsolete name', async function() {
await dnssec.setData(
16,
utils.hexEncodeName('_ens.foo.test'),
now,
now,
'0x'
);

await registrar.claim(utils.hexEncodeName('foo.test'), '0x');

assert.equal(await ens.owner(namehash.hash('foo.test')), 0);
});

it('allows anyone to update a DNSSEC referenced name', async function() {
var proof = utils.hexEncodeTXT({
name: '_ens.foo.test',
type: 'TXT',
class: 'IN',
ttl: 3600,
data: ['a=' + accounts[1]]
});

await dnssec.setData(
16,
utils.hexEncodeName('_ens.foo.test'),
now,
now,
proof
);

await registrar.claim(utils.hexEncodeName('foo.test'), proof);
assert.equal(
await ens.owner(namehash.hash('foo.test')),
accounts[1]
);
});

it('does not allow updates with stale records', async function() {
var proof = utils.hexEncodeTXT({
name: '_ens.bar.test',
type: 'TXT',
class: 'IN',
ttl: 3600,
data: ['a=' + accounts[0]]
});

await dnssec.setData(
16,
utils.hexEncodeName('_ens.foo.test'),
0,
0,
proof
);

try {
await registrar.claim(utils.hexEncodeName('bar.test'), proof);
} catch (error) {
return utils.ensureException(error);
}
});
});
140 changes: 0 additions & 140 deletions test/dnsregistrar.js

This file was deleted.

0 comments on commit f08ebad

Please sign in to comment.