From c4393fc2c2b4ce5cf8f5bab91b12aa1ce3c56ade Mon Sep 17 00:00:00 2001 From: ChiTimesChi <88190723+ChiTimesChi@users.noreply.github.com> Date: Fri, 11 Oct 2024 15:57:18 +0100 Subject: [PATCH] fix: start from nonce=1 in gas benchmark tests --- .../test/FastBridgeV2.GasBench.Src.PFees.t.sol | 10 +++++----- .../test/FastBridgeV2.GasBench.Src.t.sol | 18 +++++++++++------- packages/contracts-rfq/test/FastBridgeV2.t.sol | 4 ++++ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.PFees.t.sol b/packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.PFees.t.sol index 77b439d18e..51f17b5a96 100644 --- a/packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.PFees.t.sol +++ b/packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.PFees.t.sol @@ -27,10 +27,10 @@ contract FastBridgeV2GasBenchmarkSrcProtocolFeesTest is FastBridgeV2GasBenchmark provenTokenTx = tokenTx; bridgedEthTx = ethTx; provenEthTx = ethTx; - - bridgedTokenTx.nonce = 0; - bridgedEthTx.nonce = 1; - provenTokenTx.nonce = 2; - provenEthTx.nonce = 3; + // See FastBridgeV2GasBenchmarkSrcTest.initExistingTxs for why these start from 1, not 0 + bridgedTokenTx.nonce = 1; + bridgedEthTx.nonce = 2; + provenTokenTx.nonce = 3; + provenEthTx.nonce = 4; } } diff --git a/packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.t.sol b/packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.t.sol index fdaea68955..940eae3aa1 100644 --- a/packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.t.sol +++ b/packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.t.sol @@ -38,13 +38,14 @@ contract FastBridgeV2GasBenchmarkSrcTest is FastBridgeV2SrcBaseTest { bridgedEthTx = ethTx; provenEthTx = ethTx; - bridgedTokenTx.nonce = 0; - bridgedEthTx.nonce = 1; - provenTokenTx.nonce = 2; - provenEthTx.nonce = 3; - // Next nonce for userA tx would be 4 (either token or eth) - tokenTx.nonce = 4; - ethTx.nonce = 4; + // See initExistingTxs for why these start from 1, not 0 + bridgedTokenTx.nonce = 1; + bridgedEthTx.nonce = 2; + provenTokenTx.nonce = 3; + provenEthTx.nonce = 4; + // Next nonce for userA tx would be 5 (either token or eth) + tokenTx.nonce = 5; + ethTx.nonce = 5; } function createFixturesV2() public virtual override { @@ -67,6 +68,9 @@ contract FastBridgeV2GasBenchmarkSrcTest is FastBridgeV2SrcBaseTest { } function initExistingTxs() public { + // Set userA nonce to 1 so that the first bridge tx doesn't have inflated gas costs due to + // the storage write from the zero initial value + cheatSenderNonce(userA, 1); bridge({caller: userA, msgValue: 0, params: tokenParams, paramsV2: tokenParamsV2}); bridge({caller: userA, msgValue: ethParams.originAmount, params: ethParams, paramsV2: ethParamsV2}); bridge({caller: userA, msgValue: 0, params: tokenParams, paramsV2: tokenParamsV2}); diff --git a/packages/contracts-rfq/test/FastBridgeV2.t.sol b/packages/contracts-rfq/test/FastBridgeV2.t.sol index 8011f8a8e2..e195d8fabf 100644 --- a/packages/contracts-rfq/test/FastBridgeV2.t.sol +++ b/packages/contracts-rfq/test/FastBridgeV2.t.sol @@ -231,4 +231,8 @@ abstract contract FastBridgeV2Test is Test, IFastBridgeV2Errors { function cheatCollectedProtocolFees(address token, uint256 amount) public { stdstore.target(address(fastBridge)).sig("protocolFees(address)").with_key(token).checked_write(amount); } + + function cheatSenderNonce(address sender, uint256 nonce) public { + stdstore.target(address(fastBridge)).sig("senderNonces(address)").with_key(sender).checked_write(nonce); + } }