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

chore: update and add more e2e tests #132

Merged
merged 16 commits into from
Sep 26, 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
10 changes: 7 additions & 3 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ jobs:
- name: Rust Cache
uses: Swatinem/rust-cache@v2

- uses: actions/setup-node@v3
with:
node-version: 18.x
cache: "yarn"
cache-dependency-path: 'e2e-tests/yarn.lock'

- 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 Down
10 changes: 8 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ jobs:
with:
fetch-depth: 0

- uses: actions/setup-node@v3
with:
node-version: 18.x
cache: "yarn"
cache-dependency-path: 'e2e-tests/yarn.lock'

- name: Download artifacts
uses: actions/download-artifact@v3
with:
Expand All @@ -23,7 +29,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 +42,5 @@ jobs:
id: stop_node
if: always()
run: |
cat era_test_node_ouput.log
cat era_test_node_output.log
kill $PID
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,16 @@
"preLaunchTask": "rebuild-contracts",
"cwd": "${workspaceFolder}"
},
{
"name": "E2E Tests",
"type": "node",
"request": "launch",
"console": "integratedTerminal",
"cwd": "${workspaceFolder}/e2e-tests",
"runtimeExecutable": "yarn",
"runtimeArgs": [
"test"
]
},
]
}
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,26 @@ Please note that `era-test-node` is still in its **alpha** stage. Some features

## 📥 Installation & Setup

1. Install `era-test-node`:
1. Download `era-test-node` from latest [Release](https://github.com/matter-labs/era-test-node/releases/latest)

2. Extract the binary and mark as executable:
```bash
cargo install --git https://github.com/matter-labs/era-test-node.git --locked
tar xz -f era_test_node.tar.gz -C /usr/local/bin/
chmod +x /usr/local/bin/era_test_node
```
2. Start the node:

3. Start the node:
```bash
era_test_node run
```

## 🧑‍💻 Running Locally

1. Compile Rust project and start the node:
```bash
make run
```

## 📃 Logging

The node may be started in either of `debug`, `info`, `warn` or `error` logging levels via the `--log` option:
Expand Down
24 changes: 24 additions & 0 deletions SUPPORTED_APIS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The `status` options are:
| Namespace | API | <div style="width:130px">Status</div> | Description |
| --- | --- | --- | --- |
| [`CONFIG`](#config-namespace) | [`config_getShowCalls`](#config_getshowcalls) | `SUPPORTED` | Gets the current value of `show_calls` that's originally set with `--show-calls` option |
| [`CONFIG`](#config-namespace) | [`config_getCurrentTimestamp`](#config_getcurrenttimestamp) | `SUPPORTED` | Gets the value of `current_timestamp` for the node |
| [`CONFIG`](#config-namespace) | [`config_setResolveHashes`](#config_setresolvehashes) | `SUPPORTED` | Updates `resolve-hashes` to call OpenChain for human-readable ABI names in call traces |
| [`CONFIG`](#config-namespace) | [`config_setShowCalls`](#config_setshowcalls) | `SUPPORTED` | Updates `show_calls` to print more detailed call traces |
| [`CONFIG`](#config-namespace) | [`config_setShowStorageLogs`](#config_setshowstoragelogs) | `SUPPORTED` | Updates `show_storage_logs` to print storage log reads/writes |
Expand Down Expand Up @@ -152,6 +153,29 @@ curl --request POST \
--data '{"jsonrpc": "2.0","id": "1","method": "config_getShowCalls","params": []}'
```

### `config_getCurrentTimestamp`

[source](src/configuration_api.rs)

Gets the value of `current_timestamp` for the node

#### Arguments

+ _NONE_

#### Status

`SUPPORTED`

#### Example

```bash
curl --request POST \
--url http://localhost:8011/ \
--header 'content-type: application/json' \
--data '{"jsonrpc": "2.0","id": "1","method": "config_getCurrentTimestamp","params": []}'
```

### `config_setShowCalls`

[source](src/configuration_api.rs)
Expand Down
29 changes: 29 additions & 0 deletions e2e-tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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,
MexicanAce marked this conversation as resolved.
Show resolved Hide resolved
"useTabs": false,
"semi": true,
"singleQuote": false,
"trailingComma": "es5",
"bracketSpacing": true
}
3 changes: 3 additions & 0 deletions e2e-tests/contracts/Greeter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "hardhat/console.sol";

contract Greeter is Ownable {
string private greeting;
event LogString(string value);

constructor(string memory _greeting) {
greeting = _greeting;
Expand All @@ -18,6 +19,8 @@ contract Greeter is Ownable {
function setGreeting(string memory _greeting) public onlyOwner {
console.log("setGreeting called");
console.log(_greeting);
emit LogString(string.concat("Greeting is being updated to ", _greeting));

require(
keccak256(abi.encodePacked((_greeting))) != keccak256(abi.encodePacked(("test"))),
"Received a test value"
Expand Down
11 changes: 6 additions & 5 deletions e2e-tests/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { HardhatUserConfig } from "hardhat/config";

import "@matterlabs/hardhat-zksync-deploy";
import "@matterlabs/hardhat-zksync-solc";
import "@nomiclabs/hardhat-ethers";

const config: HardhatUserConfig = {
zksolc: {
Expand All @@ -16,7 +17,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 +26,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;
42 changes: 42 additions & 0 deletions e2e-tests/helpers/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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;
Loading