Skip to content

Commit

Permalink
Merge pull request #916 from idky137/dev_poc_tests
Browse files Browse the repository at this point in the history
Adding Fee Calculation Tests
  • Loading branch information
Oscar-Pepper authored Apr 16, 2024
2 parents 70e10e0 + bef26c0 commit 907876e
Show file tree
Hide file tree
Showing 3 changed files with 652 additions and 1 deletion.
3 changes: 3 additions & 0 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name = "integration-tests"
version = "0.2.0"
edition = "2021"

[features]
zip317 = []

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
zingolib = { path = "../zingolib", features = ["test"] }
Expand Down
375 changes: 374 additions & 1 deletion integration-tests/tests/integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3591,7 +3591,7 @@ mod slow {

mod basic_transactions {
use zingo_testutils::scenarios;
use zingolib::get_base_address;
use zingolib::{get_base_address, wallet::Pool};

#[tokio::test]
async fn send_and_sync_with_multiple_notes_no_panic() {
Expand Down Expand Up @@ -3634,6 +3634,379 @@ mod basic_transactions {
recipient.do_sync(true).await.unwrap();
faucet.do_sync(true).await.unwrap();
}

#[tokio::test]
async fn standard_send_fees() {
let (regtest_manager, _cph, faucet, recipient) =
scenarios::faucet_recipient_default().await;

let txid1 = faucet
.do_send(vec![(
get_base_address!(recipient, "unified").as_str(),
40_000,
None,
)])
.await
.unwrap();

let txid2 = faucet
.do_send(vec![(
get_base_address!(recipient, "sapling").as_str(),
40_000,
None,
)])
.await
.unwrap();

let txid3 = faucet
.do_send(vec![(
get_base_address!(recipient, "transparent").as_str(),
40_000,
None,
)])
.await
.unwrap();

zingo_testutils::generate_n_blocks_return_new_height(&regtest_manager, 1)
.await
.unwrap();

faucet.do_sync(true).await.unwrap();
recipient.do_sync(true).await.unwrap();

println!(
"Transaction Inputs:\n{:?}",
zingo_testutils::tx_inputs(&faucet, txid1.as_str()).await
);
println!(
"Transaction Outputs:\n{:?}",
zingo_testutils::tx_outputs(&recipient, txid1.as_str()).await
);
println!(
"Transaction Change:\n{:?}",
zingo_testutils::tx_outputs(&faucet, txid1.as_str()).await
);

let tx_actions_txid1 =
zingo_testutils::tx_actions(&faucet, Some(&recipient), txid1.as_str()).await;
println!("Transaction Actions:\n{:?}", tx_actions_txid1);

let calculated_fee_txid1 =
zingo_testutils::total_tx_value(&faucet, txid1.as_str()).await - 40_000;
println!("Fee Paid: {}", calculated_fee_txid1);

let expected_fee_txid1 = 10000;
// currently expected fee is always 10000 but will change to the following in zip317
// let expected_fee_txid1 = 5000
// * (cmp::max(
// 2,
// tx_actions_txid1.transparent_tx_actions
// + tx_actions_txid1.sapling_tx_actions
// + tx_actions_txid1.orchard_tx_actions,
// ));
println!("Expected Fee: {}", expected_fee_txid1);

assert_eq!(calculated_fee_txid1, expected_fee_txid1 as u64);

println!(
"Transaction Inputs:\n{:?}",
zingo_testutils::tx_inputs(&faucet, txid2.as_str()).await
);
println!(
"Transaction Outputs:\n{:?}",
zingo_testutils::tx_outputs(&recipient, txid2.as_str()).await
);
println!(
"Transaction Change:\n{:?}",
zingo_testutils::tx_outputs(&faucet, txid2.as_str()).await
);

let tx_actions_txid2 =
zingo_testutils::tx_actions(&faucet, Some(&recipient), txid2.as_str()).await;
println!("Transaction Actions:\n{:?}", tx_actions_txid2);

let calculated_fee_txid2 =
zingo_testutils::total_tx_value(&faucet, txid2.as_str()).await - 40_000;
println!("Fee Paid: {}", calculated_fee_txid2);

let expected_fee_txid2 = 10000;
// currently expected fee is always 10000 but will change to the following in zip317
// let expected_fee_txid2 = 5000
// * (cmp::max(
// 2,
// tx_actions_txid2.transparent_tx_actions
// + tx_actions_txid2.sapling_tx_actions
// + tx_actions_txid2.orchard_tx_actions,
// ));
println!("Expected Fee: {}", expected_fee_txid2);

assert_eq!(calculated_fee_txid2, expected_fee_txid2 as u64);

println!(
"Transaction Inputs:\n{:?}",
zingo_testutils::tx_inputs(&faucet, txid3.as_str()).await
);
println!(
"Transaction Outputs:\n{:?}",
zingo_testutils::tx_outputs(&recipient, txid3.as_str()).await
);
println!(
"Transaction Change:\n{:?}",
zingo_testutils::tx_outputs(&faucet, txid3.as_str()).await
);

let tx_actions_txid3 =
zingo_testutils::tx_actions(&faucet, Some(&recipient), txid3.as_str()).await;
println!("Transaction Actions:\n{:?}", tx_actions_txid3);

let calculated_fee_txid3 =
zingo_testutils::total_tx_value(&faucet, txid3.as_str()).await - 40_000;
println!("Fee Paid: {}", calculated_fee_txid3);

let expected_fee_txid3 = 10000;
// currently expected fee is always 10000 but will change to the following in zip317
// let expected_fee_txid3 = 5000
// * (cmp::max(
// 2,
// tx_actions_txid3.transparent_tx_actions
// + tx_actions_txid3.sapling_tx_actions
// + tx_actions_txid3.orchard_tx_actions,
// ));
println!("Expected Fee: {}", expected_fee_txid3);

assert_eq!(calculated_fee_txid3, expected_fee_txid3 as u64);

let txid4 = recipient
.do_send(vec![(
get_base_address!(faucet, "transparent").as_str(),
60_000,
None,
)])
.await
.unwrap();

zingo_testutils::generate_n_blocks_return_new_height(&regtest_manager, 1)
.await
.unwrap();

faucet.do_sync(true).await.unwrap();
recipient.do_sync(true).await.unwrap();

println!(
"Transaction Inputs:\n{:?}",
zingo_testutils::tx_inputs(&recipient, txid4.as_str()).await
);
println!(
"Transaction Outputs:\n{:?}",
zingo_testutils::tx_outputs(&faucet, txid4.as_str()).await
);
println!(
"Transaction Change:\n{:?}",
zingo_testutils::tx_outputs(&recipient, txid4.as_str()).await
);

let tx_actions_txid4 =
zingo_testutils::tx_actions(&recipient, Some(&faucet), txid4.as_str()).await;
println!("Transaction Actions:\n{:?}", tx_actions_txid4);

let calculated_fee_txid4 =
zingo_testutils::total_tx_value(&recipient, txid4.as_str()).await - 60_000;
println!("Fee Paid: {}", calculated_fee_txid4);

let expected_fee_txid4 = 10000;
// currently expected fee is always 10000 but will change to the following in zip317
// let expected_fee_txid4 = 5000
// * (cmp::max(
// 2,
// tx_actions_txid4.transparent_tx_actions
// + tx_actions_txid4.sapling_tx_actions
// + tx_actions_txid4.orchard_tx_actions,
// ));
println!("Expected Fee: {}", expected_fee_txid4);

assert_eq!(calculated_fee_txid4, expected_fee_txid4 as u64);
}

#[tokio::test]
async fn dust_send_fees() {
let (regtest_manager, _cph, faucet, recipient) =
scenarios::faucet_recipient_default().await;

let txid1 = faucet
.do_send(vec![(
get_base_address!(recipient, "unified").as_str(),
0,
None,
)])
.await
.unwrap();

zingo_testutils::generate_n_blocks_return_new_height(&regtest_manager, 1)
.await
.unwrap();

faucet.do_sync(true).await.unwrap();
recipient.do_sync(true).await.unwrap();

println!(
"Transaction Inputs:\n{:?}",
zingo_testutils::tx_inputs(&faucet, txid1.as_str()).await
);
println!(
"Transaction Outputs:\n{:?}",
zingo_testutils::tx_outputs(&recipient, txid1.as_str()).await
);
println!(
"Transaction Change:\n{:?}",
zingo_testutils::tx_outputs(&faucet, txid1.as_str()).await
);

let tx_actions_txid1 =
zingo_testutils::tx_actions(&faucet, Some(&recipient), txid1.as_str()).await;
println!("Transaction Actions:\n{:?}", tx_actions_txid1);

let calculated_fee_txid1 = zingo_testutils::total_tx_value(&faucet, txid1.as_str()).await;
println!("Fee Paid: {}", calculated_fee_txid1);

let expected_fee_txid1 = 10000;
// currently expected fee is always 10000 but will change to the following in zip317
// let expected_fee_txid1 = 5000
// * (cmp::max(
// 2,
// tx_actions_txid1.transparent_tx_actions
// + tx_actions_txid1.sapling_tx_actions
// + tx_actions_txid1.orchard_tx_actions,
// ));
println!("Expected Fee: {}", expected_fee_txid1);

assert_eq!(calculated_fee_txid1, expected_fee_txid1 as u64);
}

#[tokio::test]
async fn shield_send_fees() {
let (regtest_manager, _cph, faucet, recipient) =
scenarios::faucet_recipient_default().await;

faucet
.do_send(vec![(
get_base_address!(recipient, "transparent").as_str(),
40_000,
None,
)])
.await
.unwrap();

zingo_testutils::generate_n_blocks_return_new_height(&regtest_manager, 1)
.await
.unwrap();

faucet.do_sync(true).await.unwrap();
recipient.do_sync(true).await.unwrap();

let txid1 = recipient
.do_shield(
&[Pool::Transparent],
Some(get_base_address!(recipient, "unified")),
)
.await
.unwrap();

zingo_testutils::generate_n_blocks_return_new_height(&regtest_manager, 1)
.await
.unwrap();

faucet.do_sync(true).await.unwrap();
recipient.do_sync(true).await.unwrap();

println!(
"Transaction Inputs:\n{:?}",
zingo_testutils::tx_inputs(&recipient, txid1.as_str()).await
);
println!(
"Transaction Outputs:\n{:?}",
zingo_testutils::tx_outputs(&recipient, txid1.as_str()).await
);

let tx_actions_txid1 = zingo_testutils::tx_actions(&recipient, None, txid1.as_str()).await;
println!("Transaction Actions:\n{:?}", tx_actions_txid1);

let calculated_fee_txid1 =
zingo_testutils::total_tx_value(&recipient, txid1.as_str()).await;
println!("Fee Paid: {}", calculated_fee_txid1);

let expected_fee_txid1 = 10000;
// currently expected fee is always 10000 but will change to the following in zip317
// let expected_fee_txid1 = 5000
// * (cmp::max(
// 2,
// tx_actions_txid1.transparent_tx_actions
// + tx_actions_txid1.sapling_tx_actions
// + tx_actions_txid1.orchard_tx_actions,
// ));
println!("Expected Fee: {}", expected_fee_txid1);

assert_eq!(calculated_fee_txid1, expected_fee_txid1 as u64);

faucet
.do_send(vec![(
get_base_address!(recipient, "transparent").as_str(),
40_000,
None,
)])
.await
.unwrap();

zingo_testutils::generate_n_blocks_return_new_height(&regtest_manager, 1)
.await
.unwrap();

faucet.do_sync(true).await.unwrap();
recipient.do_sync(true).await.unwrap();

let txid2 = recipient
.do_shield(
&[Pool::Transparent],
Some(get_base_address!(recipient, "sapling")),
)
.await
.unwrap();

zingo_testutils::generate_n_blocks_return_new_height(&regtest_manager, 1)
.await
.unwrap();

faucet.do_sync(true).await.unwrap();
recipient.do_sync(true).await.unwrap();

println!(
"Transaction Inputs:\n{:?}",
zingo_testutils::tx_inputs(&recipient, txid2.as_str()).await
);
println!(
"Transaction Outputs:\n{:?}",
zingo_testutils::tx_outputs(&recipient, txid2.as_str()).await
);

let tx_actions_txid2 = zingo_testutils::tx_actions(&recipient, None, txid2.as_str()).await;
println!("Transaction Actions:\n{:?}", tx_actions_txid2);

let calculated_fee_txid2 =
zingo_testutils::total_tx_value(&recipient, txid2.as_str()).await;
println!("Fee Paid: {}", calculated_fee_txid2);

let expected_fee_txid2 = 10000;
// currently expected fee is always 10000 but will change to the following in zip317
// let expected_fee_txid2 = 5000
// * (cmp::max(
// 2,
// tx_actions_txid2.transparent_tx_actions
// + tx_actions_txid2.sapling_tx_actions
// + tx_actions_txid2.orchard_tx_actions,
// ));
println!("Expected Fee: {}", expected_fee_txid2);

assert_eq!(calculated_fee_txid2, expected_fee_txid2 as u64);
}
}

#[tokio::test]
Expand Down
Loading

0 comments on commit 907876e

Please sign in to comment.