Skip to content

Commit

Permalink
chore: update e2e-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MexicanAce committed Sep 22, 2023
1 parent 8b2f8c4 commit a6b9675
Show file tree
Hide file tree
Showing 13 changed files with 802 additions and 153 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ jobs:
- name: Rust Cache
uses: Swatinem/rust-cache@v2

- uses: actions/setup-node@v3
with:
node-version: 18.x
cache: "yarn"

- name: Run Linters
run: |
cargo fmt --all -- --check &&
cargo clippy -Zunstable-options -- -D warnings --allow clippy::unwrap_used
run: make lint

# ensures build is successful
build:
Expand All @@ -47,6 +50,8 @@ jobs:

- name: Rust Cache
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true

- name: Build Code
run: make all
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ jobs:
with:
fetch-depth: 0

- uses: actions/setup-node@v3
with:
node-version: 18.x
cache: "yarn"

- name: Download artifacts
uses: actions/download-artifact@v3
with:
Expand All @@ -23,7 +28,7 @@ jobs:
tar -xzf era_test_node-ubuntu-latest.tar.gz
chmod +x era_test_node
echo "Starting node in background"
./era_test_node run 2>&1 | tee era_test_node_ouput.log &
./era_test_node run 2>&1 | tee era_test_node_output.log &
echo "PID=$!" >> $GITHUB_ENV
- name: Launch tests
Expand All @@ -36,5 +41,5 @@ jobs:
id: stop_node
if: always()
run: |
cat era_test_node_ouput.log
cat era_test_node_output.log
kill $PID
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ rebuild-contracts:
rust-build:
cargo build --release

# Run local
run: rust-build
./target/release/era_test_node run

# Build the Rust project for a specific target. Primarily used for CI.
build-%:
cross build --bin era_test_node --target $* --release
Expand All @@ -27,11 +31,13 @@ rust-doc:

# Lint checks for Rust code
lint:
cd e2e-tests && yarn && yarn lint && yarn fmt && yarn typecheck
cargo fmt --all -- --check
cargo clippy -Zunstable-options -- -D warnings --allow clippy::unwrap_used

# Fix lint errors for Rust code
lint-fix:
cd e2e-tests && yarn && yarn lint:fix && yarn fmt:fix
cargo clippy --fix
cargo fmt

Expand Down
33 changes: 33 additions & 0 deletions e2e-tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module.exports = {
env: {
es2021: true,
node: true,
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
],
overrides: [
{
env: {
node: true,
},
files: [".eslintrc.{js,cjs}"],
parserOptions: {
sourceType: "script",
},
},
],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
plugins: ["@typescript-eslint"],

// Add rule exceptions here if they are too onerous to comply with
rules: {
"@typescript-eslint/ban-ts-comment": "off",
},
};
8 changes: 8 additions & 0 deletions e2e-tests/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"printWidth": 80,
"useTabs": false,
"semi": true,
"singleQuote": false,
"trailingComma": "es5",
"bracketSpacing": true
}
10 changes: 5 additions & 5 deletions e2e-tests/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const config: HardhatUserConfig = {
// ethNetwork isn't necessary, but leaving for posterity
ethNetwork: "http://127.0.0.1:8545",
zksync: true,
}
},
},
solidity: {
version: "0.8.17",
Expand All @@ -25,10 +25,10 @@ const config: HardhatUserConfig = {
// Multiple reports allow view of the ouput in the console and as a JSON for the test result exporter in CI
reporter: "mocha-multi",
reporterOptions: {
"spec": "-",
"json": "test-results.json"
}
}
spec: "-",
json: "test-results.json",
},
},
};

