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 27, 2024
1 parent 706a143 commit 24fcb3b
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 188 deletions.
6 changes: 3 additions & 3 deletions crates/apps_lib/src/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::io::Write;
use borsh::BorshDeserialize;
use borsh_ext::BorshSerializeExt;
use color_eyre::owo_colors::OwoColorize;
use namada_core::masp::MaspTransaction;
use ledger_namada_rs::{BIP44Path, KeyResponse, NamadaApp, NamadaKeys};
use masp_primitives::sapling::redjubjub::PrivateKey;
use masp_primitives::sapling::{redjubjub, ProofGenerationKey};
Expand All @@ -17,6 +16,7 @@ use masp_primitives::transaction::components::sapling::fees::InputView;
use masp_primitives::zip32::{
ExtendedFullViewingKey, ExtendedKey, PseudoExtendedKey,
};
use namada_core::masp::MaspTransaction;
use namada_sdk::address::{Address, ImplicitAddress};
use namada_sdk::args::TxBecomeValidator;
use namada_sdk::collections::HashMap;
Expand Down Expand Up @@ -1171,7 +1171,7 @@ pub async fn submit_shielded_transfer(
to date, make sure to run `namadac shielded-sync` before running \
this command.",
);

let sources = args
.data
.iter_mut()
Expand Down Expand Up @@ -1286,7 +1286,7 @@ pub async fn submit_unshielding_transfer(
to date, make sure to run `namadac shielded-sync` before running \
this command.",
);

let sources = std::iter::once(&mut args.source)
.chain(args.gas_spending_key.iter_mut());
let shielded_hw_keys =
Expand Down
18 changes: 8 additions & 10 deletions crates/core/src/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,11 +841,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 @@ -859,11 +858,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 @@ -291,8 +291,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 @@ -333,7 +334,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
4 changes: 1 addition & 3 deletions crates/sdk/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3479,9 +3479,7 @@ async fn construct_shielded_parts<N: Namada>(
.await;

shielded
.gen_shielded_transfer(
context, data, fee_data, expiration, bparams,
)
.gen_shielded_transfer(context, data, fee_data, expiration, bparams)
.await
};

Expand Down
14 changes: 6 additions & 8 deletions crates/shielded_token/src/masp/shielded_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ use rand_core::{OsRng, SeedableRng};

use crate::masp::utils::MaspClient;
use crate::masp::{
cloned_pair, ContextSyncStatus, Conversions, MaspAmount,
MaspDataLogEntry, MaspFeeData, MaspSourceTransferData,
MaspTargetTransferData, MaspTransferData, MaspTxReorderedData, NoteIndex,
ShieldedSyncConfig, ShieldedTransfer, ShieldedUtils, SpentNotesTracker,
TransferErr, WalletMap, WitnessMap, NETWORK,
cloned_pair, ContextSyncStatus, Conversions, MaspAmount, MaspDataLogEntry,
MaspFeeData, MaspSourceTransferData, MaspTargetTransferData,
MaspTransferData, MaspTxReorderedData, NoteIndex, ShieldedSyncConfig,
ShieldedTransfer, ShieldedUtils, SpentNotesTracker, TransferErr, WalletMap,
WitnessMap, NETWORK,
};
#[cfg(any(test, feature = "testing"))]
use crate::masp::{testing, ENV_VAR_MASP_TEST_SEED};
Expand Down Expand Up @@ -1623,9 +1623,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
15 changes: 8 additions & 7 deletions crates/tests/src/e2e/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ use namada_sdk::wallet::Wallet;
use toml::Value;

use super::setup::{
self, ensure_hot_key, run_cosmos_cmd, sleep, NamadaBgCmd, NamadaCmd, Test,
ENV_VAR_DEBUG, ENV_VAR_USE_PREBUILT_BINARIES,
self, run_cosmos_cmd, sleep, NamadaBgCmd, NamadaCmd, Test, ENV_VAR_DEBUG,
ENV_VAR_USE_PREBUILT_BINARIES,
};
use crate::e2e::setup::{Bin, CosmosChainType, Who, APPS_PACKAGE};
use crate::e2e::setup::{constants, Bin, CosmosChainType, Who, APPS_PACKAGE};
use crate::strings::{LEDGER_STARTED, TX_APPLIED_SUCCESS};
use crate::{run, run_as};

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 @@ -588,9 +591,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
20 changes: 13 additions & 7 deletions crates/tests/src/e2e/ibc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use sha2::{Digest, Sha256};

use crate::e2e::helpers::{
epoch_sleep, epochs_per_year_from_min_duration, find_address,
find_payment_address, get_actor_rpc, find_cosmos_address,
find_cosmos_address, find_payment_address, get_actor_rpc,
get_cosmos_gov_address, get_epoch,
};
use crate::e2e::ledger_tests::{
Expand Down Expand Up @@ -234,7 +234,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_cosmos(
&test_gaia,
COSMOS_USER,
Expand Down Expand Up @@ -294,7 +295,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_cosmos(
&test_gaia,
COSMOS_USER,
Expand Down Expand Up @@ -422,7 +424,8 @@ fn ibc_transfers() -> Result<()> {
check_cosmos_balance(&test_gaia, COSMOS_USER, COSMOS_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_cosmos(
&test_gaia,
COSMOS_USER,
Expand All @@ -449,7 +452,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_cosmos(
&test_gaia,
COSMOS_USER,
Expand Down Expand Up @@ -555,7 +559,8 @@ fn ibc_nft_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();
nft_transfer_from_cosmos(
&test_cosmwasm,
COSMOS_USER,
Expand Down Expand Up @@ -878,7 +883,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_cosmos(
&test_gaia,
COSMOS_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 @@ -89,18 +89,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 24fcb3b

Please sign in to comment.