Skip to content

Commit

Permalink
fixup! Merge branch 'origin/bat/refactor-masp-e2e' (#1714)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraccaman committed Jul 21, 2023
1 parent 8027b19 commit a85e752
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 45 deletions.
2 changes: 0 additions & 2 deletions apps/src/lib/cli/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,6 @@ where
#[cfg(not(feature = "testing"))]
/// A helper to exit after flushing output, borrowed from `clap::util` module.
pub fn safe_exit(code: i32) -> ! {
use std::io::Write;

let _ = std::io::stdout().lock().flush();
let _ = std::io::stderr().lock().flush();

Expand Down
2 changes: 1 addition & 1 deletion apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2022,7 +2022,7 @@ pub async fn epoch_sleep<C: namada::ledger::queries::Client + Sync>(
) {
let start_epoch = query_and_print_epoch(client).await;
loop {
tokio::time::sleep(Duration::from_secs(1)).await;
tokio::time::sleep(core::time::Duration::from_secs(1)).await;
let current_epoch = query_epoch(client).await;
if current_epoch > start_epoch {
println!("Reached epoch {}", current_epoch);
Expand Down
28 changes: 6 additions & 22 deletions shared/src/ledger/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,10 +1111,7 @@ pub async fn build_bond<

// TODO Should we state the same error message for the native token?
check_balance_too_low_err(
&TokenAddress {
address: args.native_token,
sub_prefix: None,
},
&args.native_token,
bond_source,
args.amount,
balance_key,
Expand Down Expand Up @@ -1205,10 +1202,7 @@ pub async fn build_ibc_transfer<
let balance_key = token::balance_key(&token, &source);

check_balance_too_low_err(
&TokenAddress {
address: token.clone(),
sub_prefix: sub_prefix.clone(),
},
&token,
&source,
args.amount,
balance_key,
Expand Down Expand Up @@ -1398,15 +1392,8 @@ pub async fn build_transfer<

args.amount = InputAmount::Validated(validated_amount);
args.tx.fee_amount = InputAmount::Validated(validate_fee);
let sub_prefix = args
.sub_prefix
.as_ref()
.map(|k| k.parse().expect("Could not parse multi-token sub-prefix"));
check_balance_too_low_err::<C>(
&TokenAddress {
address: token.clone(),
sub_prefix: sub_prefix.clone(),
},
&token,
&source,
validated_amount.amount,
balance_key,
Expand Down Expand Up @@ -1814,7 +1801,7 @@ async fn target_exists_or_err<C: crate::ledger::queries::Client + Sync>(
/// given amount, along with the balance even existing. force
/// overrides this
async fn check_balance_too_low_err<C: crate::ledger::queries::Client + Sync>(
token: &TokenAddress,
token: &Address,
source: &Address,
amount: token::Amount,
balance_key: storage::Key,
Expand All @@ -1840,7 +1827,7 @@ async fn check_balance_too_low_err<C: crate::ledger::queries::Client + Sync>(
} else {
Err(Error::BalanceTooLow(
source.clone(),
token.address.clone(),
token.clone(),
amount.to_string_native(),
balance.to_string_native(),
))
Expand All @@ -1857,10 +1844,7 @@ async fn check_balance_too_low_err<C: crate::ledger::queries::Client + Sync>(
);
Ok(())
} else {
Err(Error::NoBalanceForToken(
source.clone(),
token.address.clone(),
))
Err(Error::NoBalanceForToken(source.clone(), token.clone()))
}
}
}
Expand Down
38 changes: 19 additions & 19 deletions tests/src/integration/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn masp_incentives() -> Result<()> {
)
});

let amt = (amt20 * masp_rewards[&(btc(), None)]).0 * (ep1.0 - ep0.0);
let amt = (amt20 * masp_rewards[&btc()]).0 * (ep1.0 - ep0.0);
let denominated = DenominatedAmount {
amount: amt,
denom: NATIVE_MAX_DECIMAL_PLACES.into(),
Expand All @@ -162,7 +162,7 @@ fn masp_incentives() -> Result<()> {
],
)
});
let amt = (amt20 * masp_rewards[&(btc(), None)]).0 * (ep1.0 - ep0.0);
let amt = (amt20 * masp_rewards[&btc()]).0 * (ep1.0 - ep0.0);
let denominated = DenominatedAmount {
amount: amt,
denom: NATIVE_MAX_DECIMAL_PLACES.into(),
Expand Down Expand Up @@ -208,7 +208,7 @@ fn masp_incentives() -> Result<()> {
],
)
});
let amt = (amt20 * masp_rewards[&(btc(), None)]).0 * (ep2.0 - ep0.0);
let amt = (amt20 * masp_rewards[&btc()]).0 * (ep2.0 - ep0.0);
let denominated = DenominatedAmount {
amount: amt,
denom: NATIVE_MAX_DECIMAL_PLACES.into(),
Expand All @@ -232,7 +232,7 @@ fn masp_incentives() -> Result<()> {
],
)
});
let amt = (amt20 * masp_rewards[&(btc(), None)]).0 * (ep2.0 - ep0.0);
let amt = (amt20 * masp_rewards[&btc()]).0 * (ep2.0 - ep0.0);
let denominated = DenominatedAmount {
amount: amt,
denom: NATIVE_MAX_DECIMAL_PLACES.into(),
Expand Down Expand Up @@ -339,7 +339,7 @@ fn masp_incentives() -> Result<()> {
],
)
});
let amt = (amt10 * masp_rewards[&(eth(), None)]).0 * (ep4.0 - ep3.0);
let amt = (amt10 * masp_rewards[&eth()]).0 * (ep4.0 - ep3.0);
let denominated = DenominatedAmount {
amount: amt,
denom: NATIVE_MAX_DECIMAL_PLACES.into(),
Expand All @@ -364,8 +364,8 @@ fn masp_incentives() -> Result<()> {
],
)
});
let amt = ((amt20 * masp_rewards[&(btc(), None)]).0 * (ep4.0 - ep0.0))
+ ((amt10 * masp_rewards[&(eth(), None)]).0 * (ep4.0 - ep3.0));
let amt = ((amt20 * masp_rewards[&btc()]).0 * (ep4.0 - ep0.0))
+ ((amt10 * masp_rewards[&eth()]).0 * (ep4.0 - ep3.0));
let denominated = DenominatedAmount {
amount: amt,
denom: NATIVE_MAX_DECIMAL_PLACES.into(),
Expand Down Expand Up @@ -435,7 +435,7 @@ fn masp_incentives() -> Result<()> {
],
)
});
let amt = (amt10 * masp_rewards[&(eth(), None)]).0 * (ep5.0 - ep3.0);
let amt = (amt10 * masp_rewards[&eth()]).0 * (ep5.0 - ep3.0);
let denominated = DenominatedAmount {
amount: amt,
denom: NATIVE_MAX_DECIMAL_PLACES.into(),
Expand All @@ -461,8 +461,8 @@ fn masp_incentives() -> Result<()> {
],
)
});
let amt = ((amt20 * masp_rewards[&(btc(), None)]).0 * (ep.0 - ep0.0))
+ ((amt10 * masp_rewards[&(eth(), None)]).0 * (ep5.0 - ep3.0));
let amt = ((amt20 * masp_rewards[&btc()]).0 * (ep.0 - ep0.0))
+ ((amt10 * masp_rewards[&eth()]).0 * (ep5.0 - ep3.0));
let denominated = DenominatedAmount {
amount: amt,
denom: NATIVE_MAX_DECIMAL_PLACES.into(),
Expand Down Expand Up @@ -530,7 +530,7 @@ fn masp_incentives() -> Result<()> {
],
)
});
let amt = (amt20 * masp_rewards[&(btc(), None)]).0 * (ep6.0 - ep0.0);
let amt = (amt20 * masp_rewards[&btc()]).0 * (ep6.0 - ep0.0);
let denominated = DenominatedAmount {
amount: amt,
denom: NATIVE_MAX_DECIMAL_PLACES.into(),
Expand All @@ -555,8 +555,8 @@ fn masp_incentives() -> Result<()> {
],
)
});
let amt = ((amt20 * masp_rewards[&(btc(), None)]).0 * (ep6.0 - ep0.0))
+ ((amt10 * masp_rewards[&(eth(), None)]).0 * (ep5.0 - ep3.0));
let amt = ((amt20 * masp_rewards[&btc()]).0 * (ep6.0 - ep0.0))
+ ((amt10 * masp_rewards[&eth()]).0 * (ep5.0 - ep3.0));
let denominated = DenominatedAmount {
amount: amt,
denom: NATIVE_MAX_DECIMAL_PLACES.into(),
Expand All @@ -583,7 +583,7 @@ fn masp_incentives() -> Result<()> {
],
)
});
let amt = (amt20 * masp_rewards[&(btc(), None)]).0 * (ep6.0 - ep0.0);
let amt = (amt20 * masp_rewards[&btc()]).0 * (ep6.0 - ep0.0);
let denominated = DenominatedAmount {
amount: amt,
denom: NATIVE_MAX_DECIMAL_PLACES.into(),
Expand All @@ -607,7 +607,7 @@ fn masp_incentives() -> Result<()> {
],
)
});
let amt = (amt10 * masp_rewards[&(eth(), None)]).0 * (ep5.0 - ep3.0);
let amt = (amt10 * masp_rewards[&eth()]).0 * (ep5.0 - ep3.0);
let denominated = DenominatedAmount {
amount: amt,
denom: NATIVE_MAX_DECIMAL_PLACES.into(),
Expand All @@ -632,8 +632,8 @@ fn masp_incentives() -> Result<()> {
],
)
});
let amt = ((amt20 * masp_rewards[&(btc(), None)]).0 * (ep6.0 - ep0.0))
+ ((amt10 * masp_rewards[&(eth(), None)]).0 * (ep5.0 - ep3.0));
let amt = ((amt20 * masp_rewards[&btc()]).0 * (ep6.0 - ep0.0))
+ ((amt10 * masp_rewards[&eth()]).0 * (ep5.0 - ep3.0));
let denominated = DenominatedAmount {
amount: amt,
denom: NATIVE_MAX_DECIMAL_PLACES.into(),
Expand All @@ -658,7 +658,7 @@ fn masp_incentives() -> Result<()> {
"--token",
NAM,
"--amount",
&((amt10 * masp_rewards[&(eth(), None)]).0 * (ep5.0 - ep3.0))
&((amt10 * masp_rewards[&eth()]).0 * (ep5.0 - ep3.0))
.to_string_native(),
"--signer",
BERTHA,
Expand All @@ -684,7 +684,7 @@ fn masp_incentives() -> Result<()> {
"--token",
NAM,
"--amount",
&((amt20 * masp_rewards[&(btc(), None)]).0 * (ep6.0 - ep0.0))
&((amt20 * masp_rewards[&btc()]).0 * (ep6.0 - ep0.0))
.to_string_native(),
"--signer",
ALBERT,
Expand Down
2 changes: 1 addition & 1 deletion wasm/wasm_source/src/vp_testnet_faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn validate_tx(
ctx.read_post(key)?.unwrap_or_default();
let change = post.change() - pre.change();
let maybe_denom =
storage_api::token::read_denom(&ctx.pre(), token, None)?;
storage_api::token::read_denom(&ctx.pre(), token)?;
if maybe_denom.is_none() {
debug_log!(
"A denomination for token address {} does not exist \
Expand Down

0 comments on commit a85e752

Please sign in to comment.