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

Fix e2e tests #646

Merged
merged 36 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
34621da
Temporarily disable eth bridge e2e tests
sug0 Sep 13, 2022
5840830
Disable eth full node in ledger tests
sug0 Sep 13, 2022
8f9c604
Add abciplus feature flag to e2e tests
sug0 Sep 13, 2022
1fdd1be
Fix e2e test regex matching on fullnodes
sug0 Sep 13, 2022
4950c44
Run make fmt
sug0 Sep 13, 2022
95d71af
Fix regex for valid tx in e2e tests
sug0 Sep 13, 2022
eb798c9
Add a script to unwrap e2e log output
sug0 Sep 13, 2022
7800d90
Describe unwrap e2e tests script
sug0 Sep 13, 2022
56350f1
Revert "Fix regex for valid tx in e2e tests"
sug0 Sep 21, 2022
4babd0b
Partially fix ledger_txs_and_queries() e2e test
sug0 Sep 19, 2022
a8f69be
Merge branch 'tiago/ethbridge/remove-ws-cli' into tiago/ethbridge/fix…
sug0 Sep 30, 2022
c407015
Improve logging of namadac in e2e tests
sug0 Sep 30, 2022
7b04bad
Re-enable ledger_txs_and_queries() e2e test
sug0 Sep 30, 2022
9e4044b
Update Cargo.lock
sug0 Sep 30, 2022
301edab
Remove TODO from ledger_txs_and_queries() e2e test
sug0 Sep 30, 2022
0ccc346
Re-enable and fix run_ledger() e2e test
sug0 Sep 30, 2022
ef4cada
Refactor update config
sug0 Sep 30, 2022
4e1e8bd
Downgraded problematic deps in Cargo.lock
sug0 Sep 30, 2022
c7c9754
More Cargo.lock madness
sug0 Sep 30, 2022
fec843a
Add missing import
sug0 Sep 30, 2022
161293a
Fix most e2e tests
sug0 Sep 30, 2022
d30b908
Merge tiago/ethbridge/remove-ws-cli
sug0 Oct 6, 2022
fa2dc59
Merge branch 'tiago/ethbridge/remove-ws-cli' into tiago/ethbridge/fix…
sug0 Oct 6, 2022
25f6887
Merge tiago/ethbridge/impl-events-endpoint
sug0 Oct 19, 2022
2e685bd
Wait for Tendermint's RPC server to start in e2e tests
sug0 Oct 19, 2022
7dee715
Re-enable eth bridge tests
sug0 Oct 19, 2022
18a8b2b
Export ANOMA_TM_STDOUT env var in e2e tests
sug0 Oct 19, 2022
4729acc
Disable outdated e2e test
sug0 Oct 19, 2022
7782750
Move e2e test utils to setup.rs
sug0 Oct 19, 2022
a3517df
Merge branch 'tiago/ethbridge/fix-wasms-build' into tiago/ethbridge/f…
sug0 Oct 20, 2022
d4f444d
Merge branch 'tiago/ethbridge/fix-valset-upd-verification' into tiago…
sug0 Oct 20, 2022
d4778c0
scripts: Update unwrap_e2e_log.py
sug0 Oct 20, 2022
3d45649
Remove extra space
sug0 Oct 20, 2022
f181a57
Check if a tx is applied on chain
sug0 Oct 20, 2022
1821861
Merge remote-tracking branch 'origin/eth-bridge-integration' into tia…
sug0 Oct 21, 2022
839793f
Release lock on wallet in e2e tests
sug0 Oct 21, 2022
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
31 changes: 31 additions & 0 deletions scripts/unwrap_e2e_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python3

# this script takes `expectrl` log outputs, such as the ones emitted by
# e2e tests, and unwraps them into a more readable format

import re
import sys

UNICODE = re.compile(r'\\u{([\da-fA-F]+)}')

def main():
if len(sys.argv) > 1:
with open(sys.argv[1], 'r') as f:
process_file(f)
else:
process_file(sys.stdin)

