fix: require status of Message.None in process() (#99)

* fix: require status of Message.None in process()

* fix: change err message

* test: adds test for trying to prove same message again
buddies-main-deployment
Luke Tchang 4 years ago committed by GitHub
parent e4cb3f55e1
commit b6da94665f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      solidity/optics-core/contracts/Replica.sol
  2. 18
      solidity/optics-core/test/Replica.test.js

@ -187,6 +187,7 @@ contract ProcessingReplica is Replica {
bytes32[32] calldata proof,
uint256 index
) public returns (bool) {
require(messages[leaf] == MessageStatus.None, "!MessageStatus.None");
bytes32 actual = MerkleLib.branchRoot(leaf, proof, index);
// NB:

@ -195,6 +195,22 @@ describe('Replica', async () => {
expect(await replica.messages(leaf)).to.equal(optics.MessageStatus.PENDING);
});
it('Rejects an already-proven message', async () => {
const testCase = testCases[0];
let { leaf, index, path } = testCase.proofs[0];
await replica.setCurrentRoot(testCase.expectedRoot);
// Prove message, which changes status to MessageStatus.Pending
await replica.prove(leaf, path, index);
expect(await replica.messages(leaf)).to.equal(optics.MessageStatus.PENDING);
// Try to prove message again
await expect(replica.prove(leaf, path, index)).to.be.revertedWith(
'!MessageStatus.None',
);
});
it('Rejects invalid message proof', async () => {
// Use 1st proof of 1st merkle vector test case
const testCase = testCases[0];
@ -235,7 +251,7 @@ describe('Replica', async () => {
'0x',
);
// Set message status to Message.Pending
// Set message status to MessageStatus.Pending
await replica.setMessagePending(formattedMessage);
// Ensure proper static call return value

Loading…
Cancel
Save