Skip to content

Commit

Permalink
Merge pull request #353 from AloeareV/do_shield_sapling
Browse files Browse the repository at this point in the history
add tests to do_shield sapling and fix array index bug
  • Loading branch information
zancas authored May 31, 2023
2 parents f6288fe + 13e917c commit c08e683
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 4 deletions.
75 changes: 74 additions & 1 deletion zingocli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ async fn from_t_z_o_tz_to_zo_tzo_to_orchard() {
bump_and_check!(o: 40_000 s: 50_000 t: 0);

pool_migration_client
.do_send(vec![(&pmc_unified, 40_000, None)])
.do_shield(&[Pool::Sapling], None)
.await
.unwrap();
bump_and_check!(o: 80_000 s: 0 t: 0);
Expand Down Expand Up @@ -2391,4 +2391,77 @@ async fn zero_value_receipts() {
drop(child_process_handler);
}

#[tokio::test]
async fn shield_sapling() {
let (regtest_manager, child_process_handler, faucet, recipient) =
scenarios::faucet_recipient().await;

let sapling_dust = 100;
let _sent_transaction_id = faucet
.do_send(vec![(
&get_base_address!(recipient, "sapling"),
sapling_dust,
None,
)])
.await
.unwrap();

utils::increase_height_and_sync_client(&regtest_manager, &recipient, 1)
.await
.unwrap();
println!("{}", recipient.do_balance().await.pretty(4));

assert_eq!(
recipient.do_shield(&[Pool::Sapling], None).await,
Err(
"Not enough transparent/sapling balance to shield. Have 100 zats, \
need more than 10000 zats to cover tx fee"
.to_string()
)
);

let sapling_enough_for_fee = 10_100;
faucet.do_sync(false).await.unwrap();
let _sent_transaction_id = faucet
.do_send(vec![(
&get_base_address!(recipient, "sapling"),
sapling_enough_for_fee,
None,
)])
.await
.unwrap();

utils::increase_height_and_sync_client(&regtest_manager, &recipient, 1)
.await
.unwrap();
recipient
.do_shield(&[Pool::Sapling, Pool::Transparent], None)
.await
.unwrap();

// The exact same thing again, but with pre-existing orchard funds
// already in the shielding wallet
faucet.do_sync(false).await.unwrap();
let _sent_transaction_id = faucet
.do_send(vec![(
&get_base_address!(recipient, "sapling"),
sapling_enough_for_fee,
None,
)])
.await
.unwrap();

utils::increase_height_and_sync_client(&regtest_manager, &recipient, 1)
.await
.unwrap();
recipient
.do_shield(&[Pool::Sapling, Pool::Transparent], None)
.await
.unwrap();

println!("{}", recipient.do_balance().await.pretty(4));

drop(child_process_handler);
}

pub const TEST_SEED: &str = "chimney better bulb horror rebuild whisper improve intact letter giraffe brave rib appear bulk aim burst snap salt hill sad merge tennis phrase raise";
2 changes: 1 addition & 1 deletion zingolib/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ impl Command for ShieldCommand {
_ => return self.help().to_string(),
};
// Parse the address or amount
let address = if args.len() != 2 {
let address = if args.len() == 2 {
Some(args[1].to_string())
} else {
None
Expand Down
4 changes: 2 additions & 2 deletions zingolib/src/lightclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -995,8 +995,8 @@ impl LightClient {
};
if balance_to_shield <= fee {
return Err(format!(
"Not enough transparent balance to shield. Have {} zats, need more than {} zats to cover tx fee",
tbal, fee
"Not enough transparent/sapling balance to shield. Have {} zats, need more than {} zats to cover tx fee",
balance_to_shield, fee
));
}

Expand Down

0 comments on commit c08e683

Please sign in to comment.