def process_file(f):
for line in f.readlines():
process_line(line)
sys.stdout.flush()

def process_line(line):
prefix = 'read: '
for m in UNICODE.findall(line):
line = line.replace(f'\\u{{{m}}}', f'\\u{int(m, 16):04x}')
line = eval(line[len(prefix):])
sys.stdout.write(line)

if __name__ == '__main__':
main()
4 changes: 2 additions & 2 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ default = ["wasm-runtime"]
wasm-runtime = ["namada/wasm-runtime"]

[dependencies]
namada = {path = "../shared", features = ["testing", "ibc-mocks"]}
namada = {path = "../shared", features = ["abciplus", "testing", "ibc-mocks"]}
namada_vm_env = {path = "../vm_env"}
chrono = {version = "0.4.22", default-features = false, features = ["clock", "std"]}
concat-idents = "1.1.2"
Expand All @@ -26,7 +26,7 @@ tracing-subscriber = {version = "0.3.7", default-features = false, features = ["
derivative = "2.2.0"

[dev-dependencies]
namada_apps = {path = "../apps", default-features = false, features = ["testing"]}
namada_apps = {path = "../apps", default-features = false, features = ["abciplus", "testing"]}
assert_cmd = "1.0.7"
borsh = "0.9.1"
color-eyre = "0.5.11"
Expand Down
2 changes: 2 additions & 0 deletions tests/src/e2e/eth_bridge_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ fn storage_key(path: &str) -> String {
}

#[test]
#[ignore]
// this test is outdated, so it is ignored
Comment on lines +22 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep (also badly named...). There was this PR to clean it up (anoma/anoma#1229) but that's a bit stale now probably. This test is still testing something we should continue testing (that a random actor cannot write arbitarily to EthBridge VP storage) but this test needs cleaning up.

fn everything() {
const LEDGER_STARTUP_TIMEOUT_SECONDS: u64 = 30;
const CLIENT_COMMAND_TIMEOUT_SECONDS: u64 = 30;
Expand Down
63 changes: 44 additions & 19 deletions tests/src/e2e/ledger_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ use std::time::{Duration, Instant};
use borsh::BorshSerialize;
use color_eyre::eyre::Result;
use namada::types::token;
use namada_apps::config::ethereum;
use namada_apps::config::genesis::genesis_config::{
GenesisConfig, ParametersConfig, PosParamsConfig,
};
use serde_json::json;
use setup::constants::*;

use super::setup::working_dir;
use super::setup::{disable_eth_fullnode, working_dir};
use crate::e2e::helpers::{
find_address, find_voting_power, get_actor_rpc, get_epoch,
};
Expand All @@ -37,6 +38,9 @@ use crate::{run, run_as};
#[test]
fn run_ledger() -> Result<()> {
let test = setup::single_node_net()?;

disable_eth_fullnode(&test, &test.net.chain_id, &Who::Validator(0));

let cmd_combinations = vec![vec!["ledger"], vec!["ledger", "run"]];

// Start the ledger as a validator
Expand Down Expand Up @@ -68,20 +72,26 @@ fn test_node_connectivity() -> Result<()> {
let test =
setup::network(|genesis| setup::add_validators(1, genesis), None)?;

disable_eth_fullnode(&test, &test.net.chain_id, &Who::Validator(0));
disable_eth_fullnode(&test, &test.net.chain_id, &Who::Validator(1));

// 1. Run 2 genesis validator ledger nodes and 1 non-validator node
let args = ["ledger"];
let mut validator_0 =
run_as!(test, Who::Validator(0), Bin::Node, args, Some(40))?;
validator_0.exp_string("Anoma ledger node started")?;
validator_0.exp_string("This node is a validator")?;
validator_0.exp_string("Starting RPC HTTP server on")?;
let mut validator_1 =
run_as!(test, Who::Validator(1), Bin::Node, args, Some(40))?;
validator_1.exp_string("Anoma ledger node started")?;
validator_1.exp_string("This node is a validator")?;
validator_1.exp_string("Starting RPC HTTP server on")?;
let mut non_validator =
run_as!(test, Who::NonValidator, Bin::Node, args, Some(40))?;
non_validator.exp_string("Anoma ledger node started")?;
non_validator.exp_string("This node is a fullnode")?;
non_validator.exp_string("Starting RPC HTTP server on")?;

let bg_validator_0 = validator_0.background();
let bg_validator_1 = validator_1.background();
Expand Down Expand Up @@ -134,11 +144,14 @@ fn test_node_connectivity() -> Result<()> {
fn test_anoma_shuts_down_if_tendermint_dies() -> Result<()> {
let test = setup::single_node_net()?;

disable_eth_fullnode(&test, &test.net.chain_id, &Who::Validator(0));

// 1. Run the ledger node
let mut ledger =
run_as!(test, Who::Validator(0), Bin::Node, &["ledger"], Some(40))?;

ledger.exp_string("Anoma ledger node started")?;
ledger.exp_string("Starting RPC HTTP server on")?;

// 2. Kill the tendermint node
sleep(1);
Expand Down Expand Up @@ -170,6 +183,8 @@ fn test_anoma_shuts_down_if_tendermint_dies() -> Result<()> {
fn run_ledger_load_state_and_reset() -> Result<()> {
let test = setup::single_node_net()?;

disable_eth_fullnode(&test, &test.net.chain_id, &Who::Validator(0));

// 1. Run the ledger node
let mut ledger =
run_as!(test, Who::Validator(0), Bin::Node, &["ledger"], Some(40))?;
Expand Down Expand Up @@ -237,11 +252,13 @@ fn run_ledger_load_state_and_reset() -> Result<()> {
fn ledger_txs_and_queries() -> Result<()> {
let test = setup::network(|genesis| genesis, None)?;

disable_eth_fullnode(&test, &test.net.chain_id, &Who::Validator(0));

// 1. Run the ledger node
let mut ledger =
run_as!(test, Who::Validator(0), Bin::Node, &["ledger"], Some(40))?;

ledger.exp_string("Anoma ledger node started")?;
ledger.exp_string("Starting RPC HTTP server on")?;
let _bg_ledger = ledger.background();

let vp_user = wasm_abs_path(VP_USER_WASM);
Expand Down Expand Up @@ -409,12 +426,13 @@ fn ledger_txs_and_queries() -> Result<()> {
fn invalid_transactions() -> Result<()> {
let test = setup::single_node_net()?;

disable_eth_fullnode(&test, &test.net.chain_id, &Who::Validator(0));

// 1. Run the ledger node
let mut ledger =
run_as!(test, Who::Validator(0), Bin::Node, &["ledger"], Some(40))?;
ledger.exp_string("Anoma ledger node started")?;
// Wait to commit a block
ledger.exp_regex(r"Committed block hash.*, height: [0-9]+")?;
ledger.exp_string("Starting RPC HTTP server on")?;

let bg_ledger = ledger.background();

Expand Down Expand Up @@ -536,8 +554,6 @@ fn invalid_transactions() -> Result<()> {
/// 7. Submit a withdrawal of the self-bond
/// 8. Submit a withdrawal of the delegation
#[test]
#[ignore]
// TODO(namada#418): re-enable once working again
fn pos_bonds() -> Result<()> {
let unbonding_len = 2;
let test = setup::network(
Expand All @@ -562,11 +578,13 @@ fn pos_bonds() -> Result<()> {
None,
)?;

disable_eth_fullnode(&test, &test.net.chain_id, &Who::Validator(0));

// 1. Run the ledger node
let mut ledger =
run_as!(test, Who::Validator(0), Bin::Node, &["ledger"], Some(40))?;

ledger.exp_string("Anoma ledger node started")?;
ledger.exp_string("Starting RPC HTTP server on")?;
let _bg_ledger = ledger.background();

let validator_one_rpc = get_actor_rpc(&test, &Who::Validator(0));
Expand Down Expand Up @@ -731,8 +749,6 @@ fn pos_bonds() -> Result<()> {
/// 6. Wait for the pipeline epoch
/// 7. Check the new validator's voting power
#[test]
#[ignore]
// TODO(namada#418): re-enable once working again
fn pos_init_validator() -> Result<()> {
let pipeline_len = 1;
let test = setup::network(
Expand All @@ -757,11 +773,13 @@ fn pos_init_validator() -> Result<()> {
None,
)?;

disable_eth_fullnode(&test, &test.net.chain_id, &Who::Validator(0));

// 1. Run the ledger node
let mut ledger =
run_as!(test, Who::Validator(0), Bin::Node, &["ledger"], Some(40))?;

ledger.exp_string("Anoma ledger node started")?;
ledger.exp_string("Starting RPC HTTP server on")?;
let _bg_ledger = ledger.background();

let validator_one_rpc = get_actor_rpc(&test, &Who::Validator(0));
Expand Down Expand Up @@ -919,11 +937,13 @@ fn ledger_many_txs_in_a_block() -> Result<()> {
Some("10s"),
)?);

disable_eth_fullnode(&test, &test.net.chain_id, &Who::Validator(0));

// 1. Run the ledger node
let mut ledger =
run_as!(*test, Who::Validator(0), Bin::Node, &["ledger"], Some(40))?;

ledger.exp_string("Anoma ledger node started")?;
ledger.exp_string("Starting RPC HTTP server on")?;

// Wait to commit a block
ledger.exp_regex(r"Committed block hash.*, height: [0-9]+")?;
Expand Down Expand Up @@ -998,11 +1018,11 @@ fn ledger_many_txs_in_a_block() -> Result<()> {
/// 12. Wait proposal grace and check proposal author funds
/// 13. Check governance address funds are 0
#[test]
#[ignore]
// TODO(namada#418): re-enable once working again
fn proposal_submission() -> Result<()> {
let test = setup::network(|genesis| genesis, None)?;

disable_eth_fullnode(&test, &test.net.chain_id, &Who::Validator(0));

let anomac_help = vec!["--help"];

let mut client = run!(test, Bin::Client, anomac_help, Some(40))?;
Expand All @@ -1013,7 +1033,7 @@ fn proposal_submission() -> Result<()> {
let mut ledger =
run_as!(test, Who::Validator(0), Bin::Node, &["ledger"], Some(40))?;

ledger.exp_string("Anoma ledger node started")?;
ledger.exp_string("Starting RPC HTTP server on")?;
let _bg_ledger = ledger.background();

let validator_one_rpc = get_actor_rpc(&test, &Who::Validator(0));
Expand Down Expand Up @@ -1353,16 +1373,16 @@ fn proposal_submission() -> Result<()> {
/// 3. Create an offline vote
/// 4. Tally offline
#[test]
#[ignore]
// TODO(namada#418): re-enable once working again
fn proposal_offline() -> Result<()> {
let test = setup::network(|genesis| genesis, None)?;

disable_eth_fullnode(&test, &test.net.chain_id, &Who::Validator(0));

// 1. Run the ledger node
let mut ledger =
run_as!(test, Who::Validator(0), Bin::Node, &["ledger"], Some(20))?;

ledger.exp_string("Anoma ledger node started")?;
ledger.exp_string("Starting RPC HTTP server on")?;
let _bg_ledger = ledger.background();

let validator_one_rpc = get_actor_rpc(&test, &Who::Validator(0));
Expand Down Expand Up @@ -1516,8 +1536,6 @@ fn generate_proposal_json(
/// 4. Submit a valid token transfer tx from one validator to the other
/// 5. Check that all the nodes processed the tx with the same result
#[test]
#[ignore]
// TODO(namada#418): re-enable once working again
fn test_genesis_validators() -> Result<()> {
use std::collections::HashMap;
use std::net::SocketAddr;
Expand Down Expand Up @@ -1766,6 +1784,8 @@ fn test_genesis_validators() -> Result<()> {

// We have to update the ports in the configs again, because the ones from
// `join-network` use the defaults
//
// TODO: use `update_actor_config` from `setup`, instead
let update_config = |ix: u8, mut config: Config| {
let first_port = net_address_port_0 + 6 * (ix as u16 + 1);
config.ledger.tendermint.p2p_address.set_port(first_port);
Expand All @@ -1775,6 +1795,8 @@ fn test_genesis_validators() -> Result<()> {
.rpc_address
.set_port(first_port + 1);
config.ledger.shell.ledger_address.set_port(first_port + 2);
// disable eth full node
config.ledger.ethereum.mode = ethereum::Mode::Off;
config
};

Expand Down Expand Up @@ -1808,16 +1830,19 @@ fn test_genesis_validators() -> Result<()> {
run_as!(test, Who::Validator(0), Bin::Node, args, Some(40))?;
validator_0.exp_string("Anoma ledger node started")?;
validator_0.exp_string("This node is a validator")?;
validator_0.exp_string("Starting RPC HTTP server on")?;

let mut validator_1 =
run_as!(test, Who::Validator(1), Bin::Node, args, Some(40))?;
validator_1.exp_string("Anoma ledger node started")?;
validator_1.exp_string("This node is a validator")?;
validator_1.exp_string("Starting RPC HTTP server on")?;

let mut non_validator =
run_as!(test, Who::NonValidator, Bin::Node, args, Some(40))?;
non_validator.exp_string("Anoma ledger node started")?;
non_validator.exp_string("This node is a fullnode")?;
non_validator.exp_string("Starting RPC HTTP server on")?;

let bg_validator_0 = validator_0.background();
let bg_validator_1 = validator_1.background();
Expand Down
37 changes: 31 additions & 6 deletions tests/src/e2e/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use itertools::{Either, Itertools};
use namada::types::chain::ChainId;
use namada_apps::client::utils;
use namada_apps::config::genesis::genesis_config::{self, GenesisConfig};
use namada_apps::config::{ethereum, Config};
use namada_apps::{config, wallet};
use rand::Rng;
use tempfile::{tempdir, TempDir};
Expand Down Expand Up @@ -55,6 +56,31 @@ pub struct Network {
pub chain_id: ChainId,
}

/// Update the config of some node `who`.
pub fn update_actor_config<F>(
test: &Test,
chain_id: &ChainId,
who: &Who,
update: F,
) where
F: FnOnce(&mut Config),
{
let validator_base_dir = test.get_base_dir(who);
let mut validator_config =
Config::load(&validator_base_dir, chain_id, None);
update(&mut validator_config);
validator_config
.write(&validator_base_dir, chain_id, true)
.unwrap();
}

/// Disable the Ethereum fullnode of `who`.
pub fn disable_eth_fullnode(test: &Test, chain_id: &ChainId, who: &Who) {
update_actor_config(test, chain_id, who, |config| {
config.ledger.ethereum.mode = ethereum::Mode::Off;
});
}

/// Add `num` validators to the genesis config. Note that called from inside
/// the [`network`]'s first argument's closure, there is 1 validator already
/// present to begin with, so e.g. `add_validators(1, _)` will configure a
Expand Down Expand Up @@ -652,10 +678,10 @@ where
S: AsRef<OsStr>,
{
// Root cargo workspace manifest path
let bin_name = match bin {
Bin::Node => "namadan",
Bin::Client => "namadac",
Bin::Wallet => "namadaw",
let (bin_name, log_level) = match bin {
Bin::Node => ("namadan", "info"),
Bin::Client => ("namadac", "tendermint_rpc=debug"),
Bin::Wallet => ("namadaw", "info"),
};

let mut run_cmd = generate_bin_command(
Expand All @@ -664,10 +690,9 @@ where
);

run_cmd
.env("ANOMA_LOG", "info")
.env("ANOMA_LOG", log_level)
.env("ANOMA_TM_STDOUT", "true")
.env("TM_LOG_LEVEL", "info")
.env("ANOMA_LEDGER__ETHEREUM__MODE", "Off")
.env("ANOMA_LOG_COLOR", "false")
.current_dir(working_dir)
.args(&[
Expand Down