Skip to content

Commit

Permalink
chore: improve e2e base
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOneTony committed Nov 21, 2023
1 parent 8e55d38 commit ee2e7e1
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ MAINNET_DEPLOYER_PK=
GOERLI_RPC=
GOERLI_DEPLOYER_PK=

OPTIMISM_RPC=

ETHERSCAN_API_KEY=
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ yarn build

### Available Commands

Make sure to set `MAINNET_RPC` environment variable before running end-to-end tests.
Make sure to set `MAINNET_RPC` and `OPTIMISM_RPC` environment variable before running end-to-end tests.

| Yarn Command | Description |
| ----------------------- | ---------------------------------------------------------- |
Expand Down
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ src = 'solidity/test'
[rpc_endpoints]
mainnet = "${MAINNET_RPC}"
goerli = "${GOERLI_RPC}"
optimism = "${OPTIMISM_RPC}"
50 changes: 38 additions & 12 deletions solidity/test/e2e/Common.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,28 @@ import {UpdateStorageMirrorGuard} from 'contracts/UpdateStorageMirrorGuard.sol';
import {GuardCallbackModule} from 'contracts/GuardCallbackModule.sol';
import {BlockHeaderOracle} from 'contracts/BlockHeaderOracle.sol';
import {NeedsUpdateGuard} from 'contracts/NeedsUpdateGuard.sol';
import {VerifierModule} from 'contracts/VerifierModule.sol';
import {StorageMirrorRootRegistry} from 'contracts/StorageMirrorRootRegistry.sol';

import {IGuardCallbackModule} from 'interfaces/IGuardCallbackModule.sol';
import {ISafe} from 'interfaces/ISafe.sol';
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 {TestConstants} from 'test/utils/TestConstants.sol';
import {ContractDeploymentAddress} from 'test/utils/ContractDeploymentAddress.sol';

contract CommonE2EBase is DSTestPlus, TestConstants {

Check warning on line 27 in solidity/test/e2e/Common.sol

View workflow job for this annotation

GitHub Actions / Run Linters (16.x)

Contract has 19 states declarations but allowed no more than 15
uint256 internal constant _FORK_BLOCK = 15_452_788;
uint256 internal constant _MAINNET_FORK_BLOCK = 18_621_047;
uint256 internal constant _OPTIMISM_FORK_BLOCK = 112_491_451;

uint256 internal _MAINNET_FORK_ID;

Check warning on line 31 in solidity/test/e2e/Common.sol

View workflow job for this annotation

GitHub Actions / Run Linters (16.x)

Variable name _MAINNET_FORK_ID must be in mixedCase
uint256 internal _OPTIMISM_FORK_ID;

Check warning on line 32 in solidity/test/e2e/Common.sol

View workflow job for this annotation

GitHub Actions / Run Linters (16.x)

Variable name _OPTIMISM_FORK_ID must be in mixedCase

address public deployer = makeAddr('deployer');
address public deployerOptimism = makeAddr('deployerOptimism');
address public proposer = makeAddr('proposer');
address public safeOwner;
uint256 public safeOwnerKey;
Expand All @@ -36,18 +45,22 @@ contract CommonE2EBase is DSTestPlus, TestConstants {
GuardCallbackModule public guardCallbackModule;
BlockHeaderOracle public oracle;
NeedsUpdateGuard public needsUpdateGuard;
VerifierModule public verifierModule;
StorageMirrorRootRegistry public storageMirrorRootRegistry;
ISafe public safe;
ISafe public nonHomeChainSafe;
IVerifierModule public verifierModule = IVerifierModule(makeAddr('verifierModule'));
// IVerifierModule public verifierModule = IVerifierModule(makeAddr('verifierModule'));
IGnosisSafeProxyFactory public gnosisSafeProxyFactory = IGnosisSafeProxyFactory(GNOSIS_SAFE_PROXY_FACTORY);

function setUp() public virtual {
vm.createSelectFork(vm.rpcUrl('mainnet'), _FORK_BLOCK);
// Set up both forks
_MAINNET_FORK_ID = vm.createFork(vm.rpcUrl('mainnet'), _MAINNET_FORK_BLOCK);
_OPTIMISM_FORK_ID = vm.createFork(vm.rpcUrl('optimism'), _OPTIMISM_FORK_BLOCK);
// Select mainnet fork
vm.selectFork(_MAINNET_FORK_ID);

// Make address and key of safe owner
(safeOwner, safeOwnerKey) = makeAddrAndKey('safeOwner');
// Make address and key of non home chain safe owner
(nonHomeChainSafeOwner, nonHomeChainSafeOwnerKey) = makeAddrAndKey('nonHomeChainSafeOwner');

/// =============== HOME CHAIN ===============
vm.prank(safeOwner);
Expand Down Expand Up @@ -106,22 +119,34 @@ contract CommonE2EBase is DSTestPlus, TestConstants {
);

/// =============== NON HOME CHAIN ===============
vm.selectFork(_OPTIMISM_FORK_ID);
// Make address and key of non home chain safe owner
(nonHomeChainSafeOwner, nonHomeChainSafeOwnerKey) = makeAddrAndKey('nonHomeChainSafeOwner');

address _storageMirrorRootRegistryTheoriticalAddress = ContractDeploymentAddress.addressFrom(deployerOptimism, 2);

// Set up non home chain safe
vm.prank(nonHomeChainSafeOwner);
nonHomeChainSafe = ISafe(address(gnosisSafeProxyFactory.createProxy(GNOSIS_SAFE_SINGLETON, ''))); // nonHomeChainSafeOwner nonce 0
label(address(nonHomeChainSafe), 'NonHomeChainSafeProxy');

// Deploy non home chain contracts
vm.prank(deployerOptimism);
oracle = new BlockHeaderOracle(); // deployerOptimism nonce 0
label(address(oracle), 'BlockHeaderOracle');

vm.prank(deployer);
oracle = new BlockHeaderOracle(); // deployer nonce 3
label(address(oracle), 'MockOracle');
verifierModule =
new VerifierModule(IStorageMirrorRootRegistry(_storageMirrorRootRegistryTheoriticalAddress), address(storageMirror)); // deployerOptimism nonce 1
label(address(verifierModule), 'VerifierModule');

// vm.prank(deployer);
// verifierModule = new VerifierModule(..); // deployer nonce 4
// label(address(verifierModule), 'VerifierModule');
vm.prank(deployerOptimism);
storageMirrorRootRegistry =
new StorageMirrorRootRegistry(address(storageMirror), IVerifierModule(verifierModule), IBlockHeaderOracle(oracle)); // deployerOptimism nonce 2
label(address(storageMirrorRootRegistry), 'StorageMirrorRootRegistry');

vm.prank(deployer);
needsUpdateGuard = new NeedsUpdateGuard(verifierModule); // deployer nonce 5
vm.prank(deployerOptimism);
needsUpdateGuard = new NeedsUpdateGuard(verifierModule); // deployer nonce 3
label(address(needsUpdateGuard), 'NeedsUpdateGuard');

// set up non home chain safe
Expand All @@ -133,6 +158,7 @@ contract CommonE2EBase is DSTestPlus, TestConstants {
);

// enable verifier module
enableModule(nonHomeChainSafe, nonHomeChainSafeOwner, nonHomeChainSafeOwnerKey, address(verifierModule));

// set needs update guard
}
Expand Down

0 comments on commit ee2e7e1

Please sign in to comment.