-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from ensdomains/upgrade/truffle
upgrade/truffle
- Loading branch information
Showing
5 changed files
with
143 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.