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

[NEW] integration tests and tests coverage script #48

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ toml = { version = "0.8", optional = true }
shadow-rs = "0.29"
thiserror = "1"
tokio = { version = "1", features = ["full"] }
cmd_lib = "1.3.0"
serial_test = "2.0.0"

[dev-dependencies]
rand = "0.8"
assert_cmd = "2.0.12"
predicates = "3.0.3"

[build-dependencies]
shadow-rs = "0.29"
32 changes: 32 additions & 0 deletions scripts/tests-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

### NOTE: first we need to install grcov and llvm-tools-preview for test coverage
# cargo install grcov
# rustup component add llvm-tools-preview



# clean project
cargo clean

# clean test coverage profile previous files
rm -f *.profraw

# build with coverage flags, cmd run by cargo test so skip it
#RUSTFLAGS="-Cinstrument-coverage" LLVM_PROFILE_FILE="aurora-cli-%p-%m.profraw" cargo build

# Build test code, without running tests
#RUSTFLAGS="-Cinstrument-coverage" LLVM_PROFILE_FILE="aurora-cli-%p-%m.profraw" cargo build --tests

# run integration tests only
#RUSTFLAGS="-Cinstrument-coverage" LLVM_PROFILE_FILE="aurora-cli-%p-%m.profraw" cargo test --test simple_tests -- --show-output --test-threads=1
#RUSTFLAGS="-Cinstrument-coverage" LLVM_PROFILE_FILE="aurora-cli-%p-%m.profraw" cargo test --test '*' -- --show-output --test-threads=1
#RUSTFLAGS="-Cinstrument-coverage" LLVM_PROFILE_FILE="aurora-cli-%p-%m.profraw" cargo test --test simple_tests simple_silo_tests -- --show-output --test-threads=1

# run all tests
RUSTFLAGS="-Cinstrument-coverage" LLVM_PROFILE_FILE="aurora-cli-%p-%m.profraw" cargo test -- --show-output --test-threads=1

# generate coverage report as html
grcov . --binary-path ./target/debug/ -s . -t html --branch --ignore-not-existing --ignore "*cargo*" -o ./coverage/html

# generate coverage report as lcov
grcov . --binary-path ./target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore "*cargo*" -o ./coverage/tests.lcov
183 changes: 183 additions & 0 deletions tests/advanced_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
mod common;

