Skip to content

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
parodime committed Sep 27, 2024
1 parent 488e378 commit fbd7043
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
47 changes: 24 additions & 23 deletions packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {FastBridgeV2, FastBridgeV2SrcBaseTest, IFastBridge} from "./FastBridgeV2.Src.Base.t.sol";
import {FastBridgeV2SrcBaseTest, IFastBridge} from "./FastBridgeV2.Src.Base.t.sol";
import {IFastBridgeV2} from "../contracts/interfaces/IFastBridgeV2.sol";

// solhint-disable func-name-mixedcase, ordering
/// @notice This test is used to estimate the gas cost of FastBridgeV2 source chain functions.
Expand Down Expand Up @@ -63,12 +64,12 @@ contract FastBridgeV2GasBenchmarkSrcTest is FastBridgeV2SrcBaseTest {
prove({caller: relayerA, bridgeTx: provenTokenTx, destTxHash: hex"01"});
prove({caller: relayerB, transactionId: getTxId(provenEthTx), destTxHash: hex"02", relayer: relayerA});
// Status checks
assertEq(fastBridge.bridgeStatuses(getTxId(bridgedTokenTx)), FastBridgeV2.BridgeStatus.REQUESTED);
assertEq(fastBridge.bridgeStatuses(getTxId(bridgedEthTx)), FastBridgeV2.BridgeStatus.REQUESTED);
assertEq(fastBridge.bridgeStatuses(getTxId(provenTokenTx)), FastBridgeV2.BridgeStatus.RELAYER_PROVED);
assertEq(fastBridge.bridgeStatuses(getTxId(provenEthTx)), FastBridgeV2.BridgeStatus.RELAYER_PROVED);
assertEq(fastBridge.bridgeStatuses(getTxId(tokenTx)), FastBridgeV2.BridgeStatus.NULL);
assertEq(fastBridge.bridgeStatuses(getTxId(ethTx)), FastBridgeV2.BridgeStatus.NULL);
assertEq(fastBridge.bridgeStatuses(getTxId(bridgedTokenTx)), IFastBridgeV2.BridgeStatus.REQUESTED);
assertEq(fastBridge.bridgeStatuses(getTxId(bridgedEthTx)), IFastBridgeV2.BridgeStatus.REQUESTED);
assertEq(fastBridge.bridgeStatuses(getTxId(provenTokenTx)), IFastBridgeV2.BridgeStatus.RELAYER_PROVED);
assertEq(fastBridge.bridgeStatuses(getTxId(provenEthTx)), IFastBridgeV2.BridgeStatus.RELAYER_PROVED);
assertEq(fastBridge.bridgeStatuses(getTxId(tokenTx)), IFastBridgeV2.BridgeStatus.NULL);
assertEq(fastBridge.bridgeStatuses(getTxId(ethTx)), IFastBridgeV2.BridgeStatus.NULL);
}

