Skip to content

Commit

Permalink
Define "expected behavior" tests for ExecutionHub
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiTimesChi committed Oct 30, 2023
1 parent 35e9211 commit 23a2803
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions packages/contracts-core/test/suite/hubs/ExecutionHub.t.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import {DISPUTE_TIMEOUT_NOTARY} from "../../../contracts/libs/Constants.sol";
import {
AlreadyExecuted,
AlreadyFailed,
DisputeTimeoutNotOver,
GasLimitTooLow,
GasSuppliedTooLow,
IncorrectDestinationDomain,
Expand Down Expand Up @@ -241,6 +243,56 @@ abstract contract ExecutionHubTest is AgentSecuredTest {
verify_messageStatusNone(msgLeaf);
}

function test_execute_base_revert_notaryWonDisputeTimeout() public {
address notary = domains[DOMAIN_LOCAL].agent;
address guard = domains[0].agent;
Random memory random = Random("Random Salt 1");
// Create some simple data
(RawBaseMessage memory rbm, RawHeader memory rh, SnapshotMock memory sm) = createDataRevertTest(random);
// Create messages and get origin proof
RawMessage memory rm = createBaseMessages(rbm, rh, localDomain());
msgPayload = rm.formatMessage();
msgLeaf = rm.castToMessage().leaf();
bytes32[] memory originProof = getLatestProof(rh.nonce - 1);
// Create snapshot proof
adjustSnapshot(sm);
(, bytes32[] memory snapProof) = prepareExecution(sm);
// initiate dispute
openTestDispute({guardIndex: agentIndex[guard], notaryIndex: agentIndex[notary]});
// Make sure that optimistic period is over
skip(rh.optimisticPeriod);
resolveTestDispute({slashedIndex: agentIndex[guard], rivalIndex: agentIndex[notary]});
skip(DISPUTE_TIMEOUT_NOTARY - 1);
vm.expectRevert(DisputeTimeoutNotOver.selector);
vm.prank(executor);
testedEH().execute(msgPayload, originProof, snapProof, sm.rsi.stateIndex, rbm.request.gasLimit);
}

function test_execute_base_afterNotaryDisputeTimeout() public {
address notary = domains[DOMAIN_LOCAL].agent;
address guard = domains[0].agent;
Random memory random = Random("Random Salt 2");
// Create some simple data
(RawBaseMessage memory rbm, RawHeader memory rh, SnapshotMock memory sm) = createDataRevertTest(random);
// Create messages and get origin proof
RawMessage memory rm = createBaseMessages(rbm, rh, localDomain());
msgPayload = rm.formatMessage();
msgLeaf = rm.castToMessage().leaf();
bytes32[] memory originProof = getLatestProof(rh.nonce - 1);
// Create snapshot proof
adjustSnapshot(sm);
(bytes32 snapRoot, bytes32[] memory snapProof) = prepareExecution(sm);
// initiate dispute
openTestDispute({guardIndex: agentIndex[guard], notaryIndex: agentIndex[notary]});
// Make sure that optimistic period is over
skip(rh.optimisticPeriod);
resolveTestDispute({slashedIndex: agentIndex[guard], rivalIndex: agentIndex[notary]});
skip(DISPUTE_TIMEOUT_NOTARY);
vm.prank(executor);
testedEH().execute(msgPayload, originProof, snapProof, sm.rsi.stateIndex, rbm.request.gasLimit);
verify_messageStatus(msgLeaf, snapRoot, sm.rsi.stateIndex, MessageStatus.Success, executor, executor);
}

function test_execute_base_revert_snapRootUnknown(Random memory random) public {
// Create some simple data
(RawBaseMessage memory rbm, RawHeader memory rh, SnapshotMock memory sm) = createDataRevertTest(random);
Expand Down

0 comments on commit 23a2803

Please sign in to comment.