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

test/e2e: mainnet phases test #4013

Open
wants to merge 1 commit 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
5 changes: 3 additions & 2 deletions .github/workflows/scripts/e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
"e2e::wallet_tests::wallet_unencrypted_key_cmds": 1,
"e2e::ledger_tests::masp_txs_and_queries": 82,
"e2e::ledger_tests::test_genesis_chain_id_change": 35,
"e2e::ledger_tests::test_genesis_manipulation": 103
}
"e2e::ledger_tests::test_genesis_manipulation": 103,
"e2e::ledger_tests::test_mainnet_phases": 1706
}
10 changes: 9 additions & 1 deletion crates/test_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ pub enum TestWasms {
TxInfiniteGuestGas,
TxInfiniteHostGas,
TxProposalCode,
TxProposalMaspRewards,
TxProposalIbcTokenInflation,
TxProposalMaspRewards,
TxProposalPhase2,
TxProposalPhase3,
TxProposalPhase4,
TxProposalPhase5,
TxProposalTokenGas,
TxReadStorageKey,
TxWriteStorageKey,
Expand Down Expand Up @@ -56,6 +60,10 @@ impl TestWasms {
TestWasms::TxInfiniteGuestGas => "tx_infinite_guest_gas.wasm",
TestWasms::TxInfiniteHostGas => "tx_infinite_host_gas.wasm",
TestWasms::TxProposalCode => "tx_proposal_code.wasm",
TestWasms::TxProposalPhase2 => "tx_proposal_phase2.wasm",
TestWasms::TxProposalPhase3 => "tx_proposal_phase3.wasm",
TestWasms::TxProposalPhase4 => "tx_proposal_phase4.wasm",
TestWasms::TxProposalPhase5 => "tx_proposal_phase5.wasm",
TestWasms::TxProposalMaspRewards => "tx_proposal_masp_reward.wasm",
TestWasms::TxProposalIbcTokenInflation => {
"tx_proposal_ibc_token_inflation.wasm"
Expand Down
86 changes: 60 additions & 26 deletions crates/tests/src/e2e/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ use std::str::FromStr;
use std::time::{Duration, Instant};
use std::{env, time};

use borsh::BorshDeserialize;
use color_eyre::eyre::Result;
use color_eyre::owo_colors::OwoColorize;
use data_encoding::HEXLOWER;
use escargot::CargoBuild;
use eyre::eyre;
use namada_apps_lib::cli::context::ENV_VAR_CHAIN_ID;
use namada_apps_lib::config::utils::convert_tm_addr_to_socket_addr;
use namada_apps_lib::config::{Config, TendermintMode};
use namada_apps_lib::wallet;
use namada_core::token::NATIVE_MAX_DECIMAL_PLACES;
use namada_sdk::address::Address;
use namada_sdk::chain::Epoch;
Expand Down Expand Up @@ -128,38 +127,30 @@ pub fn find_address(test: &Test, alias: impl AsRef<str>) -> Result<Address> {
Ok(address)
}

/// Find the balance of specific token for an account.
#[allow(dead_code)]
/// Find balance of specific token for an account.
pub fn find_balance(
test: &Test,
node: Who,
token: &Address,
owner: &Address,
token: &str,
owner: &str,
denom: Option<u8>,
balance_pattern: Option<&str>,
) -> Result<token::Amount> {
let ledger_address = get_actor_rpc(test, node);
let balance_key = token::storage_key::balance_key(token, owner);
let mut bytes = run!(
test,
Bin::Client,
&[
"query-bytes",
"--storage-key",
&balance_key.to_string(),
"--ledger-address",
&ledger_address,
],
Some(10)
)?;
let (_, matched) = bytes.exp_regex("Found data: 0x.*")?;
let rpc = get_actor_rpc(test, node);
let query_args = vec![
"balance", "--owner", &owner, "--token", &token, "--node", &rpc,
];
let mut client = run!(test, Bin::Client, query_args, Some(40))?;
let token = wallet::Alias::from(token).to_string();
let balance_pattern = balance_pattern.unwrap_or(&token);
let (_unread, matched) =
client.exp_regex(&format!(r"{balance_pattern}: [0-9.]+"))?;
let data_str = strip_trailing_newline(&matched)
.trim()
.rsplit_once(' ')
.unwrap()
.1[2..]
.to_string();
let amount =
token::Amount::try_from_slice(&HEXLOWER.decode(data_str.as_bytes())?)?;
bytes.assert_success();
.1;
let amount = token::Amount::from_str(data_str, denom.unwrap_or(6)).unwrap();
Ok(amount)
}

Expand Down Expand Up @@ -738,3 +729,46 @@ pub fn get_cosmos_gov_address(test: &Test) -> Result<String> {

Ok(matched.trim().to_string())
}

pub fn check_balance(
test: &Test,
owner: impl AsRef<str>,
token: impl AsRef<str>,
expected_amount: u64,
) -> Result<()> {
let rpc = get_actor_rpc(test, Who::Validator(0));

if owner.as_ref().starts_with("zvk") {
shielded_sync(test, owner.as_ref())?;
}

let query_args = vec![
"balance",
"--owner",
owner.as_ref(),
"--token",
token.as_ref(),
"--node",
&rpc,
];
let mut client = run!(test, Bin::Client, query_args, Some(40))?;
let expected =
format!("{}: {expected_amount}", token.as_ref().to_lowercase());
client.exp_string(&expected)?;
client.assert_success();
Ok(())
}

pub fn shielded_sync(test: &Test, viewing_key: impl AsRef<str>) -> Result<()> {
let rpc = get_actor_rpc(test, Who::Validator(0));
let tx_args = vec![
"shielded-sync",
"--viewing-keys",
viewing_key.as_ref(),
"--node",
&rpc,
];
let mut client = run!(test, Bin::Client, tx_args, Some(120))?;
client.assert_success();
Ok(())
}
80 changes: 20 additions & 60 deletions crates/tests/src/e2e/ibc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ use prost::Message;
use setup::constants::*;
use sha2::{Digest, Sha256};

use super::helpers::check_balance;
use crate::e2e::helpers::{
epoch_sleep, epochs_per_year_from_min_duration, find_address,
find_cosmos_address, get_actor_rpc, get_cosmos_gov_address, get_epoch,
shielded_sync,
};
use crate::e2e::ledger_tests::{
start_namada_ledger_node_wait_wasm, write_json_file,
Expand Down Expand Up @@ -100,7 +102,7 @@ fn ibc_transfers() -> Result<()> {
setup::set_validators(1, genesis, base_dir, |_| 0, vec![])
};
let (ledger, gaia, test, test_gaia) =
run_namada_cosmos(CosmosChainType::Gaia, update_genesis)?;
run_namada_cosmos(CosmosChainType::Gaia, update_genesis, None)?;
let _bg_ledger = ledger.background();
let _bg_gaia = gaia.background();

Expand Down Expand Up @@ -473,7 +475,7 @@ fn ibc_nft_transfers() -> Result<()> {
setup::set_validators(1, genesis, base_dir, |_| 0, vec![])
};
let (ledger, cosmwasm, test, test_cosmwasm) =
run_namada_cosmos(CosmosChainType::CosmWasm, update_genesis)?;
run_namada_cosmos(CosmosChainType::CosmWasm, update_genesis, None)?;
let _bg_ledger = ledger.background();
let _bg_wasmd = cosmwasm.background();

Expand Down Expand Up @@ -607,7 +609,7 @@ fn pgf_over_ibc() -> Result<()> {
setup::set_validators(1, genesis, base_dir, |_| 0, vec![])
};
let (ledger, gaia, test, test_gaia) =
run_namada_cosmos(CosmosChainType::Gaia, update_genesis)?;
run_namada_cosmos(CosmosChainType::Gaia, update_genesis, None)?;
let _bg_ledger = ledger.background();
let _bg_gaia = gaia.background();

Expand Down Expand Up @@ -704,7 +706,7 @@ fn fee_payment_with_ibc_token() -> Result<()> {
setup::set_validators(1, genesis, base_dir, |_| 0, vec![])
};
let (ledger, gaia, test, test_gaia) =
run_namada_cosmos(CosmosChainType::Gaia, update_genesis)?;
run_namada_cosmos(CosmosChainType::Gaia, update_genesis, None)?;
let _bg_ledger = ledger.background();
let _bg_gaia = gaia.background();

Expand Down Expand Up @@ -810,7 +812,7 @@ fn ibc_token_inflation() -> Result<()> {
setup::set_validators(1, genesis, base_dir, |_| 0, vec![])
};
let (ledger, gaia, test, test_gaia) =
run_namada_cosmos(CosmosChainType::Gaia, update_genesis)?;
run_namada_cosmos(CosmosChainType::Gaia, update_genesis, None)?;
let _bg_ledger = ledger.background();
let _bg_gaia = gaia.background();

Expand Down Expand Up @@ -900,7 +902,7 @@ fn ibc_upgrade_client() -> Result<()> {
setup::set_validators(1, genesis, base_dir, |_| 0, vec![])
};
let (ledger, gaia, test, test_gaia) =
run_namada_cosmos(CosmosChainType::Gaia, update_genesis)?;
run_namada_cosmos(CosmosChainType::Gaia, update_genesis, None)?;
let _bg_ledger = ledger.background();
let _bg_gaia = gaia.background();

Expand Down Expand Up @@ -971,7 +973,7 @@ fn ibc_rate_limit() -> Result<()> {
setup::set_validators(1, genesis, base_dir, |_| 0, vec![])
};
let (ledger, gaia, test, test_gaia) =
run_namada_cosmos(CosmosChainType::Gaia, update_genesis)?;
run_namada_cosmos(CosmosChainType::Gaia, update_genesis, None)?;
let _bg_ledger = ledger.background();
let _bg_gaia = gaia.background();

Expand Down Expand Up @@ -1088,12 +1090,13 @@ fn ibc_rate_limit() -> Result<()> {
Ok(())
}

fn run_namada_cosmos(
pub fn run_namada_cosmos(
chain_type: CosmosChainType,
mut update_genesis: impl FnMut(
templates::All<templates::Unvalidated>,
&Path,
) -> templates::All<templates::Unvalidated>,
cosmos_user_balance: Option<u64>,
) -> Result<(NamadaCmd, NamadaCmd, Test, Test)> {
let test = setup::network(&mut update_genesis, None)?;

Expand All @@ -1108,14 +1111,14 @@ fn run_namada_cosmos(
let ledger = start_namada_ledger_node_wait_wasm(&test, Some(0), Some(40))?;

// Cosmos
let test_cosmos = setup_cosmos(chain_type)?;
let test_cosmos = setup_cosmos(chain_type, cosmos_user_balance)?;
let cosmos = run_cosmos(&test_cosmos)?;
sleep(5);

Ok((ledger, cosmos, test, test_cosmos))
}

fn create_channel_with_hermes(
pub fn create_channel_with_hermes(
test_a: &Test,
test_b: &Test,
port_id_a: &PortId,
Expand Down Expand Up @@ -1167,7 +1170,7 @@ fn get_channel_ids_from_hermes_output(
Ok((channel_id_a, channel_id_b))
}

fn run_hermes(test: &Test) -> Result<NamadaCmd> {
pub fn run_hermes(test: &Test) -> Result<NamadaCmd> {
let args = ["start"];
let mut hermes = run_hermes_cmd(test, args, Some(40))?;
hermes.exp_string("Hermes has started")?;
Expand Down Expand Up @@ -1195,7 +1198,7 @@ fn run_cosmos(test: &Test) -> Result<NamadaCmd> {
Ok(cosmos)
}

fn wait_for_packet_relay(
pub fn wait_for_packet_relay(
port_id: &PortId,
channel_id: &ChannelId,
test: &Test,
Expand Down Expand Up @@ -1234,7 +1237,7 @@ fn wait_for_packet_relay(
Err(eyre!("Pending packet is still left"))
}

fn clear_packet(
pub fn clear_packet(
port_id: &PortId,
channel_id: &ChannelId,
test: &Test,
Expand Down Expand Up @@ -1384,7 +1387,7 @@ fn transfer_on_chain(
}

#[allow(clippy::too_many_arguments)]
fn transfer(
pub fn transfer(
test: &Test,
sender: impl AsRef<str>,
receiver: impl AsRef<str>,
Expand Down Expand Up @@ -1797,7 +1800,7 @@ fn submit_votes(test: &Test) -> Result<()> {
}

#[allow(clippy::too_many_arguments)]
fn transfer_from_cosmos(
pub fn transfer_from_cosmos(
test: &Test,
sender: impl AsRef<str>,
receiver: impl AsRef<str>,
Expand Down Expand Up @@ -1898,43 +1901,14 @@ fn query_height(test: &Test) -> Result<Height> {
Ok(Height::new(0, status.sync_info.latest_block_height.into()).unwrap())
}

fn check_balance(
test: &Test,
owner: impl AsRef<str>,
token: impl AsRef<str>,
expected_amount: u64,
) -> Result<()> {
let rpc = get_actor_rpc(test, Who::Validator(0));

if owner.as_ref().starts_with("zvk") {
shielded_sync(test, owner.as_ref())?;
}

let query_args = vec![
"balance",
"--owner",
owner.as_ref(),
"--token",
token.as_ref(),
"--node",
&rpc,
];
let mut client = run!(test, Bin::Client, query_args, Some(40))?;
let expected =
format!("{}: {expected_amount}", token.as_ref().to_lowercase());
client.exp_string(&expected)?;
client.assert_success();
Ok(())
}

fn get_gaia_denom_hash(denom: impl AsRef<str>) -> String {
let mut hasher = Sha256::new();
hasher.update(denom.as_ref());
let hash = hasher.finalize();
format!("ibc/{hash:X}")
}

fn check_cosmos_balance(
pub fn check_cosmos_balance(
test: &Test,
owner: impl AsRef<str>,
denom: impl AsRef<str>,
Expand Down Expand Up @@ -1987,23 +1961,9 @@ fn check_inflated_balance(
Ok(())
}

fn shielded_sync(test: &Test, viewing_key: impl AsRef<str>) -> Result<()> {
let rpc = get_actor_rpc(test, Who::Validator(0));
let tx_args = vec![
"shielded-sync",
"--viewing-keys",
viewing_key.as_ref(),
"--node",
&rpc,
];
let mut client = run!(test, Bin::Client, tx_args, Some(120))?;
client.assert_success();
Ok(())
}

/// Get IBC shielding data for the following IBC transfer from the destination
/// chain
fn gen_ibc_shielding_data(
pub fn gen_ibc_shielding_data(
dst_test: &Test,
receiver: impl AsRef<str>,
token: impl AsRef<str>,
Expand Down
Loading
Loading