Skip to content

Commit

Permalink
feat: contracts dev build and test commands (ethereum-optimism#13345)
Browse files Browse the repository at this point in the history
Adds new dev commands that use the lite profile to execute
everything and ultimately reduce compile time by several minutes.
  • Loading branch information
smartcontracts authored Dec 10, 2024
1 parent be083a0 commit 839d382
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
17 changes: 16 additions & 1 deletion packages/contracts-bedrock/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ dep-status:
# BUILD #
########################################################

# Core forge build command
# Core forge build command.
forge-build:
forge build

# Developer build command (faster).
forge-build-dev:
FOUNDRY_PROFILE=lite forge build

# Builds the contracts.
build: lint-fix-no-fail forge-build interfaces-check-no-build

# Builds the contracts (developer mode).
build-dev: lint-fix-no-fail forge-build-dev interfaces-check-no-build

# Builds the go-ffi tool for contract tests.
build-go-ffi-default:
cd ./scripts/go-ffi && go build
Expand All @@ -45,10 +52,18 @@ clean:
test *ARGS: build-go-ffi
forge test {{ARGS}}

# Runs standard contract tests (developer mode).
test-dev *ARGS: build-go-ffi
FOUNDRY_PROFILE=lite forge test {{ARGS}}

# Runs standard contract tests with rerun flag.
test-rerun: build-go-ffi
forge test --rerun -vvv

# Runs standard contract tests with rerun flag (developer mode).
test-dev-rerun: build-go-ffi
FOUNDRY_PROFILE=lite forge test --rerun -vvv

# Run Kontrol tests and build all dependencies.
test-kontrol: build-go-ffi build kontrol-summary-full test-kontrol-no-build

Expand Down
16 changes: 12 additions & 4 deletions packages/contracts-bedrock/test/legacy/L1ChugSplashProxy.t.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.15;

// Testing utilities
// Forge
import { Test } from "forge-std/Test.sol";
import { VmSafe } from "forge-std/Vm.sol";

// Target contract
import { IL1ChugSplashProxy } from "interfaces/legacy/IL1ChugSplashProxy.sol";
// Scripts
import { DeployUtils } from "scripts/libraries/DeployUtils.sol";

// Libraries
import { LibString } from "@solady/utils/LibString.sol";

// Interfaces
import { IL1ChugSplashProxy } from "interfaces/legacy/IL1ChugSplashProxy.sol";

contract Owner {
bool public isUpgrading;

Expand Down Expand Up @@ -103,7 +108,10 @@ contract L1ChugSplashProxy_Test is Test {
// Because forge coverage always runs with the optimizer disabled,
// if forge coverage is run before testing this with forge test or forge snapshot, forge clean should be
// run first so that it recompiles the contracts using the foundry.toml optimizer settings.
if (vm.isContext(VmSafe.ForgeContext.Coverage)) {
if (
vm.isContext(VmSafe.ForgeContext.Coverage)
|| LibString.eq(vm.envOr("FOUNDRY_PROFILE", string("default")), "lite")
) {
gasLimit = 95_000;
} else if (vm.isContext(VmSafe.ForgeContext.Test) || vm.isContext(VmSafe.ForgeContext.Snapshot)) {
gasLimit = 65_000;
Expand Down
15 changes: 11 additions & 4 deletions packages/contracts-bedrock/test/libraries/SafeCall.t.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;

// Testing utilities
// Forge
import { Test } from "forge-std/Test.sol";
import { VmSafe } from "forge-std/Vm.sol";
import { StdCheatsSafe } from "forge-std/StdCheats.sol";

// Target contract
// Libraries
import { LibString } from "@solady/utils/LibString.sol";
import { SafeCall } from "src/libraries/SafeCall.sol";

contract SafeCall_Test is Test {
Expand Down Expand Up @@ -133,7 +134,10 @@ contract SafeCall_Test is Test {
// Because forge coverage always runs with the optimizer disabled,
// if forge coverage is run before testing this with forge test or forge snapshot, forge clean should be
// run first so that it recompiles the contracts using the foundry.toml optimizer settings.
if (vm.isContext(VmSafe.ForgeContext.Coverage)) {
if (
vm.isContext(VmSafe.ForgeContext.Coverage)
|| LibString.eq(vm.envOr("FOUNDRY_PROFILE", string("default")), "lite")
) {
// 66_290 is the exact amount of gas required to make the safe call
// successfully with the optimizer disabled (ran via forge coverage)
expected = 66_290;
Expand Down Expand Up @@ -173,7 +177,10 @@ contract SafeCall_Test is Test {
// Because forge coverage always runs with the optimizer disabled,
// if forge coverage is run before testing this with forge test or forge snapshot, forge clean should be
// run first so that it recompiles the contracts using the foundry.toml optimizer settings.
if (vm.isContext(VmSafe.ForgeContext.Coverage)) {
if (
vm.isContext(VmSafe.ForgeContext.Coverage)
|| LibString.eq(vm.envOr("FOUNDRY_PROFILE", string("default")), "lite")
) {
// 15_278_989 is the exact amount of gas required to make the safe call
// successfully with the optimizer disabled (ran via forge coverage)
expected = 15_278_989;
Expand Down

0 comments on commit 839d382

Please sign in to comment.