From 788c4fc0a762de66c2a5877a66f53139f2ba7778 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Sat, 6 Jul 2024 01:58:51 -0400 Subject: [PATCH] Fix a pair of bugs in the decoy tests Unfortunately, this test is still failing. --- coins/monero/wallet/tests/decoys.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/coins/monero/wallet/tests/decoys.rs b/coins/monero/wallet/tests/decoys.rs index 99412b79..90574f49 100644 --- a/coins/monero/wallet/tests/decoys.rs +++ b/coins/monero/wallet/tests/decoys.rs @@ -45,20 +45,18 @@ test!( (builder.build().unwrap(), (rct_type, output_tx0)) }, // Then make sure DSA selects freshly unlocked output from tx1 as a decoy - |rpc, block, tx: Transaction, mut scanner: Scanner, state: (_, _)| async move { + |rpc, _, tx: Transaction, _: Scanner, state: (_, _)| async move { use rand_core::OsRng; let rpc: SimpleRequestRpc = rpc; let height = rpc.get_height().await.unwrap(); - let output_tx1 = - scanner.scan(&rpc, &block).await.unwrap().not_additionally_locked().swap_remove(0); - assert_eq!(output_tx1.transaction(), tx.hash()); + let most_recent_o_index = rpc.get_o_indexes(tx.hash()).await.unwrap().pop().unwrap(); // Make sure output from tx1 is in the block in which it unlocks let out_tx1: OutputResponse = - rpc.get_outs(&[output_tx1.index_on_blockchain()]).await.unwrap().swap_remove(0); + rpc.get_outs(&[most_recent_o_index]).await.unwrap().swap_remove(0); assert_eq!(out_tx1.height, height - DEFAULT_LOCK_WINDOW); assert!(out_tx1.unlocked); @@ -78,7 +76,7 @@ test!( .await .unwrap(); - selected_fresh_decoy = decoys[0].positions().contains(&output_tx1.index_on_blockchain()); + selected_fresh_decoy = decoys[0].positions().contains(&most_recent_o_index); attempts -= 1; } @@ -101,6 +99,7 @@ test!( scanner.scan(&rpc, &block).await.unwrap().not_additionally_locked().swap_remove(0); assert_eq!(output.transaction(), tx.hash()); assert_eq!(output.commitment().amount, 2000000000000); + output }, ), ( @@ -125,20 +124,18 @@ test!( (builder.build().unwrap(), (rct_type, output_tx0)) }, // Then make sure DSA selects freshly unlocked output from tx1 as a decoy - |rpc, block, tx: Transaction, mut scanner: Scanner, state: (_, _)| async move { + |rpc, _, tx: Transaction, _: Scanner, state: (_, _)| async move { use rand_core::OsRng; let rpc: SimpleRequestRpc = rpc; let height = rpc.get_height().await.unwrap(); - let output_tx1 = - scanner.scan(&rpc, &block).await.unwrap().not_additionally_locked().swap_remove(0); - assert_eq!(output_tx1.transaction(), tx.hash()); + let most_recent_o_index = rpc.get_o_indexes(tx.hash()).await.unwrap().pop().unwrap(); // Make sure output from tx1 is in the block in which it unlocks let out_tx1: OutputResponse = - rpc.get_outs(&[output_tx1.index_on_blockchain()]).await.unwrap().swap_remove(0); + rpc.get_outs(&[most_recent_o_index]).await.unwrap().swap_remove(0); assert_eq!(out_tx1.height, height - DEFAULT_LOCK_WINDOW); assert!(out_tx1.unlocked); @@ -158,7 +155,7 @@ test!( .await .unwrap(); - selected_fresh_decoy = decoys[0].positions().contains(&output_tx1.index_on_blockchain()); + selected_fresh_decoy = decoys[0].positions().contains(&most_recent_o_index); attempts -= 1; }