Skip to content

Commit

Permalink
fix(contracts-rfq): gas bench tests for the views [SLT-275] (#3217)
Browse files Browse the repository at this point in the history
* test: add gas bench for encoding

* test: add gas bench for canClaim
  • Loading branch information
ChiTimesChi authored Oct 3, 2024
1 parent ad48cb0 commit 68821a7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
19 changes: 19 additions & 0 deletions packages/contracts-rfq/test/FastBridgeV2.GasBench.Encoding.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {FastBridgeV2SrcBaseTest} from "./FastBridgeV2.Src.Base.t.sol";

// solhint-disable func-name-mixedcase, ordering
contract FastBridgeV2GasBenchmarkSrcProtocolFeesTest 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);
}

function test_getBridgeTransactionV2() public view {
bytes memory request = abi.encode(tokenTx);
fastBridge.getBridgeTransactionV2(request);
}
}
16 changes: 12 additions & 4 deletions packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,21 @@ contract FastBridgeV2GasBenchmarkSrcTest is FastBridgeV2SrcBaseTest {
}

function test_claim_token() public {
bytes32 txId = getTxId(provenTokenTx);
skipTimeAtLeast({time: CLAIM_DELAY + 1});
assertTrue(fastBridge.canClaim(txId, relayerA));
claim({caller: relayerA, bridgeTx: provenTokenTx});
assertEq(fastBridge.bridgeStatuses(getTxId(provenTokenTx)), IFastBridgeV2.BridgeStatus.RELAYER_CLAIMED);
assertEq(fastBridge.bridgeStatuses(txId), IFastBridgeV2.BridgeStatus.RELAYER_CLAIMED);
assertEq(srcToken.balanceOf(relayerA), INITIAL_RELAYER_BALANCE + tokenTx.originAmount);
assertEq(srcToken.balanceOf(address(fastBridge)), initialFastBridgeBalanceToken - tokenTx.originAmount);
}

function test_claimWithAddress_token() public {
bytes32 txId = getTxId(provenTokenTx);
skipTimeAtLeast({time: CLAIM_DELAY + 1});
assertTrue(fastBridge.canClaim(txId, relayerA));
claim({caller: relayerA, bridgeTx: provenTokenTx, to: relayerB});
assertEq(fastBridge.bridgeStatuses(getTxId(provenTokenTx)), IFastBridgeV2.BridgeStatus.RELAYER_CLAIMED);
assertEq(fastBridge.bridgeStatuses(txId), IFastBridgeV2.BridgeStatus.RELAYER_CLAIMED);
assertEq(srcToken.balanceOf(relayerB), INITIAL_RELAYER_BALANCE + tokenTx.originAmount);
assertEq(srcToken.balanceOf(address(fastBridge)), initialFastBridgeBalanceToken - tokenTx.originAmount);
}
Expand Down Expand Up @@ -217,17 +221,21 @@ contract FastBridgeV2GasBenchmarkSrcTest is FastBridgeV2SrcBaseTest {
}

function test_claim_eth() public {
bytes32 txId = getTxId(provenEthTx);
skipTimeAtLeast({time: CLAIM_DELAY + 1});
assertTrue(fastBridge.canClaim(txId, relayerA));
claim({caller: relayerA, bridgeTx: provenEthTx});
assertEq(fastBridge.bridgeStatuses(getTxId(provenEthTx)), IFastBridgeV2.BridgeStatus.RELAYER_CLAIMED);
assertEq(fastBridge.bridgeStatuses(txId), IFastBridgeV2.BridgeStatus.RELAYER_CLAIMED);
assertEq(relayerA.balance, INITIAL_RELAYER_BALANCE + ethTx.originAmount);
assertEq(address(fastBridge).balance, initialFastBridgeBalanceEth - ethTx.originAmount);
}

function test_claimWithAddress_eth() public {
bytes32 txId = getTxId(provenEthTx);
skipTimeAtLeast({time: CLAIM_DELAY + 1});
assertTrue(fastBridge.canClaim(txId, relayerA));
claim({caller: relayerA, bridgeTx: provenEthTx, to: relayerB});
assertEq(fastBridge.bridgeStatuses(getTxId(provenEthTx)), IFastBridgeV2.BridgeStatus.RELAYER_CLAIMED);
assertEq(fastBridge.bridgeStatuses(txId), IFastBridgeV2.BridgeStatus.RELAYER_CLAIMED);
assertEq(relayerB.balance, INITIAL_RELAYER_BALANCE + ethTx.originAmount);
assertEq(address(fastBridge).balance, initialFastBridgeBalanceEth - ethTx.originAmount);
}
Expand Down

0 comments on commit 68821a7

Please sign in to comment.