From 5f52bc581121e9c2dd80288e58738bfe510d7351 Mon Sep 17 00:00:00 2001 From: OneTony Date: Tue, 28 Nov 2023 13:55:43 +0200 Subject: [PATCH] fix: repo details --- .env.example | 8 ++-- .github/workflows/test.yml | 6 +-- .gitignore | 2 +- README.md | 39 ++++++++++++++++--- foundry.toml | 3 +- ...odes.js => integration-tests-with-nodes.js | 2 +- package.json | 10 ++--- ...eployE2E.s.sol => DeployIntegration.s.sol} | 8 ++-- solidity/scripts/deployments/deployments.md | 2 +- solidity/test/e2e/Test.t.sol | 14 ------- .../IGnosisSafeProxyFactory.sol | 0 .../IntegrationBase.sol} | 17 ++++---- .../{e2e => integration}/VerifierModule.t.sol | 4 +- 13 files changed, 64 insertions(+), 51 deletions(-) rename e2e-tests-with-nodes.js => integration-tests-with-nodes.js (98%) rename solidity/scripts/{DeployE2E.s.sol => DeployIntegration.s.sol} (95%) delete mode 100644 solidity/test/e2e/Test.t.sol rename solidity/test/{e2e => integration}/IGnosisSafeProxyFactory.sol (100%) rename solidity/test/{e2e/Common.sol => integration/IntegrationBase.sol} (90%) rename solidity/test/{e2e => integration}/VerifierModule.t.sol (96%) diff --git a/.env.example b/.env.example index ca80b02..541dd7e 100644 --- a/.env.example +++ b/.env.example @@ -3,13 +3,13 @@ GOERLI_RPC= OPTIMISM_RPC= OPTIMISM_GOERLI_RPC= -# Deployer private key for the E2E Tests +# Deployer private key for the Integrations Tests MAINNET_DEPLOYER_PK= -# Searcher PK for E2E Tests +# Searcher PK for Integration Tests SEARCHER_PK= -# Mainnet rpc for the E2E Tests, should be the anvil url -MAINNET_E2E_RPC= +# Mainnet rpc for the Integration Tests, should be the ganache url +MAINNET_INTEGRATION_TESTS_RPC= ## For deployment scripts DEPLOYER_MAINNNET_PRIVATE_KEY= diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7bb6866..bb664f7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ concurrency: jobs: forge: - name: Run Unit and E2E Tests + name: Run Unit and Integration Tests runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -44,13 +44,13 @@ jobs: run: | touch .env echo MAINNET_RPC="${{ secrets.MAINNET_RPC }}" >> .env - echo MAINNET_E2E_RPC="${{ secrets.MAINNET_E2E_RPC }}" >> .env + echo MAINNET_INTEGRATION_TESTS_RPC="${{ secrets.MAINNET_INTEGRATION_TESTS_RPC }}" >> .env echo SEARCHER_PK="${{ secrets.SEARCHER_PK }}" >> .env echo MAINNET_DEPLOYER_PK="${{ secrets.MAINNET_DEPLOYER_PK }}" >> .env cat .env - name: Run tests - run: yarn test:e2e-workflow + run: yarn test:integration-workflow forge-optimized: name: Run Optimized Unit Tests diff --git a/.gitignore b/.gitignore index 0d9d254..fc18317 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,6 @@ docs/src/static # Cache for the python scripts proofs/__pycache__/* -# Deployments for E2E +# Deployments for Integration tests solidity/scripts/deployments/*.json proofs/proof.json diff --git a/README.md b/README.md index 7e5aa16..6983524 100644 --- a/README.md +++ b/README.md @@ -21,25 +21,52 @@ yarn install yarn build ``` -In order to run the E2E tests you will also need python setup to generate the proofs, to do this run: +## Integration Tests + +In order to run the integration tests you will need python setup to generate the proofs, ganache running and some enviroment variables. + +1. Set up python and install requirements ```sh python -m pip install --upgrade pip pip install -r requirements.txt ``` -### Available Commands +2. Run ganache + +```sh +yarn ganache +``` + +3. Set enviroment variables -Make sure to set `MAINNET_RPC` and `OPTIMISM_RPC` environment variable before running end-to-end tests. +`MAINNET_INTEGRATION_TESTS_RPC` should be the ganache endpoint +`MAINNET_DEPLOYER_PK` should be the deployer of the protocol and a safe owner +`SEARCHER_PK` should be the incentivized actor to verify + +4. Run the tests + +```sh +yarn test:integration +``` + +### Available Commands | Yarn Command | Description | | ----------------------- | ---------------------------------------------------------- | | `yarn build` | Compile all contracts. | | `yarn coverage` | See `forge coverage` report. | -| `yarn deploy` | Deploy the contracts to Mainnet. | -| `yarn test` | Run all unit and e2e tests. | +| `yarn deploy` | Deploy the contracts to Mainnet. | +| `yarn test` | Run all unit and integration tests. | | `yarn test:unit` | Run unit tests. | -| `yarn test:e2e` | Run e2e tests. | +| `yarn test:integration` | Run integration tests. | +| `yarn deploy:mainnet` | Deploys Home Chain contracts to Mainnet | +| `yarn deploy:optimism` | Deploys Non-Home Chain contracts to Optimism | +| `yarn deploy:goerli` | Deploys Home Chain contracts to Goerli | +| `yarn deploy:optimismGoerli`| Deploys Non-Home Chain contracts to Optimism Goerli | +| `yarn docs:build` | Build the docs | +| `yarn docs:run` | Runs the docs, needs mdbook | +| `yarn ganache` | Spawn a ganache instance | ## Smart Contracts diff --git a/foundry.toml b/foundry.toml index 0550769..7d12c3f 100644 --- a/foundry.toml +++ b/foundry.toml @@ -39,5 +39,4 @@ src = './solidity/interfaces/' mainnet = "${MAINNET_RPC}" goerli = "${GOERLI_RPC}" optimism = "${OPTIMISM_RPC}" -mainnet_e2e = "${MAINNET_E2E_RPC}" -optimism_e2e = "${OPTIMISM_E2E_RPC}" +mainnet_integration = "${MAINNET_INTEGRATION_TESTS_RPC}" diff --git a/e2e-tests-with-nodes.js b/integration-tests-with-nodes.js similarity index 98% rename from e2e-tests-with-nodes.js rename to integration-tests-with-nodes.js index e6afc49..4ac2802 100644 --- a/e2e-tests-with-nodes.js +++ b/integration-tests-with-nodes.js @@ -12,7 +12,7 @@ require('dotenv').config(); // Initialize dotenv to load environment variables // Running end-to-end tests console.debug(`Running tests`); - const testProcess = spawn('yarn', [`test:e2e`]); + const testProcess = spawn('yarn', [`test:integration`]); // Handle test errors testProcess.stderr.on('data', (data) => console.error(`Test error: ${data}`)); diff --git a/package.json b/package.json index 19cd46f..00f2b6b 100644 --- a/package.json +++ b/package.json @@ -10,13 +10,11 @@ }, "author": "Wonderland", "scripts": { - "anvil:mainnet": "anvil --port 8545 -f $MAINNET_RPC --fork-block-number 18621047 --chain-id 1", - "anvil:optimism": "anvil --port 9545 -f $OPTIMISM_RPC --fork-block-number 112491451 --chain-id 10", "build": "forge build", "build:optimized": "FOUNDRY_PROFILE=optimized forge build", "coverage": "forge coverage --match-contract Unit", - "deploy:e2e": "forge script solidity/scripts/DeployE2E.s.sol:DeployE2E --broadcast", "deploy:goerli": "bash -c 'source .env && forge script -vv --rpc-url $GOERLI_RPC --slow --broadcast --private-key $DEPLOYER_GOERLI_PRIVATE_KEY solidity/scripts/DeployGoerli.s.sol:DeployGoerli'", + "deploy:integration": "forge script solidity/scripts/DeployIntegration.s.sol:DeployIntegration --broadcast", "deploy:mainnet": "bash -c 'source .env && forge script -vv --rpc-url $MAINNET_RPC --slow --broadcast --private-key $DEPLOYER_MAINNNET_PRIVATE_KEY solidity/scripts/DeployMainnet.s.sol:DeployMainnet'", "deploy:optimism": "bash -c 'source .env && forge script -vv --rpc-url $OPTIMISM_RPC --slow --broadcast --private-key $DEPLOYER_OPTIMISM_PRIVATE_KEY solidity/scripts/DeployOptimism.s.sol:DeployOptimism'", "deploy:optimismGoerli": "bash -c 'source .env && forge script -vv --rpc-url $OPTIMISM_GOERLI_RPC --slow --broadcast --private-key $DEPLOYER_OPTIMISM_GOERLI_PRIVATE_KEY solidity/scripts/DeployOptimismGoerli.s.sol:DeployOptimismGoerli'", @@ -29,9 +27,9 @@ "lint:sol-tests": "solhint 'solidity/test/**/*.sol'", "prepare": "husky install", "proof": "python3 proofs/generate_proof.py", - "test": "yarn deploy:e2e && forge test --ffi -vvv", - "test:e2e": "yarn deploy:e2e && forge test --ffi --match-contract E2E -vvv", - "test:e2e-workflow": "node e2e-tests-with-nodes.js", + "test": "yarn deploy:integration && forge test --ffi -vvv", + "test:integration": "yarn deploy:integration && forge test --ffi --match-contract Integration -vvv", + "test:integration-workflow": "node integration-tests-with-nodes.js", "test:unit": "forge test --match-contract Unit -vvv", "test:unit:deep": "FOUNDRY_FUZZ_RUNS=5000 yarn test:unit" }, diff --git a/solidity/scripts/DeployE2E.s.sol b/solidity/scripts/DeployIntegration.s.sol similarity index 95% rename from solidity/scripts/DeployE2E.s.sol rename to solidity/scripts/DeployIntegration.s.sol index dc5e404..0186a19 100644 --- a/solidity/scripts/DeployE2E.s.sol +++ b/solidity/scripts/DeployIntegration.s.sol @@ -17,7 +17,7 @@ import {IVerifierModule} from 'interfaces/IVerifierModule.sol'; import {IStorageMirrorRootRegistry} from 'interfaces/IStorageMirrorRootRegistry.sol'; import {IStorageMirror} from 'interfaces/IStorageMirror.sol'; import {IBlockHeaderOracle} from 'interfaces/IBlockHeaderOracle.sol'; -import {IGnosisSafeProxyFactory} from 'test/e2e/IGnosisSafeProxyFactory.sol'; +import {IGnosisSafeProxyFactory} from 'test/integration/IGnosisSafeProxyFactory.sol'; struct Signature { uint8 v; @@ -25,7 +25,7 @@ struct Signature { bytes32 s; } -contract DeployE2E is Script, DeployHomeChain, DeployNonHomeChain { +contract DeployIntegration is Script, DeployHomeChain, DeployNonHomeChain { address internal _deployer = vm.rememberKey(vm.envUint('MAINNET_DEPLOYER_PK')); uint256 internal _pk = vm.envUint('MAINNET_DEPLOYER_PK'); address[] internal _owners = [_deployer]; @@ -34,7 +34,7 @@ contract DeployE2E is Script, DeployHomeChain, DeployNonHomeChain { IVerifierModule.SafeTxnParams internal _vars; function run() external { - vm.createSelectFork(vm.rpcUrl('mainnet_e2e')); + vm.createSelectFork(vm.rpcUrl('mainnet_integration')); vm.startBroadcast(_deployer); _singletonSafe = new Safe(); @@ -67,7 +67,7 @@ contract DeployE2E is Script, DeployHomeChain, DeployNonHomeChain { string memory _output = vm.serializeAddress(_objectKey, 'SafeOp', address(_safe)); - vm.writeJson(_output, './solidity/scripts/deployments/E2ESafeDeployments.json'); + vm.writeJson(_output, './solidity/scripts/deployments/IntegrationSafeDeployments.json'); } /** diff --git a/solidity/scripts/deployments/deployments.md b/solidity/scripts/deployments/deployments.md index 189ac34..86c8767 100644 --- a/solidity/scripts/deployments/deployments.md +++ b/solidity/scripts/deployments/deployments.md @@ -1,3 +1,3 @@ -### This is the folder where the deployments JSON will go to for the E2E tests +### This is the folder where the deployments JSON will go to for the Integration tests ### This file is needed so the folder will show in github \ No newline at end of file diff --git a/solidity/test/e2e/Test.t.sol b/solidity/test/e2e/Test.t.sol deleted file mode 100644 index 8462d82..0000000 --- a/solidity/test/e2e/Test.t.sol +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity >=0.8.4 <0.9.0; - -import {CommonE2EBase} from 'test/e2e/Common.sol'; - -contract TestE2E is CommonE2EBase { - function setUp() public override { - super.setUp(); - } - - function test_test() public { - assertTrue(true); - } -} diff --git a/solidity/test/e2e/IGnosisSafeProxyFactory.sol b/solidity/test/integration/IGnosisSafeProxyFactory.sol similarity index 100% rename from solidity/test/e2e/IGnosisSafeProxyFactory.sol rename to solidity/test/integration/IGnosisSafeProxyFactory.sol diff --git a/solidity/test/e2e/Common.sol b/solidity/test/integration/IntegrationBase.sol similarity index 90% rename from solidity/test/e2e/Common.sol rename to solidity/test/integration/IntegrationBase.sol index a18cd4c..52f7aa7 100644 --- a/solidity/test/e2e/Common.sol +++ b/solidity/test/integration/IntegrationBase.sol @@ -20,12 +20,12 @@ import {IVerifierModule} from 'interfaces/IVerifierModule.sol'; import {IStorageMirrorRootRegistry} from 'interfaces/IStorageMirrorRootRegistry.sol'; import {IBlockHeaderOracle} from 'interfaces/IBlockHeaderOracle.sol'; -import {IGnosisSafeProxyFactory} from 'test/e2e/IGnosisSafeProxyFactory.sol'; +import {IGnosisSafeProxyFactory} from 'test/integration/IGnosisSafeProxyFactory.sol'; import {TestConstants} from 'test/utils/TestConstants.sol'; import {ContractDeploymentAddress} from 'test/utils/ContractDeploymentAddress.sol'; // solhint-disable-next-line max-states-count -contract CommonE2EBase is DSTestPlus, TestConstants { +contract IntegrationBase is DSTestPlus, TestConstants { uint256 internal constant _MAINNET_FORK_BLOCK = 18_621_047; uint256 internal constant _OPTIMISM_FORK_BLOCK = 112_491_451; @@ -48,7 +48,7 @@ contract CommonE2EBase is DSTestPlus, TestConstants { function setUp() public virtual { // Set up both forks - _mainnetForkId = vm.createSelectFork(vm.rpcUrl('mainnet_e2e')); + _mainnetForkId = vm.createSelectFork(vm.rpcUrl('mainnet_integration')); // Fetches all addresses from the deploy script storageMirror = StorageMirror( @@ -84,13 +84,16 @@ contract CommonE2EBase is DSTestPlus, TestConstants { vm.readFile('./solidity/scripts/deployments/NonHomeChainDeployments.json'), '$.StorageMirrorRootRegistry' ) ); - safe = ISafe(vm.parseJsonAddress(vm.readFile('./solidity/scripts/deployments/E2ESafeDeployments.json'), '$.Safe')); - nonHomeChainSafe = - ISafe(vm.parseJsonAddress(vm.readFile('./solidity/scripts/deployments/E2ESafeDeployments.json'), '$.SafeOp')); + safe = ISafe( + vm.parseJsonAddress(vm.readFile('./solidity/scripts/deployments/IntegrationSafeDeployments.json'), '$.Safe') + ); + nonHomeChainSafe = ISafe( + vm.parseJsonAddress(vm.readFile('./solidity/scripts/deployments/IntegrationSafeDeployments.json'), '$.SafeOp') + ); // Save the storage mirror proofs saveProof( - vm.rpcUrl('mainnet_e2e'), + vm.rpcUrl('mainnet_integration'), vm.toString(address(storageMirror)), vm.toString((keccak256(abi.encode(address(safe), 0)))) ); diff --git a/solidity/test/e2e/VerifierModule.t.sol b/solidity/test/integration/VerifierModule.t.sol similarity index 96% rename from solidity/test/e2e/VerifierModule.t.sol rename to solidity/test/integration/VerifierModule.t.sol index cbdacb2..acbd92b 100644 --- a/solidity/test/e2e/VerifierModule.t.sol +++ b/solidity/test/integration/VerifierModule.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.4 <0.9.0; import {Enum} from 'safe-contracts/common/Enum.sol'; -import {CommonE2EBase} from 'test/e2e/Common.sol'; +import {IntegrationBase} from 'test/integration/IntegrationBase.sol'; import {StateVerifier} from 'libraries/StateVerifier.sol'; import {MerklePatriciaProofVerifier} from 'libraries/MerklePatriciaProofVerifier.sol'; import {RLPReader} from 'solidity-rlp/contracts/RLPReader.sol'; @@ -10,7 +10,7 @@ import {IStorageMirror} from 'interfaces/IStorageMirror.sol'; import {IVerifierModule} from 'interfaces/IVerifierModule.sol'; import {StateVerifier} from 'libraries/StateVerifier.sol'; -contract VerifierModuleE2E is CommonE2EBase { +contract Integration_VerifierModule is IntegrationBase { using RLPReader for RLPReader.RLPItem; using RLPReader for bytes;