Skip to content

Commit

Permalink
fix: overflow in parity tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiTimesChi committed Sep 25, 2024
1 parent 5045835 commit 7f5c260
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
34 changes: 19 additions & 15 deletions packages/contracts-rfq/test/FastBridge.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
// solhint-disable

import "forge-std/Test.sol";
import "forge-std/console2.sol";
Expand Down Expand Up @@ -51,6 +52,19 @@ contract FastBridgeTest is Test {
ethUSDC.mint(dstUser, 100 * 10 ** 6);
}

function assertCorrectProof(
bytes32 transactionId,
uint256 expectedTimestamp,
address expectedRelayer
)
internal
virtual
{
(uint96 timestamp, address relayer) = fastBridge.bridgeProofs(transactionId);
assertEq(timestamp, uint96(expectedTimestamp));
assertEq(relayer, expectedRelayer);
}

function _getBridgeRequestAndId(
uint256 chainId,
uint256 currentNonce,
Expand Down Expand Up @@ -1349,9 +1363,7 @@ contract FastBridgeTest is Test {
fastBridge.prove(request, fakeTxnHash);

// We check if the bridge transaction proof timestamp is set to the timestamp at which the proof was provided
(uint96 _timestamp, address _oldRelayer) = fastBridge.bridgeProofs(transactionId);
assertEq(_timestamp, uint96(block.timestamp));
assertEq(_oldRelayer, relayer);
assertCorrectProof(transactionId, block.timestamp, relayer);

// We check if the bridge status is RELAYER_PROVED
assertEq(uint256(fastBridge.bridgeStatuses(transactionId)), uint256(FastBridge.BridgeStatus.RELAYER_PROVED));
Expand Down Expand Up @@ -1383,9 +1395,7 @@ contract FastBridgeTest is Test {
fastBridge.prove(request, fakeTxnHash);

// We check if the bridge transaction proof timestamp is set to the timestamp at which the proof was provided
(uint96 _timestamp, address _oldRelayer) = fastBridge.bridgeProofs(transactionId);
assertEq(_timestamp, uint96(block.timestamp));
assertEq(_oldRelayer, relayer);
assertCorrectProof(transactionId, block.timestamp, relayer);

// We stop a prank to contain within test
vm.stopPrank();
Expand Down Expand Up @@ -1414,9 +1424,7 @@ contract FastBridgeTest is Test {
fastBridge.prove(request, fakeTxnHash);

// We check if the bridge transaction proof timestamp is set to the timestamp at which the proof was provided
(uint96 _timestamp, address _oldRelayer) = fastBridge.bridgeProofs(transactionId);
assertEq(_timestamp, uint96(block.timestamp));
assertEq(_oldRelayer, relayer);
assertCorrectProof(transactionId, block.timestamp, relayer);

// We stop a prank to contain within test
vm.stopPrank();
Expand Down Expand Up @@ -1713,10 +1721,8 @@ contract FastBridgeTest is Test {
fastBridge.dispute(transactionId);

// check status and proofs updated
(uint96 _timestamp, address _oldRelayer) = fastBridge.bridgeProofs(transactionId);
assertEq(uint256(fastBridge.bridgeStatuses(transactionId)), uint256(FastBridge.BridgeStatus.REQUESTED));
assertEq(_timestamp, 0);
assertEq(_oldRelayer, address(0));
assertCorrectProof(transactionId, 0, address(0));

// We stop a prank to contain within test
vm.stopPrank();
Expand All @@ -1739,10 +1745,8 @@ contract FastBridgeTest is Test {
fastBridge.dispute(transactionId);

// check status and proofs updated
(uint96 _timestamp, address _oldRelayer) = fastBridge.bridgeProofs(transactionId);
assertEq(uint256(fastBridge.bridgeStatuses(transactionId)), uint256(FastBridge.BridgeStatus.REQUESTED));
assertEq(_timestamp, 0);
assertEq(_oldRelayer, address(0));
assertCorrectProof(transactionId, 0, address(0));

// We stop a prank to contain within test
vm.stopPrank();
Expand Down
15 changes: 15 additions & 0 deletions packages/contracts-rfq/test/FastBridgeV2.Parity.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ contract FastBridgeV2ParityTest is FastBridgeTest {
return deployCode({what: "FastBridgeV2", args: abi.encode(owner)});
}

/// @notice We use uint40 for the timestamps in FastBridgeV2
function assertCorrectProof(
bytes32 transactionId,
uint256 expectedTimestamp,
address expectedRelayer
)
internal
virtual
override
{
(uint96 timestamp, address relayer) = fastBridge.bridgeProofs(transactionId);
assertEq(timestamp, uint40(expectedTimestamp));
assertEq(relayer, expectedRelayer);
}

/// @notice Relay function is no longer permissioned, so we skip this test
function test_failedRelayNotRelayer() public virtual override {
vm.skip(true);
Expand Down

0 comments on commit 7f5c260

Please sign in to comment.