diff --git a/.github/workflows/run-smc-tests.yml b/.github/workflows/run-smc-tests.yml index dc1610bf..cf21d409 100644 --- a/.github/workflows/run-smc-tests.yml +++ b/.github/workflows/run-smc-tests.yml @@ -48,6 +48,10 @@ jobs: - name: Check JS formatting run: pnpm -F contracts run lint:ts + # Required for hardhat commands due to @nomicfoundation/hardhat-foundry package + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + - name: Compile kzg.node run: npx node-gyp --directory=contracts/node_modules/c-kzg rebuild # explicitly running rebuild to get the .node file diff --git a/.gitignore b/.gitignore index 7a2243c2..6e797139 100644 --- a/.gitignore +++ b/.gitignore @@ -53,4 +53,5 @@ coverage tsconfig.build.tsbuildinfo ts-libs/**/lib/**/*.so ts-libs/**/lib/**/*.dylib -contracts/lib/forge-std/ \ No newline at end of file +contracts/lib/forge-std/ +cache_forge \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index 4858b4f1..66217348 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "corset"] path = corset url = git@github.com:consensys/corset.git +[submodule "contracts/lib/forge-std"] + path = contracts/lib/forge-std + url = https://github.com/foundry-rs/forge-std diff --git a/contracts/.prettierignore b/contracts/.prettierignore index 03557074..86906cc8 100644 --- a/contracts/.prettierignore +++ b/contracts/.prettierignore @@ -4,3 +4,4 @@ cache coverage* gasReporterOutput.json typechain-types +lib \ No newline at end of file diff --git a/contracts/.solhintignore b/contracts/.solhintignore index 8622e5d7..6a7b11aa 100644 --- a/contracts/.solhintignore +++ b/contracts/.solhintignore @@ -1,2 +1,4 @@ node_modules -contracts/test-contracts \ No newline at end of file +lib/forge-std +contracts/test-contracts +test/foundry \ No newline at end of file diff --git a/contracts/foundry.toml b/contracts/foundry.toml new file mode 100644 index 00000000..92a32934 --- /dev/null +++ b/contracts/foundry.toml @@ -0,0 +1,22 @@ +[profile.default] +src = 'contracts' +out = 'out' +libs = ['node_modules', 'lib'] +cache_path = 'cache_forge' + +# Test settings +match-path = 'test/foundry/*' + +# Default solc compiler settings +evm_version = "cancun" +optimizer = true +optimizer_runs = 10_000 + +# Compiler overrides +additional_compiler_profiles = [ { name = "london", evm_version = "london" } ] + +# Specify EVM_VERSION restrictions for contract compilation +compilation_restrictions = [ + { paths = "./**/L2MessageService.sol", evm_version = "london" }, + { paths = "./**/TokenBridge.sol", evm_version = "london" }, +] \ No newline at end of file diff --git a/contracts/hardhat.config.ts b/contracts/hardhat.config.ts index 9fea272b..b7c776fd 100644 --- a/contracts/hardhat.config.ts +++ b/contracts/hardhat.config.ts @@ -1,4 +1,5 @@ import "@nomicfoundation/hardhat-toolbox"; +import "@nomicfoundation/hardhat-foundry"; import "@openzeppelin/hardhat-upgrades"; import * as dotenv from "dotenv"; import "hardhat-deploy"; diff --git a/contracts/lib/forge-std b/contracts/lib/forge-std new file mode 160000 index 00000000..1eea5bae --- /dev/null +++ b/contracts/lib/forge-std @@ -0,0 +1 @@ +Subproject commit 1eea5bae12ae557d589f9f0f0edae2faa47cb262 diff --git a/contracts/package.json b/contracts/package.json index 97ab10f9..d5e09b80 100644 --- a/contracts/package.json +++ b/contracts/package.json @@ -24,6 +24,7 @@ "devDependencies": { "@ethereumjs/util": "9.0.3", "@nomicfoundation/hardhat-ethers": "3.0.5", + "@nomicfoundation/hardhat-foundry": "1.1.3", "@nomicfoundation/hardhat-network-helpers": "1.0.10", "@nomicfoundation/hardhat-toolbox": "4.0.0", "@nomicfoundation/hardhat-verify": "1.1.1", diff --git a/contracts/test/foundry/ExampleFoundryTest.t.sol b/contracts/test/foundry/ExampleFoundryTest.t.sol new file mode 100644 index 00000000..4753397e --- /dev/null +++ b/contracts/test/foundry/ExampleFoundryTest.t.sol @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity 0.8.26; + +import "forge-std/Test.sol"; + +contract ExampleFoundryTest is Test { + function setUp() public {} + + function testSample() public { + // Write test + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d39c43f1..b618b1b7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -178,6 +178,9 @@ importers: '@nomicfoundation/hardhat-ethers': specifier: 3.0.5 version: 3.0.5(ethers@6.12.0(bufferutil@4.0.8)(utf-8-validate@5.0.10))(hardhat@2.22.11(bufferutil@4.0.8)(c-kzg@2.1.2)(ts-node@10.9.2(@types/node@20.12.7)(typescript@5.4.5))(typescript@5.4.5)(utf-8-validate@5.0.10)) + '@nomicfoundation/hardhat-foundry': + specifier: 1.1.3 + version: 1.1.3(hardhat@2.22.11(bufferutil@4.0.8)(c-kzg@2.1.2)(ts-node@10.9.2(@types/node@20.12.7)(typescript@5.4.5))(typescript@5.4.5)(utf-8-validate@5.0.10)) '@nomicfoundation/hardhat-network-helpers': specifier: 1.0.10 version: 1.0.10(hardhat@2.22.11(bufferutil@4.0.8)(c-kzg@2.1.2)(ts-node@10.9.2(@types/node@20.12.7)(typescript@5.4.5))(typescript@5.4.5)(utf-8-validate@5.0.10)) @@ -2215,6 +2218,11 @@ packages: ethers: ^6.1.0 hardhat: ^2.0.0 + '@nomicfoundation/hardhat-foundry@1.1.3': + resolution: {integrity: sha512-30Ezc3hlZ4pC5Z/9W9euW5uoPKKQQKaecLETHJH8BPpd30zYOooy6HfjmcTY1/taOQjlwirOdNO7tHlje8Qcgw==} + peerDependencies: + hardhat: ^2.17.2 + '@nomicfoundation/hardhat-network-helpers@1.0.10': resolution: {integrity: sha512-R35/BMBlx7tWN5V6d/8/19QCwEmIdbnA4ZrsuXgvs8i2qFx5i7h6mH5pBS4Pwi4WigLH+upl6faYusrNPuzMrQ==} peerDependencies: @@ -2670,6 +2678,7 @@ packages: '@safe-global/safe-core-sdk-types@4.0.2': resolution: {integrity: sha512-3I60xV/BLPiBtc3nGp2itgiDL+YbMI9OwaANvnJL2AwSS1kc2kH3/SsCwAW3s4Usr3b0lE08aO7I9ropyxFHhA==} + deprecated: 'WARNING: This project has been renamed to @safe-global/types-kit. Please, migrate from @safe-global/safe-core-sdk-types@5.1.0 to @safe-global/types-kit@1.0.0.' '@safe-global/safe-deployments@1.37.10': resolution: {integrity: sha512-lcxX9CV+xdcLs4dF6Cx18zDww5JyqaX6RdcvU0o/34IgJ4Wjo3J/RNzJAoMhurCAfTGr+0vyJ9V13Qo50AR6JA==} @@ -5012,6 +5021,7 @@ packages: eslint@8.57.0: resolution: {integrity: sha512-dZ6+mexnaTIbSBZWgou51U6OmzIhYM2VcNdtiTtI7qPNZm35Akpr0f6vtw3w1Kmn5PYo+tZVfh13WrhpS6oLqQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + deprecated: This version is no longer supported. Please see https://eslint.org/version-support for other options. hasBin: true esniff@2.0.1: @@ -9824,7 +9834,7 @@ snapshots: '@babel/core': 7.25.7 '@babel/helper-module-imports': 7.25.7 '@babel/helper-simple-access': 7.25.7 - '@babel/helper-validator-identifier': 7.25.7 + '@babel/helper-validator-identifier': 7.25.9 '@babel/traverse': 7.25.7 transitivePeerDependencies: - supports-color @@ -10261,7 +10271,7 @@ snapshots: '@babel/core': 7.25.7 '@babel/helper-module-transforms': 7.25.7(@babel/core@7.25.7) '@babel/helper-plugin-utils': 7.25.7 - '@babel/helper-validator-identifier': 7.25.7 + '@babel/helper-validator-identifier': 7.25.9 '@babel/traverse': 7.25.7 transitivePeerDependencies: - supports-color @@ -11910,6 +11920,11 @@ snapshots: transitivePeerDependencies: - supports-color + '@nomicfoundation/hardhat-foundry@1.1.3(hardhat@2.22.11(bufferutil@4.0.8)(c-kzg@2.1.2)(ts-node@10.9.2(@types/node@20.12.7)(typescript@5.4.5))(typescript@5.4.5)(utf-8-validate@5.0.10))': + dependencies: + hardhat: 2.22.11(bufferutil@4.0.8)(c-kzg@2.1.2)(ts-node@10.9.2(@types/node@20.12.7)(typescript@5.4.5))(typescript@5.4.5)(utf-8-validate@5.0.10) + picocolors: 1.1.0 + '@nomicfoundation/hardhat-network-helpers@1.0.10(hardhat@2.22.11(bufferutil@4.0.8)(c-kzg@2.1.2)(ts-node@10.9.2(@types/node@20.12.7)(typescript@5.4.5))(typescript@5.4.5)(utf-8-validate@5.0.10))': dependencies: ethereumjs-util: 7.1.5 @@ -15844,7 +15859,7 @@ snapshots: debug: 4.3.7(supports-color@8.1.1) enhanced-resolve: 5.17.1 eslint: 8.57.0 - eslint-module-utils: 2.12.0(@typescript-eslint/parser@7.6.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@7.6.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.31.0)(eslint@8.57.0))(eslint@8.57.0) + eslint-module-utils: 2.12.0(@typescript-eslint/parser@7.6.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3)(eslint@8.57.0) fast-glob: 3.3.2 get-tsconfig: 4.8.1 is-bun-module: 1.2.1 @@ -15857,7 +15872,7 @@ snapshots: - eslint-import-resolver-webpack - supports-color - eslint-module-utils@2.12.0(@typescript-eslint/parser@7.6.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@7.6.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.31.0)(eslint@8.57.0))(eslint@8.57.0): + eslint-module-utils@2.12.0(@typescript-eslint/parser@7.6.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3)(eslint@8.57.0): dependencies: debug: 3.2.7 optionalDependencies: @@ -15879,7 +15894,7 @@ snapshots: doctrine: 2.1.0 eslint: 8.57.0 eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.12.0(@typescript-eslint/parser@7.6.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@7.6.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.31.0)(eslint@8.57.0))(eslint@8.57.0) + eslint-module-utils: 2.12.0(@typescript-eslint/parser@7.6.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3)(eslint@8.57.0) hasown: 2.0.2 is-core-module: 2.15.1 is-glob: 4.0.3