Skip to content

Commit

Permalink
test: Add tests for WH Message delivery failure case
Browse files Browse the repository at this point in the history
  • Loading branch information
ankurdubey521 committed Jul 11, 2023
1 parent 0d4f681 commit 6999381
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion test/wormhole/MessageDelivery.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ pragma solidity 0.8.19;

import "test/base/WormholeTestBase.sol";
import "wormhole-application/interfaces/IWormholeApplication.sol";
import "ta-transaction-allocation/interfaces/ITATransactionAllocation.sol";

contract WormholeMessageDeliveryTest is WormholeTestBase, ITATransactionAllocationEventsErrors {
using BytesLib for bytes;

contract WormholeMessageDeliveryTest is WormholeTestBase {
function setUp() public override {
super.setUp();
_configureWormholeEnvironment();
Expand Down Expand Up @@ -116,4 +119,53 @@ contract WormholeMessageDeliveryTest is WormholeTestBase {

assertEq(receiverTarget.sum(), payloadSum, "Payload was not delivered");
}

function testShouldNotGenerateReceiptIfVAAIsInvalid() external {
uint256 payload = 0x123;

// Send payload from source chain
vm.selectFork(sourceFork);
vm.recordLogs();
receiverSource.sendPayload(
targetChain, payload, Gas.wrap(100000), TargetNative.wrap(0), address(receiverTarget)
);
Vm.Log[] memory deliveryVMLogs = guardianSource.fetchWormholeMessageFromLog(vm.getRecordedLogs());
assertTrue(deliveryVMLogs.length > 0, "No delivery request was published");

// Sign the delivery request
IWormhole.VM memory deliveryVM = guardianSource.parseVMFromLogs(deliveryVMLogs[0]);
bytes memory signedDeliveryVAA = _signWormholeVM(deliveryVM, sourceChain);

// Execute the delivery request on destination chain
vm.selectFork(targetFork);
assertEq(receiverTarget.sum(), 0, "Payload was delivered before execution");

// Mock wormhole core to revert when parseAndVerifyVM is called
bytes memory error = abi.encode("MOCKED_REVERT");
vm.mockCallRevert(
address(wormholeTarget), abi.encodeWithSelector(wormholeTarget.parseAndVerifyVM.selector), error
);

bytes memory txn =
abi.encodeCall(IWormholeApplication.executeWormhole, (new bytes[](0), signedDeliveryVAA, bytes("")));
bytes[] memory txns = new bytes[](1);
txns[0] = txn;
uint256[] memory forwardedNativeAmounts = new uint256[](1);
forwardedNativeAmounts[0] = 1 ether;
(RelayerAddress relayerAddress, uint256 relayerGenerationIterations, uint256 selectedRelayerCdfIndex) =
_getRelayerAssignedToTx(txn);
_prankRA(relayerAddress);

vm.expectRevert(abi.encodeWithSelector(TransactionExecutionFailed.selector, 0, error));
ta.execute{value: forwardedNativeAmounts[0]}(
ITATransactionAllocation.ExecuteParams({
reqs: txns,
forwardedNativeAmounts: forwardedNativeAmounts,
relayerIndex: selectedRelayerCdfIndex,
relayerGenerationIterationBitmap: relayerGenerationIterations,
activeState: latestRelayerState,
latestState: latestRelayerState
})
);
}
}

0 comments on commit 6999381

Please sign in to comment.