From d786a7bd463b907bf94f6cf260b87e0bfca7ea7c Mon Sep 17 00:00:00 2001 From: spengrah Date: Tue, 19 Nov 2024 10:47:45 -0600 Subject: [PATCH 1/7] update example.env --- example.env | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/example.env b/example.env index ee2fc7e..1b28a76 100644 --- a/example.env +++ b/example.env @@ -1,10 +1,10 @@ GC_RPC= -POLYGON_RPC= INFURA_KEY= export PRIVATE_KEY= ETHERSCAN_KEY= GNOSISSCAN_KEY= POLYGONSCAN_KEY= -OPTIMISM_KEY= +OPTIMISM_ETHERSCAN_KEY= ARBISCAN_KEY= -FOUNDRY_PROFILE= \ No newline at end of file +BASESCAN_KEY= +CELOSCAN_KEY= \ No newline at end of file From 50f915b185aff6237be7927ee4174314145151b5 Mon Sep 17 00:00:00 2001 From: spengrah Date: Tue, 19 Nov 2024 10:47:51 -0600 Subject: [PATCH 2/7] update foundry.toml --- foundry.toml | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/foundry.toml b/foundry.toml index d4726d6..441d53f 100644 --- a/foundry.toml +++ b/foundry.toml @@ -7,7 +7,8 @@ optimizer_runs = 1_000_000 bytecode_hash = "none" gas_reports = [] auto_detect_solc = false -solc = "0.8.19" +solc = "0.8.28" +evm_version = "cancun" remappings = [ "ds-test/=lib/forge-std/lib/ds-test/src/", "forge-std/=lib/forge-std/src/", @@ -51,21 +52,24 @@ wrap_comments = true [rpc_endpoints] arbitrum = "https://arbitrum-mainnet.infura.io/v3/${INFURA_KEY}" +base = "https://base-mainnet.infura.io/v3/${INFURA_KEY}" +celo = "https://celo-mainnet.infura.io/v3/${INFURA_KEY}" gnosis = "${GC_RPC}" -goerli = "https://goerli.infura.io/v3/${INFURA_KEY}" local = "http://localhost:8545" mainnet = "https://mainnet.infura.io/v3/${INFURA_KEY}" optimism = "https://optimism-mainnet.infura.io/v3/${INFURA_KEY}" -polygon = "${POLYGON_RPC}" +polygon = "https://polygon-mainnet.infura.io/v3/${INFURA_KEY}" sepolia = "https://sepolia.infura.io/v3/${INFURA_KEY}" [etherscan] -arbitrum = { key = "${ARBISCAN_KEY}", url = "https://api.arbiscan.io/api" } -goerli = { key = "${ETHERSCAN_KEY}", url = "https://api-goerli.etherscan.io/api" } -gnosis = { key = "${GNOSISSCAN_KEY}", url = "https://api.gnosisscan.io/api" } -mainnet = { key = "${ETHERSCAN_KEY}", url = "https://api.etherscan.io/api" } -optimism = { key = "${OPTIMISM_KEY}", url = "https://api-optimistic.etherscan.io/api" } -sepolia = { key = "${ETHERSCAN_KEY}", url = "https://api-sepolia.etherscan.io/api" } -polygon = { key = "${POLYGONSCAN_KEY}", url = "https://api.polygonscan.com/api" } +arbitrum = {key = "${ARBISCAN_KEY}", url = "https://api.arbiscan.io/api"} +base = {key = "${BASESCAN_KEY}", url = "https://api.basescan.org/api"} +celo = {key = "${CELOSCAN_KEY}", url = "https://api.celoscan.org/api"} +goerli = {key = "${ETHERSCAN_KEY}", url = "https://api-goerli.etherscan.io/api"} +mainnet = {key = "${ETHERSCAN_KEY}", url = "https://api.etherscan.io/api"} +optimism = {key = "${OPTIMISM_ETHERSCAN_KEY}", url = "https://api-optimistic.etherscan.io/api"} +polygon = {key = "${POLYGONSCAN_KEY}", url = "https://api.polygonscan.com/api"} +gnosis = {key = "${GNOSISSCAN_KEY}", url = "https://api.gnosisscan.io/api"} +sepolia = {key = "${ETHERSCAN_KEY}", url = "https://api-sepolia.etherscan.io/api"} # See more config options https://github.com/foundry-rs/foundry/tree/master/config From 4a5ffa2a0fc0dd3099e32f1d2a3fe38473c9d60d Mon Sep 17 00:00:00 2001 From: spengrah Date: Tue, 19 Nov 2024 10:48:11 -0600 Subject: [PATCH 3/7] improve script template --- script/{Counter.s.sol => Contract.s.sol} | 26 +++++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) rename script/{Counter.s.sol => Contract.s.sol} (82%) diff --git a/script/Counter.s.sol b/script/Contract.s.sol similarity index 82% rename from script/Counter.s.sol rename to script/Contract.s.sol index 1bce003..2bb2704 100644 --- a/script/Counter.s.sol +++ b/script/Contract.s.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.18; import { Script, console2 } from "forge-std/Script.sol"; -import { Counter } from "../src/Counter.sol"; +import { Contract } from "../src/Contract.sol"; interface ImmutableCreate2Factory { function create2(bytes32 salt, bytes calldata initializationCode) @@ -12,32 +12,34 @@ interface ImmutableCreate2Factory { } contract Deploy is Script { - Counter public counter; + Contract public cntrct; bytes32 public SALT = bytes32(abi.encode("lets add some salt to these eggs")); // default values bool internal _verbose = true; + // init other variables /// @dev Override default values, if desired function prepare(bool verbose) public { _verbose = verbose; + // set other variables } /// @dev Set up the deployer via their private key from the environment - function deployer() public returns (address) { + function _deployer() internal returns (address) { uint256 privKey = vm.envUint("PRIVATE_KEY"); return vm.rememberKey(privKey); } function _log(string memory prefix) internal view { if (_verbose) { - console2.log(string.concat(prefix, "Counter:"), address(counter)); + console2.log(string.concat(prefix, "Contract:"), address(cntrct)); } } /// @dev Deploy the contract to a deterministic address via forge's create2 deployer factory. - function run() public virtual { - vm.startBroadcast(deployer()); + function run() public virtual returns (Contract) { + vm.startBroadcast(_deployer()); /** * @dev Deploy the contract to a deterministic address via forge's create2 deployer factory, which is at this @@ -47,11 +49,13 @@ contract Deploy is Script { * never differs regardless of where its being compiled * 2. The provided salt, `SALT` */ - counter = new Counter{ salt: SALT}(/* insert constructor args here */); + cntrct = new Contract{ salt: SALT }( /* insert constructor args here */ ); vm.stopBroadcast(); _log(""); + + return cntrct; } } @@ -59,17 +63,19 @@ contract Deploy is Script { contract DeployPrecompiled is Deploy { /// @dev Update SALT and default values in Deploy contract - function run() public override { - vm.startBroadcast(deployer()); + function run() public override returns (Contract) { + vm.startBroadcast(_deployer()); bytes memory args = abi.encode( /* insert constructor args here */ ); /// @dev Load and deploy pre-compiled ir-optimized bytecode. - counter = Counter(deployCode("optimized-out/Counter.sol/Counter.json", args)); + cntrct = Contract(deployCode("optimized-out/Contract.sol/Contract.json", args)); vm.stopBroadcast(); _log("Precompiled "); + + return cntrct; } } From 95e0a104e91dbc699b03aa0aa3dc7af49f14ef5c Mon Sep 17 00:00:00 2001 From: spengrah Date: Tue, 19 Nov 2024 10:48:24 -0600 Subject: [PATCH 4/7] improve test template --- test/Contract.t.sol | 35 +++++++++++++++++++++++++++++++++++ test/Counter.t.sol | 32 -------------------------------- 2 files changed, 35 insertions(+), 32 deletions(-) create mode 100644 test/Contract.t.sol delete mode 100644 test/Counter.t.sol diff --git a/test/Contract.t.sol b/test/Contract.t.sol new file mode 100644 index 0000000..2aad278 --- /dev/null +++ b/test/Contract.t.sol @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.18; + +import { Test, console2 } from "forge-std/Test.sol"; +import { Contract } from "../src/Contract.sol"; +import { Deploy, DeployPrecompiled } from "../script/Contract.s.sol"; + +contract ContractTest is Test { + /// @dev Inherit from DeployPrecompiled instead of Deploy if working with pre-compiled contracts + + Contract public cntrct; + uint256 public constant TEST_SALT_NONCE = 1; + bytes32 public constant TEST_SALT = bytes32(abi.encode(TEST_SALT_NONCE)); + + uint256 public fork; + uint256 public BLOCK_NUMBER; + + function _deploy() internal returns (Contract) { + Deploy deployer = new Deploy(); + deployer.prepare(false); + return deployer.run(); + } + + function setUp() public virtual { + // OPTIONAL: create and activate a fork, at BLOCK_NUMBER + // fork = vm.createSelectFork(vm.rpcUrl("mainnet"), BLOCK_NUMBER); + + // deploy the contract + cntrct = _deploy(); + } +} + +contract UnitTests is ContractTest { + function test_empty() public view { } +} diff --git a/test/Counter.t.sol b/test/Counter.t.sol deleted file mode 100644 index e190441..0000000 --- a/test/Counter.t.sol +++ /dev/null @@ -1,32 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.18; - -import { Test, console2 } from "forge-std/Test.sol"; -import { Counter } from "../src/Counter.sol"; -import { Deploy, DeployPrecompiled } from "../script/Counter.s.sol"; - -contract CounterTest is Deploy, Test { - /// @dev Inherit from DeployPrecompiled instead of Deploy if working with pre-compiled contracts - - /// @dev variables inhereted from Deploy script - // Counter public counter; - // bytes32 public SALT; - - uint256 public fork; - uint256 public BLOCK_NUMBER; - - function setUp() public virtual { - // OPTIONAL: create and activate a fork, at BLOCK_NUMBER - // fork = vm.createSelectFork(vm.rpcUrl("mainnet"), BLOCK_NUMBER); - - // deploy via the script - prepare(false); - run(); - } -} - -contract UnitTests is CounterTest { - function test_empty() public { - counter.setNumber(2); - } -} From c68ec2a2148905527db8b3df27d1c9574d6e9fbc Mon Sep 17 00:00:00 2001 From: spengrah Date: Tue, 19 Nov 2024 10:48:31 -0600 Subject: [PATCH 5/7] simplify contract template --- src/{Counter.sol => Contract.sol} | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) rename src/{Counter.sol => Contract.sol} (58%) diff --git a/src/Counter.sol b/src/Contract.sol similarity index 58% rename from src/Counter.sol rename to src/Contract.sol index a18659a..4949383 100644 --- a/src/Counter.sol +++ b/src/Contract.sol @@ -3,41 +3,32 @@ pragma solidity ^0.8.18; // import { console2 } from "forge-std/Test.sol"; // remove before deploy -contract Counter { - /*////////////////////////////////////////////////////////////// +contract Contract { +/*////////////////////////////////////////////////////////////// CUSTOM ERRORS //////////////////////////////////////////////////////////////*/ - /*////////////////////////////////////////////////////////////// +/*////////////////////////////////////////////////////////////// EVENTS //////////////////////////////////////////////////////////////*/ - /*////////////////////////////////////////////////////////////// +/*////////////////////////////////////////////////////////////// DATA MODELS //////////////////////////////////////////////////////////////*/ - /*////////////////////////////////////////////////////////////// +/*////////////////////////////////////////////////////////////// CONSANTS //////////////////////////////////////////////////////////////*/ - /*////////////////////////////////////////////////////////////// +/*////////////////////////////////////////////////////////////// MUTABLE STATE //////////////////////////////////////////////////////////////*/ - uint256 public number; - /*////////////////////////////////////////////////////////////// +/*////////////////////////////////////////////////////////////// CONSTRUCTOR //////////////////////////////////////////////////////////////*/ - /*////////////////////////////////////////////////////////////// +/*////////////////////////////////////////////////////////////// PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////*/ - - function setNumber(uint256 newNumber) public { - number = newNumber; - } - - function increment() public { - number++; - } } From 128e880e6bc730023d7f971cec0e098cf184c233 Mon Sep 17 00:00:00 2001 From: spengrah Date: Tue, 19 Nov 2024 11:18:27 -0600 Subject: [PATCH 6/7] fix coverage ci --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cedb8f1..d904680 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -87,14 +87,14 @@ jobs: # is why we use both in this way. - name: Post coverage report if: github.event_name == 'pull_request' # This action fails when ran outside of a pull request. - uses: romeovs/lcov-reporter-action@v0.3.1 + uses: romeovs/lcov-reporter-action@v0.4.0 with: delete-old-comments: true lcov-file: ./lcov.info github-token: ${{ secrets.GITHUB_TOKEN }} # Adds a coverage summary comment to the PR. - name: Verify minimum coverage - uses: zgosalvez/github-actions-report-lcov@v2 + uses: zgosalvez/github-actions-report-lcov@v3 with: coverage-files: ./lcov.info minimum-coverage: 95 # Set coverage threshold. \ No newline at end of file From cc39418025fa63da26c47593eaae48f4af187dbb Mon Sep 17 00:00:00 2001 From: spengrah Date: Tue, 19 Nov 2024 11:21:42 -0600 Subject: [PATCH 7/7] add basic function to test coverage ci --- src/Contract.sol | 20 ++++++++++++-------- test/Contract.t.sol | 4 +++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Contract.sol b/src/Contract.sol index 4949383..ced5442 100644 --- a/src/Contract.sol +++ b/src/Contract.sol @@ -4,31 +4,35 @@ pragma solidity ^0.8.18; // import { console2 } from "forge-std/Test.sol"; // remove before deploy contract Contract { -/*////////////////////////////////////////////////////////////// + /*////////////////////////////////////////////////////////////// CUSTOM ERRORS //////////////////////////////////////////////////////////////*/ -/*////////////////////////////////////////////////////////////// + /*////////////////////////////////////////////////////////////// EVENTS //////////////////////////////////////////////////////////////*/ -/*////////////////////////////////////////////////////////////// + /*////////////////////////////////////////////////////////////// DATA MODELS //////////////////////////////////////////////////////////////*/ -/*////////////////////////////////////////////////////////////// - CONSANTS + /*////////////////////////////////////////////////////////////// + CONSTANTS //////////////////////////////////////////////////////////////*/ -/*////////////////////////////////////////////////////////////// + /*////////////////////////////////////////////////////////////// MUTABLE STATE //////////////////////////////////////////////////////////////*/ -/*////////////////////////////////////////////////////////////// + /*////////////////////////////////////////////////////////////// CONSTRUCTOR //////////////////////////////////////////////////////////////*/ -/*////////////////////////////////////////////////////////////// + /*////////////////////////////////////////////////////////////// PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////*/ + + function doSomething() public pure returns (uint256) { + return 1; + } } diff --git a/test/Contract.t.sol b/test/Contract.t.sol index 2aad278..c20c44f 100644 --- a/test/Contract.t.sol +++ b/test/Contract.t.sol @@ -31,5 +31,7 @@ contract ContractTest is Test { } contract UnitTests is ContractTest { - function test_empty() public view { } + function test_doSomething() public view { + cntrct.doSomething(); + } }