Skip to content

Commit

Permalink
Merge pull request #20 from daostack/fix-unregister
Browse files Browse the repository at this point in the history
Fix unregister DAO
  • Loading branch information
ben-kaufman authored Feb 19, 2020
2 parents 81ec751 + 9db63b9 commit 397a694
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 43 deletions.
8 changes: 5 additions & 3 deletions contracts/DAORegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ contract DAORegistry is Ownable {

event Propose(address indexed _avatar);
event Register(address indexed _avatar, string _name);
event UnRegister(address indexed _avatar);
event UnRegister(address indexed _avatar, string _name);

mapping(string=>bool) private registry;

Expand All @@ -20,8 +20,10 @@ contract DAORegistry is Ownable {
emit Register(_avatar, _name);
}

function unRegister(address _avatar) public onlyOwner {
emit UnRegister(_avatar);
function unRegister(address _avatar, string memory _name) public onlyOwner {
require(registry[_name]);
registry[_name] = false;
emit UnRegister(_avatar, _name);
}

//This getter is needed because Dynamically-sized keys for public mappings are not supported.
Expand Down
83 changes: 50 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@daostack/arc-hive",
"version": "0.0.1-rc.5",
"version": "0.0.1-rc.6",
"description": "A dao's registry",
"files": [
"contracts/",
Expand Down
14 changes: 8 additions & 6 deletions test/daoregistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,23 @@ contract('DAORegistry', accounts => {
await daoRegistry.initialize(accounts[1]);
await daoRegistry.register(accounts[0],"test",{from:accounts[1]});
try {
await daoRegistry.unRegister(accounts[0]);
await daoRegistry.unRegister(accounts[0],"test");
assert(false, 'wrong owner');
} catch (ex) {
assertVMException(ex);
}
} catch (ex) {
assertVMException(ex);
}
assert.equal(await daoRegistry.isRegister("test"),true);
});

it("unRegister", async () => {
var daoRegistry = await DAORegistry.new();
await daoRegistry.initialize(accounts[0]);
await daoRegistry.register(accounts[0],"test");
var tx = await daoRegistry.unRegister(accounts[0]);
var tx = await daoRegistry.unRegister(accounts[0],"test");
assert.equal(tx.logs.length, 1);
assert.equal(tx.logs[0].event, "UnRegister");
assert.equal(tx.logs[0].args._avatar,accounts[0]);
assert.equal(await daoRegistry.isRegister("test"),true);
assert.equal(tx.logs[0].args._name,"test");
assert.equal(await daoRegistry.isRegister("test"),false);
});
});

0 comments on commit 397a694

Please sign in to comment.