Skip to content

Commit

Permalink
fix: start from nonce=1 in gas benchmark tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiTimesChi committed Oct 11, 2024
1 parent 39a84a1 commit c4393fc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
18 changes: 11 additions & 7 deletions packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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});
Expand Down
4 changes: 4 additions & 0 deletions packages/contracts-rfq/test/FastBridgeV2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit c4393fc

Please sign in to comment.