From 0976b1dc182241b08f4f615305d782e9305f0047 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Mon, 2 Sep 2024 15:49:11 +0400 Subject: [PATCH] e2e setup guide --- GUIDELINES.md | 54 +++++++++++++++++++++++++++++++++++---- lib/e2e/src/system.rs | 6 +++-- scripts/e2e-tests.sh | 2 +- scripts/nitro-testnode.sh | 8 +++--- 4 files changed, 58 insertions(+), 12 deletions(-) diff --git a/GUIDELINES.md b/GUIDELINES.md index 6f41be09..61f75f14 100644 --- a/GUIDELINES.md +++ b/GUIDELINES.md @@ -131,7 +131,7 @@ Use 1-word names for function parameters or variables that have larger scopes: ```rust pub fn commit(repo: &Repository, sig: &Signature) -> Result { -... + ... } ``` @@ -207,6 +207,47 @@ Make sure all tests are passing with: $ cargo test --all-features +### Running end-to-end tests + +In order to run end-to-end (e2e) tests you need to have a specific nightly toolchain. +"Nightly" is necessary to use optimization compiler flags and have contract wasm small enough to be eligible for +deployment. + +Run the following commands to install the necessary toolchain: + +```shell +rustup install nightly-2024-01-01 +rustup component add rust-src +``` + +Also, you should have the cargo stylus tool: + +```shell +cargo install cargo-stylus +``` + +Since most of the e2e tests using koba for deploying contracts, you need to install solidity compiler v0.8.21, like +this: + +```shell +curl -LO https://github.com/ethereum/solidity/releases/download/v0.8.21/solc-static-linux +sudo mv solc-static-linux /usr/bin/solc +sudo chmod a+x /usr/bin/solc +``` + +To run e2e tests, you need to have a local nitro test node set up. +Run the following command and wait till script exit successfully: + +```shell +./scripts/nitro-testnode.sh -i -d +``` + +Then you will be able to run e2e tests: + +```shell +./scripts/e2e-tests.sh +``` + ### Checking the docs If you make documentation changes, you may want to check whether there are any @@ -279,12 +320,15 @@ conventions that must be followed. - Custom errors should be declared following the [EIP-6093] rationale whenever reasonable. Also, consider the following: - - The domain prefix should be picked in the following order: - 1. Use `ERC` if the error is a violation of an ERC specification. - 2. Use the name of the underlying component where it belongs (eg. - `Governor`, `ECDSA`, or `Timelock`). + - The domain prefix should be picked in the following order: + 1. Use `ERC` if the error is a violation of an ERC specification. + 2. Use the name of the underlying component where it belongs (eg. + `Governor`, `ECDSA`, or `Timelock`). [The Rust Style Guide]: https://doc.rust-lang.org/nightly/style-guide/ + [EIP-6093]: https://eips.ethereum.org/EIPS/eip-6093 + [Semantic versioning]: https://semver.org/spec/v2.0.0.html + [Conventional Commits]: https://www.conventionalcommits.org/en/v1.0.0/ diff --git a/lib/e2e/src/system.rs b/lib/e2e/src/system.rs index 0bd0d487..aef9ac3e 100644 --- a/lib/e2e/src/system.rs +++ b/lib/e2e/src/system.rs @@ -62,9 +62,11 @@ pub fn provider() -> Provider { /// Send `amount` eth to `address` in the nitro-tesnode. pub fn fund_account(address: Address, amount: &str) -> eyre::Result<()> { - // ./test-node.bash script send-l2 --to - // address_0x01fA6bf4Ee48B6C95900BCcf9BEA172EF5DBd478 --ethamount 10 let node_script = get_node_path()?.join("test-node.bash"); + if !node_script.exists() { + bail!("Test nitro node wasn't setup properly. Try to setup it first with `./scripts/nitro-testnode.sh -i -d`") + }; + let output = std::process::Command::new(node_script) .arg("script") .arg("send-l2") diff --git a/scripts/e2e-tests.sh b/scripts/e2e-tests.sh index 3a26eacb..f7b9cdeb 100755 --- a/scripts/e2e-tests.sh +++ b/scripts/e2e-tests.sh @@ -5,7 +5,7 @@ MYDIR=$(realpath "$(dirname "$0")") cd "$MYDIR" cd .. -NIGHTLY_TOOLCHAIN=${NIGHTLY_TOOLCHAIN:-nightly} +NIGHTLY_TOOLCHAIN=${NIGHTLY_TOOLCHAIN:-nightly-2024-01-01} cargo +"$NIGHTLY_TOOLCHAIN" build --release --target wasm32-unknown-unknown -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort export RPC_URL=http://localhost:8547 diff --git a/scripts/nitro-testnode.sh b/scripts/nitro-testnode.sh index e14a8da4..815323c2 100755 --- a/scripts/nitro-testnode.sh +++ b/scripts/nitro-testnode.sh @@ -17,15 +17,15 @@ do HAS_DETACH=true shift ;; - -down|--shutdown) - docker container stop "$(docker container ls -q --filter name=nitro-testnode)" + -q|--quit) + docker container stop $(docker container ls -q --filter name=nitro-testnode) exit 0 ;; *) echo "OPTIONS:" echo "-i|--init: clone repo and init nitro test node" echo "-d|--detach: setup nitro test node in detached mode" - echo "-down|--shutdown: shutdown nitro test node docker containers" + echo "-q|--quit: shutdown nitro test node docker containers" exit 0 ;; esac @@ -46,7 +46,7 @@ then # `release` branch. git checkout 8cb6b84e31909157d431e7e4af9fb83799443e00 || exit - ./test-node.bash --no-run --init --no-tokenbridge || exit + ./test-node.bash --no-run --init || exit fi