Skip to content

Commit

Permalink
test: fix address assuming
Browse files Browse the repository at this point in the history
  • Loading branch information
agusduha committed Aug 14, 2024
1 parent f4d0bb3 commit 2a3a723
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions packages/contracts-bedrock/test/L2/L2StandardBridgeInterop.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity 0.8.15;

// Target contract is imported by the `Bridge_Initializer`
import { Bridge_Initializer } from "test/setup/Bridge_Initializer.sol";
import { console2 } from "forge-std/console2.sol";

// Target contract dependencies
import {
Expand Down Expand Up @@ -56,15 +55,24 @@ contract L2StandardBridgeInterop_Test is Bridge_Initializer {
_factory, abi.encodeWithSelector(IOptimismERC20Factory.deployments.selector, _token), abi.encode(_deployed)
);
}

/// @notice Assume a valid address for fuzzing
function _assumeAddress(address _address) internal {
vm.assume(
_address.code.length == 0 // No accounts with code
&& _address != CONSOLE // The console has no code but behaves like a contract
&& uint160(_address) > 9 // No precompiles (or zero address)
);
}
}

/// @notice Test suite when converting from a legacy token to a SuperchainERC20 token
contract L2StandardBridgeInterop_LegacyToSuper_Test is L2StandardBridgeInterop_Test {
/// @notice Set up the test for converting from a legacy token to a SuperchainERC20 token
function _setUpLegacyToSuper(address _from, address _to) internal {
// Assume
vm.assume(_from != console2.CONSOLE_ADDRESS);
vm.assume(_to != console2.CONSOLE_ADDRESS);
_assumeAddress(_from);
_assumeAddress(_to);

// Mock same decimals
_mockDecimals(_from, 18);
Expand All @@ -86,8 +94,8 @@ contract L2StandardBridgeInterop_LegacyToSuper_Test is L2StandardBridgeInterop_T
public
{
// Assume
vm.assume(_from != console2.CONSOLE_ADDRESS);
vm.assume(_to != console2.CONSOLE_ADDRESS);
_assumeAddress(_from);
_assumeAddress(_to);
vm.assume(_decimalsFrom != _decimalsTo);
vm.assume(_from != _to);

Expand Down Expand Up @@ -216,8 +224,8 @@ contract L2StandardBridgeInterop_SuperToLegacy_Test is L2StandardBridgeInterop_T
/// @notice Set up the test for converting from a SuperchainERC20 token to a legacy token
function _setUpSuperToLegacy(address _from, address _to) internal {
// Assume
vm.assume(_from != console2.CONSOLE_ADDRESS);
vm.assume(_to != console2.CONSOLE_ADDRESS);
_assumeAddress(_from);
_assumeAddress(_to);

// Mock same decimals
_mockDecimals(_from, 18);
Expand All @@ -235,8 +243,8 @@ contract L2StandardBridgeInterop_SuperToLegacy_Test is L2StandardBridgeInterop_T
public
{
// Assume
vm.assume(_from != console2.CONSOLE_ADDRESS);
vm.assume(_to != console2.CONSOLE_ADDRESS);
_assumeAddress(_from);
_assumeAddress(_to);
vm.assume(_decimalsFrom != _decimalsTo);
vm.assume(_from != _to);

Expand Down

0 comments on commit 2a3a723

Please sign in to comment.