Skip to content

Commit

Permalink
Adjust integration tests to work with both hardware and localnet gene…
Browse files Browse the repository at this point in the history
…sis files.
  • Loading branch information
murisi committed Nov 22, 2024
1 parent 69285ff commit d724bde
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 176 deletions.
18 changes: 8 additions & 10 deletions crates/core/src/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,11 +827,10 @@ mod test {
.address();
assert_eq!(addr.unwrap(), address::testing::established_address_1());

let addr =
TransferSource::ExtendedSpendingKey(
masp_primitives::zip32::ExtendedSpendingKey::master(&[0_u8]).into(),
)
.address();
let addr = TransferSource::ExtendedSpendingKey(
masp_primitives::zip32::ExtendedSpendingKey::master(&[0_u8]).into(),
)
.address();
assert!(addr.is_none());
}

Expand All @@ -845,11 +844,10 @@ mod test {
TAddrData::Addr(address::testing::established_address_1())
);

let addr =
TransferSource::ExtendedSpendingKey(
masp_primitives::zip32::ExtendedSpendingKey::master(&[0_u8]).into(),
)
.address();
let addr = TransferSource::ExtendedSpendingKey(
masp_primitives::zip32::ExtendedSpendingKey::master(&[0_u8]).into(),
)
.address();
assert!(addr.is_none());
}

