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

test: shared bridge unit tests #59

Merged
merged 6 commits into from
Oct 4, 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
45 changes: 44 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
ethereum/cache
ethereum/typechain

test:
test-hardhat:
needs: [build, lint]
runs-on: ubuntu-latest

Expand Down Expand Up @@ -103,3 +103,46 @@ jobs:

- name: Run tests
run: yarn test --no-compile

test-foundry:
needs: [build, lint]
runs-on: ubuntu-latest

defaults:
run:
working-directory: ethereum

steps:
- name: Checkout the repository
uses: actions/checkout@v3
with:
submodules: "recursive"

- name: "Install Foundry"
uses: "foundry-rs/foundry-toolchain@v1"

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 16.15.1
cache: yarn
cache-dependency-path: ethereum/yarn.lock

- name: Install yarn
run: npm install -g yarn

- name: Install dependencies
run: yarn install

- name: Restore artifacts cache
uses: actions/cache/restore@v3
with:
fail-on-cache-miss: true
key: artifacts-${{ github.sha }}
path: |
ethereum/artifacts
ethereum/cache
ethereum/typechain

- name: Run tests
run: forge test
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "ethereum/lib/forge-std"]
path = ethereum/lib/forge-std
url = https://github.com/foundry-rs/forge-std
2 changes: 2 additions & 0 deletions ethereum/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
/typechain
node_modules
./contracts/DS_Store
/artifacts-forge
/cache-forge
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma solidity ^0.8.13;
import "../../common/libraries/Diamond.sol";
import "../../proof-system/chain-deps/facets/Getters.sol";

