Skip to content

Commit

Permalink
test: gas benchmark for relay with arbitrary call
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiTimesChi committed Oct 11, 2024
1 parent 48cd1d7 commit c798dd2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {FastBridgeV2GasBenchmarkDstTest} from "./FastBridgeV2.GasBench.Dst.t.sol";
import {RecipientMock} from "./mocks/RecipientMock.sol";

// solhint-disable func-name-mixedcase, ordering
contract FastBridgeV2GasBenchmarkDstArbitraryCallTest is FastBridgeV2GasBenchmarkDstTest {
// To get an idea about how much overhead the arbitrary call adds to the relaying process, we use a mock
// recipient that has the hook function implemented as a no-op.
// The mocked callParams are chosen to be similar to the real use cases:
// - user address
// - some kind of ID to decide what to do with the tokens next

function setUp() public virtual override {
// In the inherited tests userB is always used as the recipient of the tokens.
userB = address(new RecipientMock());
vm.label(userB, "ContractRecipient");
super.setUp();
}

function createFixturesV2() public virtual override {
super.createFixturesV2();
bytes memory mockCallParams = abi.encode(userA, keccak256("Random ID"));
setTokenTestCallParams(mockCallParams);
setEthTestCallParams(mockCallParams);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ contract FastBridgeV2GasBenchmarkDstExclusivityTest is FastBridgeV2GasBenchmarkD
}

function createFixturesV2() public virtual override {
super.createFixturesV2();
setTokenTestExclusivityParams(relayerA, EXCLUSIVITY_PERIOD);
setEthTestExclusivityParams(relayerA, EXCLUSIVITY_PERIOD);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {FastBridgeV2SrcBaseTest} from "./FastBridgeV2.Src.Base.t.sol";

// solhint-disable func-name-mixedcase, ordering
contract FastBridgeV2GasBenchmarkEncodingTest is FastBridgeV2SrcBaseTest {
// TODO: add more tests with variable length requests once arbitrary call is done

function test_getBridgeTransaction() public view {
bytes memory request = abi.encode(extractV1(tokenTx));
fastBridge.getBridgeTransaction(request);
Expand All @@ -16,4 +14,9 @@ contract FastBridgeV2GasBenchmarkEncodingTest is FastBridgeV2SrcBaseTest {
bytes memory request = abi.encode(tokenTx);
fastBridge.getBridgeTransactionV2(request);
}

function test_getBridgeTransactionV2_withArbitraryCall() public {
setTokenTestCallParams({callParams: abi.encode(userA, keccak256("Random ID"))});
test_getBridgeTransactionV2();
}
}

0 comments on commit c798dd2

Please sign in to comment.