Skip to content

Commit

Permalink
Handle discrepencies between simd v8, gaia 11 and other chains
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Sep 13, 2023
1 parent 35a63b0 commit 7b1d445
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 41 deletions.
111 changes: 81 additions & 30 deletions tools/test-framework/src/chain/cli/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,32 @@ pub fn add_genesis_account(
) -> Result<(), Error> {
let amounts_str = itertools::join(amounts, ",");

simple_exec(
chain_id,
command_path,
&[
"--home",
home_path,
"add-genesis-account",
wallet_address,
&amounts_str,
],
)?;
if let Some(prefix) = get_genesis_prefix(chain_id, command_path)? {
simple_exec(
chain_id,
command_path,
&[
"--home",
home_path,
prefix,
"add-genesis-account",
wallet_address,
&amounts_str,
],
)?;
} else {
simple_exec(
chain_id,
command_path,
&[
"--home",
home_path,
"add-genesis-account",
wallet_address,
&amounts_str,
],
)?;
}

Ok(())
}
Expand All @@ -87,35 +102,71 @@ pub fn add_genesis_validator(
wallet_id: &str,
amount: &str,
) -> Result<(), Error> {
simple_exec(
chain_id,
command_path,
&[
"--home",
home_path,
"gentx",
wallet_id,
"--keyring-backend",
"test",
"--chain-id",
if let Some(prefix) = get_genesis_prefix(chain_id, command_path)? {
simple_exec(
chain_id,
amount,
],
)?;
command_path,
&[
"--home",
home_path,
prefix,
"gentx",
wallet_id,
"--keyring-backend",
"test",
"--chain-id",
chain_id,
amount,
],
)?;
} else {
simple_exec(
chain_id,
command_path,
&[
"--home",
home_path,
"gentx",
wallet_id,
"--keyring-backend",
"test",
"--chain-id",
chain_id,
amount,
],
)?;
}

Ok(())
}

pub fn collect_gen_txs(chain_id: &str, command_path: &str, home_path: &str) -> Result<(), Error> {
simple_exec(
chain_id,
command_path,
&["--home", home_path, "collect-gentxs"],
)?;
if let Some(prefix) = get_genesis_prefix(chain_id, command_path)? {
simple_exec(
chain_id,
command_path,
&["--home", home_path, prefix, "collect-gentxs"],
)?;
} else {
simple_exec(
chain_id,
command_path,
&["--home", home_path, "collect-gentxs"],
)?;
};

Ok(())
}

fn get_genesis_prefix(chain_id: &str, command_path: &str) -> Result<Option<&'static str>, Error> {
let result = simple_exec(chain_id, command_path, &["--help"])?;
if result.stdout.contains("gentx") || result.stderr.contains("gentx") {
Ok(None)
} else {
Ok(Some("genesis"))
}
}

pub fn start_chain(
command_path: &str,
home_path: &str,
Expand Down
39 changes: 28 additions & 11 deletions tools/test-framework/src/chain/cli/query.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use core::str::FromStr;
use eyre::eyre;
use ibc_relayer_types::applications::transfer::amount::Amount;
use serde::Deserialize;
use serde_json as json;
use serde_yaml as yaml;

use ibc_relayer_types::applications::transfer::amount::Amount;

use crate::chain::exec::simple_exec;
use crate::error::{handle_generic_error, Error};

Expand All @@ -24,23 +26,38 @@ pub fn query_balance(
"bank",
"balances",
wallet_id,
"--denom",
denom,
"--output",
"json",
],
)?
.stdout;

let amount_str = json::from_str::<json::Value>(&res)
.map_err(handle_generic_error)?
.get("amount")
.ok_or_else(|| eyre!("expected amount field"))?
.as_str()
.ok_or_else(|| eyre!("expected string field"))?
.to_string();
#[derive(Deserialize)]
struct Balance {
denom: String,
amount: String,
}

#[derive(Deserialize)]
struct Balances {
balances: Vec<Balance>,
}

let balances = json::from_str::<Balances>(&res).map_err(handle_generic_error)?;

let balance = balances
.balances
.iter()
.find(|b| b.denom == denom)
.ok_or_else(|| {
Error::generic(eyre!(
"no balance found for denom {} in response: {}",
denom,
res
))
})?;

let amount = Amount::from_str(&amount_str).map_err(handle_generic_error)?;
let amount = Amount::from_str(&balance.amount).map_err(handle_generic_error)?;

Ok(amount)
}
Expand Down

0 comments on commit 7b1d445

Please sign in to comment.