Skip to content

Commit

Permalink
Merge branch 'bat/feature/int-tests-io' (#1771)
Browse files Browse the repository at this point in the history
* origin/bat/feature/int-tests-io:
  [fix]: Fixed removing tokio dep from wasm targeted builds
  [chore] Merging in v0.22
  [feat]: Refactored the masp integration tests to no longer need the nightly feature
  [chore]: merge in v0.21.1
  [chore]: Formatting
  [feat]: After rebasing on bat/generic-io, need to make io read methods async for integration testing
  [fix]: Fixing downstream async io changes from bat/generic-io
  [feat]: Refactored the masp integration tests to no longer need the nightly feature
  [chore]: merge in v0.21.1
  [chore]: Formatting
  [feat]: After rebasing on bat/generic-io, need to make io read methods async for integration testing
  [fix]: Fixing downstream async io changes from bat/generic-io
  [chore]: rebasing on bat/generic-io
  [feat]: Refactored the masp integration tests to no longer need the nightly feature
  [chore]: Formatting
  [feat]: After rebasing on bat/generic-io, need to make io read methods async for integration testing
  [fix]: Fixing downstream async io changes from bat/generic-io
  [chore]: rebasing on bat/generic-io
  [feat]: Refactored the masp integration tests to no longer need the nightly feature
  [fix]: Fixing downstream async io changes from bat/generic-io
  [chore]: rebasing on bat/generic-io
  [feat]: Refactored the masp integration tests to no longer need the nightly feature
  [fix]: Fixing downstream async io changes from bat/generic-io
  [chore]: rebasing on bat/generic-io
  [feat]: Refactored the masp integration tests to no longer need the nightly feature
  [chore]: rebasing on bat/generic-io
  [feat]: Refactored the masp integration tests to no longer need the nightly feature
  [feat]: Refactored the masp integration tests to no longer need the nightly feature
  • Loading branch information
Fraccaman committed Sep 25, 2023
2 parents a6a7c4c + 40ab00a commit d789dda
Show file tree
Hide file tree
Showing 14 changed files with 301 additions and 185 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use clap::{ArgGroup, ArgMatches, ColorChoice};
use color_eyre::eyre::Result;
use namada::types::io::DefaultIo;
use utils::*;
pub use utils::{dispatch_prompt, safe_exit, Cmd, TESTIN};
pub use utils::{safe_exit, Cmd};

pub use self::context::Context;
use crate::cli::api::CliIo;
Expand Down
51 changes: 0 additions & 51 deletions apps/src/lib/cli/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::str::FromStr;

use clap::{ArgAction, ArgMatches};
use color_eyre::eyre::Result;
use lazy_static::lazy_static;

use super::args;
use super::context::{Context, FromContext};
Expand Down Expand Up @@ -363,53 +362,3 @@ pub fn safe_exit(_: i32) -> ! {

panic!("Test failed because the client exited unexpectedly.")
}

lazy_static! {
/// A replacement for stdin in testing.
pub static ref TESTIN: std::sync::Arc<std::sync::Mutex<Vec<u8>>> =
std::sync::Arc::new(std::sync::Mutex::new(vec![]));
}

/// A generic function for displaying a prompt to users and reading
/// in their response.
fn prompt_aux<R, W>(mut reader: R, mut writer: W, question: &str) -> String
where
R: std::io::Read,
W: Write,
{
write!(&mut writer, "{}", question).expect("Unable to write");
writer.flush().unwrap();
let mut s = String::new();
reader.read_to_string(&mut s).expect("Unable to read");
s
}

/// A function that chooses how to dispatch prompts
/// to users. There is a hierarchy of feature flags
/// that determines this. If no flags are set,
/// the question is printed to stdout and response
/// read from stdin.
pub fn dispatch_prompt(question: impl AsRef<str>) -> String {
if cfg!(feature = "testing") {
prompt_aux(
TESTIN.lock().unwrap().as_slice(),
std::io::stdout(),
question.as_ref(),
)
} else {
prompt_aux(
std::io::stdin().lock(),
std::io::stdout(),
question.as_ref(),
)
}
}

#[macro_export]
/// A convenience macro for formatting the user prompt before
/// forwarding it to the `[dispatch_prompt]` method.
macro_rules! prompt {
($($arg:tt)*) => {{
$crate::cli::dispatch_prompt(format!("{}", format_args!($($arg)*)))
}}
}
8 changes: 4 additions & 4 deletions apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ use namada::types::key::*;
use namada::types::masp::{BalanceOwner, ExtendedViewingKey, PaymentAddress};
use namada::types::storage::{BlockHeight, BlockResults, Epoch, Key, KeySeg};
use namada::types::token::{Change, MaspDenom};
use namada::types::{ storage, token};
use namada::{display, display_line, edisplay_line};
use namada::types::{storage, token};
use namada::{display, display_line, edisplay_line, prompt};
use tokio::time::Instant;

use crate::cli::{self, args};
use crate::facade::tendermint::merkle::proof::Proof;
use crate::facade::tendermint_rpc::error::Error as TError;
use crate::prompt;
use crate::wallet::CliWalletUtils;

/// Query the status of a given transaction.
Expand Down Expand Up @@ -463,7 +462,8 @@ pub async fn query_pinned_balance<
}
// If a suitable viewing key was not found, then demand it from the user
if is_pinned_error(&balance) {
let vk_str = prompt!("Enter the viewing key for {}: ", owner);
let vk_str =
prompt!(IO, "Enter the viewing key for {}: ", owner).await;
let fvk = match ExtendedViewingKey::from_str(vk_str.trim()) {
Ok(fvk) => fvk,
_ => {
Expand Down
12 changes: 6 additions & 6 deletions apps/src/lib/node/ledger/shell/testing/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use std::ops::ControlFlow;
use clap::Command as App;
use eyre::Report;
use namada::types::control_flow::Halt;
use namada::types::io::{DefaultIo, Io};
use namada::types::io::Io;
use tendermint_config::net::Address as TendermintAddress;

use super::node::MockNode;
use crate::cli::api::{CliApi, CliClient};
use crate::cli::args::Global;
use crate::cli::{args, cmds, Cmd, Context, NamadaClient, NamadaRelayer};
use crate::node::ledger::shell::testing::utils::Bin;
use crate::node::ledger::shell::testing::utils::{Bin, TestingIo};

pub fn run(
node: &MockNode,
Expand All @@ -25,7 +25,7 @@ pub fn run(
wasm_dir: Some(locked.wasm_dir.clone()),
}
};
let ctx = Context::new::<DefaultIo>(global.clone())?;
let ctx = Context::new::<TestingIo>(global.clone())?;

let rt = tokio::runtime::Runtime::new().unwrap();
match who {
Expand All @@ -47,7 +47,7 @@ pub fn run(
NamadaClient::WithoutContext(sub_cmd, global)
}
};
rt.block_on(CliApi::<DefaultIo>::handle_client_command(
rt.block_on(CliApi::<TestingIo>::handle_client_command(
Some(node),
cmd,
))
Expand All @@ -60,7 +60,7 @@ pub fn run(

let cmd = cmds::NamadaWallet::parse(&matches)
.expect("Could not parse wallet command");
CliApi::<DefaultIo>::handle_wallet_command(cmd, ctx)
CliApi::<TestingIo>::handle_wallet_command(cmd, ctx)
}
Bin::Relayer => {
args.insert(0, "relayer");
Expand All @@ -82,7 +82,7 @@ pub fn run(
NamadaRelayer::ValidatorSet(sub_cmd)
}
};
rt.block_on(CliApi::<DefaultIo>::handle_relayer_command(
rt.block_on(CliApi::<TestingIo>::handle_relayer_command(
Some(node),
cmd,
))
Expand Down
Loading

0 comments on commit d789dda

Please sign in to comment.