Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xDiscotech committed Oct 1, 2024
1 parent ba100f8 commit 959bb90
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 33 deletions.
4 changes: 2 additions & 2 deletions packages/contracts-bedrock/src/L2/L2StandardBridgeInterop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ contract L2StandardBridgeInterop is L2StandardBridge {
function convert(address _from, address _to, uint256 _amount) external {
_validatePair(_from, _to);

IMintableAndBurnableERC20(_from).__superchainMint(msg.sender, _amount);
IMintableAndBurnableERC20(_to).__superchainBurn(msg.sender, _amount);
IMintableAndBurnableERC20(_from).mint(msg.sender, _amount);
IMintableAndBurnableERC20(_to).burn(msg.sender, _amount);

emit Converted(_from, _to, msg.sender, _amount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ contract OptimismSuperchainERC20 is SuperchainERC20, Initializable, ERC165, IOpt

_mint(_to, _amount);

emit Burn(_to, _amount);
emit Mint(_to, _amount);
}

/// @notice Allows the L2StandardBridge and SuperchainERC20Bridge to burn tokens.
Expand Down
6 changes: 3 additions & 3 deletions packages/contracts-bedrock/src/L2/SuperchainERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Predeploys } from "src/libraries/Predeploys.sol";

// Interfaces
import { ISuperchainERC20Bridge } from "src/L2/interfaces/ISuperchainERC20Bridge.sol";
import { IMintableAndBurnableERC20 } from "src/L2/interfaces/IMintableAndBurnableERC20.sol";
import { ISuperchainERC20 } from "src/L2/interfaces/ISuperchainERC20.sol";
import { IL2ToL2CrossDomainMessenger } from "src/L2/interfaces/IL2ToL2CrossDomainMessenger.sol";

/// @custom:proxied true
Expand All @@ -29,7 +29,7 @@ contract SuperchainERC20Bridge is ISuperchainERC20Bridge {
/// @param _amount Amount of tokens to send.
/// @param _chainId Chain ID of the destination chain.
function sendERC20(address _token, address _to, uint256 _amount, uint256 _chainId) external {
IMintableAndBurnableERC20(_token).__superchainBurn(msg.sender, _amount);
ISuperchainERC20(_token).__superchainBurn(msg.sender, _amount);

bytes memory message = abi.encodeCall(this.relayERC20, (_token, msg.sender, _to, _amount));
IL2ToL2CrossDomainMessenger(MESSENGER).sendMessage(_chainId, address(this), message);
Expand All @@ -51,7 +51,7 @@ contract SuperchainERC20Bridge is ISuperchainERC20Bridge {

uint256 source = IL2ToL2CrossDomainMessenger(MESSENGER).crossDomainMessageSource();

IMintableAndBurnableERC20(_token).__superchainMint(_to, _amount);
ISuperchainERC20(_token).__superchainMint(_to, _amount);

emit RelayERC20(_token, _from, _to, _amount, source);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ interface IMintableAndBurnableERC20 is IERC20 {
/// @notice Mints `_amount` of tokens to `_to`.
/// @param _to Address to mint tokens to.
/// @param _amount Amount of tokens to mint.
function __superchainMint(address _to, uint256 _amount) external;
function mint(address _to, uint256 _amount) external;

/// @notice Burns `_amount` of tokens from `_from`.
/// @param _from Address to burn tokens from.
/// @param _amount Amount of tokens to burn.
function __superchainBurn(address _from, uint256 _amount) external;
function burn(address _from, uint256 _amount) external;
}
16 changes: 4 additions & 12 deletions packages/contracts-bedrock/test/L2/L2StandardBridgeInterop.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,10 @@ contract L2StandardBridgeInterop_LegacyToSuper_Test is L2StandardBridgeInterop_T

// Mock and expect the `burn` and `mint` functions
_mockAndExpect(
_from,
abi.encodeWithSelector(IMintableAndBurnableERC20.__superchainBurn.selector, _caller, _amount),
abi.encode()
_from, abi.encodeWithSelector(IMintableAndBurnableERC20.burn.selector, _caller, _amount), abi.encode()
);
_mockAndExpect(
_to,
abi.encodeWithSelector(IMintableAndBurnableERC20.__superchainMint.selector, _caller, _amount),
abi.encode()
_to, abi.encodeWithSelector(IMintableAndBurnableERC20.mint.selector, _caller, _amount), abi.encode()
);

// Act
Expand Down Expand Up @@ -365,14 +361,10 @@ contract L2StandardBridgeInterop_SuperToLegacy_Test is L2StandardBridgeInterop_T

// Mock and expect the `burn` and `mint` functions
_mockAndExpect(
_from,
abi.encodeWithSelector(IMintableAndBurnableERC20.__superchainBurn.selector, _caller, _amount),
abi.encode()
_from, abi.encodeWithSelector(IMintableAndBurnableERC20.burn.selector, _caller, _amount), abi.encode()
);
_mockAndExpect(
_to,
abi.encodeWithSelector(IMintableAndBurnableERC20.__superchainMint.selector, _caller, _amount),
abi.encode()
_to, abi.encodeWithSelector(IMintableAndBurnableERC20.mint.selector, _caller, _amount), abi.encode()
);

// Act
Expand Down
28 changes: 16 additions & 12 deletions packages/contracts-bedrock/test/L2/OptimismSuperchainERC20.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import { IBeacon } from "@openzeppelin/contracts-v5/proxy/beacon/IBeacon.sol";
import { BeaconProxy } from "@openzeppelin/contracts-v5/proxy/beacon/BeaconProxy.sol";

// Target contract
import { OptimismSuperchainERC20, IOptimismSuperchainERC20Extension } from "src/L2/OptimismSuperchainERC20.sol";
import { OptimismSuperchainERC20 } from "src/L2/OptimismSuperchainERC20.sol";
import {
IOptimismSuperchainERC20Extension,
IOptimismSuperchainERC20Errors
} from "src/L2/interfaces/IOptimismSuperchainERC20.sol";
import { ISuperchainERC20Errors } from "src/L2/interfaces/ISuperchainERC20.sol";

/// @title OptimismSuperchainERC20Test
Expand Down Expand Up @@ -119,12 +123,12 @@ contract OptimismSuperchainERC20Test is Test {
// Ensure the caller is not the bridge
vm.assume(_caller != L2_BRIDGE);

// Expect the revert with `OnlySuperchainERC20Bridge` selector
vm.expectRevert(ISuperchainERC20Errors.OnlySuperchainERC20Bridge.selector);
// Expect the revert with `OnlyL2StandardBridge` selector
vm.expectRevert(IOptimismSuperchainERC20Errors.OnlyL2StandardBridge.selector);

// Call the `mint` function with the non-bridge caller
vm.prank(_caller);
optimismSuperchainERC20.__superchainMint(_to, _amount);
optimismSuperchainERC20.mint(_to, _amount);
}

/// @notice Tests the `mint` function reverts when the amount is zero.
Expand All @@ -134,7 +138,7 @@ contract OptimismSuperchainERC20Test is Test {

// Call the `mint` function with the zero address
vm.prank(L2_BRIDGE);
optimismSuperchainERC20.__superchainMint({ _to: ZERO_ADDRESS, _amount: _amount });
optimismSuperchainERC20.mint({ _to: ZERO_ADDRESS, _amount: _amount });
}

/// @notice Tests the `mint` succeeds and emits the `Mint` event.
Expand All @@ -156,7 +160,7 @@ contract OptimismSuperchainERC20Test is Test {

// Call the `mint` function with the bridge caller
vm.prank(L2_BRIDGE);
optimismSuperchainERC20.__superchainMint(_to, _amount);
optimismSuperchainERC20.mint(_to, _amount);

// Check the total supply and balance of `_to` after the mint were updated correctly
assertEq(optimismSuperchainERC20.totalSupply(), _totalSupplyBefore + _amount);
Expand All @@ -168,12 +172,12 @@ contract OptimismSuperchainERC20Test is Test {
// Ensure the caller is not the bridge
vm.assume(_caller != L2_BRIDGE);

// Expect the revert with `OnlySuperchainERC20Bridge` selector
vm.expectRevert(ISuperchainERC20Errors.OnlySuperchainERC20Bridge.selector);
// Expect the revert with `OnlyL2StandardBridge` selector
vm.expectRevert(IOptimismSuperchainERC20Errors.OnlyL2StandardBridge.selector);

// Call the `burn` function with the non-bridge caller
vm.prank(_caller);
optimismSuperchainERC20.__superchainBurn(_from, _amount);
optimismSuperchainERC20.burn(_from, _amount);
}

/// @notice Tests the `burn` function reverts when the amount is zero.
Expand All @@ -183,7 +187,7 @@ contract OptimismSuperchainERC20Test is Test {

// Call the `burn` function with the zero address
vm.prank(L2_BRIDGE);
optimismSuperchainERC20.__superchainBurn({ _from: ZERO_ADDRESS, _amount: _amount });
optimismSuperchainERC20.burn({ _from: ZERO_ADDRESS, _amount: _amount });
}

/// @notice Tests the `burn` burns the amount and emits the `Burn` event.
Expand All @@ -193,7 +197,7 @@ contract OptimismSuperchainERC20Test is Test {

// Mint some tokens to `_from` so then they can be burned
vm.prank(L2_BRIDGE);
optimismSuperchainERC20.__superchainMint(_from, _amount);
optimismSuperchainERC20.mint(_from, _amount);

// Get the total supply and balance of `_from` before the burn to compare later on the assertions
uint256 _totalSupplyBefore = optimismSuperchainERC20.totalSupply();
Expand All @@ -209,7 +213,7 @@ contract OptimismSuperchainERC20Test is Test {

// Call the `burn` function with the bridge caller
vm.prank(L2_BRIDGE);
optimismSuperchainERC20.__superchainBurn(_from, _amount);
optimismSuperchainERC20.burn(_from, _amount);

// Check the total supply and balance of `_from` after the burn were updated correctly
assertEq(optimismSuperchainERC20.totalSupply(), _totalSupplyBefore - _amount);
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-bedrock/test/vendor/Initializable.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ contract Initializer_Test is Bridge_Initializer {
excludes[0] = "src/L1/SystemConfigInterop.sol";
excludes[1] = "src/L1/OptimismPortalInterop.sol";
// Contract is currently not being deployed as part of the standard deployment script.
excludes[2] = "src/L2/SuperchainERC20.sol";
excludes[2] = "src/L2/OptimismSuperchainERC20.sol";
// Periphery contracts don't get deployed as part of the standard deployment script.
excludes[3] = "src/periphery/*";
// TODO: Deployment script is currently "broken" in the sense that it doesn't properly
Expand Down

0 comments on commit 959bb90

Please sign in to comment.