-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ci): Scale integration tests (#82)
Resolves #72 - It is a bit more user focused approach (every test user should be funded at nitro test node. Instantiation of the user in rust code abstracts this process) - Now user can deploy any contract using his private key (abstracts `cargo stylus deploy`). - And call methods of any other contract. - Since user creation and contract deployment will be done per test. No need to run tests serially anymore - Possible to retrieve address of deployed contract + transaction with status not succeeded will be returned as an error #### PR Checklist - [x] Tests - [x] Documentation --------- Co-authored-by: Alexander González <[email protected]>
- Loading branch information
1 parent
c3ad795
commit 5f3915e
Showing
29 changed files
with
760 additions
and
397 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,8 @@ name: e2e-tests | |
# | ||
# It roughly follows these steps: | ||
# - A local `nitro-testnode` gets spun up. | ||
# - Contracts get deployed to the local node. | ||
# - A few addresses get funded. | ||
# - The test suite runs. | ||
# - The test suite runs | ||
# Test contract deployments and test user funding happen per test. | ||
permissions: | ||
contents: read | ||
on: | ||
|
@@ -53,20 +52,7 @@ jobs: | |
run: RUSTFLAGS="-C link-args=-rdynamic" cargo install [email protected] | ||
|
||
- name: setup nitro node | ||
run: | | ||
# clone nitro test node repo | ||
git clone -b stylus --recurse-submodules https://github.com/OffchainLabs/nitro-testnode.git && cd nitro-testnode | ||
git checkout 1886f4b89f5c20fd5b0c2cf3d08a009ee73e45ca | ||
# setup nitro test node | ||
./test-node.bash --no-run --init --no-tokenbridge | ||
./test-node.bash --detach | ||
# TODO: remove hard coded wallets when user creation will be per test case | ||
# fund Alice's wallet | ||
./test-node.bash script send-l2 --to address_0x01fA6bf4Ee48B6C95900BCcf9BEA172EF5DBd478 --ethamount 10000 | ||
# fund Bob's wallet | ||
./test-node.bash script send-l2 --to address_0xF4EaCDAbEf3c8f1EdE91b6f2A6840bc2E4DD3526 --ethamount 10000 | ||
run: ./e2e-tests/nitro-testnode.sh -d -i | ||
|
||
- name: run integration tests | ||
run: | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ | |
docs/build/ | ||
|
||
**/.DS_Store | ||
|
||
/e2e-tests/nitro-testnode |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use std::path::{Path, PathBuf}; | ||
|
||
fn main() { | ||
set_env("TARGET_DIR", &get_target_dir()); | ||
set_env("RPC_URL", "http://localhost:8547"); | ||
set_env( | ||
"TEST_NITRO_NODE_PATH", | ||
Path::new(&load_env_var("CARGO_MANIFEST_DIR")) | ||
.join("nitro-testnode") | ||
.to_str() | ||
.expect("set env var TEST_NITRO_NODE_PATH"), | ||
); | ||
} | ||
|
||
fn set_env(var_name: &str, value: &str) { | ||
println!("cargo:rustc-env={}={}", var_name, value); | ||
} | ||
|
||
fn load_env_var(var_name: &str) -> String { | ||
std::env::var(var_name) | ||
.unwrap_or_else(|_| panic!("failed to load {} env var", var_name)) | ||
} | ||
|
||
fn get_target_dir() -> String { | ||
// should be smth like | ||
// ./rust-contracts-stylus/target/debug/build/e2e-tests-b008947425bb8267/out | ||
let out_dir = load_env_var("OUT_DIR"); | ||
let target_dir = Path::new(&out_dir).join("../../../../"); | ||
target_dir.to_str().expect("target dir").to_string() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/bin/bash | ||
|
||
MYDIR=$(realpath "$(dirname "$0")") | ||
cd "$MYDIR" || exit | ||
|
||
HAS_INIT=false | ||
HAS_DETACH=false | ||
|
||
while [[ $# -gt 0 ]] | ||
do | ||
case "$1" in | ||
-i|--init) | ||
HAS_INIT=true | ||
shift | ||
;; | ||
-d|--detach) | ||
HAS_DETACH=true | ||
shift | ||
;; | ||
-down|--shutdown) | ||
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" | ||
exit 0 | ||
;; | ||
esac | ||
done | ||
|
||
TEST_NODE_DIR="$MYDIR/nitro-testnode" | ||
if [ ! -d "$TEST_NODE_DIR" ]; then | ||
HAS_INIT=true | ||
fi | ||
|
||
if $HAS_INIT | ||
then | ||
cd "$MYDIR" || exit | ||
# clone nitro test node repo | ||
git clone -b stylus --recurse-submodules https://github.com/OffchainLabs/nitro-testnode.git | ||
cd ./nitro-testnode || exit | ||
git checkout 1886f4b89f5c20fd5b0c2cf3d08a009ee73e45ca || exit | ||
|
||
# setup nitro test node | ||
./test-node.bash --no-run --init --no-tokenbridge || exit | ||
fi | ||
|
||
|
||
cd "$TEST_NODE_DIR" || exit | ||
if $HAS_DETACH | ||
then | ||
./test-node.bash --detach | ||
else | ||
./test-node.bash | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
use ethers::prelude::*; | ||
|
||
use crate::context::*; | ||
use e2e::prelude::*; | ||
|
||
abigen!( | ||
Erc20Token, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
use ethers::prelude::*; | ||
|
||
use crate::context::*; | ||
use e2e::prelude::*; | ||
|
||
abigen!( | ||
Erc721Token, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod erc20; | ||
pub mod erc721; |
Oops, something went wrong.