Permalink
Browse files

make registered usernames in older slashing rules "clearable" in ENS

  • Loading branch information...
3esmit committed Sep 17, 2018
1 parent 8a182ea commit eaefa92a258c784f1df4066e057e8170bcb6ef95
Showing with 89 additions and 7 deletions.
  1. +13 −5 contracts/registry/UsernameRegistrar.sol
  2. +76 −2 test/usernameregistrar.spec.js
@@ -597,21 +597,29 @@ contract UsernameRegistrar is Controlled, ApproveAndCallFallBack {
emit UsernameOwner(namehash, _owner);
}
/**
/**
* @dev Removes account hash of `_username` and send account.balance to msg.sender.
* @param _username Username being slashed.
*/
function slashUsername(bytes _username) internal {
bytes32 label = keccak256(_username);
bytes32 namehash = keccak256(abi.encodePacked(ensNode, label));
require(accounts[label].creationTime > 0, "Username not registered.");
uint256 amountToTransfer;
if(accounts[label].creationTime == 0) {
require(
ensRegistry.owner(namehash) != address(0) ||
ensRegistry.resolver(namehash) != address(0),
"Nothing to slash."
);
} else {
amountToTransfer = accounts[label].balance;
delete accounts[label];
}
ensRegistry.setSubnodeOwner(ensNode, label, address(this));
ensRegistry.setResolver(namehash, address(0));
ensRegistry.setOwner(namehash, address(0));
uint256 amountToTransfer = accounts[label].balance;
delete accounts[label];
if (amountToTransfer > 0) {
reserveAmount -= amountToTransfer;
require(token.transfer(msg.sender, amountToTransfer), "Error in transfer.");
@@ -23,6 +23,15 @@ const dummyRegistry = {
price: 100000000
}
const dummy2Registry = {
name: 'dummy2reg',
registry: 'dummy2reg.eth',
label: web3Utils.sha3('dummy2reg'),
namehash: namehash.hash('dummy2reg.eth'),
price: 100000000
}
// TODO: load file of reserved names and balance array lenght to be even
const merkleTree = new MerkleTree(ReservedUsernames);
@@ -94,6 +103,34 @@ var contractsConfig = {
merkleRoot,
"$DummyUsernameRegistrar"
]
},
"Dummy2UsernameRegistrar": {
"instanceOf" : "UsernameRegistrar",
"args": [
"$TestToken",
"$ENSRegistry",
"$PublicResolver",
dummy2Registry.namehash,
"3",
utils.zeroBytes32,
"0x0"
],
"onDeploy": [
"ENSRegistry.methods.setSubnodeOwner('0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae', '"+dummy2Registry.label+"', Dummy2UsernameRegistrar.address).send()",
"Dummy2UsernameRegistrar.methods.activate("+dummy2Registry.price+").send()"
]
},
"UpdatedDummy2UsernameRegistrar": {
"instanceOf" : "UsernameRegistrar",
"args": [
"$TestToken",
"$ENSRegistry",
"$PublicResolver",
dummy2Registry.namehash,
"3",
merkleRoot,
"$Dummy2UsernameRegistrar"
]
}
};
@@ -491,8 +528,6 @@ contract('UsernameRegistrar', function () {
});
it('should release moved username account balance by owner', async () => {
const registrant = accountsArr[5];
UsernameRegistrar
UpdatedUsernameRegistrar
await TestToken.methods.mint(dummyRegistry.price).send({from: registrant});
await DummyUsernameRegistrar.methods.activate(dummyRegistry.price).send({from: accountsArr[0]});
await TestToken.methods.approve(DummyUsernameRegistrar.address, dummyRegistry.price).send({from: registrant});
@@ -783,6 +818,45 @@ contract('UsernameRegistrar', function () {
assert.equal(await TestToken.methods.balanceOf(slasher).call(), (+initialSlasherBalance)+(+registry.price));
assert.equal(await ens.methods.owner(usernameHash).call(), utils.zeroAddress);
});
it('should slash a username of a not migrated subnode that became unallowed', async () => {
const registrant = accountsArr[5];
const notRegistrant = accountsArr[6];
await TestToken.methods.mint(dummy2Registry.price).send({from: registrant});
await TestToken.methods.approve(Dummy2UsernameRegistrar.address, dummy2Registry.price).send({from: registrant});
const username = ReservedUsernames[10];
const label = web3Utils.sha3(username);
const usernameHash = namehash.hash(username + '.' + dummy2Registry.registry);
await Dummy2UsernameRegistrar.methods.register(
label,
registrant,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
let initialAccountBalance = await Dummy2UsernameRegistrar.methods.getAccountBalance(label).call();
const initialRegistrantBalance = await TestToken.methods.balanceOf(registrant).call();
const initialRegistryBalance = await TestToken.methods.balanceOf(Dummy2UsernameRegistrar.address).call();
await Dummy2UsernameRegistrar.methods.moveRegistry(UpdatedDummy2UsernameRegistrar.address).send();
assert.equal(await ens.methods.owner(usernameHash).call(), registrant, "ENSRegistry owner mismatch");
assert.equal(await ens.methods.resolver(usernameHash).call(), PublicResolver.address, "Resolver wrongly defined");
assert.equal(await PublicResolver.methods.addr(usernameHash).call(), registrant, "Resolved address not set");
const resultRelease = await UpdatedDummy2UsernameRegistrar.methods.slashReservedUsername(
web3Utils.toHex(username),
merkleTree.getHexProof(username)
).send({from: notRegistrant });
//TODO: verify events
assert.equal(await ens.methods.resolver(usernameHash).call(), utils.zeroAddress, "Resolver not undefined");
assert.equal(await ens.methods.owner(usernameHash).call(), utils.zeroAddress, "Owner not removed");
//We are not cleaning PublicResolver or any resolver, so the value should remain the same.
assert.equal(await PublicResolver.methods.addr(usernameHash).call(), registrant, "Resolved address not set");
});
});
describe('moveRegistry()', function() {

0 comments on commit eaefa92

Please sign in to comment.