new test script for ENS Subdomain Registry

This commit is contained in:
Ricardo Guilherme Schmidt 2018-08-30 08:22:22 -03:00 committed by Barry G
parent adfde1c0e0
commit c35a987d84
2 changed files with 590 additions and 579 deletions

View File

@ -1,579 +0,0 @@
const utils = require('../utils/testUtils.js');
const web3Utils = require('web3-utils');
const namehash = require('eth-ens-namehash');
const TestToken = require('Embark/contracts/TestToken');
const ENSRegistry = require('Embark/contracts/ENSRegistry');
const PublicResolver = require('Embark/contracts/PublicResolver');
const ENSSubdomainRegistry = require('Embark/contracts/ENSSubdomainRegistry');
const { MerkleTree } = require('../utils/merkleTree.js');
/**
*
* Unicode decimal ranges unallowed:
* 0-47 (C0 + ASCII Punctuation & Symbols)
* 58-96 (ASCII Punctuation & Symbols + Latin Alphabet: Uppercase)
* 123-1023 (ASCII Punctuation & Symbols + C1 + Latin-1 Punctuation & Symbols, (...))
* 1023-115792089237316195423570985008687907853269984665640564039457584007913129639935 (Everything else)
* Unicode decimal ranges allowed:
* 48-57 (ASCII Digits; 0-9)
* 97-122 (Latin Alphabet: Lowercase; a-z)
*/
const reservedNames = [
'administrator',
'support',
'status',
'network',
]
const merkleTree = new MerkleTree(reservedNames);
const merkleRoot = merkleTree.getHexRoot();
var contractsConfig = {
"TestToken": {
},
"ENSRegistry": {
"onDeploy": [
"ENSRegistry.methods.setSubnodeOwner('0x0000000000000000000000000000000000000000000000000000000000000000', '0x4f5b812789fc606be1b3b16908db13fc7a9adf7ca72641f84d75b47069d3d7f0', web3.eth.defaultAccount).send()"
]
},
"PublicResolver": {
"args": [
"$ENSRegistry"
]
},
"ENSSubdomainRegistry": {
"args": [
"$TestToken",
"$ENSRegistry",
"$PublicResolver",
"3",
[merkleRoot],
"0x0"
],
"onDeploy": [
"ENSRegistry.methods.setSubnodeOwner('0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae', '0xbd99f8d5e7f81d2d7c1da34b67a2bb3a94dd8c9b0ab40ddc077621b98405983b', ENSSubdomainRegistry.address).send()",
"ENSRegistry.methods.setSubnodeOwner('0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae', '0x7b4768a525e733422bf968587a91b4036e5176d36f44a9fb5b29d0bca03ab3a3', ENSSubdomainRegistry.address).send()"
]
},
"UpdatedENSSubdomainRegistry": {
"instanceOf" : "ENSSubdomainRegistry",
"args": [
"$TestToken",
"$ENSRegistry",
"$PublicResolver",
"3",
[merkleRoot],
"$ENSSubdomainRegistry"
]
}
};
config({ contracts: contractsConfig });
contract('ENSSubdomainRegistry', function () {
//this.timeout(0);
let domains = {
free : {
name: 'freedomain.eth',
price: 0,
namehash: namehash.hash('freedomain.eth')
},
paid : {
name: 'stateofus.eth',
price: 100000000,
namehash: namehash.hash('stateofus.eth')
}
}
let ens;
let accountsArr;
before(function(done) {
web3.eth.getAccounts().then(async (accounts) => {
ens = ENSRegistry;
accountsArr = accounts;
await utils.increaseTime(1 * utils.timeUnits.days) //time cannot start zero
done();
})
});
it('should add free domain', async () => {
let result = await ENSSubdomainRegistry.methods.setDomainPrice(domains.free.namehash, 0).send({from: accountsArr[0]});
assert.equal(result.events.DomainPrice.returnValues.price, domains.free.price);
assert.equal(result.events.DomainPrice.returnValues.namehash, domains.free.namehash);
result = await ENSSubdomainRegistry.methods.getPrice(domains.free.namehash).call()
assert.equal(result, 0);
result = await ENSSubdomainRegistry.methods.domains(domains.free.namehash).call()
assert(result.state, 1)
assert(result.price, domains.free.price)
});
it('should add paid domain', async () => {
let initialPrice = 100
let result = await ENSSubdomainRegistry.methods.setDomainPrice(domains.paid.namehash, initialPrice).send({from: accountsArr[0]});
assert.equal(result.events.DomainPrice.returnValues.price, initialPrice);
assert.equal(result.events.DomainPrice.returnValues.namehash, domains.paid.namehash);
result = await ENSSubdomainRegistry.methods.getPrice(domains.paid.namehash).call()
assert.equal(result, initialPrice);
result = await ENSSubdomainRegistry.methods.domains(domains.free.namehash).call()
assert(result.state, 1)
assert(result.price, domains.paid.price)
});
it('should change paid domain price', async () => {
let newPrice = domains.paid.price;
let result = await ENSSubdomainRegistry.methods.updateDomainPrice(domains.paid.namehash, newPrice).send({from: accountsArr[0]});
assert.equal(result.events.DomainPrice.returnValues.price, newPrice, "Wrong price at event");
assert.equal(result.events.DomainPrice.returnValues.namehash, domains.paid.namehash, "Wrong namehash at event");
result = await ENSSubdomainRegistry.methods.getPrice(domains.paid.namehash).call()
assert.equal(result, newPrice, "Wrong return value at getPrice");
result = await ENSSubdomainRegistry.methods.domains(domains.paid.namehash).call()
assert(result.state, 1)
assert(result.price, newPrice)
});
it('should register free subdomain', async () => {
let subdomain = 'alice';
let usernameHash = namehash.hash(subdomain + '.' + domains.free.name);
let registrant = accountsArr[1];
let result = await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
domains.free.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
//TODO: check events
result = await ens.methods.owner(usernameHash).call()
assert.equal(result, registrant);
result = await ens.methods.resolver(usernameHash).call()
assert.equal(result, utils.zeroAddress);
let accountBalance = await ENSSubdomainRegistry.methods.getAccountBalance(usernameHash).call();
assert(accountBalance, 0, "Registry subdomain account balance wrong");
result = await ENSSubdomainRegistry.methods.getFundsOwner(usernameHash).call();
assert(result, registrant, "Backup owner not set");
});
it('should register free address only resolver-defined subdomain', async () => {
let registrant = accountsArr[2];
let subdomain = 'bob';
let usernameHash = namehash.hash(subdomain + '.' + domains.free.name);
let result = await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
domains.free.namehash,
registrant,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
//TODO: check events
result = await ens.methods.owner(usernameHash).call()
assert.equal(result, registrant, "Owner not set");
result = await ens.methods.resolver(usernameHash).call()
assert.equal(result, PublicResolver.address, "PublicResolver not set");
result = await PublicResolver.methods.addr(usernameHash).call()
assert.equal(result, registrant, "Resolved address not set");
result = await PublicResolver.methods.pubkey(usernameHash).call()
assert.equal(result[0], utils.zeroBytes32, "Unexpected resolved pubkey[0]");
assert.equal(result[1], utils.zeroBytes32, "Unexpected resolved pubkey[1]");
});
it('should register free status contact code only resolver-defined subdomain', async () => {
let registrant = accountsArr[2];
let subdomain = 'bob2';
let usernameHash = namehash.hash(subdomain + '.' + domains.free.name);
let contactCode = '0x04dbb31252d9bddb4e4d362c7b9c80cba74732280737af97971f42ccbdc716f3f3efb1db366880e52d09b1bfd59842e833f3004088892b7d14b9ce9e957cea9a82';
let points = utils.generateXY(contactCode);
let result = await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
domains.free.namehash,
registrant,
points.x,
points.y
).send({from: registrant});
result = await ens.methods.owner(usernameHash).call()
assert.equal(result, registrant, "Owner not set");
result = await ens.methods.resolver(usernameHash).call()
assert.equal(result, PublicResolver.address, "PublicResolver not set");
result = await PublicResolver.methods.pubkey(usernameHash).call();
let pubKey = utils.keyFromXY(result[0], result[1]);
assert.equal(pubKey, contactCode, "pubKey does not match contract code");
});
it('should register free pubkey only resolver-defined subdomain', async () => {
let subdomain = 'carlos';
let registrant = accountsArr[3];
let usernameHash = namehash.hash(subdomain + '.' + domains.free.name);
let pubkey = [web3Utils.sha3("0"), web3Utils.sha3("1")];
let result = await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
domains.free.namehash,
utils.zeroAddress,
pubkey[0],
pubkey[1]
).send({from: registrant});
//TODO: check events
result = await ens.methods.owner(usernameHash).call()
assert.equal(result, registrant, "Owner not set");
result = await ens.methods.resolver(usernameHash).call()
assert.equal(result, PublicResolver.address, "PublicResolver not set");
result = await PublicResolver.methods.addr(usernameHash).call()
assert.equal(result, utils.zeroAddress, "Resolved address unexpectedlly set");
result = await PublicResolver.methods.pubkey(usernameHash).call()
assert.equal(result[0], pubkey[0], "Resolved pubkey[0] not set");
assert.equal(result[1], pubkey[1], "Resolved pubkey[1] not set");
});
it('should register free full resolver-defined subdomain', async () => {
let registrant = accountsArr[4];
let subdomain = 'david';
let usernameHash = namehash.hash(subdomain + '.' + domains.free.name);
let pubkey = [web3Utils.sha3("2"), web3Utils.sha3("3")];
let result = await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
domains.free.namehash,
registrant,
pubkey[0],
pubkey[1]
).send({from: registrant});
//TODO: check events
result = await ens.methods.owner(usernameHash).call()
assert.equal(result, registrant, "Owner not set");
result = await ens.methods.resolver(usernameHash).call()
assert.equal(result, PublicResolver.address, "PublicResolver not set");
result = await PublicResolver.methods.addr(usernameHash).call()
assert.equal(result, registrant, "Resolved address not set");
result = await PublicResolver.methods.pubkey(usernameHash).call()
assert.equal(result[0], pubkey[0], "Resolved pubkey[0] not set");
assert.equal(result[1], pubkey[1], "Resolved pubkey[1] not set");
});
it('should release free subdomain', async () => {
let registrant = accountsArr[6];
let subdomain = 'frank';
let usernameHash = namehash.hash(subdomain + '.' + domains.free.name);
await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
domains.free.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
let releaseDelay = await ENSSubdomainRegistry.methods.releaseDelay().call();
await utils.increaseTime(releaseDelay)
let initialRegistrantBalance = await TestToken.methods.balanceOf(registrant).call();
let initialRegistryBalance = await TestToken.methods.balanceOf(ENSSubdomainRegistry.address).call();
let result = await ENSSubdomainRegistry.methods.release(
web3Utils.sha3(subdomain),
domains.free.namehash
).send({from: registrant});
//TODO: check events
result = await ens.methods.owner(usernameHash).call()
assert.equal(result, utils.zeroAddress, "Not released name ownship");
let finalRegistrantBalance = await TestToken.methods.balanceOf(registrant).call();
assert(finalRegistrantBalance, initialRegistrantBalance, "Registrant token balance unexpectectly changed")
let finalRegistryBalance = await TestToken.methods.balanceOf(ENSSubdomainRegistry.address).call();
assert(finalRegistryBalance, initialRegistryBalance, "Registry token balance unexpectectly changed")
});
it('should register empty subdomain with token cost', async () => {
let registrant = accountsArr[5];
let subdomain = 'erin';
let usernameHash = namehash.hash(subdomain + '.' + domains.paid.name);
let domainPrice = await ENSSubdomainRegistry.methods.getPrice(domains.paid.namehash).call()
await TestToken.methods.mint(domainPrice).send({from: registrant});
let initialRegistrantBalance = await TestToken.methods.balanceOf(registrant).call();
let initialRegistryBalance = await TestToken.methods.balanceOf(ENSSubdomainRegistry.address).call();
await TestToken.methods.approve(ENSSubdomainRegistry.address, domainPrice).send({from: registrant});
let result = await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
domains.paid.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
//TODO: check events
result = await ens.methods.owner(namehash.hash(subdomain + '.' + domains.paid.name)).call()
assert.equal(result, registrant);
result = await ens.methods.resolver(namehash.hash(subdomain + '.' + domains.paid.name)).call()
assert.equal(result, utils.zeroAddress);
let accountBalance = await ENSSubdomainRegistry.methods.getAccountBalance(usernameHash).call();
assert(accountBalance, domainPrice, "Registry subdomain account balance wrong");
let finalRegistrantBalance = await TestToken.methods.balanceOf(registrant).call();
assert(finalRegistrantBalance, +initialRegistrantBalance-domainPrice, "User final balance wrong")
let finalRegistryBalance = await TestToken.methods.balanceOf(ENSSubdomainRegistry.address).call();
assert(finalRegistryBalance, +finalRegistryBalance+domainPrice, "Registry final balance wrong")
});
it('should release subdomain with cost', async () => {;
let registrant = accountsArr[6];
let subdomain = 'frank';
let usernameHash = namehash.hash(subdomain + '.' + domains.paid.name);
let labelHash = web3Utils.sha3(subdomain);
let domainPrice = await ENSSubdomainRegistry.methods.getPrice(domains.paid.namehash).call()
await TestToken.methods.mint(domainPrice).send({from: registrant});
await TestToken.methods.approve(ENSSubdomainRegistry.address, domainPrice).send({from: registrant});
let result = await ENSSubdomainRegistry.methods.register(
labelHash,
domains.paid.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
//TODO: check events
let releaseDelay = await ENSSubdomainRegistry.methods.releaseDelay().call();
utils.increaseTime(releaseDelay)
let initialAccountBalance = await ENSSubdomainRegistry.methods.getAccountBalance(usernameHash).call();
let initialRegistrantBalance = await TestToken.methods.balanceOf(registrant).call();
let initialRegistryBalance = await TestToken.methods.balanceOf(ENSSubdomainRegistry.address).call();
await ENSSubdomainRegistry.methods.release(
web3Utils.sha3(subdomain),
domains.paid.namehash
).send({from: registrant});
let finalAccountBalance = await ENSSubdomainRegistry.methods.getAccountBalance(usernameHash).call();
assert(finalAccountBalance, 0, "Final balance didnt zeroed");
let finalRegistrantBalance = await TestToken.methods.balanceOf(registrant).call();
assert(finalRegistrantBalance, +initialRegistrantBalance+initialAccountBalance, "Releaser token balance didnt increase")
let finalRegistryBalance = await TestToken.methods.balanceOf(ENSSubdomainRegistry.address).call();
assert(finalRegistryBalance, +initialRegistryBalance-initialAccountBalance, "Registry token balance didnt decrease")
});
it('should release transfered subdomain with cost', async () => {
let registrant = accountsArr[7];
let subdomain = 'grace';
let usernameHash = namehash.hash(subdomain + '.' + domains.paid.name);
let labelHash = web3Utils.sha3(subdomain);
let newOwner = accountsArr[8];
let domainPrice = await ENSSubdomainRegistry.methods.getPrice(domains.paid.namehash).call()
await TestToken.methods.mint(domainPrice).send({from: registrant});
await TestToken.methods.approve(ENSSubdomainRegistry.address, domainPrice).send({from: registrant});
await ENSSubdomainRegistry.methods.register(
labelHash,
domains.paid.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
await ens.methods.setOwner(usernameHash, newOwner).send({from: registrant});
let releaseDelay = await ENSSubdomainRegistry.methods.releaseDelay().call();
await utils.increaseTime(releaseDelay)
let initialAccountBalance = await ENSSubdomainRegistry.methods.getAccountBalance(usernameHash).call();
let initialRegistrantBalance = await TestToken.methods.balanceOf(newOwner).call();
let initialRegistryBalance = await TestToken.methods.balanceOf(ENSSubdomainRegistry.address).call();
let result = await ENSSubdomainRegistry.methods.release(
web3Utils.sha3(subdomain),
domains.paid.namehash
).send({from: newOwner});
//TODO: check events
let finalAccountBalance = await ENSSubdomainRegistry.methods.getAccountBalance(usernameHash).call();
assert(finalAccountBalance, 0, "Final balance didnt zeroed");
let finalRegistrantBalance = await TestToken.methods.balanceOf(newOwner).call();
assert(finalRegistrantBalance, +initialRegistrantBalance+initialAccountBalance, "New owner token balance didnt increase")
let finalRegistryBalance = await TestToken.methods.balanceOf(ENSSubdomainRegistry.address).call();
assert(finalRegistryBalance, +initialRegistryBalance-initialAccountBalance, "Registry token balance didnt decrease")
});
it('should update subdomain funds owner', async () => {
let subdomain = 'heidi';
let labelHash = web3Utils.sha3(subdomain);
let registrant = accountsArr[8];
let newOwner = accountsArr[9];
let usernameHash = namehash.hash(subdomain + '.' + domains.paid.name);
let domainPrice = await ENSSubdomainRegistry.methods.getPrice(domains.paid.namehash).call()
await TestToken.methods.mint(domainPrice).send({from: registrant});
await TestToken.methods.approve(ENSSubdomainRegistry.address, domainPrice).send({from: registrant});
await ENSSubdomainRegistry.methods.register(
labelHash,
domains.paid.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
await ens.methods.setOwner(usernameHash, newOwner).send({from: registrant});
let result = await ENSSubdomainRegistry.methods.updateFundsOwner(
labelHash,
domains.paid.namehash
).send({from: newOwner});
//TODO: check events
result = await ENSSubdomainRegistry.methods.getFundsOwner(usernameHash).call();
assert(result, newOwner, "Backup owner not updated");
});
it('should move domain to new registry and migrate', async () => {
let price = await ENSSubdomainRegistry.methods.getPrice(domains.paid.namehash).call()
let result = await ENSSubdomainRegistry.methods.moveDomain(UpdatedENSSubdomainRegistry.address, domains.paid.namehash).send();
//TODO: check events
result = await ens.methods.owner(domains.paid.namehash).call()
assert(result, UpdatedENSSubdomainRegistry.address, "domain ownership not moved correctly")
result = await UpdatedENSSubdomainRegistry.methods.getPrice(domains.paid.namehash).call()
assert(result, price, "updated registry didnt migrated price")
});
xit('should release moved free subdomain account balance by funds owner', async () => {
});
xit('should migrate free subdomain to new registry by funds owner', async () => {
});
xit('should release moved paid subdomain account balance by funds owner', async () => {
});
xit('should migrate paid subdomain to new registry by funds owner', async () => {
});
it('should slash invalid free subdomain', async () => {
let subdomain = 'alicé';
let usernameHash = namehash.hash(subdomain + '.' + domains.free.name);
let registrant = accountsArr[1];
let result = await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
domains.free.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
//TODO: check events
result = await ens.methods.owner(usernameHash).call()
assert.equal(result, registrant);
let accountCreationTime = await ENSSubdomainRegistry.methods.getCreationTime(usernameHash).call();
assert(accountCreationTime > 0);
result = await ENSSubdomainRegistry.methods.slashInvalidSubdomain(web3Utils.toHex(subdomain), domains.free.namehash, 4).send()
accountCreationTime = await ENSSubdomainRegistry.methods.getCreationTime(usernameHash).call();
assert(accountCreationTime == 0);
result = await ens.methods.owner(usernameHash).call()
assert.equal(result, utils.zeroAddress);
});
it('should slash reserved name subdomain', async () => {
let subdomain = reservedNames[0];
let usernameHash = namehash.hash(subdomain + '.' + domains.free.name);
let registrant = accountsArr[1];
let result = await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
domains.free.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
//TODO: check events
let accountCreationTime = await ENSSubdomainRegistry.methods.getCreationTime(usernameHash).call();
assert(accountCreationTime > 0);
const proof = merkleTree.getHexProof(reservedNames[0]);
result = await ENSSubdomainRegistry.methods.slashReservedSubdomain(web3Utils.toHex(subdomain), domains.free.namehash, 0, proof).send()
accountCreationTime = await ENSSubdomainRegistry.methods.getCreationTime(usernameHash).call();
assert(accountCreationTime == 0);
});
it('should slash small subdomain', async () => {
let subdomain = 'a';
let usernameHash = namehash.hash(subdomain + '.' + domains.free.name);
let registrant = accountsArr[1];
let result = await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
domains.free.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
let accountCreationTime = await ENSSubdomainRegistry.methods.getCreationTime(usernameHash).call();
assert(accountCreationTime > 0);
result = await ENSSubdomainRegistry.methods.slashSmallSubdomain(web3Utils.toHex(subdomain), domains.free.namehash).send()
accountCreationTime = await ENSSubdomainRegistry.methods.getCreationTime(usernameHash).call();
assert(accountCreationTime == 0);
});
xit('should slash address like subdomain', async () => {
let subdomain = "0xc6b95bd26";
let usernameHash = web3Utils.soliditySha3(namehash.hash(domains.free.name), web3Utils.sha3(subdomain));
let registrant = accountsArr[1];
let result = await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
domains.free.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
let accountCreationTime = await ENSSubdomainRegistry.methods.getCreationTime(usernameHash).call();
assert(accountCreationTime > 0);
result = await ENSSubdomainRegistry.methods.slashAddressLikeSubdomain(subdomain, domains.free.namehash).send()
accountCreationTime = await ENSSubdomainRegistry.methods.getCreationTime(usernameHash).call();
assert(accountCreationTime == 0);
});
});

View File

@ -0,0 +1,590 @@
const utils = require('../utils/testUtils.js');
const web3Utils = require('web3-utils');
const namehash = require('eth-ens-namehash');
const TestToken = require('Embark/contracts/TestToken');
const ENSRegistry = require('Embark/contracts/ENSRegistry');
const PublicResolver = require('Embark/contracts/PublicResolver');
const ENSSubdomainRegistry = require('Embark/contracts/ENSSubdomainRegistry');
const { MerkleTree } = require('../utils/merkleTree.js');
const reservedNames = [
'administrator',
'support',
'status',
'network',
]
// TODO: load file of reserved names and balance array lenght to be even
const merkleTree = new MerkleTree(reservedNames);
const merkleRoot = merkleTree.getHexRoot();
var contractsConfig = {
"TestToken": {
},
"ENSRegistry": {
"onDeploy": [
"ENSRegistry.methods.setSubnodeOwner('0x0000000000000000000000000000000000000000000000000000000000000000', '0x4f5b812789fc606be1b3b16908db13fc7a9adf7ca72641f84d75b47069d3d7f0', web3.eth.defaultAccount).send()"
]
},
"PublicResolver": {
"args": [
"$ENSRegistry"
]
},
"ENSSubdomainRegistry": {
"args": [
"$TestToken",
"$ENSRegistry",
"$PublicResolver",
"3",
[merkleRoot],
"0x0"
],
"onDeploy": [
"ENSRegistry.methods.setSubnodeOwner('0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae', '0xbd99f8d5e7f81d2d7c1da34b67a2bb3a94dd8c9b0ab40ddc077621b98405983b', ENSSubdomainRegistry.address).send()",
"ENSRegistry.methods.setSubnodeOwner('0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae', '0x7b4768a525e733422bf968587a91b4036e5176d36f44a9fb5b29d0bca03ab3a3', ENSSubdomainRegistry.address).send()"
]
},
"UpdatedENSSubdomainRegistry": {
"instanceOf" : "ENSSubdomainRegistry",
"args": [
"$TestToken",
"$ENSRegistry",
"$PublicResolver",
"3",
[merkleRoot],
"$ENSSubdomainRegistry"
]
}
};
config({ contracts: contractsConfig });
contract('ENSSubdomainRegistry', function () {
//this.timeout(0);
const domains = {
free : {
name: 'freedomain.eth',
price: 0,
namehash: namehash.hash('freedomain.eth')
},
paid : {
name: 'stateofus.eth',
price: 100000000,
namehash: namehash.hash('stateofus.eth')
}
}
let ens;
let accountsArr;
before(function(done) {
web3.eth.getAccounts().then(async (accounts) => {
ens = ENSRegistry;
accountsArr = accounts;
await utils.increaseTime(1 * utils.timeUnits.days) //time cannot start zero
await utils.increaseTime(1000)
done();
})
});
describe('setDomainPrice()', function() {
it('should add free domain', async () => {
const domain = domains.free;
const resultSetDomainPrice = await ENSSubdomainRegistry.methods.setDomainPrice(domain.namehash, domain.price).send({from: accountsArr[0]});
assert.equal(resultSetDomainPrice.events.DomainPrice.returnValues.price, domain.price, "event DomainPrice wrong price");
assert.equal(resultSetDomainPrice.events.DomainPrice.returnValues.namehash, domain.namehash, "event DomainPrice wrong namehash");
assert.equal(await ENSSubdomainRegistry.methods.getPrice(domain.namehash).call(), domain.price, "getPrice() wrong price");
const resultDomainAccount = await ENSSubdomainRegistry.methods.domains(domain.namehash).call()
assert.equal(resultDomainAccount.state, 1, "Wrong domain state")
assert.equal(resultDomainAccount.price, domain.price, "Wrong domain price")
});
it('should add paid domain', async () => {
const initialPrice = 100
const domain = domains.paid;
const resultSetDomainPrice = await ENSSubdomainRegistry.methods.setDomainPrice(domain.namehash, initialPrice).send({from: accountsArr[0]});
assert.equal(resultSetDomainPrice.events.DomainPrice.returnValues.price, initialPrice, "event DomainPrice wrong price");
assert.equal(resultSetDomainPrice.events.DomainPrice.returnValues.namehash, domain.namehash, "event DomainPrice wrong namehash");
assert.equal(await ENSSubdomainRegistry.methods.getPrice(domain.namehash).call(), initialPrice, "getPrice() wrong price");
const resultDomainAccount = await ENSSubdomainRegistry.methods.domains(domain.namehash).call()
assert.equal(resultDomainAccount.state, 1, "Wrong domain state")
assert.equal(resultDomainAccount.price, initialPrice, "Wrong domain price")
});
});
describe('updateDomainPrice()', function() {
it('should change paid domain price', async () => {
const newPrice = domains.paid.price;
const resultUpdateDomainPrice = await ENSSubdomainRegistry.methods.updateDomainPrice(domains.paid.namehash, newPrice).send({from: accountsArr[0]});
assert.equal(resultUpdateDomainPrice.events.DomainPrice.returnValues.price, domains.paid.price, "event DomainPrice wrong price");
assert.equal(resultUpdateDomainPrice.events.DomainPrice.returnValues.namehash, domains.paid.namehash, "event DomainPrice wrong namehash");
assert.equal(await ENSSubdomainRegistry.methods.getPrice(domains.paid.namehash).call(), newPrice, "Wrong return value at getPrice");
const resultDomainAccount= await ENSSubdomainRegistry.methods.domains(domains.paid.namehash).call()
assert.equal(resultDomainAccount.state, 1, "Wrong domain state")
assert.equal(resultDomainAccount.price, newPrice, "Wrong domain price")
});
});
describe('register()', function() {
it('should register free subdomain', async () => {
const subdomain = 'alice';
const subdomainHash = namehash.hash(subdomain + '.' + domains.free.name);
const registrant = accountsArr[1];
const label = web3Utils.sha3(subdomain);
const node = domains.free.namehash;
const resultRegister = await ENSSubdomainRegistry.methods.register(
label,
node,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
assert.equal(resultRegister.events['0'].raw.topics[0], '0xce0457fe73731f824cc272376169235128c118b49d344817417c6d108d155e82', "Wrong Event");
assert.equal(resultRegister.events['0'].raw.topics[1], node, "Wrong Node");
assert.equal(resultRegister.events['0'].raw.topics[2], label, "Wrong Label");
assert.equal(web3Utils.toChecksumAddress("0x"+resultRegister.events['0'].raw.data.substring(26)), registrant, "Wrong subnode owner");
assert.equal(resultRegister.events.SubdomainOwner.returnValues.accountOwner, registrant, "event SubdomainOwner accountOwner mismatch");
assert.equal(resultRegister.events.SubdomainOwner.returnValues.subdomainHash, subdomainHash, "event SubdomainOwner subdomainHash mismatch");
assert.equal(await ens.methods.owner(subdomainHash).call(), registrant, "ENSRegistry owner mismatch");
assert.equal(await ens.methods.resolver(subdomainHash).call(), utils.zeroAddress, "Resolver wrongly defined");
assert.equal(await ENSSubdomainRegistry.methods.getAccountBalance(subdomainHash).call(), 0, "Free domain accounts shouldn't have balance");
assert.equal(await ENSSubdomainRegistry.methods.getAccountOwner(subdomainHash).call(), registrant, "Account owner mismatch");
});
it('should register free address only resolver-defined subdomain', async () => {
const registrant = accountsArr[2];
const subdomain = 'bob';
const subdomainHash = namehash.hash(subdomain + '.' + domains.free.name);
const label = web3Utils.sha3(subdomain);
const node = domains.free.namehash;
const resultRegister = await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
domains.free.namehash,
registrant,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
assert.equal(resultRegister.events['0'].raw.topics[0], '0xce0457fe73731f824cc272376169235128c118b49d344817417c6d108d155e82', "Wrong Event");
assert.equal(resultRegister.events['0'].raw.topics[1], node, "Wrong Node");
assert.equal(resultRegister.events['0'].raw.topics[2], label, "Wrong Label");
assert.equal(web3Utils.toChecksumAddress("0x"+resultRegister.events['0'].raw.data.substring(26)), ENSSubdomainRegistry.address, "Wrong subnode owner");
assert.equal(resultRegister.events['1'].raw.topics[0], '0x335721b01866dc23fbee8b6b2c7b1e14d6f05c28cd35a2c934239f94095602a0', "Wrong Event");
assert.equal(resultRegister.events['1'].raw.topics[1], subdomainHash, "Wrong Subdomain");
assert.equal(web3Utils.toChecksumAddress("0x"+resultRegister.events['1'].raw.data.substring(26)), PublicResolver.address, "Wrong Resolver");
assert.equal(resultRegister.events['2'].raw.topics[0], '0x52d7d861f09ab3d26239d492e8968629f95e9e318cf0b73bfddc441522a15fd2', "Wrong Event");
assert.equal(resultRegister.events['2'].raw.topics[1], subdomainHash, "Wrong Subdomain");
assert.equal(web3Utils.toChecksumAddress("0x"+resultRegister.events['2'].raw.data.substring(26)), registrant, "Wrong address to resolve");
assert.equal(resultRegister.events['3'].raw.topics[0], '0xd4735d920b0f87494915f556dd9b54c8f309026070caea5c737245152564d266', "Wrong Event");
assert.equal(resultRegister.events['3'].raw.topics[1], subdomainHash, "Wrong Subdomain");
assert.equal(web3Utils.toChecksumAddress("0x"+resultRegister.events['3'].raw.data.substring(26)), registrant, "Wrong node owner");
assert.equal(resultRegister.events.SubdomainOwner.returnValues.accountOwner, registrant, "event SubdomainOwner accountOwner mismatch");
assert.equal(resultRegister.events.SubdomainOwner.returnValues.subdomainHash, subdomainHash, "event SubdomainOwner subdomainHash mismatch");
assert.equal(await ens.methods.owner(subdomainHash).call(), registrant, "ENSRegistry owner mismatch");
assert.equal(await ens.methods.resolver(subdomainHash).call(), PublicResolver.address, "Resolver wrongly defined");
assert.equal(await ENSSubdomainRegistry.methods.getAccountBalance(subdomainHash).call(), 0, "Free domain accounts shouldn't have balance");
assert.equal(await ENSSubdomainRegistry.methods.getAccountOwner(subdomainHash).call(), registrant, "Account owner mismatch");
assert.equal(await PublicResolver.methods.addr(subdomainHash).call(), registrant, "Resolved address not set");
const resolverPubKey = await PublicResolver.methods.pubkey(subdomainHash).call();
assert.equal(resolverPubKey[0], utils.zeroBytes32 , "Unexpected resolved pubkey[0]");
assert.equal(resolverPubKey[1], utils.zeroBytes32 , "Unexpected resolved pubkey[1]");
});
it('should register free status contact code and address resolver-defined subdomain', async () => {
const registrant = accountsArr[2];
const subdomain = 'bob2';
const subdomainHash = namehash.hash(subdomain + '.' + domains.free.name);
const contactCode = '0x04dbb31252d9bddb4e4d362c7b9c80cba74732280737af97971f42ccbdc716f3f3efb1db366880e52d09b1bfd59842e833f3004088892b7d14b9ce9e957cea9a82';
const points = utils.generateXY(contactCode);
const label = web3Utils.sha3(subdomain);
const node = domains.free.namehash;
const resultRegister = await ENSSubdomainRegistry.methods.register(
label,
node,
registrant,
points.x,
points.y
).send({from: registrant});
assert.equal(resultRegister.events['0'].raw.topics[0], '0xce0457fe73731f824cc272376169235128c118b49d344817417c6d108d155e82', "Wrong Event");
assert.equal(resultRegister.events['0'].raw.topics[1], node, "Wrong Node");
assert.equal(resultRegister.events['0'].raw.topics[2], label, "Wrong Label");
assert.equal(web3Utils.toChecksumAddress("0x"+resultRegister.events['0'].raw.data.substring(26)), ENSSubdomainRegistry.address, "Wrong subnode owner");
assert.equal(resultRegister.events['1'].raw.topics[0], '0x335721b01866dc23fbee8b6b2c7b1e14d6f05c28cd35a2c934239f94095602a0', "Wrong Event");
assert.equal(resultRegister.events['1'].raw.topics[1], subdomainHash, "Wrong Subdomain");
assert.equal(web3Utils.toChecksumAddress("0x"+resultRegister.events['1'].raw.data.substring(26)), await ENSSubdomainRegistry.methods.resolver().call(), "Wrong Resolver");
assert.equal(resultRegister.events['2'].raw.topics[0], '0x52d7d861f09ab3d26239d492e8968629f95e9e318cf0b73bfddc441522a15fd2', "Wrong Event");
assert.equal(resultRegister.events['2'].raw.topics[1], subdomainHash, "Wrong Subdomain");
assert.equal(web3Utils.toChecksumAddress("0x"+resultRegister.events['2'].raw.data.substring(26)), registrant, "Wrong address to resolve");
assert.equal(resultRegister.events['3'].raw.topics[0], '0x1d6f5e03d3f63eb58751986629a5439baee5079ff04f345becb66e23eb154e46', "Wrong Event");
assert.equal(resultRegister.events['3'].raw.topics[1], subdomainHash, "Wrong Subdomain");
assert.equal(resultRegister.events['3'].raw.data, points.x.concat(points.y.substr(2)))
assert.equal(resultRegister.events['4'].raw.topics[0], '0xd4735d920b0f87494915f556dd9b54c8f309026070caea5c737245152564d266', "Wrong Event");
assert.equal(resultRegister.events['4'].raw.topics[1], subdomainHash, "Wrong Subdomain");
assert.equal(web3Utils.toChecksumAddress("0x"+resultRegister.events['4'].raw.data.substring(26)), registrant, "Wrong node owner");
assert.equal(resultRegister.events.SubdomainOwner.returnValues.accountOwner, registrant, "event SubdomainOwner accountOwner mismatch");
assert.equal(resultRegister.events.SubdomainOwner.returnValues.subdomainHash, subdomainHash, "event SubdomainOwner subdomainHash mismatch");
assert.equal(await ens.methods.owner(subdomainHash).call(), registrant, "ENSRegistry owner mismatch");
assert.equal(await ens.methods.resolver(subdomainHash).call(), PublicResolver.address, "Resolver wrongly defined");
assert.equal(await ENSSubdomainRegistry.methods.getAccountBalance(subdomainHash).call(), 0, "Free domain accounts shouldn't have balance");
assert.equal(await ENSSubdomainRegistry.methods.getAccountOwner(subdomainHash).call(), registrant, "Account owner mismatch");
assert.equal(await PublicResolver.methods.addr(subdomainHash).call(), registrant, "Resolved address not set");
const resolverPubKey = await PublicResolver.methods.pubkey(subdomainHash).call();
const pubKey = utils.keyFromXY(resolverPubKey[0], resolverPubKey[1]);
assert.equal(pubKey, contactCode, "pubKey does not match contract code");
});
it('should register free pubkey only resolver-defined subdomain', async () => {
const subdomain = 'carlos';
const registrant = accountsArr[3];
const subdomainHash = namehash.hash(subdomain + '.' + domains.free.name);
const contactCode = '0x04dbb31252d9bddb4e4d362c7b9c80cba74732280737af97971f42ccbdc716f3f3efb1db366880e52d09b1bfd59842e833f3004088892b7d14b9ce9e957cea9a82';
const points = utils.generateXY(contactCode);
const label = web3Utils.sha3(subdomain);
const node = domains.free.namehash;
const resultRegister = await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
domains.free.namehash,
utils.zeroAddress,
points.x,
points.y
).send({from: registrant});
assert.equal(resultRegister.events['0'].raw.topics[0], '0xce0457fe73731f824cc272376169235128c118b49d344817417c6d108d155e82', "Wrong Event");
assert.equal(resultRegister.events['0'].raw.topics[1], node, "Wrong Node");
assert.equal(resultRegister.events['0'].raw.topics[2], label, "Wrong Label");
assert.equal(web3Utils.toChecksumAddress("0x"+resultRegister.events['0'].raw.data.substring(26)), ENSSubdomainRegistry.address, "Wrong subnode owner");
assert.equal(resultRegister.events['1'].raw.topics[0], '0x335721b01866dc23fbee8b6b2c7b1e14d6f05c28cd35a2c934239f94095602a0', "Wrong Event");
assert.equal(resultRegister.events['1'].raw.topics[1], subdomainHash, "Wrong Subdomain");
assert.equal(web3Utils.toChecksumAddress("0x"+resultRegister.events['1'].raw.data.substring(26)), PublicResolver.address, "Wrong Resolver");
assert.equal(resultRegister.events['2'].raw.topics[0], '0x1d6f5e03d3f63eb58751986629a5439baee5079ff04f345becb66e23eb154e46', "Wrong Event");
assert.equal(resultRegister.events['2'].raw.topics[1], subdomainHash, "Wrong Subdomain");
assert.equal(resultRegister.events['2'].raw.data, points.x.concat(points.y.substr(2)))
assert.equal(resultRegister.events['3'].raw.topics[0], '0xd4735d920b0f87494915f556dd9b54c8f309026070caea5c737245152564d266', "Wrong Event");
assert.equal(resultRegister.events['3'].raw.topics[1], subdomainHash, "Wrong Subdomain");
assert.equal(web3Utils.toChecksumAddress("0x"+resultRegister.events['3'].raw.data.substring(26)), registrant, "Wrong node owner");
assert.equal(resultRegister.events.SubdomainOwner.returnValues.accountOwner, registrant, "event SubdomainOwner accountOwner mismatch");
assert.equal(resultRegister.events.SubdomainOwner.returnValues.subdomainHash, subdomainHash, "event SubdomainOwner subdomainHash mismatch");
assert.equal(await ens.methods.owner(subdomainHash).call(), registrant, "ENSRegistry owner mismatch");
assert.equal(await ens.methods.resolver(subdomainHash).call(), PublicResolver.address, "Resolver wrongly defined");
assert.equal(await ENSSubdomainRegistry.methods.getAccountBalance(subdomainHash).call(), 0, "Free domain accounts shouldn't have balance");
assert.equal(await ENSSubdomainRegistry.methods.getAccountOwner(subdomainHash).call(), registrant, "Account owner mismatch");
assert.equal(await PublicResolver.methods.addr(subdomainHash).call(), utils.zeroAddress, "Resolved address not set");
const resolverPubKey = await PublicResolver.methods.pubkey(subdomainHash).call();
const pubKey = utils.keyFromXY(resolverPubKey[0], resolverPubKey[1]);
assert.equal(pubKey, contactCode, "pubKey does not match contract code");
});
it('should register empty subdomain with token cost', async () => {
const registrant = accountsArr[5];
const subdomain = 'erin';
const subdomainHash = namehash.hash(subdomain + '.' + domains.paid.name);
const domainPrice = await ENSSubdomainRegistry.methods.getPrice(domains.paid.namehash).call()
const label = web3Utils.sha3(subdomain);
const node = domains.paid.namehash;
await TestToken.methods.mint(domainPrice).send({from: registrant});
const initialRegistrantBalance = await TestToken.methods.balanceOf(registrant).call();
const initialRegistryBalance = await TestToken.methods.balanceOf(ENSSubdomainRegistry.address).call();
await TestToken.methods.approve(ENSSubdomainRegistry.address, domainPrice).send({from: registrant});
const resultRegister = await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
domains.paid.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
assert.equal(resultRegister.events['0'].raw.topics[0], '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', "Wrong Event");
assert.equal(web3Utils.toChecksumAddress("0x"+resultRegister.events['0'].raw.topics[1].substring(26)), registrant, "Wrong subnode owner");
assert.equal(web3Utils.toChecksumAddress("0x"+resultRegister.events['0'].raw.topics[2].substring(26)), ENSSubdomainRegistry.address, "Wrong subnode owner");
assert.equal(resultRegister.events['1'].raw.topics[0], '0xce0457fe73731f824cc272376169235128c118b49d344817417c6d108d155e82', "Wrong Event");
assert.equal(resultRegister.events['1'].raw.topics[1], node, "Wrong Node");
assert.equal(resultRegister.events['1'].raw.topics[2], label, "Wrong Label");
assert.equal(web3Utils.toChecksumAddress("0x"+resultRegister.events['1'].raw.data.substring(26)), registrant, "Wrong subnode owner");
assert.equal(resultRegister.events.SubdomainOwner.returnValues.accountOwner, registrant, "event SubdomainOwner accountOwner mismatch");
assert.equal(resultRegister.events.SubdomainOwner.returnValues.subdomainHash, subdomainHash, "event SubdomainOwner subdomainHash mismatch");
assert.equal(await ens.methods.owner(subdomainHash).call(), registrant, "ENSRegistry owner mismatch");
assert.equal(await ens.methods.resolver(subdomainHash).call(), utils.zeroAddress, "Resolver wrongly defined");
assert.equal(await ENSSubdomainRegistry.methods.getAccountBalance(subdomainHash).call(), domainPrice, "Registry subdomain account balance wrong");
assert.equal(await ENSSubdomainRegistry.methods.getAccountOwner(subdomainHash).call(), registrant, "Account owner mismatch");
assert.equal(await TestToken.methods.balanceOf(registrant).call(), +initialRegistrantBalance-domainPrice, "User final balance wrong")
assert.equal(await TestToken.methods.balanceOf(ENSSubdomainRegistry.address).call(), (+initialRegistryBalance)+(+domainPrice), "Registry final balance wrong")
});
});
describe('release()', function() {
it('should release free subdomain', async () => {
let registrant = accountsArr[6];
let subdomain = 'frank';
let subdomainHash = namehash.hash(subdomain + '.' + domains.free.name);
await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
domains.free.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
const releaseDelay = await ENSSubdomainRegistry.methods.releaseDelay().call();
await utils.increaseTime(releaseDelay)
await utils.increaseTime(1000)
const initialRegistrantBalance = await TestToken.methods.balanceOf(registrant).call();
const initialRegistryBalance = await TestToken.methods.balanceOf(ENSSubdomainRegistry.address).call();
await utils.increaseTime(1000)
const resultRelease = await ENSSubdomainRegistry.methods.release(
web3Utils.sha3(subdomain),
domains.free.namehash
).send({from: registrant});
//TODO: check events
assert.equal(await ens.methods.owner(subdomainHash).call(), utils.zeroAddress, "Not released name ownship");
assert.equal(await TestToken.methods.balanceOf(registrant).call(), initialRegistrantBalance, "Registrant token balance unexpectectly changed")
assert.equal(await TestToken.methods.balanceOf(ENSSubdomainRegistry.address).call(), initialRegistryBalance, "Registry token balance unexpectectly changed")
});
it('should release subdomain with cost', async () => {;
const registrant = accountsArr[6];
const subdomain = 'frank';
const subdomainHash = namehash.hash(subdomain + '.' + domains.paid.name);
const labelHash = web3Utils.sha3(subdomain);
const domainPrice = await ENSSubdomainRegistry.methods.getPrice(domains.paid.namehash).call()
await TestToken.methods.mint(domainPrice).send({from: registrant});
await TestToken.methods.approve(ENSSubdomainRegistry.address, domainPrice).send({from: registrant});
await ENSSubdomainRegistry.methods.register(
labelHash,
domains.paid.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
const releaseDelay = await ENSSubdomainRegistry.methods.releaseDelay().call();
await utils.increaseTime(releaseDelay)
await utils.increaseTime(1000)
const initialAccountBalance = await ENSSubdomainRegistry.methods.getAccountBalance(subdomainHash).call();
const initialRegistrantBalance = await TestToken.methods.balanceOf(registrant).call();
const initialRegistryBalance = await TestToken.methods.balanceOf(ENSSubdomainRegistry.address).call();
await utils.increaseTime(1000)
const resultRelease = await ENSSubdomainRegistry.methods.release(
web3Utils.sha3(subdomain),
domains.paid.namehash
).send({from: registrant});
//TODO: check events
assert.equal(await ENSSubdomainRegistry.methods.getAccountBalance(subdomainHash).call(), 0, "Final balance didnt zeroed");
assert.equal(await TestToken.methods.balanceOf(registrant).call(), (+initialRegistrantBalance)+(+initialAccountBalance), "Releaser token balance didnt increase")
assert.equal(await TestToken.methods.balanceOf(ENSSubdomainRegistry.address).call(), (+initialRegistryBalance)-(+initialAccountBalance), "Registry token balance didnt decrease")
});
it('should release transfered subdomain with cost', async () => {
let registrant = accountsArr[7];
let subdomain = 'grace';
let subdomainHash = namehash.hash(subdomain + '.' + domains.paid.name);
let labelHash = web3Utils.sha3(subdomain);
let newOwner = accountsArr[8];
let domainPrice = await ENSSubdomainRegistry.methods.getPrice(domains.paid.namehash).call()
await TestToken.methods.mint(domainPrice).send({from: registrant});
await TestToken.methods.approve(ENSSubdomainRegistry.address, domainPrice).send({from: registrant});
await ENSSubdomainRegistry.methods.register(
labelHash,
domains.paid.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
await ens.methods.setOwner(subdomainHash, newOwner).send({from: registrant});
let releaseDelay = await ENSSubdomainRegistry.methods.releaseDelay().call();
await utils.increaseTime(releaseDelay)
await utils.increaseTime(1000)
let initialAccountBalance = await ENSSubdomainRegistry.methods.getAccountBalance(subdomainHash).call();
let initialRegistrantBalance = await TestToken.methods.balanceOf(newOwner).call();
let initialRegistryBalance = await TestToken.methods.balanceOf(ENSSubdomainRegistry.address).call();
await utils.increaseTime(1000)
let resultRelease = await ENSSubdomainRegistry.methods.release(
web3Utils.sha3(subdomain),
domains.paid.namehash
).send({from: newOwner});
//TODO: check events
assert.equal(await ENSSubdomainRegistry.methods.getAccountBalance(subdomainHash).call(), 0, "Final balance didnt zeroed");
assert.equal(await TestToken.methods.balanceOf(newOwner).call(), (+initialRegistrantBalance)+(+initialAccountBalance), "New owner token balance didnt increase")
assert.equal(await TestToken.methods.balanceOf(ENSSubdomainRegistry.address).call(), (+initialRegistryBalance)-(+initialAccountBalance), "Registry token balance didnt decrease")
});
xit('should release moved subdomain account balance by funds owner', async () => {
});
});
describe('updateAccountOwner()', function() {
it('should update subdomain funds owner', async () => {
let subdomain = 'heidi';
let labelHash = web3Utils.sha3(subdomain);
let registrant = accountsArr[8];
let newOwner = accountsArr[9];
let subdomainHash = namehash.hash(subdomain + '.' + domains.paid.name);
let domainPrice = await ENSSubdomainRegistry.methods.getPrice(domains.paid.namehash).call()
await TestToken.methods.mint(domainPrice).send({from: registrant});
await TestToken.methods.approve(ENSSubdomainRegistry.address, domainPrice).send({from: registrant});
await ENSSubdomainRegistry.methods.register(
labelHash,
domains.paid.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
await ens.methods.setOwner(subdomainHash, newOwner).send({from: registrant});
let resultUpdateOwner = await ENSSubdomainRegistry.methods.updateAccountOwner(
labelHash,
domains.paid.namehash
).send({from: newOwner});
//TODO: check events
assert.equal(await ENSSubdomainRegistry.methods.getAccountOwner(subdomainHash).call(), newOwner, "Backup owner not updated");
});
});
describe('slashInvalidSubdomain()', function() {
it('should slash invalid free subdomain', async () => {
let subdomain = 'alicé';
let subdomainHash = namehash.hash(subdomain + '.' + domains.free.name);
let registrant = accountsArr[1];
await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
domains.free.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
assert.equal(await ens.methods.owner(subdomainHash).call(), registrant);
assert.notEqual(await ENSSubdomainRegistry.methods.getCreationTime(subdomainHash).call(), 0);
await ENSSubdomainRegistry.methods.slashInvalidSubdomain(web3Utils.toHex(subdomain), domains.free.namehash, 4).send()
//TODO: check events
assert.equal(await ENSSubdomainRegistry.methods.getCreationTime(subdomainHash).call(), 0);
assert.equal(await ens.methods.owner(subdomainHash).call(), utils.zeroAddress);
});
});
describe('slashReservedSubdomain()', function() {
it('should slash reserved name subdomain', async () => {
let subdomain = reservedNames[0];
let subdomainHash = namehash.hash(subdomain + '.' + domains.free.name);
let registrant = accountsArr[1];
await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
domains.free.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
assert.equal(await ens.methods.owner(subdomainHash).call(), registrant);
const proof = merkleTree.getHexProof(reservedNames[0]);
result = await ENSSubdomainRegistry.methods.slashReservedSubdomain(web3Utils.toHex(subdomain), domains.free.namehash, 0, proof).send()
assert.equal(await ens.methods.owner(subdomainHash).call(), utils.zeroAddress);
});
});
describe('slashSmallSubdomain()', function() {
it('should slash small subdomain', async () => {
let subdomain = 'a';
let subdomainHash = namehash.hash(subdomain + '.' + domains.free.name);
let registrant = accountsArr[1];
await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
domains.free.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
assert.equal(await ens.methods.owner(subdomainHash).call(), registrant);
result = await ENSSubdomainRegistry.methods.slashSmallSubdomain(web3Utils.toHex(subdomain), domains.free.namehash).send()
assert.equal(await ens.methods.owner(subdomainHash).call(), utils.zeroAddress);
});
});
describe('slashAddressLikeSubdomain()', function() {
it('should slash address like subdomain', async () => {
let subdomain = "0xc6b95bd26";
let userlabelHash = "0x59bf8d16c517a40a5dacc3471abd002f3bc0850a13e930e4bee49070a58517e8"; //sha3("0xc6b95bd26")
let subdomainHash = "0x6f15e192c1c4537c2d774431219ed42efc6be95efe362104ba546eb574f3f1e5"; //namehash("0xc6b95bd26.freedomain.eth")
let domainnameHash = "0x297836a76312224372ac04e26dd23d1294bb8256598ec113ecc52735f826beff"; //namehash("freedomain.eth")
let registrant = accountsArr[1];
let result = await ENSSubdomainRegistry.methods.register(
userlabelHash,
domainnameHash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
assert.equal(await ens.methods.owner(subdomainHash).call(), registrant);
result = await ENSSubdomainRegistry.methods.slashAddressLikeSubdomain(subdomain, domainnameHash).send()
assert.equal(await ens.methods.owner(subdomainHash).call(), utils.zeroAddress);
});
});
describe('slashSubdomain()', function() {
it('should slash a paid subdomain and get funds from registrant', async () => {
let subdomain = 'b';
let subdomainHash = namehash.hash(subdomain + '.' + domains.paid.name);
let registrant = accountsArr[1];
let slasher = accountsArr[2];
const domainPrice = await ENSSubdomainRegistry.methods.getPrice(domains.paid.namehash).call()
await TestToken.methods.mint(domainPrice).send({from: registrant});
await TestToken.methods.approve(ENSSubdomainRegistry.address, domainPrice).send({from: registrant});
await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
domains.paid.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
assert.equal(await ens.methods.owner(subdomainHash).call(), registrant);
let initialSlasherBalance = await TestToken.methods.balanceOf(slasher).call();
await ENSSubdomainRegistry.methods.slashSmallSubdomain(web3Utils.toHex(subdomain), domains.paid.namehash).send({from: slasher})
assert.equal(await TestToken.methods.balanceOf(slasher).call(), (+initialSlasherBalance)+(+domainPrice));
assert.equal(await ens.methods.owner(subdomainHash).call(), utils.zeroAddress);
});
});
describe('moveDomain()', function() {
it('should move free domain to new registry and migrate', async () => {
const resultMoveDomain = await ENSSubdomainRegistry.methods.moveDomain(UpdatedENSSubdomainRegistry.address, domains.free.namehash).send();
//TODO: check events
assert.equal(await ens.methods.owner(domains.free.namehash).call(), UpdatedENSSubdomainRegistry.address, "domain ownership not moved correctly")
});
it('should move paid domain to new registry and migrate', async () => {
let price = await ENSSubdomainRegistry.methods.getPrice(domains.paid.namehash).call()
const result = await ENSSubdomainRegistry.methods.moveDomain(UpdatedENSSubdomainRegistry.address, domains.paid.namehash).send();
//TODO: check events
assert.equal(await ens.methods.owner(domains.paid.namehash).call(), UpdatedENSSubdomainRegistry.address, "domain ownership not moved correctly")
assert.equal(await UpdatedENSSubdomainRegistry.methods.getPrice(domains.paid.namehash).call(), price, "updated registry didnt migrated price")
});
});
describe('moveAccount()', function() {
xit('should move free subdomain to new registry by funds owner', async () => {
});
xit('should move paid subdomain to new registry by funds owner', async () => {
});
});
});