|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +pragma solidity ^0.8.13; |
| 3 | + |
| 4 | +import {Test} from "forge-std/Test.sol"; |
| 5 | +import {Executor} from "../src/Executor.sol"; |
| 6 | +import {ExecutorQuoterRouter} from "../src/ExecutorQuoterRouter.sol"; |
| 7 | + |
| 8 | +contract ExecutorQuoterRouterTest is Test { |
| 9 | + Executor public executor; |
| 10 | + ExecutorQuoterRouter public executorQuoterRouter; |
| 11 | + |
| 12 | + uint16 constant OUR_CHAIN = 10002; |
| 13 | + bytes32 constant UPDATE_IMPLEMENTATION = 0x000000000000000000000000aaa039ee238299b23cb4f9cd40775589efa962fd; |
| 14 | + bytes32 constant BAD_UPDATE_IMPLEMENTATION = 0x100000000000000000000000aaa039ee238299b23cb4f9cd40775589efa962fd; |
| 15 | + uint64 constant EXPIRY = 1762880900; |
| 16 | + |
| 17 | + function setUp() public { |
| 18 | + executor = new Executor(OUR_CHAIN); |
| 19 | + executorQuoterRouter = new ExecutorQuoterRouter(address(executor)); |
| 20 | + } |
| 21 | + |
| 22 | + function makeAndSignGovernance(uint16 chainId, address quoterAddr, bytes32 updateImplementation, uint256 quoterPk) |
| 23 | + private |
| 24 | + pure |
| 25 | + returns (bytes memory) |
| 26 | + { |
| 27 | + bytes memory govBody = abi.encodePacked(hex"45473031", chainId, quoterAddr, updateImplementation, EXPIRY); |
| 28 | + bytes32 digest = keccak256(govBody); |
| 29 | + (uint8 v, bytes32 r, bytes32 s) = vm.sign(quoterPk, digest); |
| 30 | + return abi.encodePacked(govBody, r, s, v); |
| 31 | + } |
| 32 | + |
| 33 | + function test_updateQuoterContract() public { |
| 34 | + (address alice, uint256 alicePk) = makeAddrAndKey("alice"); |
| 35 | + executorQuoterRouter.updateQuoterContract( |
| 36 | + makeAndSignGovernance(OUR_CHAIN, alice, UPDATE_IMPLEMENTATION, alicePk) |
| 37 | + ); |
| 38 | + } |
| 39 | + |
| 40 | + function test_updateQuoterContractChainIdMismatch() public { |
| 41 | + (address alice, uint256 alicePk) = makeAddrAndKey("alice"); |
| 42 | + uint16 badChain = OUR_CHAIN + 1; |
| 43 | + vm.expectRevert(abi.encodeWithSelector(ExecutorQuoterRouter.ChainIdMismatch.selector, badChain, OUR_CHAIN)); |
| 44 | + executorQuoterRouter.updateQuoterContract( |
| 45 | + makeAndSignGovernance(badChain, alice, UPDATE_IMPLEMENTATION, alicePk) |
| 46 | + ); |
| 47 | + } |
| 48 | + |
| 49 | + function test_updateQuoterContractBadImplementation() public { |
| 50 | + (address alice, uint256 alicePk) = makeAddrAndKey("alice"); |
| 51 | + vm.expectRevert( |
| 52 | + abi.encodeWithSelector(ExecutorQuoterRouter.NotAnEvmAddress.selector, BAD_UPDATE_IMPLEMENTATION) |
| 53 | + ); |
| 54 | + executorQuoterRouter.updateQuoterContract( |
| 55 | + makeAndSignGovernance(OUR_CHAIN, alice, BAD_UPDATE_IMPLEMENTATION, alicePk) |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + function test_updateQuoterContractExpired() public { |
| 60 | + vm.warp(1762880901); |
| 61 | + vm.expectRevert(abi.encodeWithSelector(ExecutorQuoterRouter.GovernanceExpired.selector, EXPIRY)); |
| 62 | + (address alice, uint256 alicePk) = makeAddrAndKey("alice"); |
| 63 | + executorQuoterRouter.updateQuoterContract( |
| 64 | + makeAndSignGovernance(OUR_CHAIN, alice, UPDATE_IMPLEMENTATION, alicePk) |
| 65 | + ); |
| 66 | + } |
| 67 | + |
| 68 | + function test_updateQuoterContractBadSignature() public { |
| 69 | + vm.expectRevert(abi.encodeWithSelector(ExecutorQuoterRouter.InvalidSignature.selector)); |
| 70 | + executorQuoterRouter.updateQuoterContract( |
| 71 | + hex"4547303127125241c9276698439fef2780dbab76fec90b633fbd000000000000000000000000aaa039ee238299b23cb4f9cd40775589efa962fd00000000691248922111b9ac29b0d785d41e8f8c66980f4651c9a35c066e875cab67fd625e5e59c62fc65912c14a2c2ee99acdd809397f932bcf35ba7d269f02f96e8688588145701b" |
| 72 | + ); |
| 73 | + } |
| 74 | + |
| 75 | + function test_updateQuoterContractQuoterMismatch() public { |
| 76 | + (address alice,) = makeAddrAndKey("alice"); |
| 77 | + (, uint256 bobPk) = makeAddrAndKey("bob"); |
| 78 | + vm.expectRevert(abi.encodeWithSelector(ExecutorQuoterRouter.InvalidSignature.selector)); |
| 79 | + executorQuoterRouter.updateQuoterContract(makeAndSignGovernance(OUR_CHAIN, alice, UPDATE_IMPLEMENTATION, bobPk)); |
| 80 | + } |
| 81 | +} |
0 commit comments