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

testfix: flaky tests fix attempt #410

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## v0.5.0 (TBD)

* Fix flaky integration tests (#410).
* Add conversions for `NoteRecordDetails` (#392).

## v0.4.0 (2024-07-05)
Expand Down
18 changes: 12 additions & 6 deletions tests/integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,16 +841,22 @@ async fn test_update_ignored_tag() {
.unwrap();

// Ignored notes are only retrieved for "Ignored" or "All" filters
assert_eq!(client_2.get_input_notes(NoteFilter::All).unwrap().len(), 1);
assert_eq!(client_2.get_input_notes(NoteFilter::Ignored).unwrap().len(), 1);
assert_eq!(client_2.get_input_notes(NoteFilter::Expected).unwrap().len(), 0);
let all_notes = client_2.get_input_notes(NoteFilter::All).unwrap();
let ignored_notes = client_2.get_input_notes(NoteFilter::Ignored).unwrap();
let expected_notes = client_2.get_input_notes(NoteFilter::Expected).unwrap();
assert!(all_notes.iter().any(|candidate_note| candidate_note.id() == note.id()));
assert!(ignored_notes.iter().any(|candidate_note| candidate_note.id() == note.id()));
assert!(expected_notes.iter().all(|candidate_note| candidate_note.id() != note.id()));

client_2.add_note_tag(untracked_tag).unwrap();

// After adding tag, the note stops being ignored
assert_eq!(client_2.get_input_notes(NoteFilter::All).unwrap().len(), 1);
assert_eq!(client_2.get_input_notes(NoteFilter::Ignored).unwrap().len(), 0);
assert_eq!(client_2.get_input_notes(NoteFilter::Expected).unwrap().len(), 1);
let all_notes = client_2.get_input_notes(NoteFilter::All).unwrap();
let ignored_notes = client_2.get_input_notes(NoteFilter::Ignored).unwrap();
let expected_notes = client_2.get_input_notes(NoteFilter::Expected).unwrap();
assert!(all_notes.iter().any(|candidate_note| candidate_note.id() == note.id()));
assert!(ignored_notes.iter().all(|candidate_note| candidate_note.id() != note.id()));
assert!(expected_notes.iter().any(|candidate_note| candidate_note.id() == note.id()));
}

#[tokio::test]
Expand Down
51 changes: 30 additions & 21 deletions tests/integration/swap_transactions_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use miden_client::{
use miden_objects::{
accounts::{AccountId, AccountStorageType},
assets::{Asset, FungibleAsset, TokenSymbol},
notes::{NoteExecutionHint, NoteFile, NoteTag, NoteType},
notes::{NoteExecutionHint, NoteFile, NoteId, NoteTag, NoteType},
};

use super::common::*;
Expand Down Expand Up @@ -66,17 +66,17 @@ async fn test_swap_fully_onchain() {

// mint 1000 BTC for accountA
println!("minting 1000 btc for account A");
mint(
let account_a_mint_note_id = mint(
&mut client_with_faucets,
account_a.id(),
btc_faucet_account.id(),
NoteType::Public,
BTC_MINT_AMOUNT,
)
.await;
println!("minting 1000 eth for account B");
// mint 1000 ETH for accountB
mint(
println!("minting 1000 eth for account B");
let account_b_mint_note_id = mint(
&mut client_with_faucets,
account_b.id(),
eth_faucet_account.id(),
Expand All @@ -87,23 +87,27 @@ async fn test_swap_fully_onchain() {

// Sync and consume note for accountA
client1.sync_state().await.unwrap();
let client_1_notes = client1.get_input_notes(miden_client::store::NoteFilter::All).unwrap();
assert_eq!(client_1_notes.len(), 1);
let client_1_consumable_notes = client1.get_consumable_notes(Some(account_a.id())).unwrap();
assert!(client_1_consumable_notes
.iter()
.any(|(note, _)| note.id() == account_a_mint_note_id));

println!("Consuming mint note on first client...");
let tx_template =
TransactionTemplate::ConsumeNotes(account_a.id(), vec![client_1_notes[0].id()]);
TransactionTemplate::ConsumeNotes(account_a.id(), vec![account_a_mint_note_id]);
let tx_request = client1.build_transaction_request(tx_template).unwrap();
execute_tx_and_sync(&mut client1, tx_request).await;

// Sync and consume note for accountB
client2.sync_state().await.unwrap();
let client_2_notes = client2.get_input_notes(miden_client::store::NoteFilter::All).unwrap();
assert_eq!(client_2_notes.len(), 1);
let client_2_consumable_notes = client2.get_consumable_notes(Some(account_b.id())).unwrap();
assert!(client_2_consumable_notes
.iter()
.any(|(note, _)| note.id() == account_b_mint_note_id));

println!("Consuming mint note on second client...");
let tx_template =
TransactionTemplate::ConsumeNotes(account_b.id(), vec![client_2_notes[0].id()]);
TransactionTemplate::ConsumeNotes(account_b.id(), vec![account_b_mint_note_id]);
let tx_request = client2.build_transaction_request(tx_template).unwrap();
execute_tx_and_sync(&mut client2, tx_request).await;

Expand Down Expand Up @@ -272,7 +276,7 @@ async fn test_swap_offchain() {

// mint 1000 BTC for accountA
println!("minting 1000 btc for account A");
mint(
let account_a_mint_note_id = mint(
&mut client_with_faucets,
account_a.id(),
btc_faucet_account.id(),
Expand All @@ -282,7 +286,7 @@ async fn test_swap_offchain() {
.await;
// mint 1000 ETH for accountB
println!("minting 1000 eth for account B");
mint(
let account_b_mint_note_id = mint(
&mut client_with_faucets,
account_b.id(),
eth_faucet_account.id(),
Expand All @@ -293,23 +297,27 @@ async fn test_swap_offchain() {

// Sync and consume note for accountA
client1.sync_state().await.unwrap();
let client_1_notes = client1.get_input_notes(miden_client::store::NoteFilter::All).unwrap();
assert_eq!(client_1_notes.len(), 1);
let client_1_consumable_notes = client1.get_consumable_notes(Some(account_a.id())).unwrap();
assert!(client_1_consumable_notes
.iter()
.any(|(note, _)| note.id() == account_a_mint_note_id));

println!("Consuming mint note on first client...");
let tx_template =
TransactionTemplate::ConsumeNotes(account_a.id(), vec![client_1_notes[0].id()]);
TransactionTemplate::ConsumeNotes(account_a.id(), vec![account_a_mint_note_id]);
let tx_request = client1.build_transaction_request(tx_template).unwrap();
execute_tx_and_sync(&mut client1, tx_request).await;

// Sync and consume note for accountB
client2.sync_state().await.unwrap();
let client_2_notes = client2.get_input_notes(miden_client::store::NoteFilter::All).unwrap();
assert_eq!(client_2_notes.len(), 1);
let client_2_consumable_notes = client2.get_consumable_notes(Some(account_b.id())).unwrap();
assert!(client_2_consumable_notes
.iter()
.any(|(note, _)| note.id() == account_b_mint_note_id));

println!("Consuming mint note on second client...");
let tx_template =
TransactionTemplate::ConsumeNotes(account_b.id(), vec![client_2_notes[0].id()]);
TransactionTemplate::ConsumeNotes(account_b.id(), vec![account_b_mint_note_id]);
let tx_request = client2.build_transaction_request(tx_template).unwrap();
execute_tx_and_sync(&mut client2, tx_request).await;

Expand Down Expand Up @@ -468,8 +476,7 @@ fn build_swap_tag(
.unwrap()
}

/// Mints a note from faucet_account_id for basic_account_id, waits for inclusion and returns it
/// with 1000 units of the corresponding fungible asset
/// Mints a note from faucet_account_id for basic_account_id with 1000 units of the corresponding fungible asset, waits for inclusion and returns the note id.
///
/// `basic_account_id` does not need to be tracked by the client, but `faucet_account_id` does
async fn mint(
Expand All @@ -478,7 +485,7 @@ async fn mint(
faucet_account_id: AccountId,
note_type: NoteType,
mint_amount: u64,
) {
) -> NoteId {
// Create a Mint Tx for 1000 units of our fungible asset
let fungible_asset = FungibleAsset::new(faucet_account_id, mint_amount).unwrap();
let tx_template =
Expand All @@ -487,4 +494,6 @@ async fn mint(
println!("Minting Asset");
let tx_request = client.build_transaction_request(tx_template).unwrap();
execute_tx_and_sync(client, tx_request.clone()).await;

tx_request.expected_output_notes()[0].id()
}