Skip to content

Commit 417b006

Browse files
committed
✅ contracts: add polygon hyperlane bridge test
1 parent 413f164 commit 417b006

3 files changed

Lines changed: 91 additions & 26 deletions

File tree

contracts/.gas-snapshot

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
ExaAccountFactoryTest:testFuzz_createAccount_EOAOwners(uint256,address[63]) (runs: 256, μ: 5916295, ~: 5447138)
1+
ExaAccountFactoryTest:testFuzz_createAccount_EOAOwners(uint256,address[63]) (runs: 256, μ: 5900851, ~: 5393451)
22
ExaAccountFactoryTest:test_deploy_deploysToSameAddress() (gas: 15338064)
3-
ExaPluginTest:testFork_claimAndVestEscrowedEXA_claimsAndVests() (gas: 38616338)
4-
ExaPluginTest:testFork_collectCollateral_collects() (gas: 32117511)
5-
ExaPluginTest:testFork_crossRepay_repays() (gas: 33939665)
6-
ExaPluginTest:testFork_repay_whenFlashLoanerHasFees() (gas: 25572520)
7-
ExaPluginTest:testFork_stakeEXA_stakes() (gas: 32695581)
8-
ExaPluginTest:testFork_swap_swaps() (gas: 28060506)
3+
ExaPluginTest:testFork_claimAndVestEscrowedEXA_claimsAndVests() (gas: 38619453)
4+
ExaPluginTest:testFork_collectCollateral_collects() (gas: 32120425)
5+
ExaPluginTest:testFork_crossRepay_repays() (gas: 33942579)
6+
ExaPluginTest:testFork_repay_whenFlashLoanerHasFees() (gas: 25573719)
7+
ExaPluginTest:testFork_stakeEXA_stakes() (gas: 32698581)
8+
ExaPluginTest:testFork_swap_swaps() (gas: 28063154)
99
ExaPluginTest:test_allowPlugin_emitsPluginAllowed() (gas: 58464)
1010
ExaPluginTest:test_allowPlugin_reverts_whenAddressZero() (gas: 32411)
1111
ExaPluginTest:test_allowPlugin_reverts_whenNotAdmin() (gas: 40964)
@@ -32,12 +32,12 @@ ExaPluginTest:test_collectCredit_collects_whenHealthFactorHigherThanOne() (gas:
3232
ExaPluginTest:test_collectCredit_collects_whenProposalCausesInsufficientLiquidity() (gas: 1064982)
3333
ExaPluginTest:test_collectCredit_collects_whenProposalLeavesHealthFactorLowerThanOne() (gas: 1055379)
3434
ExaPluginTest:test_collectCredit_collects_withEnoughSlippage() (gas: 782246)
35-
ExaPluginTest:test_collectCredit_collects_withPrevIssuerSignature() (gas: 986135)
35+
ExaPluginTest:test_collectCredit_collects_withPrevIssuerSignature() (gas: 986192)
3636
ExaPluginTest:test_collectCredit_passes_whenProposalLeavesEnoughLiquidity() (gas: 1082579)
3737
ExaPluginTest:test_collectCredit_reverts_asNotKeeper() (gas: 342148)
3838
ExaPluginTest:test_collectCredit_reverts_whenDisagreement() (gas: 538817)
3939
ExaPluginTest:test_collectCredit_reverts_whenExpired() (gas: 352767)
40-
ExaPluginTest:test_collectCredit_reverts_whenPrevSignatureNotValidAnymore() (gas: 483048)
40+
ExaPluginTest:test_collectCredit_reverts_whenPrevSignatureNotValidAnymore() (gas: 483105)
4141
ExaPluginTest:test_collectCredit_reverts_whenReplay() (gas: 825827)
4242
ExaPluginTest:test_collectCredit_reverts_whenTimelocked() (gas: 334568)
4343
ExaPluginTest:test_collectCredit_toleratesTimeDrift() (gas: 798846)
@@ -58,7 +58,7 @@ ExaPluginTest:test_collectInstallments_reverts_whenTimelocked() (gas: 336703)
5858
ExaPluginTest:test_collectInstallments_toleratesTimeDrift() (gas: 1161587)
5959
ExaPluginTest:test_collect_collects_whenProposalsLeaveNoLiquidity() (gas: 1783636)
6060
ExaPluginTest:test_collect_collects_whenTooMuchProposedDebt() (gas: 1923835)
61-
ExaPluginTest:test_crossRepay_avoidsFrozenDeposit() (gas: 980223)
61+
ExaPluginTest:test_crossRepay_avoidsFrozenDeposit() (gas: 980280)
6262
ExaPluginTest:test_crossRepay_avoidsZeroSharesDeposit() (gas: 1392815)
6363
ExaPluginTest:test_crossRepay_consumesProposal() (gas: 2204416)
6464
ExaPluginTest:test_crossRepay_repays() (gas: 2268206)
@@ -202,9 +202,10 @@ ExaPreviewerTest:test_collect_reverts_whenProposalsLeaveNoLiquidity() (gas: 1437
202202
ExaPreviewerTest:test_markets_returnsMarkets() (gas: 150447)
203203
ExaPreviewerTest:test_pendingProposals_returnsPendingProposals() (gas: 1984093)
204204
ExaPreviewerTest:test_utilizations_returns() (gas: 134922)
205-
HypEXATest:test_handle_reverts_withoutBridgeRole() (gas: 122496)
206-
HypEXATest:test_roundTrip_opToBaseToOp() (gas: 1046501)
207-
HypEXATest:test_setupRouter_reverts_whenRouterNotDeployed() (gas: 21905809)
205+
HypEXATest:test_handle_reverts_withoutBridgeRole() (gas: 122511)
206+
HypEXATest:test_roundTrip_opToBaseToOp() (gas: 1046479)
207+
HypEXATest:test_roundTrip_opToPolygonToBaseToOp() (gas: 1549147)
208+
HypEXATest:test_setupRouter_reverts_whenRouterNotDeployed() (gas: 21907000)
208209
HypEXATest:test_transferRemote_reverts_withoutBridgeRole() (gas: 230258)
209210
IssuerCheckerTest:test_setIssuer_emits_IssuerSet() (gas: 82935)
210211
IssuerCheckerTest:test_setIssuer_reverts_whenNotAdmin() (gas: 43708)
@@ -216,20 +217,20 @@ IssuerCheckerTest:test_setPrevIssuerWindow_emits_PrevIssuerWindowSet() (gas: 526
216217
IssuerCheckerTest:test_setPrevIssuerWindow_reverts_whenNotAdmin() (gas: 45548)
217218
MockSwapperTest:test_swapExactAmountIn_swaps() (gas: 269414)
218219
MockSwapperTest:test_swapExactAmountOut_swaps() (gas: 269410)
219-
RedeployerTest:test_deployEXA_deploysAtSameAddress_onBase() (gas: 58417630)
220+
RedeployerTest:test_deployEXA_deploysAtSameAddress_onBase() (gas: 58418267)
220221
RedeployerTest:test_deployExaFactoryWithProxy_reverts_whenNotPrepared() (gas: 18996556)
221-
RedeployerTest:test_deployExaFactoryWithProxy_succeeds_whenAlreadyUpgraded() (gas: 34228296)
222-
RedeployerTest:test_deployExaFactory_deploysAtSameAddress_onEthereum() (gas: 263265537)
223-
RedeployerTest:test_deployExaFactory_deploysAtSameAddress_onPolygon() (gas: 358976446)
224-
RedeployerTest:test_deployExaFactory_deploysViaCreate3AtSameAddress_onPolygon() (gas: 37419994)
225-
RedeployerTest:test_deployExaFactory_reverts_whenNotPrepared() (gas: 19019914)
226-
RedeployerTest:test_deployExaFactory_succeeds_whenVersionAlreadyDeployed() (gas: 34775044)
227-
RedeployerTest:test_prepare_reusesExistingDeps_onBase() (gas: 22498324)
228-
RedeployerTest:test_prepare_reverts_whenAdminIsDeployer() (gas: 19023449)
229-
RedeployerTest:test_prepare_succeeds_whenCalledTwice() (gas: 33718441)
230-
RedeployerTest:test_recoversNativeETHOnPolygon() (gas: 37591234)
231-
RedeployerTest:test_serialProxies_reverts_whenAttackerUpgradesProxy() (gas: 41767579)
232-
RedeployerTest:test_serialProxies_reverts_whenTargetNonceTooLow() (gas: 49862385)
222+
RedeployerTest:test_deployExaFactoryWithProxy_succeeds_whenAlreadyUpgraded() (gas: 34229304)
223+
RedeployerTest:test_deployExaFactory_deploysAtSameAddress_onEthereum() (gas: 263266592)
224+
RedeployerTest:test_deployExaFactory_deploysAtSameAddress_onPolygon() (gas: 358977552)
225+
RedeployerTest:test_deployExaFactory_deploysViaCreate3AtSameAddress_onPolygon() (gas: 37420993)
226+
RedeployerTest:test_deployExaFactory_reverts_whenNotPrepared() (gas: 19019971)
227+
RedeployerTest:test_deployExaFactory_succeeds_whenVersionAlreadyDeployed() (gas: 34776100)
228+
RedeployerTest:test_prepare_reusesExistingDeps_onBase() (gas: 22499778)
229+
RedeployerTest:test_prepare_reverts_whenAdminIsDeployer() (gas: 19023568)
230+
RedeployerTest:test_prepare_succeeds_whenCalledTwice() (gas: 33719506)
231+
RedeployerTest:test_recoversNativeETHOnPolygon() (gas: 37592257)
232+
RedeployerTest:test_serialProxies_reverts_whenAttackerUpgradesProxy() (gas: 41768151)
233+
RedeployerTest:test_serialProxies_reverts_whenTargetNonceTooLow() (gas: 49862897)
233234
RefunderTest:test_refund_refunds() (gas: 263363)
234235
RefunderTest:test_refund_reverts_whenExpired() (gas: 88359)
235236
RefunderTest:test_refund_reverts_whenNotKeeper() (gas: 68861)

contracts/deploy.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
},
4242
"mailbox": {
4343
"10": "0xd4C1905BB1D26BC93DAC913e13CaCC278CdCC80D",
44+
"137": "0x5d934f4e2f797775e53561bB72aca21ba36B96BB",
4445
"8453": "0xeA87ae93Fa0019a82A727bfd3eBd1cFCa8f64f1D"
4546
}
4647
},

contracts/test/HypEXA.t.sol

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,33 @@ contract HypEXATest is ForkTest {
1313

1414
uint256 internal opFork;
1515
uint256 internal baseFork;
16+
uint256 internal polygonFork;
1617
HypXERC20 internal opRouter;
1718
HypXERC20 internal baseRouter;
19+
HypXERC20 internal polygonRouter;
1820
address internal admin;
1921
address internal opMailbox;
2022
address internal baseMailbox;
23+
address internal polygonMailbox;
2124
EXA internal exa = EXA(0x1e925De1c68ef83bD98eE3E130eF14a50309C01B);
2225
address internal exaHolder = 0x92024C4bDa9DA602b711B9AbB610d072018eb58b;
2326

2427
uint32 internal constant OP_DOMAIN = 10;
2528
uint32 internal constant BASE_DOMAIN = 8453;
29+
uint32 internal constant POLYGON_DOMAIN = 137;
2630

2731
function setUp() external {
32+
polygonFork = vm.createSelectFork("polygon", 83_700_000);
33+
polygonMailbox = acct("mailbox");
34+
Redeployer polygonRedeployer = new Redeployer();
35+
polygonRedeployer.setUp();
36+
if (address(polygonRedeployer.proxyAdmin()).code.length == 0) polygonRedeployer.prepare();
37+
polygonRedeployer.proxyThrough(polygonRedeployer.findNonce(acct("deployer"), address(exa), 1000) + 1);
38+
polygonRedeployer.deployEXA(address(exa));
39+
polygonRouter = polygonRedeployer.deployRouter(address(exa));
40+
polygonRedeployer.setupRouter(address(exa), OP_DOMAIN);
41+
polygonRedeployer.setupRouter(address(exa), BASE_DOMAIN);
42+
2843
baseFork = vm.createSelectFork("base", 42_380_000);
2944
baseMailbox = acct("mailbox");
3045
Redeployer baseRedeployer = new Redeployer();
@@ -34,6 +49,7 @@ contract HypEXATest is ForkTest {
3449
baseRedeployer.deployEXA(address(exa));
3550
baseRouter = baseRedeployer.deployRouter(address(exa));
3651
baseRedeployer.setupRouter(address(exa), OP_DOMAIN);
52+
baseRedeployer.setupRouter(address(exa), POLYGON_DOMAIN);
3753

3854
opFork = vm.createSelectFork("optimism", 147_967_000);
3955
opMailbox = acct("mailbox");
@@ -45,6 +61,7 @@ contract HypEXATest is ForkTest {
4561
opRedeployer.upgradeEXA(address(exa));
4662
opRouter = opRedeployer.deployRouter(address(exa));
4763
opRedeployer.setupRouter(address(exa), BASE_DOMAIN);
64+
opRedeployer.setupRouter(address(exa), POLYGON_DOMAIN);
4865
}
4966

5067
// solhint-disable func-name-mixedcase
@@ -83,6 +100,52 @@ contract HypEXATest is ForkTest {
83100
assertEq(exa.totalSupply(), opSupply, "op didn't restore supply");
84101
}
85102

103+
function test_roundTrip_opToPolygonToBaseToOp() external {
104+
uint256 amount = 100e18;
105+
uint256 opSupply = exa.totalSupply();
106+
107+
uint256 fee = opRouter.quoteGasPayment(POLYGON_DOMAIN);
108+
vm.deal(exaHolder, fee);
109+
vm.prank(exaHolder);
110+
opRouter.transferRemote{ value: fee }(POLYGON_DOMAIN, exaHolder.addressToBytes32(), amount);
111+
assertEq(exa.totalSupply(), opSupply - amount, "op didn't burn");
112+
113+
vm.selectFork(polygonFork);
114+
uint256 polygonSupply = exa.totalSupply();
115+
vm.prank(polygonMailbox);
116+
polygonRouter.handle(
117+
OP_DOMAIN, address(opRouter).addressToBytes32(), abi.encodePacked(exaHolder.addressToBytes32(), amount)
118+
);
119+
assertEq(exa.totalSupply(), polygonSupply + amount, "polygon didn't mint");
120+
121+
fee = polygonRouter.quoteGasPayment(BASE_DOMAIN);
122+
vm.deal(exaHolder, fee);
123+
vm.prank(exaHolder);
124+
polygonRouter.transferRemote{ value: fee }(BASE_DOMAIN, exaHolder.addressToBytes32(), amount);
125+
assertEq(exa.totalSupply(), polygonSupply, "polygon didn't burn");
126+
127+
vm.selectFork(baseFork);
128+
uint256 baseSupply = exa.totalSupply();
129+
vm.prank(baseMailbox);
130+
baseRouter.handle(
131+
POLYGON_DOMAIN, address(polygonRouter).addressToBytes32(), abi.encodePacked(exaHolder.addressToBytes32(), amount)
132+
);
133+
assertEq(exa.totalSupply(), baseSupply + amount, "base didn't mint");
134+
135+
fee = baseRouter.quoteGasPayment(OP_DOMAIN);
136+
vm.deal(exaHolder, fee);
137+
vm.prank(exaHolder);
138+
baseRouter.transferRemote{ value: fee }(OP_DOMAIN, exaHolder.addressToBytes32(), amount);
139+
assertEq(exa.totalSupply(), baseSupply, "base didn't burn");
140+
141+
vm.selectFork(opFork);
142+
vm.prank(opMailbox);
143+
opRouter.handle(
144+
BASE_DOMAIN, address(baseRouter).addressToBytes32(), abi.encodePacked(exaHolder.addressToBytes32(), amount)
145+
);
146+
assertEq(exa.totalSupply(), opSupply, "op didn't restore supply");
147+
}
148+
86149
function test_transferRemote_reverts_withoutBridgeRole() external {
87150
vm.prank(admin);
88151
exa.revokeRole(keccak256("BRIDGE_ROLE"), address(opRouter));

0 commit comments

Comments
 (0)