From c3cb7f663c2e3cfcd53c62675d9a6d5362d834b6 Mon Sep 17 00:00:00 2001 From: agusduha Date: Thu, 3 Oct 2024 12:00:22 -0300 Subject: [PATCH 1/3] fix: semver natspec check failure --- .../scripts/checks/semver-natspec/main.go | 13 ++++++++++-- .../test/L2/SuperchainERC20.t.sol | 13 ++---------- .../SuperchainERC20ImplementationMock.sol | 20 +++++++++++++++++++ 3 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 packages/contracts-bedrock/test/mocks/SuperchainERC20ImplementationMock.sol diff --git a/packages/contracts-bedrock/scripts/checks/semver-natspec/main.go b/packages/contracts-bedrock/scripts/checks/semver-natspec/main.go index d1e2153c02ef..c6650d9bc2b7 100644 --- a/packages/contracts-bedrock/scripts/checks/semver-natspec/main.go +++ b/packages/contracts-bedrock/scripts/checks/semver-natspec/main.go @@ -63,6 +63,7 @@ func run() error { artifactsDir := filepath.Join(cwd, "forge-artifacts") srcDir := filepath.Join(cwd, "src") + testDir := filepath.Join(cwd, "test") artifactFiles, err := glob(artifactsDir, ".json") if err != nil { @@ -72,6 +73,10 @@ func run() error { if err != nil { return fmt.Errorf("failed to get contract files: %w", err) } + testFiles, err := glob(testDir, ".sol") + if err != nil { + return fmt.Errorf("failed to get test files: %w", err) + } var hasErr int32 var outMtx sync.Mutex @@ -129,8 +134,12 @@ func run() error { return } - contractPath := contractFiles[contractName] - if contractPath == "" { + var contractPath string + if path, ok := contractFiles[contractName]; ok { + contractPath = path + } else if path, ok := testFiles[contractName]; ok { + contractPath = path + } else { fail("%s: Source file not found", contractName) return } diff --git a/packages/contracts-bedrock/test/L2/SuperchainERC20.t.sol b/packages/contracts-bedrock/test/L2/SuperchainERC20.t.sol index bc5785901d14..b4909bf26134 100644 --- a/packages/contracts-bedrock/test/L2/SuperchainERC20.t.sol +++ b/packages/contracts-bedrock/test/L2/SuperchainERC20.t.sol @@ -18,16 +18,7 @@ import { BeaconProxy } from "@openzeppelin/contracts-v5/proxy/beacon/BeaconProxy // Target contract import { SuperchainERC20, ISuperchainERC20Extension } from "src/L2/SuperchainERC20.sol"; import { ISuperchainERC20Errors } from "src/L2/interfaces/ISuperchainERC20.sol"; - -contract SuperchainERC20Implementation is SuperchainERC20 { - function name() public pure override returns (string memory) { - return "SuperchainERC20"; - } - - function symbol() public pure override returns (string memory) { - return "SCE"; - } -} +import { SuperchainERC20ImplementationMock } from "test/mocks/SuperchainERC20ImplementationMock.sol"; /// @title SuperchainERC20Test /// @notice Contract for testing the SuperchainERC20 contract. @@ -40,7 +31,7 @@ contract SuperchainERC20Test is Test { /// @notice Sets up the test suite. function setUp() public { - superchainERC20 = new SuperchainERC20Implementation(); + superchainERC20 = new SuperchainERC20ImplementationMock(); } /// @notice Helper function to setup a mock and expect a call to it. diff --git a/packages/contracts-bedrock/test/mocks/SuperchainERC20ImplementationMock.sol b/packages/contracts-bedrock/test/mocks/SuperchainERC20ImplementationMock.sol new file mode 100644 index 000000000000..c4eb67259e38 --- /dev/null +++ b/packages/contracts-bedrock/test/mocks/SuperchainERC20ImplementationMock.sol @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +import { SuperchainERC20 } from "src/L2/SuperchainERC20.sol"; + +/// @title SuperchainERC20ImplementationMock +/// @notice Mock contract just to create tests over an implementation of the SuperchainERC20 abstract contract. +contract SuperchainERC20ImplementationMock is SuperchainERC20 { + /// @notice Semantic version. + /// @custom:semver 1.0.0-beta.1 + string public constant override version = "1.0.0-beta.1"; + + function name() public pure override returns (string memory) { + return "SuperchainERC20"; + } + + function symbol() public pure override returns (string memory) { + return "SCE"; + } +} From 2b75646596e218a79dcf95e080fbb5e9e406be11 Mon Sep 17 00:00:00 2001 From: agusduha Date: Thu, 3 Oct 2024 12:18:38 -0300 Subject: [PATCH 2/3] fix: ignore mock contracts in semver natspec script --- .../scripts/checks/semver-natspec/main.go | 18 +++++++----------- .../test/L2/SuperchainERC20.t.sol | 4 ++-- ...k.sol => SuperchainERC20Implementation.sol} | 4 ++-- 3 files changed, 11 insertions(+), 15 deletions(-) rename packages/contracts-bedrock/test/mocks/{SuperchainERC20ImplementationMock.sol => SuperchainERC20Implementation.sol} (81%) diff --git a/packages/contracts-bedrock/scripts/checks/semver-natspec/main.go b/packages/contracts-bedrock/scripts/checks/semver-natspec/main.go index c6650d9bc2b7..7b290dd9a734 100644 --- a/packages/contracts-bedrock/scripts/checks/semver-natspec/main.go +++ b/packages/contracts-bedrock/scripts/checks/semver-natspec/main.go @@ -63,7 +63,6 @@ func run() error { artifactsDir := filepath.Join(cwd, "forge-artifacts") srcDir := filepath.Join(cwd, "src") - testDir := filepath.Join(cwd, "test") artifactFiles, err := glob(artifactsDir, ".json") if err != nil { @@ -73,10 +72,6 @@ func run() error { if err != nil { return fmt.Errorf("failed to get contract files: %w", err) } - testFiles, err := glob(testDir, ".sol") - if err != nil { - return fmt.Errorf("failed to get test files: %w", err) - } var hasErr int32 var outMtx sync.Mutex @@ -134,12 +129,13 @@ func run() error { return } - var contractPath string - if path, ok := contractFiles[contractName]; ok { - contractPath = path - } else if path, ok := testFiles[contractName]; ok { - contractPath = path - } else { + // Skip mock contracts + if strings.Contains(contractName, "_MockContract") { + return + } + + contractPath := contractFiles[contractName] + if contractPath == "" { fail("%s: Source file not found", contractName) return } diff --git a/packages/contracts-bedrock/test/L2/SuperchainERC20.t.sol b/packages/contracts-bedrock/test/L2/SuperchainERC20.t.sol index b4909bf26134..30b758a38e6d 100644 --- a/packages/contracts-bedrock/test/L2/SuperchainERC20.t.sol +++ b/packages/contracts-bedrock/test/L2/SuperchainERC20.t.sol @@ -18,7 +18,7 @@ import { BeaconProxy } from "@openzeppelin/contracts-v5/proxy/beacon/BeaconProxy // Target contract import { SuperchainERC20, ISuperchainERC20Extension } from "src/L2/SuperchainERC20.sol"; import { ISuperchainERC20Errors } from "src/L2/interfaces/ISuperchainERC20.sol"; -import { SuperchainERC20ImplementationMock } from "test/mocks/SuperchainERC20ImplementationMock.sol"; +import { SuperchainERC20Implementation_MockContract } from "test/mocks/SuperchainERC20Implementation.sol"; /// @title SuperchainERC20Test /// @notice Contract for testing the SuperchainERC20 contract. @@ -31,7 +31,7 @@ contract SuperchainERC20Test is Test { /// @notice Sets up the test suite. function setUp() public { - superchainERC20 = new SuperchainERC20ImplementationMock(); + superchainERC20 = new SuperchainERC20Implementation_MockContract(); } /// @notice Helper function to setup a mock and expect a call to it. diff --git a/packages/contracts-bedrock/test/mocks/SuperchainERC20ImplementationMock.sol b/packages/contracts-bedrock/test/mocks/SuperchainERC20Implementation.sol similarity index 81% rename from packages/contracts-bedrock/test/mocks/SuperchainERC20ImplementationMock.sol rename to packages/contracts-bedrock/test/mocks/SuperchainERC20Implementation.sol index c4eb67259e38..4f3dec45896c 100644 --- a/packages/contracts-bedrock/test/mocks/SuperchainERC20ImplementationMock.sol +++ b/packages/contracts-bedrock/test/mocks/SuperchainERC20Implementation.sol @@ -3,9 +3,9 @@ pragma solidity 0.8.25; import { SuperchainERC20 } from "src/L2/SuperchainERC20.sol"; -/// @title SuperchainERC20ImplementationMock +/// @title SuperchainERC20Implementation Mock contract /// @notice Mock contract just to create tests over an implementation of the SuperchainERC20 abstract contract. -contract SuperchainERC20ImplementationMock is SuperchainERC20 { +contract SuperchainERC20Implementation_MockContract is SuperchainERC20 { /// @notice Semantic version. /// @custom:semver 1.0.0-beta.1 string public constant override version = "1.0.0-beta.1"; From 4d965053eb676532f6969c1c58151b5631d40b3d Mon Sep 17 00:00:00 2001 From: agusduha Date: Thu, 3 Oct 2024 12:35:00 -0300 Subject: [PATCH 3/3] fix: error message --- .../contracts-bedrock/scripts/checks/semver-natspec/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/contracts-bedrock/scripts/checks/semver-natspec/main.go b/packages/contracts-bedrock/scripts/checks/semver-natspec/main.go index 7b290dd9a734..cc65480d2c00 100644 --- a/packages/contracts-bedrock/scripts/checks/semver-natspec/main.go +++ b/packages/contracts-bedrock/scripts/checks/semver-natspec/main.go @@ -136,7 +136,7 @@ func run() error { contractPath := contractFiles[contractName] if contractPath == "" { - fail("%s: Source file not found", contractName) + fail("%s: Source file not found (For test mock contracts, suffix the name with '_MockContract' to ignore this warning)", contractName) return }