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: Move l1 tests to foundry Part-1 #26

Merged
merged 35 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6d02695
chore(*): foundry init EVM-216
benceharomi Aug 9, 2023
aab9246
feat(foundry): test:foundry command added EVM-216
benceharomi Aug 9, 2023
85b2ed0
chore(foundry): remappings.txt added EVM-216
benceharomi Aug 9, 2023
5b2e0b3
feat(hardhat): solpp task created EVM-216
benceharomi Aug 9, 2023
b108f5d
test(foundry): UnsafeBytes test added EVM-216
benceharomi Aug 9, 2023
152b924
test(foundry): AllowList test added EVM-216
benceharomi Aug 11, 2023
81c587a
chore(tests): missing license identifiers EVM-216
benceharomi Aug 11, 2023
ac1b59b
chore(DiamondCutTest): renamed to DiamondCutTestContract EVM-216
benceharomi Aug 14, 2023
14e25e3
test(foundry): DiamondCut test added EVM-216
benceharomi Aug 15, 2023
b8020dd
test(foundry): Executor test Part-1 EVM-216
benceharomi Aug 17, 2023
3e7f3df
test(foundry): Executor test Part-2 EVM-216
benceharomi Aug 18, 2023
88016cb
test(foundry): a bit more randomness EVM-216
benceharomi Aug 18, 2023
0ef682b
fix(executor-test): fix after upgrade changes EVM-216
benceharomi Aug 22, 2023
0fc3388
test(foundry): Executor test Part-3 EVM-216
benceharomi Aug 23, 2023
a9d43fa
test(foundry): Executor test Part-4 EVM-216
benceharomi Aug 23, 2023
1f58257
test(foundry): Executor test Part-5 EVM-216
benceharomi Sep 4, 2023
2a0f601
chore(tests): renamed to follow foundry convention EVM-216
benceharomi Sep 5, 2023
38fb066
chore(test/foundry): directory organised EVM-216
benceharomi Sep 5, 2023
5a43248
test(Utils): packBatchTimestampAndBlockTimestamp and randomBytes32 EV…
benceharomi Sep 11, 2023
f2af121
test(Executing): less duplication EVM-216
benceharomi Sep 11, 2023
2e5ebfe
test(Committing): too long storage changes tests EVM-216
benceharomi Sep 11, 2023
5a86465
test(unit_tests): remove migrated hardhat tests EVM-216
benceharomi Sep 11, 2023
9ff25fc
chore(AllowList/Permission): test file renamed EVM-216
benceharomi Sep 11, 2023
17f62ba
lint(test): test formatting/linting scripts added EVM-216
benceharomi Sep 18, 2023
be3593d
lint(test): test files formatted/linted EVM-216
benceharomi Sep 18, 2023
df9bfb0
ci(ci.yml): foundry testing added EVM-216
benceharomi Sep 18, 2023
950b354
chore(test): explicit imports EVM-216
benceharomi Sep 18, 2023
536fb4b
chore(test): solidity 0.8.13 -> 0.8.17 EVM-216
benceharomi Sep 18, 2023
fc3cc60
Merge branch 'dev' into bh-EVM-216-move-l1-tests-to-foundry
benceharomi Sep 27, 2023
008b905
Merge branch 'boojum-integration' into bh-EVM-216-move-l1-tests-to-fo…
benceharomi Sep 27, 2023
b520592
test(foundry): Executor tests updated to work with new changes
benceharomi Sep 28, 2023
b56680d
Merge remote-tracking branch 'origin/boojum-integration' into bh-EVM-…
benceharomi Sep 28, 2023
5ee02b0
Fix tests
vladbochok Sep 28, 2023
24fb56b
Fix lints
vladbochok Sep 28, 2023
024971a
Remove redundant tests & fix l2 upgrade test
vladbochok Sep 28, 2023
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 "../../zksync/libraries/Diamond.sol";
import "../../zksync/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
13 changes: 9 additions & 4 deletions ethereum/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import '@nomiclabs/hardhat-waffle';
import '@nomiclabs/hardhat-solpp';
import '@nomiclabs/hardhat-ethers';
import '@nomiclabs/hardhat-etherscan';
import 'hardhat-typechain';
import '@nomiclabs/hardhat-solpp';
import '@nomiclabs/hardhat-waffle';
import 'hardhat-contract-sizer';
import 'solidity-coverage';
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
Expand Down Expand Up @@ -111,3 +113,6 @@ export default {
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 @@ -51,11 +51,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",
vladbochok marked this conversation as resolved.
Show resolved Hide resolved
"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",
"deploy-weth-bridges": "ts-node scripts/deploy-weth-bridges.ts",
"initialize-weth-bridges": "ts-node scripts/initialize-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");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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 SetAccessModeTest is AccessModeTest {
function test_RevertWhen_NonOwner() public {
vm.expectRevert(abi.encodePacked("Ownable: caller is not the owner"));
vm.prank(randomSigner);
allowList.setAccessMode(target, IAllowList.AccessMode.Public);
}

function test_Owner() public {
vm.prank(owner);
allowList.setAccessMode(target, IAllowList.AccessMode.Public);
}

function test_OwnerTwice() public {
vm.prank(owner);
allowList.setAccessMode(target, IAllowList.AccessMode.Public);

vm.prank(owner);
allowList.setAccessMode(target, IAllowList.AccessMode.Public);
}

function test_AccessModeBefore() public {
bool hasSpecialAccessToCall = allowList.hasSpecialAccessToCall(owner, target, functionSig);
assertEq(hasSpecialAccessToCall, false, "hasSpecialAccessToCall should be false");

IAllowList.AccessMode accessMode = allowList.getAccessMode(target);
bool isClosed = accessMode == IAllowList.AccessMode.Closed;
assertEq(isClosed, true, "AccessMode should be Closed");

bool canCall = allowList.canCall(owner, target, functionSig);
assertEq(canCall, false, "canCall should be false");
}

function test_AccessModeAfter() public {
vm.prank(owner);
allowList.setAccessMode(target, IAllowList.AccessMode.Public);

bool hasSpecialAccessToCall = allowList.hasSpecialAccessToCall(owner, target, functionSig);
assertEq(hasSpecialAccessToCall, false, "hasSpecialAccessToCall should be false");

IAllowList.AccessMode accessMode = allowList.getAccessMode(target);
bool isPublic = accessMode == IAllowList.AccessMode.Public;
assertEq(isPublic, true, "AccessMode should be Public");

bool canCall = allowList.canCall(owner, target, functionSig);
assertEq(canCall, true, "canCall should be true");
}

function test_RemovePermission() public {
vm.prank(owner);
allowList.setAccessMode(target, IAllowList.AccessMode.Closed);

vm.prank(owner);
allowList.setAccessMode(target, IAllowList.AccessMode.Public);

bool hasSpecialAccessToCall = allowList.hasSpecialAccessToCall(owner, target, functionSig);
assertEq(hasSpecialAccessToCall, false, "hasSpecialAccessToCall should be false");

IAllowList.AccessMode accessMode = allowList.getAccessMode(target);
bool isPublic = accessMode == IAllowList.AccessMode.Public;
assertEq(isPublic, true, "AccessMode should be Public");

bool canCall = allowList.canCall(owner, target, functionSig);
assertEq(canCall, true, "canCall should be true");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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 SetBatchAccessModeTest is AccessModeTest {
function test_RevertWhen_NonOwner() public {
address[] memory targets = new address[](2);
targets[0] = target;
targets[1] = target;

IAllowList.AccessMode[] memory accessModes = new IAllowList.AccessMode[](2);
accessModes[0] = IAllowList.AccessMode.Public;
accessModes[1] = IAllowList.AccessMode.Public;

vm.expectRevert("Ownable: caller is not the owner");
vm.prank(randomSigner);
allowList.setBatchAccessMode(targets, accessModes);
}

function test_Owner() public {
address[] memory targets = new address[](2);
targets[0] = target;
targets[1] = target;

IAllowList.AccessMode[] memory accessModes = new IAllowList.AccessMode[](2);
accessModes[0] = IAllowList.AccessMode.Public;
accessModes[1] = IAllowList.AccessMode.Public;

vm.prank(owner);
allowList.setBatchAccessMode(targets, accessModes);
}

function test_RevertWhen_ArrayLengthNotEqual() public {
address[] memory targets = new address[](1);
targets[0] = target;

IAllowList.AccessMode[] memory accessModes = new IAllowList.AccessMode[](2);
accessModes[0] = IAllowList.AccessMode.Public;
accessModes[1] = IAllowList.AccessMode.Public;

vm.expectRevert(abi.encodePacked("yg"));
vm.prank(owner);
allowList.setBatchAccessMode(targets, accessModes);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.17;

import {AllowListTest} from "../_AllowList_Shared.t.sol";

contract AccessModeTest is AllowListTest {
address internal target = 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045;
bytes4 internal functionSig = 0xdeadbeaf;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.17;

import {PermissionTest} from "./_Permission_Shared.t.sol";

contract SetBatchPermissionToCall is PermissionTest {
function test_RevertWhen_NonOwner() public {
address[] memory callers = new address[](2);
callers[0] = owner;
callers[1] = owner;

address[] memory targets = new address[](2);
targets[0] = target;
targets[1] = target;

bytes4[] memory functionSigs = new bytes4[](2);
functionSigs[0] = functionSig;
functionSigs[1] = functionSig;

bool[] memory enables = new bool[](2);
enables[0] = true;
enables[1] = true;

vm.expectRevert("Ownable: caller is not the owner");
vm.prank(randomSigner);
allowList.setBatchPermissionToCall(callers, targets, functionSigs, enables);
}

function test_Owner() public {
address[] memory callers = new address[](2);
callers[0] = owner;
callers[1] = owner;

address[] memory targets = new address[](2);
targets[0] = target;
targets[1] = target;

bytes4[] memory functionSigs = new bytes4[](2);
functionSigs[0] = functionSig;
functionSigs[1] = functionSig;

bool[] memory enables = new bool[](2);
enables[0] = true;
enables[1] = true;

vm.prank(owner);
allowList.setBatchPermissionToCall(callers, targets, functionSigs, enables);
}

function test_RevertWhen_ArrayLengthNotEqual() public {
address[] memory callers = new address[](1);
callers[0] = owner;

address[] memory targets = new address[](2);
targets[0] = target;
targets[1] = target;

bytes4[] memory functionSigs = new bytes4[](2);
functionSigs[0] = functionSig;
functionSigs[1] = functionSig;

bool[] memory enables = new bool[](2);
enables[0] = true;
enables[1] = true;

vm.expectRevert(abi.encodePacked("yw"));
vm.prank(owner);
allowList.setBatchPermissionToCall(callers, targets, functionSigs, enables);
}
}
Loading