Skip to content

Commit

Permalink
Merge pull request #3570 from anoma/murisi/hw-e2e
Browse files Browse the repository at this point in the history
Make genesis file based on hardware wallet.
  • Loading branch information
mergify[bot] authored Aug 7, 2024
2 parents 6d3fc90 + 5959d7d commit dd3a56f
Show file tree
Hide file tree
Showing 27 changed files with 1,072 additions and 231 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/testing/3570-hw-e2e.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Enable E2E tests to be run using hardware wallet.
([\#3570](https://github.com/anoma/namada/pull/3570))
16 changes: 11 additions & 5 deletions crates/apps_lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7044,7 +7044,8 @@ pub mod args {
DRY_RUN_TX
.def()
.help(wrap!("Simulate the transaction application."))
.conflicts_with(DRY_RUN_WRAPPER_TX.name),
.conflicts_with(DRY_RUN_WRAPPER_TX.name)
.conflicts_with(USE_DEVICE.name),
)
.arg(
DRY_RUN_WRAPPER_TX
Expand Down Expand Up @@ -7154,10 +7155,15 @@ pub mod args {
))
.conflicts_with(DISPOSABLE_SIGNING_KEY.name),
)
.arg(USE_DEVICE.def().help(wrap!(
"Use an attached hardware wallet device to sign the \
transaction."
)))
.arg(
USE_DEVICE
.def()
.help(wrap!(
"Use an attached hardware wallet device to sign the \
transaction."
))
.conflicts_with(DRY_RUN_TX.name),
)
.arg(
MEMO_OPT
.def()
Expand Down
39 changes: 33 additions & 6 deletions crates/apps_lib/src/wallet/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
pub use dev::{
addresses, albert_address, albert_keypair, bertha_address, bertha_keypair,
christel_address, christel_keypair, daewon_address, daewon_keypair,
ester_address, ester_keypair, keys, tokens, validator_account_keypair,
validator_address, validator_keypair, validator_keys,
derive_template_dir, ester_address, ester_keypair, get_unencrypted_keypair,
is_use_device, keys, tokens, validator_account_keypair, validator_address,
validator_keypair, validator_keys,
};

#[cfg(any(test, feature = "testing", feature = "benches"))]
mod dev {
use std::path::{Path, PathBuf};

use lazy_static::lazy_static;
use namada_sdk::address::testing::{
apfel, btc, dot, eth, kartoffel, nam, schnitzel,
Expand Down Expand Up @@ -182,12 +185,36 @@ mod dev {
get_unencrypted_keypair("validator-0-account-key")
}

/// Env. var to enable the usage of hardware wallets in tests
pub const ENV_VAR_USE_DEVICE: &str = "NAMADA_E2E_USE_DEVICE";

/// Check whether the ENV_VAR_USE_DEVICE environment variable is set
pub fn is_use_device() -> bool {
match std::env::var(ENV_VAR_USE_DEVICE) {
Ok(val) => val.to_ascii_lowercase() != "false",
_ => false,
}
}

/// Derive the genesis path depending on whether the hardware wallet is in
/// use
pub fn derive_template_dir(working_dir: &Path) -> PathBuf {
// The E2E tests genesis config source.
// This file must contain a single validator with alias "validator-0".
// To add more validators, use the [`set_validators`] function in the
// call to setup the [`network`].
if is_use_device() {
working_dir.join("genesis").join("hardware")
} else {
working_dir.join("genesis").join("localnet")
}
}

/// The name of a file that is unique to the project's root directory.
const PROJECT_ROOT_UNIQUE_FILE: &str = "rust-toolchain.toml";

/// The pre-genesis directory of `validator-0`.
const VALIDATOR_0_PREGENESIS_DIR: &str =
"genesis/localnet/src/pre-genesis/validator-0";
const VALIDATOR_0_PREGENESIS_DIR: &str = "src/pre-genesis/validator-0";

lazy_static! {
static ref PREGENESIS_WALLET: Wallet<CliWalletUtils> = {
Expand All @@ -199,7 +226,7 @@ mod dev {
while !root_dir.join(PROJECT_ROOT_UNIQUE_FILE).exists() {
root_dir.pop();
}
let path = root_dir.join("genesis/localnet/src/pre-genesis");
let path = derive_template_dir(&root_dir).join("src/pre-genesis");
crate::wallet::load(&path).unwrap()
};

Expand All @@ -213,7 +240,7 @@ mod dev {
root_dir.pop();
}
let path =
root_dir.join(VALIDATOR_0_PREGENESIS_DIR);
derive_template_dir(&root_dir).join(VALIDATOR_0_PREGENESIS_DIR);
crate::wallet::pre_genesis::load(&path).unwrap()
};
}
Expand Down
13 changes: 7 additions & 6 deletions crates/tests/src/e2e/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ use namada_sdk::wallet::Wallet;
use toml::Value;

use super::setup::{
self, run_gaia_cmd, sleep, NamadaBgCmd, NamadaCmd, Test, ENV_VAR_DEBUG,
ENV_VAR_USE_PREBUILT_BINARIES,
self, ensure_hot_key, run_gaia_cmd, sleep, NamadaBgCmd, NamadaCmd, Test,
ENV_VAR_DEBUG, ENV_VAR_USE_PREBUILT_BINARIES,
};
use crate::e2e::setup::{constants, Bin, Who, APPS_PACKAGE};
use crate::strings::{LEDGER_STARTED, TX_APPLIED_SUCCESS};
Expand Down Expand Up @@ -219,9 +219,8 @@ pub fn get_pregenesis_pk<P: AsRef<Path>>(
alias: &str,
base_dir_path: P,
) -> Option<common::PublicKey> {
let mut wallet = get_pregenesis_wallet(base_dir_path);
let sk = wallet.find_secret_key(alias, None).ok()?;
Some(sk.ref_to())
let wallet = get_pregenesis_wallet(base_dir_path);
wallet.find_public_key(alias).ok()
}

/// Get a pregenesis public key.
Expand Down Expand Up @@ -610,7 +609,9 @@ fn make_hermes_chain_config(test: &Test) -> Value {
chain.insert("account_prefix".to_owned(), Value::String("".to_owned()));
chain.insert(
"key_name".to_owned(),
Value::String(setup::constants::CHRISTEL_KEY.to_owned()),
Value::String(
ensure_hot_key(setup::constants::CHRISTEL_KEY).to_owned(),
),
);
chain.insert("store_prefix".to_owned(), Value::String("ibc".to_owned()));
let mut table = toml::map::Map::new();
Expand Down
Loading

0 comments on commit dd3a56f

Please sign in to comment.