Skip to content

Commit

Permalink
Fix revoke bug (#177)
Browse files Browse the repository at this point in the history
* Fix revoke bug
  • Loading branch information
makoto committed Jul 26, 2018
1 parent 8945c27 commit 230efa0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
10 changes: 5 additions & 5 deletions contracts/GroupAdmin.sol
Expand Up @@ -31,12 +31,12 @@ contract GroupAdmin is Ownable {
* @param oldAdmins An array of addresses
*/
function revoke(address[] oldAdmins) public onlyOwner{
for(uint i = 0; i < oldAdmins.length; i++){
for (uint j = 0; j < admins.length; ++i) {
if (admins[j] == oldAdmins[i]) {
admins[j] = admins[admins.length - 1];
for(uint oldIdx = 0; oldIdx < oldAdmins.length; oldIdx++){
for (uint idx = 0; idx < admins.length; idx++) {
if (admins[idx] == oldAdmins[oldIdx]) {
admins[idx] = admins[admins.length - 1];
admins.length--;
emit AdminRevoked(oldAdmins[i]);
emit AdminRevoked(oldAdmins[oldIdx]);
break;
}
}
Expand Down
17 changes: 13 additions & 4 deletions test/group_admin.js
Expand Up @@ -4,7 +4,9 @@ contract('GroupAdmin', function(accounts) {
beforeEach(async function(){
owner = accounts[0];
operator = accounts[1];
non_operator = accounts[2];
another_operator = accounts[2];
one_more_operator = accounts[3];
non_operator = accounts[4];
admin = await GroupAdmin.new();
})

Expand All @@ -16,8 +18,9 @@ contract('GroupAdmin', function(accounts) {

describe('on grant', function(){
it('is added to admin', async function(){
await admin.grant([operator], {from:owner});
await admin.grant([operator, another_operator], {from:owner});
assert.strictEqual(await admin.isAdmin.call(operator), true);
assert.strictEqual(await admin.isAdmin.call(another_operator), true);
assert.strictEqual(await admin.isAdmin.call(non_operator), false);
})

Expand All @@ -29,13 +32,19 @@ contract('GroupAdmin', function(accounts) {

describe('on revoke', function(){
beforeEach(async function(){
await admin.grant([operator], {from:owner});
await admin.grant([operator, another_operator, one_more_operator], {from:owner});
assert.strictEqual(await admin.isAdmin.call(operator), true);
assert.strictEqual(await admin.isAdmin.call(another_operator), true);
assert.strictEqual(await admin.isAdmin.call(one_more_operator), true);
assert.strictEqual((await admin.numOfAdmins.call()).toNumber(), 3);
})

it('is revoked from admin', async function(){
await admin.revoke([operator], {from:owner});
await admin.revoke([operator, one_more_operator], {from:owner});
assert.strictEqual(await admin.isAdmin.call(operator), false);
assert.strictEqual(await admin.isAdmin.call(another_operator), true);
assert.strictEqual(await admin.isAdmin.call(one_more_operator), false);
assert.strictEqual((await admin.numOfAdmins.call()).toNumber(), 1);
})

it('cannot be revoked by non owner', async function(){
Expand Down

0 comments on commit 230efa0

Please sign in to comment.