Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: repo details #26

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
39 changes: 33 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Original file line number Diff line number Diff line change
Expand Up @@ -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}`));
Expand Down
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
Expand All @@ -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"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ 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;
bytes32 r;
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];
Expand All @@ -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();
Expand Down Expand Up @@ -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');
}

/**
Expand Down
10 changes: 6 additions & 4 deletions solidity/scripts/DeployNonHomeChain.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ abstract contract DeployNonHomeChain is Script, TestConstants {
_blockHeaderOracle = new BlockHeaderOracle(); // deployer nonce 0
console.log('ORACLE: ', address(_blockHeaderOracle));

_verifierModule =
new VerifierModule(IStorageMirrorRootRegistry(_storageMirrorRootRegistryTheoriticalAddress), address(_deployVars.storageMirror)); // deployer nonce 1
_verifierModule = new VerifierModule(
IStorageMirrorRootRegistry(_storageMirrorRootRegistryTheoriticalAddress), address(_deployVars.storageMirror)
); // deployer nonce 1
console.log('VERIFIER_MODULE: ', address(_verifierModule));

_storageMirrorRootRegistry =
new StorageMirrorRootRegistry(address(_deployVars.storageMirror), IVerifierModule(_verifierModule), IBlockHeaderOracle(_blockHeaderOracle)); // deployer nonce 2
_storageMirrorRootRegistry = new StorageMirrorRootRegistry(
address(_deployVars.storageMirror), IVerifierModule(_verifierModule), IBlockHeaderOracle(_blockHeaderOracle)
); // deployer nonce 2
console.log('STORAGE_MIRROR_ROOT_REGISTRY: ', address(_storageMirrorRootRegistry));

assert(address(_storageMirrorRootRegistry) == _storageMirrorRootRegistryTheoriticalAddress);
Expand Down
2 changes: 1 addition & 1 deletion solidity/scripts/deployments/deployments.md
Original file line number Diff line number Diff line change
@@ -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
14 changes: 0 additions & 14 deletions solidity/test/e2e/Test.t.sol

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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(
Expand Down Expand Up @@ -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))))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
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';
import {IStorageMirror} from 'interfaces/IStorageMirror.sol';
import {IVerifierModule} from 'interfaces/IVerifierModule.sol';
import {StateVerifier} from 'libraries/StateVerifier.sol';

contract VerifierModuleE2E is CommonE2EBase {
contract IntegrationVerifierModule is IntegrationBase {
using RLPReader for RLPReader.RLPItem;
using RLPReader for bytes;

IVerifierModule.SafeTxnParams _txn = IVerifierModule.SafeTxnParams({
IVerifierModule.SafeTxnParams public txn = IVerifierModule.SafeTxnParams({
to: address(0),
value: 1,
data: '',
Expand Down Expand Up @@ -63,7 +63,7 @@ contract VerifierModuleE2E is CommonE2EBase {
);

(uint8 _v, bytes32 _r, bytes32 _s) = vm.sign(vm.envUint('MAINNET_DEPLOYER_PK'), keccak256(_encodedTxn));
_txn.signatures = abi.encodePacked(_r, _s, _v);
txn.signatures = abi.encodePacked(_r, _s, _v);

IStorageMirror.SafeSettings memory _safeSettings = IStorageMirror.SafeSettings({owners: _owners, threshold: 1});

Expand All @@ -79,7 +79,7 @@ contract VerifierModuleE2E is CommonE2EBase {
uint256 _addressZeroBalance = address(0).balance;

vm.prank(_searcher);
verifierModule.proposeAndVerifyUpdate(address(nonHomeChainSafe), _safeSettings, _storageProof, _txn);
verifierModule.proposeAndVerifyUpdate(address(nonHomeChainSafe), _safeSettings, _storageProof, txn);

address[] memory _newOwners = nonHomeChainSafe.getOwners();

Expand Down Expand Up @@ -110,7 +110,7 @@ contract VerifierModuleE2E is CommonE2EBase {
);

(uint8 _v, bytes32 _r, bytes32 _s) = vm.sign(vm.envUint('MAINNET_DEPLOYER_PK'), keccak256(_encodedTxn));
_txn.signatures = abi.encodePacked(_r, _s, _v);
txn.signatures = abi.encodePacked(_r, _s, _v);

IStorageMirror.SafeSettings memory _safeSettings = IStorageMirror.SafeSettings({owners: _owners, threshold: 1});

Expand All @@ -126,7 +126,7 @@ contract VerifierModuleE2E is CommonE2EBase {
uint256 _addressZeroBalance = address(0).balance;

vm.prank(_searcher);
verifierModule.proposeAndVerifyUpdate(address(nonHomeChainSafe), _safeSettings, _storageProof, _txn);
verifierModule.proposeAndVerifyUpdate(address(nonHomeChainSafe), _safeSettings, _storageProof, txn);

address[] memory _newOwners = nonHomeChainSafe.getOwners();

Expand Down Expand Up @@ -156,7 +156,7 @@ contract VerifierModuleE2E is CommonE2EBase {
);

(uint8 _v, bytes32 _r, bytes32 _s) = vm.sign(vm.envUint('MAINNET_DEPLOYER_PK'), keccak256(_encodedTxn));
_txn.signatures = abi.encodePacked(_r, _s, _v);
txn.signatures = abi.encodePacked(_r, _s, _v);

IStorageMirror.SafeSettings memory _safeSettings = IStorageMirror.SafeSettings({owners: _owners, threshold: 1});

Expand All @@ -172,7 +172,7 @@ contract VerifierModuleE2E is CommonE2EBase {
uint256 _addressZeroBalance = address(0).balance;

vm.prank(_searcher);
verifierModule.proposeAndVerifyUpdate(address(nonHomeChainSafe), _safeSettings, _storageProof, _txn);
verifierModule.proposeAndVerifyUpdate(address(nonHomeChainSafe), _safeSettings, _storageProof, txn);

address[] memory _newOwners = nonHomeChainSafe.getOwners();

Expand Down Expand Up @@ -225,7 +225,7 @@ contract VerifierModuleE2E is CommonE2EBase {
);

(uint8 _v, bytes32 _r, bytes32 _s) = vm.sign(vm.envUint('MAINNET_DEPLOYER_PK'), keccak256(_encodedTxn));
_txn.signatures = abi.encodePacked(_r, _s, _v);
txn.signatures = abi.encodePacked(_r, _s, _v);

IStorageMirror.SafeSettings memory _safeSettings = IStorageMirror.SafeSettings({owners: _owners, threshold: 1});

Expand All @@ -243,7 +243,7 @@ contract VerifierModuleE2E is CommonE2EBase {

vm.prank(_searcher);
verifierModule.extractStorageRootAndVerifyUpdate(
address(nonHomeChainSafe), _safeSettings, _accountProof, _storageProof, _txn
address(nonHomeChainSafe), _safeSettings, _accountProof, _storageProof, txn
);

address[] memory _newOwners = nonHomeChainSafe.getOwners();
Expand Down