diff --git a/.github/actions/run-e2e-test/action.yml b/.github/actions/run-e2e-test/action.yml index 9a79c5cf74..870a248989 100644 --- a/.github/actions/run-e2e-test/action.yml +++ b/.github/actions/run-e2e-test/action.yml @@ -89,4 +89,4 @@ runs: - name: Run finalization e2e test if: inputs.follow-up-finalization-check == 'true' shell: bash - run: ./.github/scripts/run_e2e_test.sh -t finalization -m "${{ inputs.min-validator-count }}" + run: ./.github/scripts/run_e2e_test.sh -t finalization::finalization -m "${{ inputs.min-validator-count }}" diff --git a/.github/workflows/e2e-tests-main-devnet.yml b/.github/workflows/e2e-tests-main-devnet.yml index 9f1547e4c8..fd9047eb87 100644 --- a/.github/workflows/e2e-tests-main-devnet.yml +++ b/.github/workflows/e2e-tests-main-devnet.yml @@ -165,7 +165,8 @@ jobs: - name: Build binary and docker image run: | cd e2e-tests/ - cargo build --release + rm -f target/release/deps/aleph_e2e_client* + cp $(cargo test --no-run --release --message-format=json | jq -r .executable | grep aleph_e2e_client) target/release/aleph-e2e-client docker build --tag aleph-e2e-client:latest -f Dockerfile . docker save -o aleph-e2e-client.tar aleph-e2e-client:latest @@ -192,7 +193,7 @@ jobs: - name: Run e2e test uses: ./.github/actions/run-e2e-test with: - test-case: finalization + test-case: finalization::finalization timeout-minutes: 2 @@ -207,7 +208,7 @@ jobs: - name: Run e2e test uses: ./.github/actions/run-e2e-test with: - test-case: rewards_disable_node + test-case: rewards::disable_node follow-up-finalization-check: true timeout-minutes: 15 @@ -360,7 +361,7 @@ jobs: - name: Run e2e test uses: ./.github/actions/run-e2e-test with: - test-case: era_payout + test-case: era_payout::era_payout follow-up-finalization-check: true timeout-minutes: 10 @@ -390,7 +391,7 @@ jobs: - name: Run e2e test uses: ./.github/actions/run-e2e-test with: - test-case: rewards_force_new_era + test-case: rewards::force_new_era follow-up-finalization-check: true timeout-minutes: 10 @@ -405,7 +406,7 @@ jobs: - name: Run e2e test uses: ./.github/actions/run-e2e-test with: - test-case: rewards_stake_change + test-case: rewards::points_stake_change follow-up-finalization-check: true timeout-minutes: 10 @@ -420,7 +421,7 @@ jobs: - name: Run e2e test uses: ./.github/actions/run-e2e-test with: - test-case: rewards_change_stake_and_force_new_era + test-case: rewards::change_stake_and_force_new_era follow-up-finalization-check: true timeout-minutes: 10 @@ -528,7 +529,7 @@ jobs: - name: Run e2e test uses: ./.github/actions/run-e2e-test with: - test-case: version_upgrade + test-case: version_upgrade::schedule_version_change env: UPGRADE_VERSION: 1 UPGRADE_SESSION: 3 @@ -556,7 +557,6 @@ jobs: # UPGRADE_FINALIZATION_WAIT_SESSIONS: 2 # ONLY_LEGACY: true # timeout-minutes: 10 - # run-e2e-version-upgrade-catchup: # needs: [build-test-docker, build-cliain-image] # name: Run series of tests where some of the nodes need to do version-upgrade during catch-up diff --git a/.github/workflows/nightly-pipeline.yaml b/.github/workflows/nightly-pipeline.yaml index 8d8bec3367..25ee16ca50 100644 --- a/.github/workflows/nightly-pipeline.yaml +++ b/.github/workflows/nightly-pipeline.yaml @@ -108,7 +108,8 @@ jobs: - name: Build binary and docker image run: | cd e2e-tests/ - cargo build --release + rm -f target/release/deps/aleph_e2e_client* + cp $(cargo test --no-run --release --message-format=json | jq -r .executable | grep aleph_e2e_client) target/release/aleph-e2e-client docker build --tag aleph-e2e-client:latest -f Dockerfile . docker save -o aleph-e2e-client.tar aleph-e2e-client:latest diff --git a/e2e-tests/.dockerignore b/e2e-tests/.dockerignore new file mode 100644 index 0000000000..9b2ec2d766 --- /dev/null +++ b/e2e-tests/.dockerignore @@ -0,0 +1,2 @@ +target +!target/release/aleph-e2e-client diff --git a/e2e-tests/Cargo.lock b/e2e-tests/Cargo.lock index 1bf96b1341..8d3e01291e 100644 --- a/e2e-tests/Cargo.lock +++ b/e2e-tests/Cargo.lock @@ -60,6 +60,7 @@ dependencies = [ "futures", "hex", "log", + "once_cell", "pallet-balances", "pallet-elections", "pallet-staking", @@ -2267,6 +2268,7 @@ name = "pallets-support" version = "0.1.2" dependencies = [ "frame-support", + "sp-std 4.0.0 (git+https://github.com/Cardinal-Cryptography/substrate.git?branch=aleph-v0.9.30)", ] [[package]] diff --git a/e2e-tests/Cargo.toml b/e2e-tests/Cargo.toml index c884ba81c5..e472076061 100644 --- a/e2e-tests/Cargo.toml +++ b/e2e-tests/Cargo.toml @@ -15,6 +15,7 @@ codec = { package = 'parity-scale-codec', version = "3.0", default-features = fa rayon = "1.5" tokio = { version = "1.21.2", features = ["full"] } futures = "0.3.25" +once_cell = "1.16" sp-core = { git = "https://github.com/Cardinal-Cryptography/substrate.git", branch = "aleph-v0.9.30", default-features = false, features = ["full_crypto"] } sp-runtime = { git = "https://github.com/Cardinal-Cryptography/substrate.git", branch = "aleph-v0.9.30", default-features = false } diff --git a/e2e-tests/docker_entrypoint.sh b/e2e-tests/docker_entrypoint.sh index 3ab44def91..3fa2fe11d0 100644 --- a/e2e-tests/docker_entrypoint.sh +++ b/e2e-tests/docker_entrypoint.sh @@ -25,6 +25,6 @@ if [[ -n "${UPGRADE_VERSION:-}" && -n "${UPGRADE_SESSION:-}" && -n "${UPGRADE_FI ) fi -aleph-e2e-client "${ARGS[@]}" +E2E_CONFIG="${ARGS[*]}" aleph-e2e-client $TEST_CASES --nocapture echo "Done!" diff --git a/e2e-tests/src/ban.rs b/e2e-tests/src/ban.rs index f4542853ae..3972508623 100644 --- a/e2e-tests/src/ban.rs +++ b/e2e-tests/src/ban.rs @@ -12,8 +12,8 @@ use primitives::{SessionCount, SessionIndex}; use sp_runtime::Perbill; use crate::{ - accounts::account_ids_from_keys, elections::get_members_subset_for_session, - validators::get_test_validators, Config, + accounts::account_ids_from_keys, config::Config, elections::get_members_subset_for_session, + validators::get_test_validators, }; const RESERVED_SEATS: u32 = 2; diff --git a/e2e-tests/src/cases.rs b/e2e-tests/src/cases.rs deleted file mode 100644 index 813f18dd3a..0000000000 --- a/e2e-tests/src/cases.rs +++ /dev/null @@ -1,90 +0,0 @@ -use crate::{ - config::Config, - test::{ - authorities_are_staking as test_authorities_are_staking, - ban_automatic as test_ban_automatic, ban_manual as test_ban_manual, - ban_threshold as test_ban_threshold, batch_transactions as test_batch_transactions, - change_stake_and_force_new_era as test_change_stake_and_force_new_era, - change_validators as test_change_validators, - channeling_fee_and_tip as test_channeling_fee_and_tip, - clearing_session_count as test_clearing_session_count, disable_node as test_disable_node, - era_payouts_calculated_correctly as test_era_payout, era_validators as test_era_validators, - fee_calculation as test_fee_calculation, finalization as test_finalization, - force_new_era as test_force_new_era, points_basic as test_points_basic, - points_stake_change as test_points_stake_change, - schedule_doomed_version_change_and_verify_finalization_stopped as test_schedule_doomed_version_change_and_verify_finalization_stopped, - schedule_version_change as test_schedule_version_change, - staking_era_payouts as test_staking_era_payouts, - staking_new_validator as test_staking_new_validator, token_transfer as test_token_transfer, - treasury_access as test_treasury_access, validators_rotate as test_validators_rotate, - }, -}; - -pub async fn run_testcase(id: &str, config: &Config) -> anyhow::Result<()> { - match id { - "finalization" => test_finalization(config).await, - "version_upgrade" => test_schedule_version_change(config).await, - "rewards_disable_node" => test_disable_node(config).await, - "token_transfer" => test_token_transfer(config).await, - "channeling_fee_and_tip" => test_channeling_fee_and_tip(config).await, - "treasury_access" => test_treasury_access(config).await, - "batch_transactions" => test_batch_transactions(config).await, - "staking_era_payouts" => test_staking_era_payouts(config).await, - "validators_rotate" => test_validators_rotate(config).await, - "staking_new_validator" => test_staking_new_validator(config).await, - "change_validators" => test_change_validators(config).await, - "fee_calculation" => test_fee_calculation(config).await, - "era_payout" => test_era_payout(config).await, - "era_validators" => test_era_validators(config).await, - "rewards_change_stake_and_force_new_era" => { - test_change_stake_and_force_new_era(config).await - } - "points_basic" => test_points_basic(config).await, - "rewards_force_new_era" => test_force_new_era(config).await, - "rewards_stake_change" => test_points_stake_change(config).await, - "authorities_are_staking" => test_authorities_are_staking(config).await, - - "clearing_session_count" => test_clearing_session_count(config).await, - "ban_automatic" => test_ban_automatic(config).await, - "ban_manual" => test_ban_manual(config).await, - "ban_threshold" => test_ban_threshold(config).await, - "doomed_version_upgrade" => { - test_schedule_doomed_version_change_and_verify_finalization_stopped(config).await - } - _ => panic!("unknown testcase"), - } -} - -pub async fn run_all_testcases(config: &Config) -> anyhow::Result<()> { - let all = vec![ - "finalization", - "version_upgrade", - "rewards_disable_node", - "token_transfer", - "channeling_fee_and_tip", - "treasury_access", - "batch_transactions", - "staking_era_payouts", - "validators_rotate", - "staking_new_validator", - "change_validators", - "fee_calculation", - "era_payout", - "era_validators", - "rewards_change_stake_and_force_new_era", - "points_basic", - "rewards_force_new_era", - "rewards_stake_change", - "authorities_are_staking", - "clearing_session_count", - "ban_automatic", - "ban_manual", - "ban_threshold", - "doomed_version_upgrade", - ]; - - for testcase in all { - run_testcase(testcase, config).await?; - } - Ok(()) -} diff --git a/e2e-tests/src/config.rs b/e2e-tests/src/config.rs index 0dd4a68143..f3364a218c 100644 --- a/e2e-tests/src/config.rs +++ b/e2e-tests/src/config.rs @@ -1,9 +1,23 @@ +use std::env; + use aleph_client::{RootConnection, SignedConnection}; use clap::{Args, Parser}; +use once_cell::sync::Lazy; use primitives::SessionIndex; use crate::accounts::{get_sudo_key, get_validators_keys, get_validators_seeds, NodeKeys}; +static GLOBAL_CONFIG: Lazy = Lazy::new(|| { + let unparsed = env::var("E2E_CONFIG").unwrap_or("".to_string()); + let unparsed = format!("e2e {}", unparsed); + Config::parse_from(unparsed.split_whitespace()) +}); + +pub fn setup_test() -> &'static Config { + let _ = env_logger::builder().is_test(true).try_init(); + &GLOBAL_CONFIG +} + #[derive(Debug, Parser, Clone)] #[clap(version = "1.0")] pub struct Config { diff --git a/e2e-tests/src/lib.rs b/e2e-tests/src/lib.rs index f37546f64a..9f150c60b8 100644 --- a/e2e-tests/src/lib.rs +++ b/e2e-tests/src/lib.rs @@ -1,12 +1,16 @@ -pub use cases::{run_all_testcases, run_testcase}; -pub use config::Config; - +#[cfg(test)] mod accounts; +#[cfg(test)] mod ban; -mod cases; +#[cfg(test)] mod config; +#[cfg(test)] mod elections; +#[cfg(test)] mod rewards; +#[cfg(test)] mod test; +#[cfg(test)] mod transfer; +#[cfg(test)] mod validators; diff --git a/e2e-tests/src/main.rs b/e2e-tests/src/main.rs deleted file mode 100644 index c1067bebf3..0000000000 --- a/e2e-tests/src/main.rs +++ /dev/null @@ -1,52 +0,0 @@ -use std::{env, time::Instant}; - -use aleph_e2e_client::{run_all_testcases, run_testcase, Config}; -use clap::Parser; -use log::info; - -#[tokio::main(flavor = "multi_thread")] -async fn main() -> anyhow::Result<()> { - init_env(); - - let config: Config = Config::parse(); - let test_cases = config.test_cases.clone(); - // Possibility to handle specified vs. default test cases - // is helpful to parallelize e2e tests. - match test_cases { - Some(cases) => { - info!("Running specified test cases."); - run_specified_test_cases(cases, &config).await?; - } - None => { - info!("Running all handled test cases."); - run_all_testcases(&config).await?; - } - }; - Ok(()) -} - -fn init_env() { - if env::var(env_logger::DEFAULT_FILTER_ENV).is_err() { - env::set_var(env_logger::DEFAULT_FILTER_ENV, "warn"); - } - env_logger::init(); -} - -/// Runs specified test cases in sequence. -/// Checks whether each provided test case is valid. -async fn run_specified_test_cases(test_names: Vec, config: &Config) -> anyhow::Result<()> { - for test_name in test_names { - run(&test_name, config).await?; - } - Ok(()) -} - -/// Runs single test case. Allows for a generic return type. -async fn run(name: &str, config: &Config) -> anyhow::Result<()> { - info!("Running test: {}", name); - let start = Instant::now(); - run_testcase(name, config).await.map(|_| { - let elapsed = Instant::now().duration_since(start); - println!("Ok! Elapsed time {}ms", elapsed.as_millis()); - }) -} diff --git a/e2e-tests/src/rewards.rs b/e2e-tests/src/rewards.rs index ad3ef85845..0ba70fcb6e 100644 --- a/e2e-tests/src/rewards.rs +++ b/e2e-tests/src/rewards.rs @@ -21,7 +21,7 @@ use sp_runtime::Perquintill; use crate::{ accounts::{get_validators_keys, get_validators_seeds, NodeKeys}, - Config, + config::Config, }; const COMMITTEE_SEATS: CommitteeSeats = CommitteeSeats { @@ -51,7 +51,9 @@ pub async fn set_invalid_keys_for_validator( } /// Rotates session_keys of a given `controller`, making it able to rejoin the `consensus`. -pub async fn reset_validator_keys(controller_connection: &SignedConnection) -> anyhow::Result<()> { +pub(super) async fn reset_validator_keys( + controller_connection: &SignedConnection, +) -> anyhow::Result<()> { let validator_keys = controller_connection.connection.author_rotate_keys().await; controller_connection .set_keys(validator_keys, TxStatus::InBlock) diff --git a/e2e-tests/src/test/ban.rs b/e2e-tests/src/test/ban.rs index a25711b884..c7b8869ff1 100644 --- a/e2e-tests/src/test/ban.rs +++ b/e2e-tests/src/test/ban.rs @@ -22,8 +22,8 @@ use crate::{ check_underperformed_count_for_sessions, check_underperformed_validator_reason, check_underperformed_validator_session_count, check_validators, setup_test, }, + config, rewards::set_invalid_keys_for_validator, - Config, }; const SESSIONS_TO_CHECK: SessionCount = 5; @@ -54,7 +54,10 @@ async fn disable_validator(validator_address: &str, validator_seed: u32) -> anyh /// validators. Waits for the offending validator to hit the ban threshold of sessions without /// producing blocks. Verifies that the offending validator has in fact been banned out for the /// appropriate reason. -pub async fn ban_automatic(config: &Config) -> anyhow::Result<()> { +#[tokio::test] +#[ignore] +pub async fn ban_automatic() -> anyhow::Result<()> { + let config = config::setup_test(); let (root_connection, reserved_validators, non_reserved_validators, _) = setup_test(config).await?; @@ -139,7 +142,9 @@ pub async fn ban_automatic(config: &Config) -> anyhow::Result<()> { /// Runs a chain, sets up a committee and validators. Manually bans one of the validators /// from the committee with a specific reason. Verifies that validator marked for ban has in /// fact been banned for the given reason. -pub async fn ban_manual(config: &Config) -> anyhow::Result<()> { +#[tokio::test] +pub async fn ban_manual() -> anyhow::Result<()> { + let config = config::setup_test(); let (root_connection, reserved_validators, non_reserved_validators, _) = setup_test(config).await?; @@ -222,7 +227,9 @@ pub async fn ban_manual(config: &Config) -> anyhow::Result<()> { /// underperformed_session_count_threshold to 3. /// Disable one non_reserved validator. Check if the disabled validator is still in the committee /// and his underperformed session count is less or equal to 2. -pub async fn clearing_session_count(config: &Config) -> anyhow::Result<()> { +#[tokio::test] +pub async fn clearing_session_count() -> anyhow::Result<()> { + let config = config::setup_test(); let (root_connection, reserved_validators, non_reserved_validators, _) = setup_test(config).await?; @@ -268,7 +275,9 @@ pub async fn clearing_session_count(config: &Config) -> anyhow::Result<()> { /// Runs a chain, sets up a committee and validators. Changes the ban config to require 100% /// performance. Checks that each validator has all the sessions in which they were chosen for the /// committee marked as ones in which they underperformed. -pub async fn ban_threshold(config: &Config) -> anyhow::Result<()> { +#[tokio::test] +pub async fn ban_threshold() -> anyhow::Result<()> { + let config = config::setup_test(); let (root_connection, reserved_validators, non_reserved_validators, seats) = setup_test(config).await?; diff --git a/e2e-tests/src/test/electing_validators.rs b/e2e-tests/src/test/electing_validators.rs index 60d78e7f63..31994843b3 100644 --- a/e2e-tests/src/test/electing_validators.rs +++ b/e2e-tests/src/test/electing_validators.rs @@ -14,8 +14,8 @@ use log::info; use primitives::EraIndex; use crate::{ + config::setup_test, validators::{prepare_validators, setup_accounts}, - Config, }; /// Verify that `pallet_staking::ErasStakers` contains all target validators. @@ -147,7 +147,10 @@ async fn chill_validators(node: &str, chilling: Vec) { /// parameter to set `MinimumValidatorCount` in the chain spec as the chain is set up. /// For this specific test case, we use `node-count = 6` and `min-validator-count = 4`, which /// satisfies the outlined conditions. -pub async fn authorities_are_staking(config: &Config) -> anyhow::Result<()> { +#[tokio::test] +pub async fn authorities_are_staking() -> anyhow::Result<()> { + let config = setup_test(); + let node = &config.node; let root_connection = config.create_root_connection().await; diff --git a/e2e-tests/src/test/era_payout.rs b/e2e-tests/src/test/era_payout.rs index 9124fd403d..d2576d1584 100644 --- a/e2e-tests/src/test/era_payout.rs +++ b/e2e-tests/src/test/era_payout.rs @@ -8,9 +8,11 @@ use primitives::{ MILLISECS_PER_BLOCK, }; -use crate::Config; +use crate::config::{setup_test, Config}; -pub async fn era_payouts_calculated_correctly(config: &Config) -> anyhow::Result<()> { +#[tokio::test] +pub async fn era_payouts_calculated_correctly() -> anyhow::Result<()> { + let config = setup_test(); normal_era_payout(config).await?; force_era_payout(config).await?; diff --git a/e2e-tests/src/test/era_validators.rs b/e2e-tests/src/test/era_validators.rs index 8be1c52db9..81c2570116 100644 --- a/e2e-tests/src/test/era_validators.rs +++ b/e2e-tests/src/test/era_validators.rs @@ -8,7 +8,7 @@ use aleph_client::{ use crate::{ accounts::{account_ids_from_keys, get_validators_raw_keys}, - Config, + config::{setup_test, Config}, }; fn get_initial_reserved_validators(config: &Config) -> Vec { @@ -58,7 +58,9 @@ async fn get_current_and_next_era_non_reserved_validators( (current_non_reserved, stored_non_reserved) } -pub async fn era_validators(config: &Config) -> anyhow::Result<()> { +#[tokio::test] +pub async fn era_validators() -> anyhow::Result<()> { + let config = setup_test(); let connection = config.get_first_signed_connection().await; let root_connection = config.create_root_connection().await; diff --git a/e2e-tests/src/test/fee.rs b/e2e-tests/src/test/fee.rs index 41b4b62259..3fcf1a4132 100644 --- a/e2e-tests/src/test/fee.rs +++ b/e2e-tests/src/test/fee.rs @@ -8,9 +8,11 @@ use log::info; use primitives::Balance; use sp_runtime::{FixedPointNumber, FixedU128}; -use crate::{config::Config, transfer::setup_for_transfer}; +use crate::{config::setup_test, transfer::setup_for_transfer}; -pub async fn fee_calculation(config: &Config) -> anyhow::Result<()> { +#[tokio::test] +pub async fn fee_calculation() -> anyhow::Result<()> { + let config = setup_test(); // An initial transfer is needed to establish the fee multiplier. let (connection, to) = setup_for_transfer(config).await; let root_connection = config.create_root_connection().await; diff --git a/e2e-tests/src/test/finalization.rs b/e2e-tests/src/test/finalization.rs index 1aca8bbfc3..2c28b5d32f 100644 --- a/e2e-tests/src/test/finalization.rs +++ b/e2e-tests/src/test/finalization.rs @@ -3,9 +3,11 @@ use aleph_client::{ waiting::{AlephWaiting, BlockStatus}, }; -use crate::config::Config; +use crate::config::setup_test; -pub async fn finalization(config: &Config) -> anyhow::Result<()> { +#[tokio::test] +pub async fn finalization() -> anyhow::Result<()> { + let config = setup_test(); let connection = config.create_root_connection().await; let finalized = connection.connection.get_finalized_block_hash().await; @@ -18,5 +20,6 @@ pub async fn finalization(config: &Config) -> anyhow::Result<()> { .connection .wait_for_block(|n| n > finalized_number, BlockStatus::Finalized) .await; + Ok(()) } diff --git a/e2e-tests/src/test/mod.rs b/e2e-tests/src/test/mod.rs index 79e4d51b3b..052e5184ea 100644 --- a/e2e-tests/src/test/mod.rs +++ b/e2e-tests/src/test/mod.rs @@ -11,7 +11,6 @@ pub use staking::{staking_era_payouts, staking_new_validator}; pub use transfer::token_transfer; pub use treasury::{channeling_fee_and_tip, treasury_access}; pub use utility::batch_transactions; -pub use validators_change::change_validators; pub use validators_rotate::validators_rotate; pub use version_upgrade::{ schedule_doomed_version_change_and_verify_finalization_stopped, schedule_version_change, diff --git a/e2e-tests/src/test/rewards.rs b/e2e-tests/src/test/rewards.rs index 514cdb170a..9ca7ff4e16 100644 --- a/e2e-tests/src/test/rewards.rs +++ b/e2e-tests/src/test/rewards.rs @@ -12,12 +12,12 @@ use log::info; use primitives::{staking::MIN_VALIDATOR_BOND, EraIndex, SessionIndex}; use crate::{ + config::setup_test, elections::get_and_test_members_for_session, rewards::{ check_points, reset_validator_keys, set_invalid_keys_for_validator, setup_validators, validators_bond_extra_stakes, }, - Config, }; // Maximum difference between fractions of total reward that a validator gets. @@ -25,7 +25,9 @@ use crate::{ // retrieved from pallet Staking. const MAX_DIFFERENCE: f64 = 0.07; -pub async fn points_basic(config: &Config) -> anyhow::Result<()> { +#[tokio::test] +pub async fn points_basic() -> anyhow::Result<()> { + let config = setup_test(); let (era_validators, committee_size, start_session) = setup_validators(config).await?; let connection = config.get_first_signed_connection().await; @@ -72,7 +74,9 @@ pub async fn points_basic(config: &Config) -> anyhow::Result<()> { /// Runs a chain, bonds extra stakes to validator accounts and checks that reward points /// are calculated correctly afterward. -pub async fn points_stake_change(config: &Config) -> anyhow::Result<()> { +#[tokio::test] +pub async fn points_stake_change() -> anyhow::Result<()> { + let config = setup_test(); let (era_validators, committee_size, _) = setup_validators(config).await?; validators_bond_extra_stakes( @@ -131,7 +135,9 @@ pub async fn points_stake_change(config: &Config) -> anyhow::Result<()> { /// Runs a chain, sets invalid session keys for one validator, re-sets the keys to valid ones /// and checks that reward points are calculated correctly afterward. -pub async fn disable_node(config: &Config) -> anyhow::Result<()> { +#[tokio::test] +pub async fn disable_node() -> anyhow::Result<()> { + let config = setup_test(); let (era_validators, committee_size, start_session) = setup_validators(config).await?; let root_connection = config.create_root_connection().await; @@ -187,7 +193,9 @@ pub async fn disable_node(config: &Config) -> anyhow::Result<()> { /// for 3 sessions: 1) immediately following the forcing call, 2) in the subsequent, interim /// session, when the new era has not yet started, 3) in the next session, second one after /// the call, when the new era has already begun. -pub async fn force_new_era(config: &Config) -> anyhow::Result<()> { +#[tokio::test] +pub async fn force_new_era() -> anyhow::Result<()> { + let config = setup_test(); let (era_validators, committee_size, start_session) = setup_validators(config).await?; let connection = config.get_first_signed_connection().await; @@ -229,7 +237,9 @@ pub async fn force_new_era(config: &Config) -> anyhow::Result<()> { /// Expected behaviour: until the next (forced) era, rewards are calculated using old stakes, /// and after two sessions (required for a new era to be forced) they are adjusted to the new /// stakes. -pub async fn change_stake_and_force_new_era(config: &Config) -> anyhow::Result<()> { +#[tokio::test] +pub async fn change_stake_and_force_new_era() -> anyhow::Result<()> { + let config = setup_test(); let (era_validators, committee_size, start_session) = setup_validators(config).await?; let connection = config.get_first_signed_connection().await; diff --git a/e2e-tests/src/test/staking.rs b/e2e-tests/src/test/staking.rs index 9f634d50eb..82d4957191 100644 --- a/e2e-tests/src/test/staking.rs +++ b/e2e-tests/src/test/staking.rs @@ -21,7 +21,7 @@ use primitives::{ use crate::{ accounts::{account_ids_from_keys, accounts_seeds_to_keys, get_validators_seeds}, - config::Config, + config::{setup_test, Config}, }; fn get_validator_stashes_key_pairs(config: &Config) -> (Vec, Vec) { @@ -41,7 +41,9 @@ fn get_validator_stashes_key_pairs(config: &Config) -> (Vec, Vec anyhow::Result<()> { +#[tokio::test] +pub async fn staking_era_payouts() -> anyhow::Result<()> { + let config = setup_test(); let (stashes_accounts_key_pairs, validator_accounts) = get_validator_stashes_key_pairs(config); let node = &config.node; @@ -106,7 +108,9 @@ pub async fn staking_era_payouts(config: &Config) -> anyhow::Result<()> { // 7. add 4th validator which is the new stash account // 8. wait for next era // 9. claim rewards for the stash account -pub async fn staking_new_validator(config: &Config) -> anyhow::Result<()> { +#[tokio::test] +pub async fn staking_new_validator() -> anyhow::Result<()> { + let config = setup_test(); let controller_seed = "//Controller"; let controller = keypair_from_string(controller_seed); let controller_account = AccountId::from(controller.signer().public()); diff --git a/e2e-tests/src/test/transfer.rs b/e2e-tests/src/test/transfer.rs index 52eb1792d7..8cd33daa3c 100644 --- a/e2e-tests/src/test/transfer.rs +++ b/e2e-tests/src/test/transfer.rs @@ -4,9 +4,11 @@ use aleph_client::{ }; use log::info; -use crate::{config::Config, transfer::setup_for_transfer}; +use crate::{config::setup_test, transfer::setup_for_transfer}; -pub async fn token_transfer(config: &Config) -> anyhow::Result<()> { +#[tokio::test] +pub async fn token_transfer() -> anyhow::Result<()> { + let config = setup_test(); let (connection, to) = setup_for_transfer(config).await; let balance_before = connection diff --git a/e2e-tests/src/test/treasury.rs b/e2e-tests/src/test/treasury.rs index 58348c5798..50df832815 100644 --- a/e2e-tests/src/test/treasury.rs +++ b/e2e-tests/src/test/treasury.rs @@ -13,7 +13,7 @@ use log::info; use primitives::Balance; use crate::{ - accounts::get_validators_raw_keys, config::Config, test::fee::current_fees, + accounts::get_validators_raw_keys, config::setup_test, test::fee::current_fees, transfer::setup_for_transfer, }; @@ -33,7 +33,9 @@ async fn balance_info(connection: &Connection) -> (Balance, Balance) { (treasury_balance, issuance) } -pub async fn channeling_fee_and_tip(config: &Config) -> anyhow::Result<()> { +#[tokio::test] +pub async fn channeling_fee_and_tip() -> anyhow::Result<()> { + let config = setup_test(); let (transfer_amount, tip) = (1_000u128, 10_000u128); let (connection, to) = setup_for_transfer(config).await; @@ -100,7 +102,9 @@ fn check_treasury_balance( ); } -pub async fn treasury_access(config: &Config) -> anyhow::Result<()> { +#[tokio::test] +pub async fn treasury_access() -> anyhow::Result<()> { + let config = setup_test(); let proposer = KeyPair::new(get_validators_raw_keys(config)[0].clone()); let beneficiary = account_from_keypair(proposer.signer()); let connection = SignedConnection::new(config.node.clone(), proposer).await; diff --git a/e2e-tests/src/test/utility.rs b/e2e-tests/src/test/utility.rs index aef3d384be..c675dc32c3 100644 --- a/e2e-tests/src/test/utility.rs +++ b/e2e-tests/src/test/utility.rs @@ -2,9 +2,11 @@ use std::iter::repeat; use aleph_client::{pallets::balances::BalanceUserBatchExtApi, TxStatus}; -use crate::{config::Config, transfer::setup_for_transfer}; +use crate::{config::setup_test, transfer::setup_for_transfer}; -pub async fn batch_transactions(config: &Config) -> anyhow::Result<()> { +#[tokio::test] +pub async fn batch_transactions() -> anyhow::Result<()> { + let config = setup_test(); const NUMBER_OF_TRANSACTIONS: usize = 100; let (connection, to) = setup_for_transfer(config).await; diff --git a/e2e-tests/src/test/validators_change.rs b/e2e-tests/src/test/validators_change.rs index ec1905f17c..e1e0e8cb4a 100644 --- a/e2e-tests/src/test/validators_change.rs +++ b/e2e-tests/src/test/validators_change.rs @@ -8,9 +8,12 @@ use aleph_client::{ }; use log::info; -use crate::{accounts::get_validators_keys, config::Config}; +use crate::{accounts::get_validators_keys, config::setup_test}; + +#[tokio::test] +pub async fn change_validators() -> anyhow::Result<()> { + let config = setup_test(); -pub async fn change_validators(config: &Config) -> anyhow::Result<()> { let accounts = get_validators_keys(config); let connection = config.create_root_connection().await; diff --git a/e2e-tests/src/test/validators_rotate.rs b/e2e-tests/src/test/validators_rotate.rs index 51f9ad9da9..56d222346c 100644 --- a/e2e-tests/src/test/validators_rotate.rs +++ b/e2e-tests/src/test/validators_rotate.rs @@ -9,13 +9,15 @@ use aleph_client::{ }; use crate::{ - accounts::account_ids_from_keys, elections::get_members_subset_for_session, - validators::get_test_validators, Config, + accounts::account_ids_from_keys, config::setup_test, elections::get_members_subset_for_session, + validators::get_test_validators, }; const TEST_LENGTH: u32 = 5; -pub async fn validators_rotate(config: &Config) -> anyhow::Result<()> { +#[tokio::test] +pub async fn validators_rotate() -> anyhow::Result<()> { + let config = setup_test(); let connection = config.get_first_signed_connection().await; let root_connection = config.create_root_connection().await; diff --git a/e2e-tests/src/test/version_upgrade.rs b/e2e-tests/src/test/version_upgrade.rs index 1f8fb03617..8f718335b3 100644 --- a/e2e-tests/src/test/version_upgrade.rs +++ b/e2e-tests/src/test/version_upgrade.rs @@ -6,7 +6,7 @@ use aleph_client::{ }; use primitives::SessionIndex; -use crate::Config; +use crate::config::setup_test; const UPGRADE_TO_VERSION: u32 = 1; @@ -15,7 +15,9 @@ const UPGRADE_SESSION: SessionIndex = 3; const UPGRADE_FINALIZATION_WAIT_SESSIONS: u32 = 3; // Simple test that schedules a version upgrade, awaits it, and checks if node is still finalizing after planned upgrade session. -pub async fn schedule_version_change(config: &Config) -> anyhow::Result<()> { +#[tokio::test] +pub async fn schedule_version_change() -> anyhow::Result<()> { + let config = setup_test(); let connection = config.create_root_connection().await; let test_case_params = config.test_case_params.clone(); @@ -53,9 +55,10 @@ pub async fn schedule_version_change(config: &Config) -> anyhow::Result<()> { // A test that schedules a version upgrade which is supposed to fail, awaits it, and checks if finalization stopped. // It's up to the user of this test to ensure that version upgrade will actually break finalization (non-compatible change in protocol, # updated nodes k is f < k < 2/3n). -pub async fn schedule_doomed_version_change_and_verify_finalization_stopped( - config: &Config, -) -> anyhow::Result<()> { +#[tokio::test] +pub async fn schedule_doomed_version_change_and_verify_finalization_stopped() -> anyhow::Result<()> +{ + let config = setup_test(); let connection = config.create_root_connection().await; let test_case_params = config.test_case_params.clone(); diff --git a/e2e-tests/src/validators.rs b/e2e-tests/src/validators.rs index 9a8df557e5..a4567e429c 100644 --- a/e2e-tests/src/validators.rs +++ b/e2e-tests/src/validators.rs @@ -10,7 +10,7 @@ use aleph_client::{ use futures::future::join_all; use primitives::{staking::MIN_VALIDATOR_BOND, TOKEN}; -use crate::{accounts::get_validators_raw_keys, Config}; +use crate::{accounts::get_validators_raw_keys, config::Config}; /// Get all validators assumed for test pub fn get_test_validators(config: &Config) -> EraValidators { diff --git a/scripts/run_e2e.sh b/scripts/run_e2e.sh index 56c7343ee1..d7d0266cc0 100755 --- a/scripts/run_e2e.sh +++ b/scripts/run_e2e.sh @@ -4,6 +4,6 @@ set -e cd e2e-tests/ -RUST_LOG=aleph_e2e_client=info,aleph-client=info cargo run -- --node ws://127.0.0.1:9943 +E2E_CONFIG="--node ws://127.0.0.1:9943" RUST_LOG=info cargo test -- --nocapture exit $?