From 3de6310d60df3b23fb8114778fd3c94ae2b77688 Mon Sep 17 00:00:00 2001 From: Joel Torstensson Date: Wed, 19 Jul 2017 10:54:15 +0200 Subject: [PATCH] Added isOwner and isRecovery functions to IdentityManager --- contracts/IdentityManager.sol | 8 ++++++++ test/identityManager.js | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/contracts/IdentityManager.sol b/contracts/IdentityManager.sol index bcfaf47..2674960 100644 --- a/contracts/IdentityManager.sol +++ b/contracts/IdentityManager.sol @@ -208,4 +208,12 @@ contract IdentityManager { t := eq(a, and(mask, calldataload(4))) } } + + function isOwner(address identity, address user) constant returns (bool) { + return owners[identity][user] != 0; + } + + function isRecovery(address identity, address key) constant returns (bool) { + return recoveryKeys[identity] == key; + } } diff --git a/test/identityManager.js b/test/identityManager.js index 4be2c1d..4b2c83e 100644 --- a/test/identityManager.js +++ b/test/identityManager.js @@ -149,6 +149,8 @@ contract('IdentityManager', (accounts) => { }) it('owner can add other owner', async function() { + let isOwner = await identityManager.isOwner(proxy.address, user5, {from: user1}) + assert.isFalse(isOwner, 'user5 should not be owner yet') let tx = await identityManager.addOwner(user1, proxy.address, user5, {from: user1}) let log = tx.logs[0] assert.equal(log.event, 'OwnerAdded', 'should trigger correct event') @@ -161,6 +163,8 @@ contract('IdentityManager', (accounts) => { assert.equal(log.args.instigator, user1, 'Instigator key is set in event') + isOwner = await identityManager.isOwner(proxy.address, user5, {from: user1}) + assert.isTrue(isOwner, 'user5 should be owner now') }) it('owner is rateLimited on some functions', async function() { @@ -328,6 +332,8 @@ contract('IdentityManager', (accounts) => { }) it('can change recoveryKey', async function() { + let isRecovery = await identityManager.isRecovery(proxy.address, recoveryKey2, {from: user1}) + assert.isFalse(isRecovery, 'recoveryKey2 should not be recovery yet') let tx = await identityManager.changeRecovery(user2, proxy.address, recoveryKey2, {from: user2}) const log = tx.logs[0] assert.equal(log.args.recoveryKey, @@ -336,6 +342,8 @@ contract('IdentityManager', (accounts) => { assert.equal(log.args.instigator, user2, 'Instigator key is set in event') + isRecovery = await identityManager.isRecovery(proxy.address, recoveryKey2, {from: user1}) + assert.isTrue(isRecovery, 'recoveryKey2 should be recovery now') }) }) })