Skip to content

Commit

Permalink
Merge branch 'yuji/add-ibc-e2e-hermes' (#1797)
Browse files Browse the repository at this point in the history
* origin/yuji/add-ibc-e2e-hermes:
  clean unneeded stuff
  add changelog
  set chain ID
  build hermes in CI
  add sleep
  wait for compiling
  for clippy
  fix waiting for the second block
  fix e2e script
  CI runs IBC e2e test with Hermes
  add IBC e2e test with Hermes
  • Loading branch information
brentstone committed Jan 12, 2024
2 parents 50caebb + 9a1c1b1 commit c24d0e8
Show file tree
Hide file tree
Showing 6 changed files with 463 additions and 101 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/testing/773-ibc-e2e-hermes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add IBC E2E test with Hermes
([\#773](https://github.com/anoma/namada/issues/773))
3 changes: 2 additions & 1 deletion .github/workflows/scripts/e2e.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"e2e::eth_bridge_tests::everything": 4,
"e2e::ibc_tests::run_ledger_ibc": 155,
"e2e::ibc_tests::run_ledger_ibc_with_hermes": 130,
"e2e::eth_bridge_tests::test_add_to_bridge_pool": 10,
"e2e::ledger_tests::double_signing_gets_slashed": 12,
"e2e::ledger_tests::invalid_transactions": 13,
Expand Down Expand Up @@ -32,4 +33,4 @@
"e2e::wallet_tests::wallet_encrypted_key_cmds": 1,
"e2e::wallet_tests::wallet_encrypted_key_cmds_env_var": 1,
"e2e::wallet_tests::wallet_unencrypted_key_cmds": 1
}
}
4 changes: 2 additions & 2 deletions .github/workflows/scripts/schedule-e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
NIGHTLY_VERSION = open("rust-nightly-version", "r").read().strip()

E2E_FILE = ".github/workflows/scripts/e2e.json"
CARGO_TEST_COMMAND = "cargo +{} test {} -- --test-threads=1 --nocapture"
CARGO_TEST_COMMAND = "cargo +{} test {} -- --test-threads=1 --nocapture --exact"

MACHINES = [{'tasks': [], 'time': [], 'total_time': 0} for _ in range(N_OF_MACHINES)]

Expand Down Expand Up @@ -73,4 +73,4 @@ def find_freer_machine():
print(" Run locally with: {}".format(test_command))

if has_failures:
exit(1)
exit(1)
110 changes: 110 additions & 0 deletions tests/src/e2e/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! E2E test helpers

use std::fs::File;
use std::future::Future;
use std::io::Write;
use std::path::Path;
use std::process::Command;
use std::str::FromStr;
Expand All @@ -19,13 +21,15 @@ use namada::types::address::Address;
use namada::types::key::*;
use namada::types::storage::Epoch;
use namada::types::token;
use namada_apps::cli::context::ENV_VAR_CHAIN_ID;
use namada_apps::config::genesis::chain::DeriveEstablishedAddress;
use namada_apps::config::genesis::templates;
use namada_apps::config::utils::convert_tm_addr_to_socket_addr;
use namada_apps::config::{Config, TendermintMode};
use namada_core::types::token::NATIVE_MAX_DECIMAL_PLACES;
use namada_sdk::wallet::fs::FsWalletUtils;
use namada_sdk::wallet::Wallet;
use toml::Value;

use super::setup::{
self, sleep, NamadaBgCmd, NamadaCmd, Test, ENV_VAR_DEBUG,
Expand Down Expand Up @@ -504,3 +508,109 @@ pub fn wait_for_wasm_pre_compile(ledger: &mut NamadaCmd) -> Result<()> {
pub fn epochs_per_year_from_min_duration(min_duration: u64) -> u64 {
60 * 60 * 24 * 365 / min_duration
}

/// Make a Hermes config
pub fn make_hermes_config(test_a: &Test, test_b: &Test) -> Result<()> {
let mut config = toml::map::Map::new();

let mut global = toml::map::Map::new();
global.insert("log_level".to_owned(), Value::String("debug".to_owned()));
config.insert("global".to_owned(), Value::Table(global));

let mut mode = toml::map::Map::new();
let mut clients = toml::map::Map::new();
clients.insert("enabled".to_owned(), Value::Boolean(true));
clients.insert("refresh".to_owned(), Value::Boolean(true));
clients.insert("misbehaviour".to_owned(), Value::Boolean(true));
mode.insert("clients".to_owned(), Value::Table(clients));

let mut connections = toml::map::Map::new();
connections.insert("enabled".to_owned(), Value::Boolean(false));
mode.insert("connections".to_owned(), Value::Table(connections));

let mut channels = toml::map::Map::new();
channels.insert("enabled".to_owned(), Value::Boolean(false));
mode.insert("channels".to_owned(), Value::Table(channels));

let mut packets = toml::map::Map::new();
packets.insert("enabled".to_owned(), Value::Boolean(true));
packets.insert("clear_interval".to_owned(), Value::Integer(10));
packets.insert("clear_on_start".to_owned(), Value::Boolean(false));
packets.insert("tx_confirmation".to_owned(), Value::Boolean(true));
mode.insert("packets".to_owned(), Value::Table(packets));

config.insert("mode".to_owned(), Value::Table(mode));

let mut telemetry = toml::map::Map::new();
telemetry.insert("enabled".to_owned(), Value::Boolean(false));
telemetry.insert("host".to_owned(), Value::String("127.0.0.1".to_owned()));
telemetry.insert("port".to_owned(), Value::Integer(3001));
config.insert("telemetry".to_owned(), Value::Table(telemetry));

let chains = vec![
make_hermes_chain_config(test_a),
make_hermes_chain_config(test_b),
];

config.insert("chains".to_owned(), Value::Array(chains));

let toml_string = toml::to_string(&Value::Table(config)).unwrap();
let hermes_dir = test_a.test_dir.as_ref().join("hermes");
std::fs::create_dir_all(&hermes_dir).unwrap();
let config_path = hermes_dir.join("config.toml");
let mut file = File::create(config_path).unwrap();
file.write_all(toml_string.as_bytes()).map_err(|e| {
eyre!(format!("Writing a Hermes config failed: {}", e,))
})?;
// One Hermes config.toml is OK, but add one more config.toml to execute
// Hermes from test_b
let hermes_dir = test_b.test_dir.as_ref().join("hermes");
std::fs::create_dir_all(&hermes_dir).unwrap();
let config_path = hermes_dir.join("config.toml");
let mut file = File::create(config_path).unwrap();
file.write_all(toml_string.as_bytes()).map_err(|e| {
eyre!(format!("Writing a Hermes config failed: {}", e,))
})?;

Ok(())
}

fn make_hermes_chain_config(test: &Test) -> Value {
let chain_id = test.net.chain_id.as_str();
let rpc_addr = get_actor_rpc(test, Who::Validator(0));

let mut table = toml::map::Map::new();
table.insert("mode".to_owned(), Value::String("push".to_owned()));
let url = format!("ws://{}/websocket", rpc_addr);
table.insert("url".to_owned(), Value::String(url));
table.insert("batch_delay".to_owned(), Value::String("500ms".to_owned()));
let event_source = Value::Table(table);

let mut chain = toml::map::Map::new();
chain.insert("id".to_owned(), Value::String(chain_id.to_owned()));
chain.insert("type".to_owned(), Value::String("Namada".to_owned()));
chain.insert(
"rpc_addr".to_owned(),
Value::String(format!("http://{rpc_addr}")),
);
// The grpc isn't used for Namada, but it's required
chain.insert(
"grpc_addr".to_owned(),
Value::String("http://127.0.0.1:9090".to_owned()),
);
chain.insert("event_source".to_owned(), event_source);
chain.insert("account_prefix".to_owned(), Value::String("".to_owned()));
chain.insert(
"key_name".to_owned(),
Value::String(setup::constants::CHRISTEL_KEY.to_owned()),
);
chain.insert("store_prefix".to_owned(), Value::String("ibc".to_owned()));
let mut table = toml::map::Map::new();
table.insert("price".to_owned(), Value::Float(0.001));
std::env::set_var(ENV_VAR_CHAIN_ID, test.net.chain_id.to_string());
let nam_addr = find_address(test, setup::constants::NAM).unwrap();
table.insert("denom".to_owned(), Value::String(nam_addr.to_string()));
chain.insert("gas_price".to_owned(), Value::Table(table));

Value::Table(chain)
}
Loading

0 comments on commit c24d0e8

Please sign in to comment.