#[cfg(feature = "advanced")]
mod advanced_tests {
use super::common::*;
use cmd_lib::run_cmd;
use cmd_lib::run_fun;
use cmd_lib::*;
use serial_test::serial;

// export NEARCORE_HOME="/tmp/localnet"
//static NEARCORE_HOME: &str = "/tmp/localnet";

// static EVM_CODE = &run_fun!(cat docs/res/Counter.hex)?;
//static COUNTER_ABI_PATH: &str = "docs/res/Counter.abi";
//static ENGINE_SILO_WASM_PATH: &str = "docs/res/aurora-mainnet-silo.wasm";
//static NODE_KEY_PATH: &str = "/tmp/localnet/node0/validator_key.json";
//static AURORA_KEY_PATH: &str = "/tmp/localnet/node0/aurora_key.json";
//static AURORA_SECRET_KEY: &str = "27cb3ddbd18037b38d7fb9ae3433a9d6f5cd554a4ba5768c8a15053f688ee167";
//static ENGINE_ACCOUNT: &str = "aurora.node0";

// static EVM_CODE=$(cat docs/res/HelloWorld.hex)
//static ABI_PATH="docs/res/HelloWorld.abi";
// AURORA_LAST_VERSION="2.9.2"
//AURORA_LAST_VERSION="3.0.0"
//ENGINE_WASM_URL="https://github.com/aurora-is-near/aurora-engine/releases/download/3.0.0/aurora-mainnet.wasm"
//ENGINE_WASM_PATH="/tmp/aurora-mainnet.wasm"
// USER_BASE_BIN=$(python3 -m site --user-base)/bin

//export PATH="$PATH:$USER_BASE_BIN:$HOME/.cargo/bin"
//export NEARCORE_HOME="/tmp/localnet"




#[test]
#[serial]
//#[ignore]
fn init_0_logger() -> Result<(), Box<dyn std::error::Error>> {
// init logger
init_builtin_logger();
Ok(())
}



#[test]
//#[serial("ordered init fn 0")] //new serial group based on given text
#[serial]
//#[ignore]
fn init_1() -> Result<(), Box<dyn std::error::Error>> {
//# stop near node first
run_cmd!(
echo "stop nearup node";
nearup stop;
rm -rf $NEARCORE_HOME/node0/data;
echo "done...";
)?;
Ok(())
}



#[test]
//#[serial("ordered init fn 1")]
#[serial]
//#[ignore]
fn init_2() -> Result<(), Box<dyn std::error::Error>> {
//# Update configs and add aurora key.
run_cmd!(
echo "Update configs and add aurora key...";
$BIN_NAME near init genesis --path $GENESIS_FILE_PATH;
echo "genesis done...";
sleep 1;
$BIN_NAME near init local-config -n $CONFIG_FILE_PATH -a $AURORA_KEY_PATH;
echo "config done...";
sleep 1;
)?;
Ok(())
}



#[test]
#[serial]
//#[ignore]
fn init_3() -> Result<(), Box<dyn std::error::Error>> {
// Start NEAR node:
//# nearup run localnet --home $NEARCORE_HOME --num-nodes 1
run_cmd!(
echo "nearup run...";
nearup run localnet --home $NEARCORE_HOME --num-nodes 1;
sleep 20;
echo "done...";
)?;
Ok(())
}



#[test]
#[serial]
//#[ignore]
fn test_00() -> Result<(), Box<dyn std::error::Error>> {
//# Download Aurora EVM.
run_cmd!(
echo "Download Aurora EVM...";
curl -sL $ENGINE_WASM_URL -o $ENGINE_WASM_PATH;
sleep 15;
echo "done...";
)?;
Ok(())
}



#[test]
#[serial]
fn test_01() -> Result<(), Box<dyn std::error::Error>> {
//# Deploy and init Aurora EVM smart contract.
run_cmd!(
echo "Deploy and init Aurora EVM smart contract...";
$BIN_NAME near write engine-init -w $ENGINE_WASM_PATH;
sleep 2;
)?;

Ok(())
}



#[test]
#[serial]
//#[ignore]
fn test_02() -> Result<(), Box<dyn std::error::Error>> {
//# Deploy EVM code
//evm_code = $(cat docs/res/HelloWorld.hex)
let EVM_CODE: &str = &get_evm_code().to_string();
run_cmd!(
echo "Deploy EVM code...";
$BIN_NAME near write deploy-code $EVM_CODE;
echo "done...";
sleep 2;
)?;

Ok(())
}



#[test]
#[serial]
//#[ignore]
fn test_03() -> Result<(), Box<dyn std::error::Error>> {
//# Run EVM view call
run_cmd!(
echo "Run EVM view call...";
$BIN_NAME near read solidity -t 0x592186c059e3d9564cac6b1ada6f2dc7ff1d78e9 call-args-by-name
--abi-path $ABI_PATH -m "greet" --arg "{}";
echo "done...";
sleep 1;
)?;
Ok(())
}



#[test]
#[serial]
//#[ignore]
fn test_04_cleanup() -> Result<(), Box<dyn std::error::Error>> {
//nearup stop;
//rm -rf $NEARCORE_HOME;
run_cmd!(
echo "nearup stop node...";
nearup stop;
echo "Cleanup...";
rm -rf $NEARCORE_HOME;
echo "finished.";
)?;
Ok(())
}
}
84 changes: 84 additions & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
pub use assert_cmd::prelude::*; // Add methods on commands
pub use predicates::prelude::*; // Used for writing assertions

Check warning on line 2 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / Linux

unused import: `predicates::prelude::*`

Check warning on line 2 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / macOS

unused import: `predicates::prelude::*`
pub use std::process::Command; // Run programs
use cmd_lib::run_fun;

pub static BIN_NAME: &str = "aurora-cli";

Check warning on line 6 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / Linux

static `BIN_NAME` is never used

Check warning on line 6 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / macOS

static `BIN_NAME` is never used

// export NEARCORE_HOME="/tmp/localnet"
pub static NEARCORE_HOME: &str = "/tmp/localnet";

Check warning on line 9 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / Linux

static `NEARCORE_HOME` is never used

Check warning on line 9 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / macOS

static `NEARCORE_HOME` is never used

//static EVM_CODE: &str = &run_fun!(cat docs/res/HelloWorld.hex)?; //$(cat docs/res/HelloWorld.hex);
pub static ABI_PATH: &str = "docs/res/HelloWorld.abi";

Check warning on line 12 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / Linux

static `ABI_PATH` is never used

Check warning on line 12 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / macOS

static `ABI_PATH` is never used

//static COUNTER_EVM_CODE: &str = &run_fun!(cat docs/res/Counter.hex)?;
pub static COUNTER_ABI_PATH: &str = "docs/res/Counter.abi";

Check warning on line 15 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / Linux

static `COUNTER_ABI_PATH` is never used

Check warning on line 15 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / macOS

static `COUNTER_ABI_PATH` is never used

pub static ENGINE_SILO_WASM_PATH: &str = "docs/res/aurora-mainnet-silo.wasm";

Check warning on line 17 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / Linux

static `ENGINE_SILO_WASM_PATH` is never used

Check warning on line 17 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / macOS