export default config;
52 changes: 52 additions & 0 deletions e2e-tests/helpers/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
export const RichAccounts = {
0: {
Account: "0x36615Cf349d7F6344891B1e7CA7C72883F5dc049",
PrivateKey:
"0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110",
},
1: {
Account: "0xa61464658AfeAf65CccaaFD3a512b69A83B77618",
PrivateKey:
"0xac1e735be8536c6534bb4f17f06f6afc73b2b5ba84ac2cfb12f7461b20c0bbe3",
},
2: {
Account: "0x0D43eB5B8a47bA8900d84AA36656c92024e9772e",
PrivateKey:
"0xd293c684d884d56f8d6abd64fc76757d3664904e309a0645baf8522ab6366d9e",
},
3: {
Account: "0xA13c10C0D5bd6f79041B9835c63f91de35A15883",
PrivateKey:
"0x850683b40d4a740aa6e745f889a6fdc8327be76e122f5aba645a5b02d0248db8",
},
4: {
Account: "0x8002cD98Cfb563492A6fB3E7C8243b7B9Ad4cc92",
PrivateKey:
"0xf12e28c0eb1ef4ff90478f6805b68d63737b7f33abfa091601140805da450d93",
},
5: {
Account: "0x4F9133D1d3F50011A6859807C837bdCB31Aaab13",
PrivateKey:
"0xe667e57a9b8aaa6709e51ff7d093f1c5b73b63f9987e4ab4aa9a5c699e024ee8",
},
6: {
Account: "0xbd29A1B981925B94eEc5c4F1125AF02a2Ec4d1cA",
PrivateKey:
"0x28a574ab2de8a00364d5dd4b07c4f2f574ef7fcc2a86a197f65abaec836d1959",
},
7: {
Account: "0xedB6F5B4aab3dD95C7806Af42881FF12BE7e9daa",
PrivateKey:
"0x74d8b3a188f7260f67698eb44da07397a298df5427df681ef68c45b34b61f998",
},
8: {
Account: "0xe706e60ab5Dc512C36A4646D719b889F398cbBcB",
PrivateKey:
"0xbe79721778b48bcc679b78edac0ce48306a8578186ffcb9f2ee455ae6efeace1",
},
9: {
Account: "0xE90E12261CCb0F3F7976Ae611A29e84a6A85f424",
PrivateKey:
"0x3eb15da85647edd9a1159a4a13b9e7c56877c4eb33f614546d4db06a51868b1c",
},
} as const;
64 changes: 64 additions & 0 deletions e2e-tests/helpers/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import { expect } from "chai";
import { Contract, Provider } from "zksync-web3";
import * as hre from "hardhat";
import { HttpNetworkUserConfig } from "hardhat/types";

/**
* * Deploy a contract using HardHat Deployer
*
* @param {Deployer} deployer - HardHat Deployer
* @param {string} contractName - Name of the contract, without file extension e.g. "Greeter"
* @param {string[]?} args - Optional arguments to pass to the contract constructor
*
*
* @returns {Promise<Contract>} Returns a promise that resolves to the deployed contract
* @example
* const greeter = await deployContract(deployer, 'Greeter', ['Hi']);
*/
export async function deployContract(
deployer: Deployer,
contractName: string,
args: string[] = []
): Promise<Contract> {
const artifact = await deployer.loadArtifact(contractName);
return await deployer.deploy(artifact, args);
}

export function getTestProvider(): Provider {
const network = hre.userConfig.networks?.zkSyncTestnet;
return new Provider((network as HttpNetworkUserConfig).url);
}

/**
* * Helper for validating error thrown contains string
*
* @param {any} method - Async function to be executed
* @param {string} errorMessage - String to be searched for in error message
*
*
* @returns {Promise<void>} Returns an empty promise
* @example
* const action = async () => {
* await doSomething();
* throw new Error("Error: Failure 100");
* };
* await expectThrowsAsync(action, "Failure 100");
*/
export async function expectThrowsAsync(
// eslint-disable-next-line @typescript-eslint/ban-types
method: Function,
errorMessage: string
): Promise<void> {
let error = null;
try {
await method();
} catch (err) {
error = err;
}

expect(error).to.be.an("Error");
if (errorMessage) {
expect((error as Error).message).to.include(errorMessage);
}
}
17 changes: 15 additions & 2 deletions e2e-tests/package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
{
"name": "era-test-node-e2e-tests",
"private": true,
"version": "1.0.0",
"main": "index.js",
"author": "The Matter Labs Team <hello@matterlabs.dev>",
"license": "MIT",
"devDependencies": {
"@matterlabs/hardhat-zksync-deploy": "^0.6.5",
"@matterlabs/hardhat-zksync-solc": "^0.4.2",
"@nomiclabs/hardhat-etherscan": "^3.1.7",
"@openzeppelin/contracts": "^4.9.3",
"@types/chai": "^4.3.4",
"@types/mocha": "^10.0.1",
"@types/node": "^18.17.12",
"@typescript-eslint/eslint-plugin": "latest",
"@typescript-eslint/parser": "latest",
"chai": "^4.3.7",
"eslint": "^8.48.0",
"eslint-config-prettier": "^9.0.0",
"ethers": "^5.7.2",
"hardhat": "^2.12.4",
"mocha": "^10.2.0",
"mocha-multi": "^1.1.7",
"prettier": "^3.0.3",
"ts-node": "^10.9.1",
"typescript": "^4.9.4",
"zksync-web3": "^0.14.3"
},
"scripts": {
"test": "hardhat test --network zkSyncTestnet"
"build": "hardhat compile",
"clean": "hardhat clean",
"fmt": "prettier --check \"**/*.{js,ts,md}\"",
"fmt:fix": "prettier --write \"**/*.{js,ts,md}\"",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --fix --ext .ts",
"test": "hardhat test --network zkSyncTestnet",
"typecheck": "tsc -p . --noEmit"
}
}
Loading

0 comments on commit a6b9675

Please sign in to comment.