|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +pragma solidity ^0.8.13; |
| 3 | + |
| 4 | +import {Test, console} from "forge-std/Test.sol"; |
| 5 | +import {RelayInstructions} from "../../src/libraries/executor/RelayInstructions.sol"; |
| 6 | + |
| 7 | +//from https://github.com/wormholelabs-xyz/example-messaging-executor/blob/ec5daea3c03f8860a62c23e28db5c6dc8771a9ce/evm/test/RelayInstructions.t.sol |
| 8 | +contract RelayInstructionsTest is Test { |
| 9 | + function test_encodeGas() public { |
| 10 | + uint128 gasLimit = 123456000; |
| 11 | + uint128 msgVal = 42000; |
| 12 | + bytes memory expected = abi.encodePacked(uint8(1), gasLimit, msgVal); |
| 13 | + bytes memory buf = RelayInstructions.encodeGas(gasLimit, msgVal); |
| 14 | + assertEq(expected, buf); |
| 15 | + } |
| 16 | + |
| 17 | + function test_encodeGasDropOffInstructions() public { |
| 18 | + uint128 dropOff = 123456000; |
| 19 | + bytes32 recipient = bytes32(uint256(uint160(0xdeadbeef))); |
| 20 | + bytes memory expected = abi.encodePacked(uint8(2), dropOff, recipient); |
| 21 | + bytes memory buf = RelayInstructions.encodeGasDropOffInstructions(dropOff, recipient); |
| 22 | + assertEq(expected, buf); |
| 23 | + } |
| 24 | + |
| 25 | + function test_multipleInstructions() public { |
| 26 | + uint128 gasLimit = 123456000; |
| 27 | + uint128 msgVal = 42000; |
| 28 | + uint128 dropOff = 123456000; |
| 29 | + bytes32 recipient = bytes32(uint256(uint160(0xdeadbeef))); |
| 30 | + bytes memory expected = abi.encodePacked(uint8(1), gasLimit, msgVal, uint8(2), dropOff, recipient); |
| 31 | + bytes memory buf = abi.encodePacked( |
| 32 | + RelayInstructions.encodeGas(gasLimit, msgVal), |
| 33 | + RelayInstructions.encodeGasDropOffInstructions(dropOff, recipient) |
| 34 | + ); |
| 35 | + assertEq(expected, buf); |
| 36 | + } |
| 37 | +} |
0 commit comments