Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Fee Calculation Tests #916

Merged
merged 30 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
acf1098
added tx_inputs ans tx_outputs to zingo-testutils
idky137 Apr 8, 2024
8d1c648
tx_inputs and tx_outputs now return TxNotes
idky137 Apr 8, 2024
061ee88
extract data from do_list_summaries
idky137 Apr 8, 2024
24bf1f9
Merge remote-tracking branch 'zingolabs/dev' into dev_poc_tests
idky137 Apr 9, 2024
257e741
added shield_send_fee test
idky137 Apr 9, 2024
df76a84
finished shield_send_fee test
idky137 Apr 9, 2024
a0951f6
fixed shield_send_fee test
idky137 Apr 9, 2024
21bfdee
fixed transparent output calculation
idky137 Apr 10, 2024
a1e0a03
tidied shield_send_fee test
idky137 Apr 10, 2024
a6a6dcf
finished standard_send_fee test
idky137 Apr 10, 2024
9e477f6
finished adding fee tests
idky137 Apr 10, 2024
6c00206
Merge remote-tracking branch 'zingolabs/dev' into dev_poc_tests
idky137 Apr 10, 2024
b0386df
fixed action calculation
idky137 Apr 10, 2024
911666c
updated tx_inputs and tx_outputs to return TxNotes
idky137 Apr 10, 2024
589a6f1
removed do_list_txsummaries
idky137 Apr 10, 2024
6b2d820
tidied helper functions
idky137 Apr 10, 2024
6c5615b
feature gate expected fee calculation under zip317
idky137 Apr 10, 2024
27144bd
changed TxNotes to TxNotesCount
idky137 Apr 11, 2024
8719fad
fixed for CI
idky137 Apr 11, 2024
b18e0df
Merge remote-tracking branch 'zingolabs/dev' into dev_poc_tests
idky137 Apr 11, 2024
0fb02d4
Merge branch 'dev' into dev_poc_tests
zancas Apr 11, 2024
404759a
Merge pull request #1 from zancas/dev_poc_tests
idky137 Apr 11, 2024
4dad162
Merge remote-tracking branch 'zingolabs/dev' into dev_poc_tests
idky137 Apr 11, 2024
6e3cb8b
review changes
idky137 Apr 11, 2024
d58d247
changed TxActions to TxActionsCount
idky137 Apr 12, 2024
90e1428
spelling mistakes
idky137 Apr 12, 2024
cc276b2
Merge remote-tracking branch 'zingolabs/dev' into dev_poc_tests
idky137 Apr 12, 2024
fd4baa7
Merge branch 'dev' into dev_poc_tests
fluidvanadium Apr 12, 2024
11de09d
Merge remote-tracking branch 'zingolabs/dev' into dev_poc_tests
idky137 Apr 15, 2024
bef26c0
Merge remote-tracking branch 'idky137/dev_poc_tests' into dev_poc_tests
idky137 Apr 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading