The home for Hyperlane core contracts, sdk packages, and other infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hyperlane-monorepo/solidity/test/GasRouter.t.sol

123 lines
3.9 KiB

// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.13;
import "forge-std/Test.sol";
import "../contracts/test/TestGasRouter.sol";
import "../contracts/test/TestMailbox.sol";
import "../contracts/test/TestIsm.sol";
import "../contracts/test/TestInterchainGasPaymaster.sol";
import "../contracts/test/TestMerkleTreeHook.sol";
contract GasRouterTest is Test {
event DestinationGasSet(uint32 indexed domain, uint256 gas);
uint32 originDomain = 1;
uint32 remoteDomain = 2;
On chain gas oracles in the IGP (#1765) * Rough implementations of all gas oracles, done with StaticGasOracle & tests * more tests, beef up StorageGasOracle * Tests cleaned up, moved to Foundry test for IGP * rm StaticGasOracle, fix all tests * cleaning up * comment * yarn gas, better comments * Fix sdk test * Fix e2e * Rm LZ stuff * fix router test * Rm MockInterchainGasPaymaster * pr comments * Move to setGasConfigs instead of setGasConfig * fix test * nit * yarn gas * IGP deploy & checker tooling, script to update on-chain StorageGasOracle data (#1794) * Add IGP gas oracle to checker * Checker works * Support different gas oracle contracts in IGP deploy tooling too * Export some types * Build out set-storage-gas-oracle-values * nit * nit * rm comment * Add pricing data * nits * nearly there * haven't tested e2e yet, but added new proxy upgrade logic to set gas oracles in IGP in upgradeAndCall * pr comments * lots * Move away from upgradeAndCall for IGP upgrade, trying to debug annoying dependency issue * Got working, cleaned a little * Add test to ensure a new implementation is deployed * yarn hyperlane * nits * cleaning * Map in description * Dedupe submission type logic * yarn gas * Separate beneficiary in IGP (#1801) * Add IGP gas oracle to checker * Checker works * Support different gas oracle contracts in IGP deploy tooling too * Export some types * Build out set-storage-gas-oracle-values * nit * nit * Add separate beneficiary to IGP * Checker / govern / deploy tooling * nits * Add compare-storage-gas-oracle * successful test upgrade, minor changes * Nits * Fix tests * Performed testne3 upgrade. Need to clean up code, but should probably use this for the mainnet upgrade * nit * update prices * Update gas prices and token exchange rates for mainnet * mainnet upgrade. needs lots of cleaning, but here it is in all its glory * Starting to clean up * more cleanup * Use updated submodules * yarn gas * nit * PR comments * yarn hyperlane * yarn gas
2 years ago
uint256 gasPrice; // The gas price used in IGP.quoteGasPayment
TestMailbox originMailbox;
TestMailbox remoteMailbox;
TestGasRouter originRouter;
TestGasRouter remoteRouter;
function setUp() public {
originMailbox = new TestMailbox(originDomain);
TestIsm ism = new TestIsm();
TestInterchainGasPaymaster igp = new TestInterchainGasPaymaster();
TestMerkleTreeHook _requiredHook = new TestMerkleTreeHook(
address(originMailbox)
);
originMailbox.initialize(
address(this),
address(ism),
address(igp),
address(_requiredHook)
);
remoteMailbox = new TestMailbox(remoteDomain);
remoteMailbox.initialize(
address(this),
address(ism),
address(igp),
address(_requiredHook)
);
On chain gas oracles in the IGP (#1765) * Rough implementations of all gas oracles, done with StaticGasOracle & tests * more tests, beef up StorageGasOracle * Tests cleaned up, moved to Foundry test for IGP * rm StaticGasOracle, fix all tests * cleaning up * comment * yarn gas, better comments * Fix sdk test * Fix e2e * Rm LZ stuff * fix router test * Rm MockInterchainGasPaymaster * pr comments * Move to setGasConfigs instead of setGasConfig * fix test * nit * yarn gas * IGP deploy & checker tooling, script to update on-chain StorageGasOracle data (#1794) * Add IGP gas oracle to checker * Checker works * Support different gas oracle contracts in IGP deploy tooling too * Export some types * Build out set-storage-gas-oracle-values * nit * nit * rm comment * Add pricing data * nits * nearly there * haven't tested e2e yet, but added new proxy upgrade logic to set gas oracles in IGP in upgradeAndCall * pr comments * lots * Move away from upgradeAndCall for IGP upgrade, trying to debug annoying dependency issue * Got working, cleaned a little * Add test to ensure a new implementation is deployed * yarn hyperlane * nits * cleaning * Map in description * Dedupe submission type logic * yarn gas * Separate beneficiary in IGP (#1801) * Add IGP gas oracle to checker * Checker works * Support different gas oracle contracts in IGP deploy tooling too * Export some types * Build out set-storage-gas-oracle-values * nit * nit * Add separate beneficiary to IGP * Checker / govern / deploy tooling * nits * Add compare-storage-gas-oracle * successful test upgrade, minor changes * Nits * Fix tests * Performed testne3 upgrade. Need to clean up code, but should probably use this for the mainnet upgrade * nit * update prices * Update gas prices and token exchange rates for mainnet * mainnet upgrade. needs lots of cleaning, but here it is in all its glory * Starting to clean up * more cleanup * Use updated submodules * yarn gas * nit * PR comments * yarn hyperlane * yarn gas
2 years ago
// Same for origin and remote
gasPrice = igp.gasPrice();
originRouter = new TestGasRouter(address(originMailbox));
remoteRouter = new TestGasRouter(address(remoteMailbox));
originRouter.enrollRemoteRouter(
remoteDomain,
TypeCasts.addressToBytes32(address(remoteRouter))
);
remoteRouter.enrollRemoteRouter(
originDomain,
TypeCasts.addressToBytes32(address(originRouter))
);
}
function setDestinationGas(
GasRouter gasRouter,
uint32 domain,
uint256 gas
) public {
gasRouter.setDestinationGas(domain, gas);
}
function testSetDestinationGas(uint256 gas) public {
vm.expectEmit(true, true, true, true);
emit GasRouter.GasSet(originDomain, gas);
setDestinationGas(remoteRouter, originDomain, gas);
assertEq(remoteRouter.destinationGas(originDomain), gas);
setDestinationGas(originRouter, remoteDomain, gas);
assertEq(originRouter.destinationGas(remoteDomain), gas);
}
function testQuoteGasPayment(uint256 gas) public {
vm.assume(gas > 0 && type(uint256).max / gas > gasPrice);
setDestinationGas(originRouter, remoteDomain, gas);
assertEq(originRouter.quoteGasPayment(remoteDomain), gas * gasPrice);
setDestinationGas(remoteRouter, originDomain, gas);
assertEq(remoteRouter.quoteGasPayment(originDomain), gas * gasPrice);
}
uint256 refund = 0;
bool passRefund = true;
receive() external payable {
refund = msg.value;
assert(passRefund);
}
function testDispatch(uint256 gas) public {
vm.assume(gas > 0 && type(uint256).max / gas > gasPrice);
vm.deal(address(this), gas * gasPrice);
setDestinationGas(originRouter, remoteDomain, gas);
uint256 requiredPayment = gas * gasPrice;
vm.expectRevert("IGP: insufficient interchain gas payment");
originRouter.dispatch{value: requiredPayment - 1}(remoteDomain, "");
vm.deal(address(this), requiredPayment + 1);
originRouter.dispatch{value: requiredPayment + 1}(remoteDomain, "");
assertEq(refund, 1);
// Reset the IGP balance to avoid a balance overflow
vm.deal(address(originMailbox.defaultHook()), 0);
vm.deal(address(this), requiredPayment + 1);
passRefund = false;
vm.expectRevert(
"Address: unable to send value, recipient may have reverted"
);
originRouter.dispatch{value: requiredPayment + 1}(remoteDomain, "");
}
}