- Added event to inform of an identity instance upgrade

- Added test units for Identity factory and its kernel upgrading
This commit is contained in:
Richard Ramos 2018-02-28 11:47:59 -04:00
parent 8ed73f82d7
commit e8cc00be53
2 changed files with 69 additions and 4 deletions

View File

@ -0,0 +1,20 @@
pragma solidity ^0.4.17;
import "../identity/IdentityKernel.sol";
contract UpdatedIdentityKernel is IdentityKernel {
function initIdentity(address _caller) external {
require(minimumApprovalsByKeyType[MANAGEMENT_KEY] == 0);
_addKey(bytes32(_caller), MANAGEMENT_KEY, 0);
minimumApprovalsByKeyType[MANAGEMENT_KEY] = 1;
}
event TestFunctionExecuted();
function test() public {
TestFunctionExecuted();
}
}

View File

@ -1,21 +1,66 @@
const TestUtils = require("./TestUtils.js")
const Identity = artifacts.require("./identity/Identity.sol");
const IdentityFactory = artifacts.require("./identity/IdentityFactory.sol");
const UpdatableInstance = artifacts.require('./deploy/UpdatableInstance.sol');
const UpdatedIdentityKernel = artifacts.require("./tests/UpdatedIdentityKernel.sol");
contract('IdentityFactory', function(accounts) {
let identityFactory;
let identity;
let updatedIdentity;
let updatedIdentityKernel;
beforeEach(async () => {
identityFactory = await IdentityFactory.new("0x0", {from: accounts[0]});
before(async () => {
identityFactory = await IdentityFactory.new("0xaaa", {from: accounts[0]});
})
describe("IdentityFactory()", () => {
it("Creates a new identity", async () => {
let tx = await identityFactory.createIdentity({from: accounts[0]});
const logEntry = tx.logs[0];
assert.strictEqual(logEntry.event, "IdentityCreated");
it("test1", async () => {
identity = await Identity.at(logEntry.args.instance, {from: accounts[0]})
assert.equal(
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[0])),
1,
identity.address + ".getKeyPurpose("+accounts[0]+") is not MANAGEMENT_KEY")
});
it("Registers a updated identity contract", async() => {
updatedIdentityKernel = await UpdatedIdentityKernel.new({from: accounts[0]});
let tx = await identityFactory.setKernel(updatedIdentityKernel.address, "0xbbb");
assert.strictEqual(tx.logs[0].event, "NewKernel");
});
it("Creates a new identity using latest version", async() => {
let tx = await identityFactory.createIdentity({from: accounts[0]});
const logEntry = tx.logs[0];
assert.strictEqual(logEntry.event, "IdentityCreated");
updatedIdentity = await UpdatedIdentityKernel.at(logEntry.args.instance, {from: accounts[0]})
tx = await updatedIdentity.test({from: accounts[0]});
assert.strictEqual(tx.logs[0].event, "TestFunctionExecuted");
// Test if it still executes identity functions as expected
let baseIdentity = await Identity.at(updatedIdentity.address, {from: accounts[0]})
assert.equal(
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[0])),
1,
identity.address + ".getKeyPurpose("+accounts[0]+") is not MANAGEMENT_KEY")
});
it("Updates an identity to the latest version", async() => {
})
});
});