contract DiamondCutTest is GettersFacet {
contract DiamondCutTestContract is GettersFacet {
function diamondCut(Diamond.DiamondCutData memory _diamondCut) external {
Diamond.diamondCut(_diamondCut);
}
Expand Down
8 changes: 8 additions & 0 deletions ethereum/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[profile.default]
src = 'cache/solpp-generated-contracts'
out = 'artifacts-forge'
libs = ['node_modules', 'lib']
cache_path = 'cache-forge'
test = 'test/foundry'

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
195 changes: 106 additions & 89 deletions ethereum/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,114 +1,131 @@
import '@nomiclabs/hardhat-waffle';
import '@nomiclabs/hardhat-solpp';
import '@nomiclabs/hardhat-ethers';
import '@nomiclabs/hardhat-etherscan';
import '@openzeppelin/hardhat-upgrades';
import 'hardhat-typechain';
import 'hardhat-contract-sizer';
import 'solidity-coverage';
import 'hardhat-gas-reporter';
import { getNumberFromEnv } from './scripts/utils';
import "@nomiclabs/hardhat-ethers";
import "@nomiclabs/hardhat-etherscan";
import "@nomiclabs/hardhat-solpp";
import "@nomiclabs/hardhat-waffle";
import "@openzeppelin/hardhat-upgrades";
import "hardhat-contract-sizer";
import "hardhat-gas-reporter";
import "hardhat-typechain";
import { TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } from "hardhat/builtin-tasks/task-names";
import { task } from "hardhat/config";
import "solidity-coverage";
import { getNumberFromEnv } from "./scripts/utils";

// If no network is specified, use the default config
if (!process.env.CHAIN_ETH_NETWORK) {
require('dotenv').config();
require("dotenv").config();
}

const systemParams = require('../SystemConfig.json');
const systemParams = require("../SystemConfig.json");

const PRIORITY_TX_MAX_GAS_LIMIT = getNumberFromEnv('CONTRACTS_PRIORITY_TX_MAX_GAS_LIMIT');
const DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT = getNumberFromEnv('CONTRACTS_DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT');
const PRIORITY_TX_MAX_GAS_LIMIT = getNumberFromEnv(
"CONTRACTS_PRIORITY_TX_MAX_GAS_LIMIT"
);
const DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT = getNumberFromEnv(
"CONTRACTS_DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT"
);

const prodConfig = {
UPGRADE_NOTICE_PERIOD: 0,
// PRIORITY_EXPIRATION: 101,
// NOTE: Should be greater than 0, otherwise zero approvals will be enough to make an instant upgrade!
SECURITY_COUNCIL_APPROVALS_FOR_EMERGENCY_UPGRADE: 1,
PRIORITY_TX_MAX_GAS_LIMIT,
DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT,
DUMMY_VERIFIER: false
UPGRADE_NOTICE_PERIOD: 0,
// PRIORITY_EXPIRATION: 101,
// NOTE: Should be greater than 0, otherwise zero approvals will be enough to make an instant upgrade!
SECURITY_COUNCIL_APPROVALS_FOR_EMERGENCY_UPGRADE: 1,
PRIORITY_TX_MAX_GAS_LIMIT,
DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT,
DUMMY_VERIFIER: false,
};
const testnetConfig = {
UPGRADE_NOTICE_PERIOD: 0,
// PRIORITY_EXPIRATION: 101,
// NOTE: Should be greater than 0, otherwise zero approvals will be enough to make an instant upgrade!
SECURITY_COUNCIL_APPROVALS_FOR_EMERGENCY_UPGRADE: 1,
PRIORITY_TX_MAX_GAS_LIMIT,
DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT,
DUMMY_VERIFIER: true
UPGRADE_NOTICE_PERIOD: 0,
// PRIORITY_EXPIRATION: 101,
// NOTE: Should be greater than 0, otherwise zero approvals will be enough to make an instant upgrade!
SECURITY_COUNCIL_APPROVALS_FOR_EMERGENCY_UPGRADE: 1,
PRIORITY_TX_MAX_GAS_LIMIT,
DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT,
DUMMY_VERIFIER: true,
};
const testConfig = {
UPGRADE_NOTICE_PERIOD: 0,
PRIORITY_EXPIRATION: 101,
SECURITY_COUNCIL_APPROVALS_FOR_EMERGENCY_UPGRADE: 2,
PRIORITY_TX_MAX_GAS_LIMIT,
DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT,
DUMMY_VERIFIER: true
UPGRADE_NOTICE_PERIOD: 0,
PRIORITY_EXPIRATION: 101,
SECURITY_COUNCIL_APPROVALS_FOR_EMERGENCY_UPGRADE: 2,
PRIORITY_TX_MAX_GAS_LIMIT,
DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT,
DUMMY_VERIFIER: true,
};
const localConfig = {
...prodConfig,
DUMMY_VERIFIER: true
...prodConfig,
DUMMY_VERIFIER: true,
};

const contractDefs = {
sepolia: testnetConfig,
rinkeby: testnetConfig,
ropsten: testnetConfig,
goerli: testnetConfig,
mainnet: prodConfig,
test: testConfig,
localhost: localConfig
sepolia: testnetConfig,
rinkeby: testnetConfig,
ropsten: testnetConfig,
goerli: testnetConfig,
mainnet: prodConfig,
test: testConfig,
localhost: localConfig,
};

export default {
defaultNetwork: 'env',
solidity: {
version: '0.8.17',
settings: {
optimizer: {
enabled: true,
runs: 9999999
},
outputSelection: {
'*': {
'*': ['storageLayout']
}
}
}
},
contractSizer: {
runOnCompile: false,
except: ['dev-contracts', 'zksync/upgrade-initializers', 'zksync/libraries', 'common/libraries']
},
paths: {
sources: './contracts'
defaultNetwork: "env",
solidity: {
version: "0.8.17",
settings: {
optimizer: {
enabled: true,
runs: 9999999,
},
outputSelection: {
"*": {
"*": ["storageLayout"],
},
},
},
solpp: {
defs: (() => {
const defs = process.env.CONTRACT_TESTS ? contractDefs.test : contractDefs[process.env.CHAIN_ETH_NETWORK];
},
contractSizer: {
runOnCompile: false,
except: [
"dev-contracts",
"zksync/upgrade-initializers",
"zksync/libraries",
"common/libraries",
],
},
paths: {
sources: "./contracts",
},
solpp: {
defs: (() => {
const defs = process.env.CONTRACT_TESTS
? contractDefs.test
: contractDefs[process.env.CHAIN_ETH_NETWORK];

return {
...systemParams,
...defs
};
})()
return {
...systemParams,
...defs,
};
})(),
},
networks: {
env: {
url: process.env.ETH_CLIENT_WEB3_URL?.split(",")[0],
},
networks: {
env: {
url: process.env.ETH_CLIENT_WEB3_URL?.split(',')[0]
},
hardhat: {
allowUnlimitedContractSize: false,
forking: {
url: 'https://eth-goerli.g.alchemy.com/v2/' + process.env.ALCHEMY_KEY,
enabled: process.env.TEST_CONTRACTS_FORK === '1'
}
}
},
etherscan: {
apiKey: process.env.MISC_ETHERSCAN_API_KEY
hardhat: {
allowUnlimitedContractSize: false,
forking: {
url: "https://eth-goerli.g.alchemy.com/v2/" + process.env.ALCHEMY_KEY,
enabled: process.env.TEST_CONTRACTS_FORK === "1",
},
},
gasReporter: {
enabled: true
}
},
etherscan: {
apiKey: process.env.MISC_ETHERSCAN_API_KEY,
},
gasReporter: {
enabled: true,
},
};

task("solpp", "Preprocess Solidity source files").setAction(async (_, hre) =>
hre.run(TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS)
);
1 change: 1 addition & 0 deletions ethereum/lib/forge-std
Submodule forge-std added at 705263
13 changes: 10 additions & 3 deletions ethereum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,18 @@
"build": "hardhat compile",
"clean": "hardhat clean",
"test": "CONTRACT_TESTS=1 yarn hardhat test test/unit_tests/*.spec.ts --network hardhat",
"test:foundry": "hardhat solpp && forge test",
"test:fork": "CONTRACT_TESTS=1 TEST_CONTRACTS_FORK=1 yarn run hardhat test test/unit_tests/*.fork.ts --network hardhat",
"lint": "yarn lint:sol && yarn prettier:check",
"lint:sol": "solhint --max-warnings 29 contracts/**/*.sol",
"prettier:check": "prettier --check contracts/**/*.sol",
"prettier:write": "prettier --write contracts/**/*.sol",
"lint:sol-contracts": "solhint --max-warnings 29 contracts/**/*.sol",
"lint:sol-tests": "solhint --max-warnings 0 test/**/*.sol",
"lint:sol": "yarn lint:sol-contracts && yarn lint:sol-tests",
"prettier:check-contracts": "prettier --check contracts/**/*.sol",
"prettier:check-tests": "prettier --check test/**/*.sol",
"prettier:check": "yarn prettier:check-contracts && yarn prettier:check-tests",
"prettier:write-contracts": "prettier --write contracts/**/*.sol",
"prettier:write-tests": "prettier --write test/**/*.sol",
"prettier:write": "yarn prettier:write-contracts && yarn prettier:write-tests",
"deploy-no-build": "ts-node scripts/deploy.ts",
"register-hyperchain": "ts-node scripts/register-hyperchain.ts",
"deploy-weth-bridges": "ts-node scripts/deploy-weth-bridges.ts",
Expand Down
6 changes: 6 additions & 0 deletions ethereum/remappings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@ensdomains/=node_modules/@ensdomains/
@openzeppelin/=node_modules/@openzeppelin/
ds-test/=lib/forge-std/lib/ds-test/src/
eth-gas-reporter/=node_modules/eth-gas-reporter/
forge-std/=lib/forge-std/src/
hardhat/=node_modules/hardhat/
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.17;

import {AccessModeTest} from "./_AccessMode_Shared.t.sol";
import {IAllowList} from "../../../../../../cache/solpp-generated-contracts/common/interfaces/IAllowList.sol";

contract DepositLimitTest is AccessModeTest {
address private l1token = makeAddr("l1token");

function test_RevertWhen_NonOwner() public {
vm.expectRevert(abi.encodePacked("Ownable: caller is not the owner"));
vm.prank(randomSigner);
allowList.setDepositLimit(l1token, true, 1000);
}

function test_Owner() public {
vm.prank(owner);
allowList.setDepositLimit(l1token, true, 1000);

IAllowList.Deposit memory deposit = allowList.getTokenDepositLimitData(l1token);
assertEq(deposit.depositLimitation, true, "depositLimitation should be true");
assertEq(deposit.depositCap, 1000, "depositCap should be 1000");
}

function test_UnlimitedToken() public {
address unlimitedToken = makeAddr("unlimitedToken");

IAllowList.Deposit memory deposit = allowList.getTokenDepositLimitData(unlimitedToken);

assertEq(deposit.depositLimitation, false, "depositLimitation should be false");
assertEq(deposit.depositCap, 0, "depositCap should be 0");
}
}
Loading
Loading