Updated factory unit test and docs to include delay functionality

This commit is contained in:
Richard Ramos 2018-03-13 14:37:15 -04:00
parent f6ec000091
commit 7695b461fb
2 changed files with 64 additions and 5 deletions

View File

@ -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");
})

View File

@ -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
}
}