|
| 1 | +// SPDX-License-Identifier: MIT OR Apache-2.0 |
| 2 | +pragma solidity 0.8.26; |
| 3 | + |
| 4 | +// test contracts |
| 5 | +import {Transactor} from "../../src/Transactor.sol"; |
| 6 | +import {Passage} from "../../src/passage/Passage.sol"; |
| 7 | +// utils |
| 8 | +import {SignetStdTest} from "../SignetStdTest.t.sol"; |
| 9 | +import {Test, console2} from "forge-std/Test.sol"; |
| 10 | + |
| 11 | +contract TransactFuzzTest is SignetStdTest { |
| 12 | + Transactor public target; |
| 13 | + |
| 14 | + event Transact( |
| 15 | + uint256 indexed rollupChainId, |
| 16 | + address indexed sender, |
| 17 | + address indexed to, |
| 18 | + bytes data, |
| 19 | + uint256 value, |
| 20 | + uint256 gas, |
| 21 | + uint256 maxFeePerGas |
| 22 | + ); |
| 23 | + |
| 24 | + event GasConfigured(uint256 perBlock, uint256 perTransact); |
| 25 | + |
| 26 | + // Passage event |
| 27 | + event Enter(uint256 indexed rollupChainId, address indexed rollupRecipient, uint256 amount); |
| 28 | + |
| 29 | + function setUp() public virtual { |
| 30 | + // deploy target |
| 31 | + target = HOST_TRANSACTOR; |
| 32 | + } |
| 33 | + |
| 34 | + function test_transact( |
| 35 | + uint256 rollupChainId, |
| 36 | + address sender, |
| 37 | + address to, |
| 38 | + bytes memory data, |
| 39 | + uint256 value, |
| 40 | + uint256 gas, |
| 41 | + uint256 maxFeePerGas |
| 42 | + ) public { |
| 43 | + vm.assume(gas <= target.perTransactGasLimit() && gas <= target.perBlockGasLimit()); |
| 44 | + |
| 45 | + vm.startPrank(sender); |
| 46 | + vm.expectEmit(address(target)); |
| 47 | + emit Transact(rollupChainId, sender, to, data, value, gas, maxFeePerGas); |
| 48 | + target.transact(rollupChainId, to, data, value, gas, maxFeePerGas); |
| 49 | + } |
| 50 | + |
| 51 | + function test_enterTransact_emitsEnter( |
| 52 | + uint256 rollupChainId, |
| 53 | + address to, |
| 54 | + bytes memory data, |
| 55 | + uint256 value, |
| 56 | + uint256 gas, |
| 57 | + uint256 maxFeePerGas, |
| 58 | + uint256 amount |
| 59 | + ) public { |
| 60 | + vm.assume(gas <= target.perTransactGasLimit() && gas <= target.perBlockGasLimit()); |
| 61 | + vm.assume(amount > 0 && amount < payable(address(this)).balance); |
| 62 | + |
| 63 | + vm.expectEmit(address(HOST_PASSAGE)); |
| 64 | + emit Enter(rollupChainId, address(this), amount); |
| 65 | + target.transact{value: amount}(rollupChainId, to, data, value, gas, maxFeePerGas); |
| 66 | + } |
| 67 | + |
| 68 | + function test_enterTransact_emitsTransact( |
| 69 | + uint256 rollupChainId, |
| 70 | + address to, |
| 71 | + bytes memory data, |
| 72 | + uint256 value, |
| 73 | + uint256 gas, |
| 74 | + uint256 maxFeePerGas, |
| 75 | + uint256 amount |
| 76 | + ) public { |
| 77 | + vm.assume(gas <= target.perTransactGasLimit() && gas <= target.perBlockGasLimit()); |
| 78 | + vm.assume(amount > 0 && amount < payable(address(this)).balance); |
| 79 | + |
| 80 | + vm.expectEmit(address(target)); |
| 81 | + emit Transact(rollupChainId, address(this), to, data, value, gas, maxFeePerGas); |
| 82 | + target.transact{value: amount}(rollupChainId, to, data, value, gas, maxFeePerGas); |
| 83 | + } |
| 84 | + |
| 85 | + function test_transact_defaultChain( |
| 86 | + address sender, |
| 87 | + address to, |
| 88 | + bytes memory data, |
| 89 | + uint256 value, |
| 90 | + uint256 gas, |
| 91 | + uint256 maxFeePerGas |
| 92 | + ) public { |
| 93 | + vm.assume(gas <= target.perTransactGasLimit() && gas <= target.perBlockGasLimit()); |
| 94 | + |
| 95 | + vm.startPrank(sender); |
| 96 | + vm.expectEmit(address(target)); |
| 97 | + emit Transact(ROLLUP_CHAIN_ID, sender, to, data, value, gas, maxFeePerGas); |
| 98 | + target.transact(to, data, value, gas, maxFeePerGas); |
| 99 | + } |
| 100 | + |
| 101 | + function test_transactWithValue_defaultChain_emitsEnter( |
| 102 | + address to, |
| 103 | + bytes memory data, |
| 104 | + uint256 value, |
| 105 | + uint256 gas, |
| 106 | + uint256 maxFeePerGas, |
| 107 | + uint256 amount |
| 108 | + ) public { |
| 109 | + vm.assume(gas <= target.perTransactGasLimit() && gas <= target.perBlockGasLimit()); |
| 110 | + vm.assume(amount > 0 && amount < payable(address(this)).balance); |
| 111 | + |
| 112 | + vm.expectEmit(address(HOST_PASSAGE)); |
| 113 | + emit Enter(ROLLUP_CHAIN_ID, address(this), amount); |
| 114 | + target.transact{value: amount}(to, data, value, gas, maxFeePerGas); |
| 115 | + } |
| 116 | + |
| 117 | + function test_transactWithValue_defaultChain_emitsTransact( |
| 118 | + address to, |
| 119 | + bytes memory data, |
| 120 | + uint256 value, |
| 121 | + uint256 gas, |
| 122 | + uint256 maxFeePerGas, |
| 123 | + uint256 amount |
| 124 | + ) public { |
| 125 | + vm.assume(gas <= target.perTransactGasLimit() && gas <= target.perBlockGasLimit()); |
| 126 | + vm.assume(amount > 0 && amount < payable(address(this)).balance); |
| 127 | + |
| 128 | + vm.expectEmit(address(target)); |
| 129 | + emit Transact(ROLLUP_CHAIN_ID, address(this), to, data, value, gas, maxFeePerGas); |
| 130 | + target.transact{value: amount}(to, data, value, gas, maxFeePerGas); |
| 131 | + } |
| 132 | + |
| 133 | + function test_enterTransact_defaultChain_emitsEnter( |
| 134 | + uint256 rollupChainId, |
| 135 | + address recipient, |
| 136 | + address to, |
| 137 | + bytes memory data, |
| 138 | + uint256 value, |
| 139 | + uint256 gas, |
| 140 | + uint256 maxFeePerGas, |
| 141 | + uint256 amount |
| 142 | + ) public { |
| 143 | + vm.assume(gas <= target.perTransactGasLimit() && gas <= target.perBlockGasLimit()); |
| 144 | + vm.assume(amount > 0 && amount < payable(address(this)).balance); |
| 145 | + |
| 146 | + vm.expectEmit(address(HOST_PASSAGE)); |
| 147 | + emit Enter(rollupChainId, recipient, amount); |
| 148 | + target.enterTransact{value: amount}(rollupChainId, recipient, to, data, value, gas, maxFeePerGas); |
| 149 | + } |
| 150 | + |
| 151 | + function test_transactWithValue_defaultChain_emitsTransact( |
| 152 | + uint256 rollupChainId, |
| 153 | + address recipient, |
| 154 | + address to, |
| 155 | + bytes memory data, |
| 156 | + uint256 value, |
| 157 | + uint256 gas, |
| 158 | + uint256 maxFeePerGas, |
| 159 | + uint256 amount |
| 160 | + ) public { |
| 161 | + vm.assume(gas <= target.perTransactGasLimit() && gas <= target.perBlockGasLimit()); |
| 162 | + vm.assume(amount > 0 && amount < payable(address(this)).balance); |
| 163 | + |
| 164 | + vm.expectEmit(address(target)); |
| 165 | + emit Transact(rollupChainId, address(this), to, data, value, gas, maxFeePerGas); |
| 166 | + target.enterTransact{value: amount}(rollupChainId, recipient, to, data, value, gas, maxFeePerGas); |
| 167 | + } |
| 168 | + |
| 169 | + function test_transact_perTransactGasLimit( |
| 170 | + uint256 rollupChainId, |
| 171 | + address to, |
| 172 | + bytes memory data, |
| 173 | + uint256 value, |
| 174 | + uint256 gas, |
| 175 | + uint256 maxFeePerGas |
| 176 | + ) public { |
| 177 | + vm.assume(gas > target.perTransactGasLimit()); |
| 178 | + vm.expectRevert(Transactor.PerTransactGasLimit.selector); |
| 179 | + target.transact(rollupChainId, to, data, value, gas, maxFeePerGas); |
| 180 | + } |
| 181 | + |
| 182 | + function test_onlyGasAdmin(address caller, uint256 perBlockGas, uint256 perTransactGas) public { |
| 183 | + vm.assume(caller != GAS_ADMIN); |
| 184 | + vm.startPrank(caller); |
| 185 | + |
| 186 | + vm.expectRevert(Transactor.OnlyGasAdmin.selector); |
| 187 | + target.configureGas(perBlockGas, perTransactGas); |
| 188 | + } |
| 189 | + |
| 190 | + function test_configureGas(uint256 newPerBlock, uint256 newPerTransact) public { |
| 191 | + // configure gas |
| 192 | + vm.startPrank(GAS_ADMIN); |
| 193 | + vm.expectEmit(); |
| 194 | + emit GasConfigured(newPerBlock, newPerTransact); |
| 195 | + target.configureGas(newPerBlock, newPerTransact); |
| 196 | + vm.stopPrank(); |
| 197 | + |
| 198 | + assertEq(target.perBlockGasLimit(), newPerBlock); |
| 199 | + assertEq(target.perTransactGasLimit(), newPerTransact); |
| 200 | + } |
| 201 | +} |
0 commit comments