From 7695b461fb68572afff7d1f8fa637bf5985d6fcd Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 13 Mar 2018 14:37:15 -0400 Subject: [PATCH] Updated factory unit test and docs to include delay functionality --- test/factory.js | 25 ++++++++++++++++++++---- utils/identityUtils.js | 44 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/test/factory.js b/test/factory.js index 32d9b35..84375c1 100644 --- a/test/factory.js +++ b/test/factory.js @@ -65,18 +65,35 @@ contract('IdentityFactory', function(accounts) { let tx1 = await identity.execute( identity.address, 0, - idUtils.encode.updateUpdatableInstance(updatedIdentityKernel.address), + idUtils.encode.updateRequestUpdatableInstance(updatedIdentityKernel.address), {from: accounts[0]} ); + assert.strictEqual(tx1.logs[tx1.logs.length - 1].event, "Executed"); + // Updating EVM timestamp to test delay + const plus31days = 60 * 60 * 24 * 31; + + web3.currentProvider.send({jsonrpc: "2.0", method: "evm_increaseTime", params: [plus31days], id: 0}); + web3.currentProvider.send({jsonrpc: "2.0", method: "evm_mine", params: [], id: 0}) + + // Confirm update + let tx2 = await identity.execute( + identity.address, + 0, + idUtils.encode.updateConfirmUpdatableInstance(updatedIdentityKernel.address), + {from: accounts[0]} + ); + + assert.strictEqual(tx2.logs[tx2.logs.length - 1].event, "Executed"); + // Calling function available in updated identity kernel let updatedIdentity1 = await UpdatedIdentityKernel.at(identity.address, {from: accounts[0]}) - let tx2 = await updatedIdentity1.test({from: accounts[0]}); + let tx3 = await updatedIdentity1.test({from: accounts[0]}); - assert.strictEqual(tx2.logs[tx2.logs.length - 1].event, "TestFunctionExecuted"); + assert.strictEqual(tx3.logs[tx3.logs.length - 1].event, "TestFunctionExecuted"); assert.equal( - tx2.logs[tx2.logs.length - 1].args.minApprovalsByManagementKeys.toString(10), + tx3.logs[tx3.logs.length - 1].args.minApprovalsByManagementKeys.toString(10), 1, identity.address + " wasn't updated to last version"); }) diff --git a/utils/identityUtils.js b/utils/identityUtils.js index 91613a4..5998092 100644 --- a/utils/identityUtils.js +++ b/utils/identityUtils.js @@ -117,6 +117,45 @@ const _updateUpdatableInstance = function(address){ }, [address]); } +const _updateRequestUpdatableInstance = function(address){ + if(!/^(0x)?[0-9a-f]{0,40}$/i.test(address)) + throw new Error('Address "'+ address +'" is not a valid Ethereum address.'); + + return web3EthAbi.encodeFunctionCall({ + name: 'updateRequestUpdatableInstance', + type: 'function', + inputs: [{ + type: 'address', + name: '_kernel' + }] + }, [address]); +} + +const _updateConfirmUpdatableInstance = function(address){ + if(!/^(0x)?[0-9a-f]{0,40}$/i.test(address)) + throw new Error('Address "'+ address +'" is not a valid Ethereum address.'); + + return web3EthAbi.encodeFunctionCall({ + name: 'updateConfirmUpdatableInstance', + type: 'function', + inputs: [{ + type: 'address', + name: '_kernel' + }] + }, [address]); +} + +const _updateCancelUpdatableInstance = function(address){ + if(!/^(0x)?[0-9a-f]{0,40}$/i.test(address)) + throw new Error('Address "'+ address +'" is not a valid Ethereum address.'); + + return web3EthAbi.encodeFunctionCall({ + name: 'updateCancelUpdatableInstance', + type: 'function', + inputs: [] + }, []); +} + @@ -128,6 +167,9 @@ module.exports = { removeKey: _removeKey, setMinimumApprovalsByKeyType: _setMinimumApprovalsByKeyType, setupRecovery: _setupRecovery, - updateUpdatableInstance: _updateUpdatableInstance + updateUpdatableInstance: _updateUpdatableInstance, + updateRequestUpdatableInstance: _updateRequestUpdatableInstance, + updateConfirmUpdatableInstance: _updateConfirmUpdatableInstance, + updateCancelUpdatableInstance: _updateCancelUpdatableInstance } } \ No newline at end of file