reorganize tests + domain migration test

This commit is contained in:
Ricardo Guilherme Schmidt 2018-05-15 19:36:20 -03:00 committed by Barry Gitarts
parent c4e6a396e8
commit c7bde0bfde
1 changed files with 133 additions and 94 deletions

View File

@ -3,7 +3,18 @@ const web3Utils = require('web3-utils');
const namehash = require('eth-ens-namehash');
contract('ENSSubdomainRegistry', function () {
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;
@ -29,7 +40,17 @@ contract('ENSSubdomainRegistry', function () {
"$PublicResolver",
"0x0"
]
},
"UpdatedENSSubdomainRegistry": {
"instanceOf" : "ENSSubdomainRegistry",
"args": [
"$TestToken",
"$ENSRegistry",
"$PublicResolver",
"$ENSSubdomainRegistry"
]
}
};
EmbarkSpec.deployAll(contractsConfig, async (accounts) => {
ens = ENSRegistry;
@ -37,33 +58,51 @@ contract('ENSSubdomainRegistry', function () {
await utils.increaseTime(1 * utils.timeUnits.days) //time cannot start zero
await ens.methods.setSubnodeOwner(utils.zeroBytes32, web3Utils.sha3('eth'), accountsArr[0]).send({from: accountsArr[0]});
await ens.methods.setSubnodeOwner(namehash.hash('eth'), web3Utils.sha3('stateofus'), ENSSubdomainRegistry.address).send({from: accountsArr[0]});
await ens.methods.setSubnodeOwner(namehash.hash('eth'), web3Utils.sha3('stateofus'), ENSSubdomainRegistry.address).send({from: accountsArr[0]});
await ens.methods.setSubnodeOwner(namehash.hash('eth'), web3Utils.sha3('freedomain'), ENSSubdomainRegistry.address).send({from: accountsArr[0]});
done()
});
});
it('should add domain with price zero', async () => {
let result = await ENSSubdomainRegistry.methods.addDomain(namehash.hash('stateofus.eth'), 0).send({from: accountsArr[0]});
assert.equal(result.events.DomainPrice.returnValues.price, 0);
assert.equal(result.events.DomainPrice.returnValues.namehash, namehash.hash('stateofus.eth'));
result = await ENSSubdomainRegistry.methods.getPrice(namehash.hash('stateofus.eth')).call()
it('should add free domain', async () => {
let result = await ENSSubdomainRegistry.methods.addDomain(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);
});
it('should register empty subdomain with zero cost', async () => {
let domain = 'stateofus.eth';
it('should add paid domain', async () => {
let initialPrice = 100
let result = await ENSSubdomainRegistry.methods.addDomain(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);
});
it('should change paid domain price', async () => {
let newPrice = domains.paid.price;
let result = await ENSSubdomainRegistry.methods.setDomainPrice(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");
});
it('should register free subdomain', async () => {
let subdomain = 'alice';
let usernameHash = namehash.hash(subdomain + '.' + domain);
let usernameHash = namehash.hash(subdomain + '.' + domains.free.name);
let registrant = accountsArr[1];
let result = await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
namehash.hash(domain),
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()
@ -74,19 +113,18 @@ contract('ENSSubdomainRegistry', function () {
assert(result, registrant, "Backup owner not set");
});
it('should register address only resolver-defined subdomain', async () => {
let domain = 'stateofus.eth';
let subdomain = 'bob';
let usernameHash = namehash.hash(subdomain + '.' + domain);
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),
namehash.hash(domain),
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");
@ -99,20 +137,20 @@ contract('ENSSubdomainRegistry', function () {
assert.equal(result[1], utils.zeroBytes32, "Unexpected resolved pubkey[1]");
});
it('should register pubkey only resolver-defined subdomain', async () => {
let domain = 'stateofus.eth';
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),
namehash.hash(domain),
domains.free.namehash,
utils.zeroAddress,
pubkey[0],
pubkey[1]
).send({from: registrant});
let usernameHash = namehash.hash(subdomain + '.' + domain);
//TODO: check events
result = await ens.methods.owner(usernameHash).call()
assert.equal(result, registrant, "Owner not set");
result = await ens.methods.resolver(usernameHash).call()
@ -125,21 +163,21 @@ contract('ENSSubdomainRegistry', function () {
});
it('should register full resolver-defined subdomain', async () => {
let domain = 'stateofus.eth';
let subdomain = 'david';
let usernameHash = namehash.hash(subdomain + '.' + domain);
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),
namehash.hash(domain),
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()
@ -151,30 +189,31 @@ contract('ENSSubdomainRegistry', function () {
assert.equal(result[1], pubkey[1], "Resolved pubkey[1] not set");
});
it('should release subdomain registered with zero cost', async () => {
let domain = 'stateofus.eth';
let subdomain = 'frank';
it('should release free subdomain', async () => {
let registrant = accountsArr[6];
let domainHash = namehash.hash('stateofus.eth');
let usernameHash = namehash.hash(subdomain + '.' + domain);
let subdomain = 'frank';
let usernameHash = namehash.hash(subdomain + '.' + domains.free.name);
await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
namehash.hash(domain),
domains.free.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
let releaseDelay = await ENSSubdomainRegistry.methods.releaseDelay().call();
await utils.increaseTime(releaseDelay)
this.timeout(1000)
let initialRegistrantBalance = await TestToken.methods.balanceOf(registrant).call();
let initialRegistryBalance = await TestToken.methods.balanceOf(ENSSubdomainRegistry.address).call();
await ENSSubdomainRegistry.methods.release(
let result = await ENSSubdomainRegistry.methods.release(
web3Utils.sha3(subdomain),
domainHash
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();
@ -183,26 +222,12 @@ contract('ENSSubdomainRegistry', function () {
assert(finalRegistryBalance, initialRegistryBalance, "Registry token balance unexpectectly changed")
});
it('should change domain price', async () => {
let newPrice = 100000000000000;
let domainHash = namehash.hash('stateofus.eth');
let result = await ENSSubdomainRegistry.methods.setDomainPrice(domainHash, newPrice).send({from: accountsArr[0]});
assert.equal(result.events.DomainPrice.returnValues.price, newPrice, "Wrong price at event");
assert.equal(result.events.DomainPrice.returnValues.namehash, domainHash, "Wrong namehash at event");
result = await ENSSubdomainRegistry.methods.getPrice(domainHash).call()
assert.equal(result, newPrice, "Wrong return value at getPrice");
});
it('should register empty subdomain with token cost', async () => {
let domain = 'stateofus.eth';
let subdomain = 'erin';
let registrant = accountsArr[5];
let domainHash = namehash.hash('stateofus.eth');
let usernameHash = namehash.hash(subdomain + '.' + domain);
let domainPrice = await ENSSubdomainRegistry.methods.getPrice(domainHash).call()
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();
@ -212,15 +237,15 @@ contract('ENSSubdomainRegistry', function () {
let result = await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
domainHash,
domains.paid.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
result = await ens.methods.owner(namehash.hash(subdomain + '.' + domain)).call()
//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 + '.' + domain)).call()
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();
@ -233,34 +258,33 @@ contract('ENSSubdomainRegistry', function () {
});
it('should release subdomain with cost', async () => {
let domain = 'stateofus.eth';
let subdomain = 'frank';
let labelHash = web3Utils.sha3(subdomain);
it('should release subdomain with cost', async () => {;
let registrant = accountsArr[6];
let domainHash = namehash.hash('stateofus.eth');
let usernameHash = namehash.hash(subdomain + '.' + domain);
let domainPrice = await ENSSubdomainRegistry.methods.getPrice(domainHash).call()
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});
await ENSSubdomainRegistry.methods.register(
let result = await ENSSubdomainRegistry.methods.register(
labelHash,
domainHash,
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)
this.timeout(1000)
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),
domainHash
domains.paid.namehash
).send({from: registrant});
let finalAccountBalance = await ENSSubdomainRegistry.methods.getAccountBalance(usernameHash).call();
assert(finalAccountBalance, 0, "Final balance didnt zeroed");
@ -272,19 +296,18 @@ contract('ENSSubdomainRegistry', function () {
});
it('should release transfered subdomain with cost', async () => {
let domain = 'stateofus.eth';
let subdomain = 'grace';
let labelHash = web3Utils.sha3(subdomain);
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 domainHash = namehash.hash('stateofus.eth');
let usernameHash = namehash.hash(subdomain + '.' + domain);
let domainPrice = await ENSSubdomainRegistry.methods.getPrice(domainHash).call()
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,
domainHash,
domains.paid.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
@ -293,15 +316,18 @@ contract('ENSSubdomainRegistry', function () {
let releaseDelay = await ENSSubdomainRegistry.methods.releaseDelay().call();
await utils.increaseTime(releaseDelay)
this.timeout(1000)
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();
await ENSSubdomainRegistry.methods.release(
let result = await ENSSubdomainRegistry.methods.release(
web3Utils.sha3(subdomain),
domainHash
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();
@ -312,44 +338,57 @@ contract('ENSSubdomainRegistry', function () {
});
it('should update subdomain backup owner', async () => {
let domain = 'stateofus.eth';
let subdomain = 'heidi';
let labelHash = web3Utils.sha3(subdomain);
let registrant = accountsArr[8];
let newOwner = accountsArr[9];
let domainHash = namehash.hash('stateofus.eth');
let usernameHash = namehash.hash(subdomain + '.' + domain);
let domainPrice = await ENSSubdomainRegistry.methods.getPrice(domainHash).call()
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,
domainHash,
domains.paid.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
await ens.methods.setOwner(usernameHash, newOwner).send({from: registrant});
await ENSSubdomainRegistry.methods.updateBackupOwner(
let result = await ENSSubdomainRegistry.methods.updateBackupOwner(
usernameHash
).send({from: newOwner});
let result = await ENSSubdomainRegistry.methods.getBackupOwner(usernameHash).call();
//TODO: check events
result = await ENSSubdomainRegistry.methods.getBackupOwner(usernameHash).call();
assert(result, newOwner, "Backup owner not updated");
});
xit('should move domain to new registry', async () => {
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 domain account balance to backup owner', async () => {
xit('should release moved free subdomain account balance by backup owner', async () => {
});
xit('should migrate free subdomain to new registry by backup owner', async () => {
});
xit('should release moved paid subdomain account balance by backup owner', async () => {
});
xit('should migrate paid subdomain to new registry by backup owner', async () => {
});
});