add test for slashing mechanism

This commit is contained in:
Ricardo Guilherme Schmidt 2018-08-27 10:58:19 -03:00 committed by Barry G
parent 81aa4a4004
commit fc7a77a8e4
1 changed files with 68 additions and 1 deletions

View File

@ -5,6 +5,32 @@ const TestToken = require('Embark/contracts/TestToken');
const ENSRegistry = require('Embark/contracts/ENSRegistry'); const ENSRegistry = require('Embark/contracts/ENSRegistry');
const PublicResolver = require('Embark/contracts/PublicResolver'); const PublicResolver = require('Embark/contracts/PublicResolver');
const ENSSubdomainRegistry = require('Embark/contracts/ENSSubdomainRegistry'); 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 unallowedRanges = [
web3Utils.soliditySha3(0,47),
web3Utils.soliditySha3(58,96),
web3Utils.soliditySha3(123,1023),
web3Utils.soliditySha3(1023,9999999999)
];
const merkleTree = new MerkleTree(unallowedRanges);
const merkleRoot = merkleTree.getHexRoot();
var contractsConfig = { var contractsConfig = {
"TestToken": { "TestToken": {
@ -25,7 +51,7 @@ var contractsConfig = {
"$TestToken", "$TestToken",
"$ENSRegistry", "$ENSRegistry",
"$PublicResolver", "$PublicResolver",
"0x0", merkleRoot,
"0x0" "0x0"
], ],
"onDeploy": [ "onDeploy": [
@ -39,6 +65,7 @@ var contractsConfig = {
"$TestToken", "$TestToken",
"$ENSRegistry", "$ENSRegistry",
"$PublicResolver", "$PublicResolver",
merkleRoot,
"$ENSSubdomainRegistry" "$ENSSubdomainRegistry"
] ]
} }
@ -448,4 +475,44 @@ contract('ENSSubdomainRegistry', function () {
}); });
it('should slash 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);
const proof = merkleTree.getHexProof(unallowedRanges[2]);
result = await ENSSubdomainRegistry.methods.slashSubdomain(web3Utils.toHex(subdomain), domains.free.namehash, 4, 123, 1023, proof).send()
accountCreationTime = await ENSSubdomainRegistry.methods.getCreationTime(usernameHash).call();
assert(accountCreationTime == 0);
result = await ens.methods.owner(usernameHash).call()
assert.equal(result, utils.zeroAddress);
});
}); });