function skipBlocksExactly(uint256 blocks) public {
Expand All @@ -86,15 +87,15 @@ contract FastBridgeV2GasBenchmarkSrcTest is FastBridgeV2SrcBaseTest {

function test_bridge_token() public {
bridge({caller: userA, msgValue: 0, params: tokenParams});
assertEq(fastBridge.bridgeStatuses(getTxId(tokenTx)), FastBridgeV2.BridgeStatus.REQUESTED);
assertEq(fastBridge.bridgeStatuses(getTxId(tokenTx)), IFastBridgeV2.BridgeStatus.REQUESTED);
assertEq(srcToken.balanceOf(userA), initialUserBalanceToken - tokenParams.originAmount);
assertEq(srcToken.balanceOf(address(fastBridge)), initialFastBridgeBalanceToken + tokenParams.originAmount);
}

function test_prove_token() public {
bytes32 txId = getTxId(bridgedTokenTx);
prove({caller: relayerA, bridgeTx: bridgedTokenTx, destTxHash: hex"03"});
assertEq(fastBridge.bridgeStatuses(txId), FastBridgeV2.BridgeStatus.RELAYER_PROVED);
assertEq(fastBridge.bridgeStatuses(txId), IFastBridgeV2.BridgeStatus.RELAYER_PROVED);
(uint96 timestamp, address relayer) = fastBridge.bridgeProofs(txId);
assertEq(timestamp, block.timestamp);
assertEq(relayer, relayerA);
Expand All @@ -104,7 +105,7 @@ contract FastBridgeV2GasBenchmarkSrcTest is FastBridgeV2SrcBaseTest {
function test_proveWithAddress_token() public {
bytes32 txId = getTxId(bridgedTokenTx);
prove({caller: relayerB, transactionId: txId, destTxHash: hex"03", relayer: relayerA});
assertEq(fastBridge.bridgeStatuses(txId), FastBridgeV2.BridgeStatus.RELAYER_PROVED);
assertEq(fastBridge.bridgeStatuses(txId), IFastBridgeV2.BridgeStatus.RELAYER_PROVED);
(uint96 timestamp, address relayer) = fastBridge.bridgeProofs(txId);
assertEq(timestamp, block.timestamp);
assertEq(relayer, relayerA);
Expand All @@ -113,31 +114,31 @@ contract FastBridgeV2GasBenchmarkSrcTest is FastBridgeV2SrcBaseTest {
function test_claim_token() public {
skipTimeAtLeast({time: CLAIM_DELAY + 1});
claim({caller: relayerA, bridgeTx: provenTokenTx});
assertEq(fastBridge.bridgeStatuses(getTxId(provenTokenTx)), FastBridgeV2.BridgeStatus.RELAYER_CLAIMED);
assertEq(fastBridge.bridgeStatuses(getTxId(provenTokenTx)), 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 {
skipTimeAtLeast({time: CLAIM_DELAY + 1});
claim({caller: relayerA, bridgeTx: provenTokenTx, to: relayerB});
assertEq(fastBridge.bridgeStatuses(getTxId(provenTokenTx)), FastBridgeV2.BridgeStatus.RELAYER_CLAIMED);
assertEq(fastBridge.bridgeStatuses(getTxId(provenTokenTx)), IFastBridgeV2.BridgeStatus.RELAYER_CLAIMED);
assertEq(srcToken.balanceOf(relayerB), INITIAL_RELAYER_BALANCE + tokenTx.originAmount);
assertEq(srcToken.balanceOf(address(fastBridge)), initialFastBridgeBalanceToken - tokenTx.originAmount);
}

function test_dispute_token() public {
bytes32 txId = getTxId(provenTokenTx);
dispute({caller: guard, txId: txId});
assertEq(fastBridge.bridgeStatuses(txId), FastBridgeV2.BridgeStatus.REQUESTED);
assertEq(fastBridge.bridgeStatuses(txId), IFastBridgeV2.BridgeStatus.REQUESTED);
assertEq(srcToken.balanceOf(address(fastBridge)), initialFastBridgeBalanceToken);
}

function test_refundPermissioned_token() public {
bytes32 txId = getTxId(bridgedTokenTx);
skipTimeAtLeast({time: DEADLINE});
refund({caller: refunder, bridgeTx: bridgedTokenTx});
assertEq(fastBridge.bridgeStatuses(txId), FastBridgeV2.BridgeStatus.REFUNDED);
assertEq(fastBridge.bridgeStatuses(txId), IFastBridgeV2.BridgeStatus.REFUNDED);
assertEq(srcToken.balanceOf(userA), initialUserBalanceToken + tokenParams.originAmount);
assertEq(srcToken.balanceOf(address(fastBridge)), initialFastBridgeBalanceToken - tokenParams.originAmount);
}
Expand All @@ -146,7 +147,7 @@ contract FastBridgeV2GasBenchmarkSrcTest is FastBridgeV2SrcBaseTest {
bytes32 txId = getTxId(bridgedTokenTx);
skipTimeAtLeast({time: DEADLINE + PERMISSIONLESS_REFUND_DELAY});
refund({caller: userB, bridgeTx: bridgedTokenTx});
assertEq(fastBridge.bridgeStatuses(txId), FastBridgeV2.BridgeStatus.REFUNDED);
assertEq(fastBridge.bridgeStatuses(txId), IFastBridgeV2.BridgeStatus.REFUNDED);
assertEq(srcToken.balanceOf(userA), initialUserBalanceToken + tokenParams.originAmount);
assertEq(srcToken.balanceOf(address(fastBridge)), initialFastBridgeBalanceToken - tokenParams.originAmount);
}
Expand All @@ -155,15 +156,15 @@ contract FastBridgeV2GasBenchmarkSrcTest is FastBridgeV2SrcBaseTest {

function test_bridge_eth() public {
bridge({caller: userA, msgValue: ethParams.originAmount, params: ethParams});
assertEq(fastBridge.bridgeStatuses(getTxId(ethTx)), FastBridgeV2.BridgeStatus.REQUESTED);
assertEq(fastBridge.bridgeStatuses(getTxId(ethTx)), IFastBridgeV2.BridgeStatus.REQUESTED);
assertEq(userA.balance, initialUserBalanceEth - ethParams.originAmount);
assertEq(address(fastBridge).balance, initialFastBridgeBalanceEth + ethParams.originAmount);
}

function test_prove_eth() public {
bytes32 txId = getTxId(bridgedEthTx);
prove({caller: relayerA, bridgeTx: bridgedEthTx, destTxHash: hex"03"});
assertEq(fastBridge.bridgeStatuses(txId), FastBridgeV2.BridgeStatus.RELAYER_PROVED);
assertEq(fastBridge.bridgeStatuses(txId), IFastBridgeV2.BridgeStatus.RELAYER_PROVED);
(uint96 timestamp, address relayer) = fastBridge.bridgeProofs(txId);
assertEq(timestamp, block.timestamp);
assertEq(relayer, relayerA);
Expand All @@ -173,7 +174,7 @@ contract FastBridgeV2GasBenchmarkSrcTest is FastBridgeV2SrcBaseTest {
function test_proveWithAddress_eth() public {
bytes32 txId = getTxId(bridgedEthTx);
prove({caller: relayerB, transactionId: txId, destTxHash: hex"03", relayer: relayerA});
assertEq(fastBridge.bridgeStatuses(txId), FastBridgeV2.BridgeStatus.RELAYER_PROVED);
assertEq(fastBridge.bridgeStatuses(txId), IFastBridgeV2.BridgeStatus.RELAYER_PROVED);
(uint96 timestamp, address relayer) = fastBridge.bridgeProofs(txId);
assertEq(timestamp, block.timestamp);
assertEq(relayer, relayerA);
Expand All @@ -183,31 +184,31 @@ contract FastBridgeV2GasBenchmarkSrcTest is FastBridgeV2SrcBaseTest {
function test_claim_eth() public {
skipTimeAtLeast({time: CLAIM_DELAY + 1});
claim({caller: relayerA, bridgeTx: provenEthTx});
assertEq(fastBridge.bridgeStatuses(getTxId(provenEthTx)), FastBridgeV2.BridgeStatus.RELAYER_CLAIMED);
assertEq(fastBridge.bridgeStatuses(getTxId(provenEthTx)), IFastBridgeV2.BridgeStatus.RELAYER_CLAIMED);
assertEq(relayerA.balance, INITIAL_RELAYER_BALANCE + ethTx.originAmount);
assertEq(address(fastBridge).balance, initialFastBridgeBalanceEth - ethTx.originAmount);
}

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

function test_dispute_eth() public {
bytes32 txId = getTxId(provenEthTx);
dispute({caller: guard, txId: txId});
assertEq(fastBridge.bridgeStatuses(txId), FastBridgeV2.BridgeStatus.REQUESTED);
assertEq(fastBridge.bridgeStatuses(txId), IFastBridgeV2.BridgeStatus.REQUESTED);
assertEq(address(fastBridge).balance, initialFastBridgeBalanceEth);
}

function test_refundPermissioned_eth() public {
bytes32 txId = getTxId(bridgedEthTx);
skipTimeAtLeast({time: DEADLINE});
refund({caller: refunder, bridgeTx: bridgedEthTx});
assertEq(fastBridge.bridgeStatuses(txId), FastBridgeV2.BridgeStatus.REFUNDED);
assertEq(fastBridge.bridgeStatuses(txId), IFastBridgeV2.BridgeStatus.REFUNDED);
assertEq(userA.balance, initialUserBalanceEth + ethParams.originAmount);
assertEq(address(fastBridge).balance, initialFastBridgeBalanceEth - ethParams.originAmount);
}
Expand All @@ -216,7 +217,7 @@ contract FastBridgeV2GasBenchmarkSrcTest is FastBridgeV2SrcBaseTest {
bytes32 txId = getTxId(bridgedEthTx);
skipTimeAtLeast({time: DEADLINE + PERMISSIONLESS_REFUND_DELAY});
refund({caller: userB, bridgeTx: bridgedEthTx});
assertEq(fastBridge.bridgeStatuses(txId), FastBridgeV2.BridgeStatus.REFUNDED);
assertEq(fastBridge.bridgeStatuses(txId), IFastBridgeV2.BridgeStatus.REFUNDED);
assertEq(userA.balance, initialUserBalanceEth + ethParams.originAmount);
assertEq(address(fastBridge).balance, initialFastBridgeBalanceEth - ethParams.originAmount);
}
Expand Down
7 changes: 2 additions & 5 deletions packages/contracts-rfq/test/FastBridgeV2.Src.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
ZeroAddress
} from "../contracts/libs/Errors.sol";

import {FastBridgeV2, FastBridgeV2Test, IFastBridge, IFastBridgeV2} from "./FastBridgeV2.t.sol";
import {FastBridgeV2SrcBaseTest} from "./FastBridgeV2.Src.Base.t.sol";
import {IFastBridge, IFastBridgeV2} from "./FastBridgeV2.t.sol";

// solhint-disable func-name-mixedcase, ordering
contract FastBridgeV2SrcTest is FastBridgeV2SrcBaseTest {
Expand Down Expand Up @@ -96,10 +97,6 @@ contract FastBridgeV2SrcTest is FastBridgeV2SrcBaseTest {
});
}

function assertEq(IFastBridgeV2.BridgeStatus a, IFastBridgeV2.BridgeStatus b) public pure {
assertEq(uint8(a), uint8(b));
}

// ══════════════════════════════════════════════════ BRIDGE ═══════════════════════════════════════════════════════

function checkTokenBalancesAfterBridge(address caller) public view {
Expand Down
1 change: 1 addition & 0 deletions packages/contracts-rfq/test/FastBridgeV2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.8.20;

import {IFastBridge} from "../contracts/interfaces/IFastBridge.sol";
import {IFastBridgeV2} from "../contracts/interfaces/IFastBridgeV2.sol";

import {IFastBridgeV2Errors} from "../contracts/interfaces/IFastBridgeV2Errors.sol";
import {FastBridgeV2} from "../contracts/FastBridgeV2.sol";

Expand Down

0 comments on commit fbd7043

Please sign in to comment.