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/igps/OverheadIgp.t.sol

147 lines
4.3 KiB

// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.13;
import {Test} from "forge-std/Test.sol";
import {OverheadIgp} from "../../contracts/igps/OverheadIgp.sol";
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
import {TestInterchainGasPaymaster} from "../../contracts/test/TestInterchainGasPaymaster.sol";
contract OverheadIgpTest is Test {
OverheadIgp igp;
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
TestInterchainGasPaymaster innerIgp;
bytes32 constant testMessageId =
bytes32(
0xf00000000000000000000000000000000000000000000000000000000000000f
);
uint32 constant testDestinationDomain = 1234;
uint256 constant testGasOverhead = 123000;
uint256 constant testGasAmount = 50000;
address constant nonOwner = 0xCAfEcAfeCAfECaFeCaFecaFecaFECafECafeCaFe;
event InnerIgpSet(address innerIgp);
event DestinationGasOverheadSet(uint32 indexed domain, uint256 gasOverhead);
function setUp() public {
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
innerIgp = new TestInterchainGasPaymaster(address(this));
igp = new OverheadIgp(address(innerIgp));
}
function testInnerIgpSet() public {
assertEq(address(igp.innerIgp()), address(innerIgp));
}
function testPayForGas() public {
setTestDestinationGasOverhead();
uint256 testPayment = 123456789;
vm.expectCall(
address(innerIgp),
testPayment,
abi.encodeCall(
innerIgp.payForGas,
(
testMessageId,
testDestinationDomain,
testGasOverhead + testGasAmount,
msg.sender
)
)
);
igp.payForGas{value: testPayment}(
testMessageId,
testDestinationDomain,
testGasAmount,
msg.sender
);
}
function testQuoteGasPayment() public {
setTestDestinationGasOverhead();
vm.expectCall(
address(innerIgp),
abi.encodeCall(
innerIgp.quoteGasPayment,
(testDestinationDomain, testGasOverhead + testGasAmount)
)
);
igp.quoteGasPayment(testDestinationDomain, testGasAmount);
}
function testDestinationGasAmount() public {
setTestDestinationGasOverhead();
assertEq(
igp.destinationGasAmount(testDestinationDomain, testGasAmount),
testGasOverhead + testGasAmount
);
}
// Test that it doesn't revert, and just doesn't add any value to the
// provided gas amount
function testDestinationGasAmountWhenOverheadNotSet() public {
assertEq(
igp.destinationGasAmount(testDestinationDomain, testGasAmount),
testGasAmount
);
}
function testSetDestinationGasAmounts() public {
OverheadIgp.DomainConfig[]
memory configs = new OverheadIgp.DomainConfig[](2);
configs[0] = OverheadIgp.DomainConfig(
testDestinationDomain,
testGasOverhead
);
configs[1] = OverheadIgp.DomainConfig(4321, 432100);
// Topic 0 = event signature
// Topic 1 = indexed domain
// Topic 2 = not set
// Data = gas amount
vm.expectEmit(true, true, false, true);
emit DestinationGasOverheadSet(
configs[0].domain,
configs[0].gasOverhead
);
vm.expectEmit(true, true, false, true);
emit DestinationGasOverheadSet(
configs[1].domain,
configs[1].gasOverhead
);
igp.setDestinationGasOverheads(configs);
}
function testSetDestinationGasAmountsNotOwner() public {
OverheadIgp.DomainConfig[]
memory configs = new OverheadIgp.DomainConfig[](2);
configs[0] = OverheadIgp.DomainConfig(
testDestinationDomain,
testGasOverhead
);
configs[1] = OverheadIgp.DomainConfig(4321, 432100);
vm.expectRevert("Ownable: caller is not the owner");
vm.prank(nonOwner);
igp.setDestinationGasOverheads(configs);
}
// ============ Helper Functions ============
function setTestDestinationGasOverhead() internal {
OverheadIgp.DomainConfig[]
memory configs = new OverheadIgp.DomainConfig[](1);
configs[0] = OverheadIgp.DomainConfig(
testDestinationDomain,
testGasOverhead
);
igp.setDestinationGasOverheads(configs);
}
}