-
-
Save tinchoabbate/1a2120e37b141f63d9e6e3ce9cde23ff to your computer and use it in GitHub Desktop.
OpenZeppelin Audit of UMA contracts - Test for mutliple parties in multiple contracts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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