Skip to content

Commit

Permalink
Merge pull request #83 from OriginTrail/v6/additional-identity-test
Browse files Browse the repository at this point in the history
check for key removal
  • Loading branch information
NZT48 authored Dec 9, 2022
2 parents 74230a9 + e504cc1 commit 8221ba1
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/identity.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { ethers } = require('ethers');
const {assert} = require('chai');
const truffleAssert = require('truffle-assertions');
const Hub = artifacts.require('Hub');
Expand Down Expand Up @@ -92,6 +93,30 @@ contract('DKG v6 Identity', async (accounts) => {
assert(keys.length === 0, 'Failed to get empty keys array for un-existent identity id');
});

it('Create an identity, add another admin key, then remove old; expect to work', async () => {
let opKey = ethers.utils.keccak256(ethers.utils.solidityPack(["address"], [accounts[3]])),
adminKey = ethers.utils.keccak256(ethers.utils.solidityPack(["address"], [accounts[4]])),
newAdminKey = ethers.utils.keccak256(ethers.utils.solidityPack(["address"], [accounts[5]]));

let result = await identity.createIdentity(accounts[3], accounts[4], {from: accounts[0]});
truffleAssert.eventEmitted(result, 'IdentityCreated');

const identityId = await identityStorage.getIdentityId(accounts[3]);

assert.equal(await identityStorage.keyHasPurpose(identityId, adminKey, ADMIN_KEY), true);
assert.equal(await identityStorage.keyHasPurpose(identityId, opKey, OPERATIONAL_KEY), true);

let resultAddKey = await identity.addKey(identityId, newAdminKey, ADMIN_KEY, ECDSA, {from: accounts[4]});

// truffleAssert.eventEmitted(resultAddKey, 'KeyAdded');
assert.equal(await identityStorage.keyHasPurpose(identityId, newAdminKey, ADMIN_KEY), ADMIN_KEY);

let resultRemoveKey = await identity.removeKey(identityId, adminKey, {from: accounts[5]});
// truffleAssert.eventEmitted(resultRemoveKey, 'KeyRemoved');

assert.equal(await identityStorage.keyHasPurpose(identityId, adminKey, ADMIN_KEY), false);
});

// it('Create an identity; expect identity created', async () => {
// const txReceipt = await identity.createIdentity(operational, admin, {from: accounts[0] });
// identityId = txReceipt.logs[0].args.identityId.toString();
Expand Down

0 comments on commit 8221ba1

Please sign in to comment.