Skip to content

Commit

Permalink
fix: refactor common errors (#90)
Browse files Browse the repository at this point in the history
* fix: refactor common errors

* fix: remove unused version
  • Loading branch information
agusduha authored Oct 9, 2024
1 parent a79bf4e commit af9694e
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ func run() error {
}

// Skip mock contracts
if strings.Contains(contractName, "_mock") {
if strings.HasPrefix(contractName, "Mock") {
return
}

contractPath := contractFiles[contractName]
if contractPath == "" {
fail("%s: Source file not found (For test mock contracts, suffix the name with '_mock' to ignore this warning)", contractName)
fail("%s: Source file not found (For test mock contracts, prefix the name with 'Mock' to ignore this warning)", contractName)
return
}

Expand Down
8 changes: 4 additions & 4 deletions packages/contracts-bedrock/semver-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
},
"src/L2/OptimismSuperchainERC20.sol": {
"initCodeHash": "0xadeaebb33c1d758d88d7aadd0ad654c9a1f2d59824c5dad19e1d9cf05ea3e516",
"sourceCodeHash": "0x5a40eabbdc33bd96ff0a7bc2be6699a7b6233610bf67f3da899f0efb367bb486"
"sourceCodeHash": "0xacf5ca4cdebd7e1d52f691db0f873cc026c6336a9ea309af1364a46aba723180"
},
"src/L2/OptimismSuperchainERC20Beacon.sol": {
"initCodeHash": "0x99ce8095b23c124850d866cbc144fee6cee05dbc6bb5d83acadfe00b90cf42c7",
Expand All @@ -129,11 +129,11 @@
},
"src/L2/SuperchainTokenBridge.sol": {
"initCodeHash": "0xfeba60d8e17a0c62cc56c7319da323e154ccc6c379e7b72c48c9d0ce1e5b9474",
"sourceCodeHash": "0xbfd1a6959cf5ae96c3e0aaf9aa638633e6cb8a7a183484e91ec29d619d687a42"
"sourceCodeHash": "0x7f718c438e8289696fc92d61be612e53e5c5b17f432d109397248e5385076aaa"
},
"src/L2/SuperchainWETH.sol": {
"initCodeHash": "0x5db03c5c4cd6ea9e4b3e74e28f50d04fd3e130af5109b34fa208808fa9ba7742",
"sourceCodeHash": "0x2cab7c31850a90813555b20cc9fa22e64a76cd5897e89c41786a848edf820f28"
"initCodeHash": "0x50f6ea9bfe650fcf792e98e44b1bf66c036fd0e6d4b753da680253d7d8609816",
"sourceCodeHash": "0x82d03262decf52d5954d40bca8703f96a0f3ba7accf6c1d75292856c2f34cf8f"
},
"src/L2/WETH.sol": {
"initCodeHash": "0xfb253765520690623f177941c2cd9eba23e4c6d15063bccdd5e98081329d8956",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Predeploys } from "src/libraries/Predeploys.sol";
import { ERC165 } from "@openzeppelin/contracts-v5/utils/introspection/ERC165.sol";
import { SuperchainERC20 } from "src/L2/SuperchainERC20.sol";
import { Initializable } from "@openzeppelin/contracts-v5/proxy/utils/Initializable.sol";
import { ZeroAddress } from "src/libraries/errors/CommonErrors.sol";

/// @custom:proxied true
/// @title OptimismSuperchainERC20
Expand All @@ -16,9 +17,6 @@ import { Initializable } from "@openzeppelin/contracts-v5/proxy/utils/Initializa
/// also enables the inverse conversion path.
/// Moreover, it builds on top of the L2ToL2CrossDomainMessenger for both replay protection and domain binding.
contract OptimismSuperchainERC20 is SuperchainERC20, Initializable, ERC165 {
/// @notice Thrown when attempting to perform an operation and the account is the zero address.
error ZeroAddress();

/// @notice Thrown when attempting to mint or burn tokens and the function caller is not the L2StandardBridge
error OnlyL2StandardBridge();

Expand Down
4 changes: 1 addition & 3 deletions packages/contracts-bedrock/src/L2/SuperchainTokenBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity 0.8.25;

// Libraries
import { Predeploys } from "src/libraries/Predeploys.sol";
import { ZeroAddress } from "src/libraries/errors/CommonErrors.sol";

// Interfaces
import { ISuperchainERC20 } from "src/L2/interfaces/ISuperchainERC20.sol";
Expand All @@ -15,9 +16,6 @@ import { IL2ToL2CrossDomainMessenger } from "src/L2/interfaces/IL2ToL2CrossDomai
/// Superchain. It builds on top of the L2ToL2CrossDomainMessenger for both replay protection and domain
/// binding.
contract SuperchainTokenBridge {
/// @notice Thrown when attempting to perform an operation and the account is the zero address.
error ZeroAddress();

/// @notice Thrown when attempting to relay a message and the function caller (msg.sender) is not
/// L2ToL2CrossDomainMessenger.
error CallerNotL2ToL2CrossDomainMessenger();
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts-bedrock/src/L2/SuperchainWETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { ISuperchainWETH } from "src/L2/interfaces/ISuperchainWETH.sol";
/// do not use a custom gas token.
contract SuperchainWETH is WETH98, ISuperchainWETH, ISemver {
/// @notice Semantic version.
/// @custom:semver 1.0.0-beta.7
string public constant version = "1.0.0-beta.7";
/// @custom:semver 1.0.0-beta.6
string public constant version = "1.0.0-beta.6";

/// @inheritdoc WETH98
function deposit() public payable override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ error NotCustomGasToken();

/// @notice Error for when a transfer via call fails.
error TransferFailed();

/// @notice Thrown when attempting to perform an operation and the account is the zero address.
error ZeroAddress();
4 changes: 2 additions & 2 deletions packages/contracts-bedrock/test/L2/SuperchainERC20.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { IERC20 } from "@openzeppelin/contracts-v5/token/ERC20/IERC20.sol";
import { SuperchainERC20 } from "src/L2/SuperchainERC20.sol";
import { ICrosschainERC20 } from "src/L2/interfaces/ICrosschainERC20.sol";
import { ISuperchainERC20 } from "src/L2/interfaces/ISuperchainERC20.sol";
import { SuperchainERC20Implementation_mock } from "test/mocks/SuperchainERC20Implementation.sol";
import { MockSuperchainERC20Implementation } from "test/mocks/SuperchainERC20Implementation.sol";

/// @title SuperchainERC20Test
/// @notice Contract for testing the SuperchainERC20 contract.
Expand All @@ -25,7 +25,7 @@ contract SuperchainERC20Test is Test {

/// @notice Sets up the test suite.
function setUp() public {
superchainERC20 = new SuperchainERC20Implementation_mock();
superchainERC20 = new MockSuperchainERC20Implementation();
}

/// @notice Helper function to setup a mock and expect a call to it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import { SuperchainERC20 } from "src/L2/SuperchainERC20.sol";

/// @title SuperchainERC20Implementation Mock contract
/// @notice Mock contract just to create tests over an implementation of the SuperchainERC20 abstract contract.
contract SuperchainERC20Implementation_mock is SuperchainERC20 {
/// @notice Semantic version.
/// @custom:semver 1.0.0-beta.1
string public constant override version = "1.0.0-beta.1";

contract MockSuperchainERC20Implementation is SuperchainERC20 {
function name() public pure override returns (string memory) {
return "SuperchainERC20";
}
Expand Down

0 comments on commit af9694e

Please sign in to comment.