static `ENGINE_SILO_WASM_PATH` is never used

pub static GENESIS_FILE_PATH: &str = "/tmp/localnet/node0/genesis.json";

Check warning on line 19 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / Linux

static `GENESIS_FILE_PATH` is never used

Check warning on line 19 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / macOS

static `GENESIS_FILE_PATH` is never used
pub static CONFIG_FILE_PATH: &str = "/tmp/localnet/node0/config.json";

Check warning on line 20 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / Linux

static `CONFIG_FILE_PATH` is never used

Check warning on line 20 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / macOS

static `CONFIG_FILE_PATH` is never used

pub static NODE_KEY_PATH: &str = "/tmp/localnet/node0/validator_key.json";

Check warning on line 22 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / Linux

static `NODE_KEY_PATH` is never used

Check warning on line 22 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / macOS

static `NODE_KEY_PATH` is never used
pub static AURORA_KEY_PATH: &str = "/tmp/localnet/node0/aurora_key.json";

Check warning on line 23 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / Linux

static `AURORA_KEY_PATH` is never used

Check warning on line 23 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / macOS

static `AURORA_KEY_PATH` is never used

pub static AURORA_SECRET_KEY: &str = "27cb3ddbd18037b38d7fb9ae3433a9d6f5cd554a4ba5768c8a15053f688ee167";
pub static ENGINE_ACCOUNT: &str = "aurora.node0";



pub static AURORA_PREV_VERSION: &str = "2.10.0";
pub static AURORA_LAST_VERSION: &str = "3.0.0";

pub static ENGINE_WASM_URL: &str = "https://github.com/aurora-is-near/aurora-engine/releases/download/3.0.0/aurora-mainnet.wasm";
pub static ENGINE_PREV_WASM_URL: &str = "https://github.com/aurora-is-near/aurora-engine/releases/download/2.10.0/aurora-mainnet.wasm"; //, AURORA_PREV_VERSION);
pub static ENGINE_LAST_WASM_URL: &str = "https://github.com/aurora-is-near/aurora-engine/releases/download/3.0.0/aurora-mainnet.wasm"; //, AURORA_LAST_VERSION);

pub static XCC_ROUTER_LAST_WASM_URL: &str = "https://github.com/aurora-is-near/aurora-engine/releases/download/3.0.0/aurora-factory-mainnet.wasm"; //, AURORA_LAST_VERSION);

pub static ENGINE_WASM_PATH: &str = "/tmp/aurora-mainnet.wasm";
pub static XCC_ROUTER_WASM_PATH: &str = "/tmp/aurora-factory-mainnet.wasm";
//static USER_BASE_BIN: &str = $(python3 -m site --user-base)/bin
//pub static NODE_KEY_PATH: &str = "/tmp/localnet/node0/validator_key.json"; //, NEARCORE_HOME);
//pub static AURORA_KEY_PATH: &str = "/tmp/localnet/node0/aurora_key.json"; //, NEARCORE_HOME);
pub static MANAGER_KEY_PATH: &str = "/tmp/localnet/node0/manager_key.json"; //, NEARCORE_HOME);
pub static RELAYER_KEY_PATH: &str = "/tmp/localnet/node0/relayer_key.json"; //, NEARCORE_HOME);
//pub static AURORA_SECRET_KEY: &str = "27cb3ddbd18037b38d7fb9ae3433a9d6f5cd554a4ba5768c8a15053f688ee167";
//pub static ENGINE_ACCOUNT: &str = "aurora.node0";
// the following line for MANAGER_ACCOUNT throws error: Non-sub accounts could be created for mainnet or testnet only
//static MANAGER_ACCOUNT: &str = "key-manager.aurora.node0"; //# NOTE: use key-manager-aurora.node0 instead of key-manager.aurora.node0
pub static MANAGER_ACCOUNT: &str = "key-manager-aurora.node0";



pub fn get_evm_code() -> String {
//$(cat docs/res/HelloWorld.hex);
let code = run_fun!(cat docs/res/HelloWorld.hex).unwrap();
String::from(code)
}

pub fn get_counter_evm_code() -> String {
//$(cat docs/res/Counter.hex);
let code = run_fun!(cat docs/res/Counter.hex).unwrap();
String::from(code)
}

pub fn get_relayer_public_key() -> String {
let relayer_public_key = run_fun!(jq -r .public_key < $RELAYER_KEY_PATH).unwrap();
String::from(relayer_public_key)
}



/// setup Command with given args from string
pub fn setup_cmd(test_args: &str) -> Command {
let args: Vec<&str> = test_args.split_whitespace().collect();
println!("---args: {:?}", args);

//let mut cmd = Command::cargo_bin(BIN_NAME)?;
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
for arg1 in args {
cmd.arg(arg1);
}
cmd
}
Loading
Loading