Expand Down
8 changes: 6 additions & 2 deletions crates/node/src/shell/testing/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ pub fn run(
NamadaClient::WithoutContext(Box::new((sub_cmd, global)))
}
};
rt.block_on(CliApi::handle_client_command(
let result = rt.block_on(CliApi::handle_client_command(
Some(node.clone()),
cmd,
TestingIo,
))
));
if let Err(err) = &result {
TestingIo.eprintln(format!("{}", err));
}
result
}
Bin::Wallet => {
args.insert(0, "wallet");
Expand Down
7 changes: 4 additions & 3 deletions crates/sdk/src/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,9 @@ where

// Then try to sign the raw header using the hardware wallet
for pubkey in &signing_data.public_keys {
if !used_pubkeys.contains(pubkey) &&
(*pubkey != signing_data.fee_payer || args.wrapper_signature.is_some())
if !used_pubkeys.contains(pubkey)
&& (*pubkey != signing_data.fee_payer
|| args.wrapper_signature.is_some())
{
if let Ok(ntx) = sign(
tx.clone(),
Expand Down Expand Up @@ -329,7 +330,7 @@ where
Signable::FeeRawHeader,
user_data,
)
.await?;
.await?;
if signing_data.public_keys.contains(&signing_data.fee_payer) {
used_pubkeys.insert(signing_data.fee_payer.clone());
}
Expand Down
8 changes: 3 additions & 5 deletions crates/shielded_token/src/masp/shielded_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ use rand_core::{OsRng, SeedableRng};

use crate::masp::utils::MaspClient;
use crate::masp::{
cloned_pair, ContextSyncStatus, Conversions, MaspAmount,
MaspDataLog, MaspFeeData, MaspSourceTransferData, MaspTargetTransferData,
cloned_pair, ContextSyncStatus, Conversions, MaspAmount, MaspDataLog,
MaspFeeData, MaspSourceTransferData, MaspTargetTransferData,
MaspTransferData, MaspTxReorderedData, NoteIndex, ShieldedSyncConfig,
ShieldedTransfer, ShieldedUtils, SpentNotesTracker, TransferErr, WalletMap,
WitnessMap, NETWORK,
Expand Down Expand Up @@ -1472,9 +1472,7 @@ pub trait ShieldedApi<U: ShieldedUtils + MaybeSend + MaybeSync>:
// If we are sending to a shielded address, we need the outgoing
// viewing key in the following computations.
let ovk_opt = source.clone().and_then(|source| {
source
.spending_key()
.map(|x| x.to_viewing_key().fvk.ovk)
source.spending_key().map(|x| x.to_viewing_key().fvk.ovk)
});
// Make transaction output tied to the current token,
// denomination, and epoch.
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 @@ -31,8 +31,8 @@ use namada_sdk::wallet::Wallet;
use toml::Value;

use super::setup::{
self, ensure_hot_key, run_gaia_cmd, sleep, NamadaBgCmd, NamadaCmd, Test,
ENV_VAR_DEBUG, ENV_VAR_USE_PREBUILT_BINARIES,
self, 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 @@ -130,7 +130,10 @@ pub fn find_address(test: &Test, alias: impl AsRef<str>) -> Result<Address> {
}

/// Find the address of an account by its alias from the wallet
pub fn find_payment_address(test: &Test, alias: impl AsRef<str>) -> Result<PaymentAddress> {
pub fn find_payment_address(
test: &Test,
alias: impl AsRef<str>,
) -> Result<PaymentAddress> {
let mut find = run!(
test,
Bin::Wallet,
Expand Down Expand Up @@ -587,9 +590,7 @@ 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(
ensure_hot_key(setup::constants::CHRISTEL_KEY).to_owned(),
),
Value::String(constants::FRANK_KEY.to_owned()),
);
chain.insert("store_prefix".to_owned(), Value::String("ibc".to_owned()));
let mut table = toml::map::Map::new();
Expand Down
15 changes: 10 additions & 5 deletions crates/tests/src/e2e/ibc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ fn ibc_transfers() -> Result<()> {
&port_id_namada,
&channel_id_namada,
)?;
let masp_receiver = find_payment_address(&test, AA_PAYMENT_ADDRESS)?.to_string();
let masp_receiver =
find_payment_address(&test, AA_PAYMENT_ADDRESS)?.to_string();
transfer_from_gaia(
&test_gaia,
GAIA_USER,
Expand Down Expand Up @@ -273,7 +274,8 @@ fn ibc_transfers() -> Result<()> {
&port_id_namada,
&channel_id_namada,
)?;
let masp_receiver = find_payment_address(&test, AA_PAYMENT_ADDRESS)?.to_string();
let masp_receiver =
find_payment_address(&test, AA_PAYMENT_ADDRESS)?.to_string();
transfer_from_gaia(
&test_gaia,
GAIA_USER,
Expand Down Expand Up @@ -405,7 +407,8 @@ fn ibc_transfers() -> Result<()> {
check_gaia_balance(&test_gaia, GAIA_USER, GAIA_COIN, 810)?;

// Missing memo
let masp_receiver = find_payment_address(&test, AA_PAYMENT_ADDRESS)?.to_string();
let masp_receiver =
find_payment_address(&test, AA_PAYMENT_ADDRESS)?.to_string();
transfer_from_gaia(
&test_gaia,
GAIA_USER,
Expand All @@ -432,7 +435,8 @@ fn ibc_transfers() -> Result<()> {
&port_id_namada,
&channel_id_namada,
)?;
let masp_receiver = find_payment_address(&test, AA_PAYMENT_ADDRESS)?.to_string();
let masp_receiver =
find_payment_address(&test, AA_PAYMENT_ADDRESS)?.to_string();
transfer_from_gaia(
&test_gaia,
GAIA_USER,
Expand Down Expand Up @@ -711,7 +715,8 @@ fn ibc_token_inflation() -> Result<()> {
&port_id_namada,
&channel_id_namada,
)?;
let masp_receiver = find_payment_address(&test, AA_PAYMENT_ADDRESS)?.to_string();
let masp_receiver =
find_payment_address(&test, AA_PAYMENT_ADDRESS)?.to_string();
transfer_from_gaia(
&test_gaia,
GAIA_USER,
Expand Down
2 changes: 1 addition & 1 deletion crates/tests/src/e2e/ledger_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use namada_apps_lib::config::genesis::templates::TokenBalances;
use namada_apps_lib::config::utils::convert_tm_addr_to_socket_addr;
use namada_apps_lib::config::{self, ethereum_bridge};
use namada_apps_lib::tendermint_config::net::Address as TendermintAddress;
use namada_apps_lib::wallet::{self, Alias};
use namada_apps_lib::wallet::defaults::is_use_device;
use namada_apps_lib::wallet::{self, Alias};
use namada_core::chain::ChainId;
use namada_core::token::NATIVE_MAX_DECIMAL_PLACES;
use namada_sdk::address::Address;
Expand Down
12 changes: 0 additions & 12 deletions crates/tests/src/e2e/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,6 @@ pub fn apply_use_device(mut tx_args: Vec<&str>) -> Vec<&str> {
tx_args
}

/// Replace the given key with a key that is stored unencrypted in the wallet.
/// This is useful for IBC tests where a keypair needs to be added to the Hermes
/// keyring or where IBC messages unsupported by the hardware wallet need to be
/// signed
pub fn ensure_hot_key(key: &str) -> &str {
if is_use_device() {
constants::FRANK_KEY
} else {
key
}
}

/// Default functions for offsetting ports when
/// adding multiple validators to a network
pub fn default_port_offset(ix: u8) -> u16 {
Expand Down
7 changes: 3 additions & 4 deletions crates/tests/src/integration/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use namada_node::shell::testing::client::run;
use namada_node::shell::testing::node::MockNode;
use namada_node::shell::testing::utils::{Bin, CapturedOutput};
use namada_sdk::key::common;

use crate::e2e::setup::constants::{FRANK, FRANK_KEY};
use crate::strings::TX_APPLIED_SUCCESS;

Expand Down Expand Up @@ -112,8 +113,7 @@ pub fn make_temp_account(
"--node",
ledger_address,
];
let captured =
CapturedOutput::of(|| run(node, Bin::Client, reveal_args));
let captured = CapturedOutput::of(|| run(node, Bin::Client, reveal_args));
assert!(captured.result.is_ok());
assert!(captured.contains(TX_APPLIED_SUCCESS));
// c. Send some funds to the implicit account.
Expand All @@ -133,8 +133,7 @@ pub fn make_temp_account(
"--node",
ledger_address,
];
let captured =
CapturedOutput::of(|| run(node, Bin::Client, credit_args));
let captured = CapturedOutput::of(|| run(node, Bin::Client, credit_args));
assert!(captured.result.is_ok());
assert!(captured.contains(TX_APPLIED_SUCCESS));
// d. Obtain the key pair associated with the new address
Expand Down
Loading

0 comments on commit d724bde

Please sign in to comment.