Skip to content

Instantly share code, notes, and snippets.

@tinchoabbate
Last active March 27, 2020 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tinchoabbate/1a2120e37b141f63d9e6e3ce9cde23ff to your computer and use it in GitHub Desktop.
Save tinchoabbate/1a2120e37b141f63d9e6e3ce9cde23ff to your computer and use it in GitHub Desktop.
OpenZeppelin Audit of UMA contracts - Test for mutliple parties in multiple contracts
// Place this `it` block in the `core/test/oracle/Registry.js` file, right after the existing `Contract creation` block.
it.only("OZ AUDIT - Register multiple contracts with duplicate parties", async function () {
await registry.addMember(RegistryRolesEnum.CONTRACT_CREATOR, creator1, { from: owner });
const party = web3.utils.randomHex(20);
const party2 = web3.utils.randomHex(20);
await registry.registerContract(
[party, party, party, party2],
contract1,
{ from: creator1 }
);
await registry.registerContract(
[party, party2],
contract2,
{ from: creator1 }
);
let partyContracts = await registry.getRegisteredContracts(party);
assert.equal(partyContracts.length, 4);
assert.isTrue(areAddressesEqual(partyContracts[0], contract1));
assert.isTrue(areAddressesEqual(partyContracts[1], contract1));
assert.isTrue(areAddressesEqual(partyContracts[2], contract1));
assert.isTrue(areAddressesEqual(partyContracts[3], contract2));
assert.isTrue(
await registry.isPartyMemberOfContract(party, contract1)
);
assert.isTrue(
await registry.isPartyMemberOfContract(party, contract2)
);
assert.equal((await registry.getAllRegisteredContracts()).length, 2);
// Remove party from the contract
await registry.removePartyFromContract(party, {from: contract1});
// The party is still member of the contract
assert.isTrue(
await registry.isPartyMemberOfContract(party, contract1)
);
partyContracts = await registry.getRegisteredContracts(party);
assert.equal(partyContracts.length, 3);
// Remove the party from the contract, again
await registry.removePartyFromContract(party, {from: contract1});
partyContracts = await registry.getRegisteredContracts(party);
assert.equal(partyContracts.length, 2);
assert.isTrue(areAddressesEqual(partyContracts[0], contract2));
// We've reached an inconsistent state:
assert.isTrue(areAddressesEqual(partyContracts[1], contract1)); // This ...
assert.isFalse(
await registry.isPartyMemberOfContract(party, contract1) // ... contradicts this
);
// Now trying to remove the party from the contract fails
assert(
await didContractThrow(registry.removePartyFromContract(party, {from: contract1}))
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment