Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
SWvheerden committed Aug 15, 2024
1 parent b74b1d3 commit 20fbdd8
Showing 1 changed file with 47 additions and 27 deletions.
74 changes: 47 additions & 27 deletions base_layer/wallet/tests/output_manager_service_tests/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,7 @@ async fn test_txo_validation() {
&oms.key_manager_handle,
)
.await;
let output3_tx_output = output3.to_transaction_output(&oms.key_manager_handle).await.unwrap();

oms.output_manager_handle
.add_output_with_tx_id(TxId::from(3u64), output3.clone(), None)
Expand All @@ -1386,7 +1387,7 @@ async fn test_txo_validation() {
block_headers.insert(4, block4_header.clone());
oms.base_node_wallet_rpc_mock_state.set_blocks(block_headers.clone());

// These responses will mark outputs 1 and 2 and mined confirmed
// These responses will mark outputs 1,2,3 and mined confirmed
let responses = vec![
UtxoQueryResponse {
output: Some(output1_tx_output.clone().try_into().unwrap()),
Expand All @@ -1402,6 +1403,13 @@ async fn test_txo_validation() {
output_hash: output2_tx_output.hash().to_vec(),
mined_timestamp: 0,
},
UtxoQueryResponse {
output: Some(output3_tx_output.clone().try_into().unwrap()),
mined_at_height: 1,
mined_in_block: block1_header.hash().to_vec(),
output_hash: output3_tx_output.hash().to_vec(),
mined_timestamp: 0,
},
];

let utxo_query_responses = UtxoQueryResponses {
Expand All @@ -1413,7 +1421,7 @@ async fn test_txo_validation() {
oms.base_node_wallet_rpc_mock_state
.set_utxo_query_response(utxo_query_responses.clone());

// This response sets output1 and output2 as mined, not spent
// This response sets output1 and output2, output3 as mined, not spent
let query_deleted_response = QueryDeletedResponse {
best_block_hash: block4_header.hash().to_vec(),
best_block_height: 4,
Expand All @@ -1430,6 +1438,12 @@ async fn test_txo_validation() {
height_deleted_at: 0,
block_deleted_in: Vec::new(),
},
QueryDeletedData {
mined_at_height: 1,
block_mined_in: block1_header.hash().to_vec(),
height_deleted_at: 0,
block_deleted_in: Vec::new(),
},
],
};

Expand Down Expand Up @@ -1511,7 +1525,7 @@ async fn test_txo_validation() {

// Output 1: Spent in Block 5 - Unconfirmed
// Output 2: Mined block 1 Confirmed Block 4
// Output 3: Imported so will have Unspent status.
// Output 3: Mined block 1 Confirmed Block 4.
// Output 4: Received in Block 5 - Unconfirmed - Change from spending Output 1
// Output 5: Received in Block 5 - Unconfirmed
// Output 6: Coinbase from Block 5 - Unconfirmed
Expand All @@ -1536,6 +1550,13 @@ async fn test_txo_validation() {
output_hash: output2_tx_output.hash().to_vec(),
mined_timestamp: 0,
},
UtxoQueryResponse {
output: Some(output3_tx_output.clone().try_into().unwrap()),
mined_at_height: 1,
mined_in_block: block1_header.hash().to_vec(),
output_hash: output3_tx_output.hash().to_vec(),
mined_timestamp: 0,
},
UtxoQueryResponse {
output: Some(output4_tx_output.clone().try_into().unwrap()),
mined_at_height: 5,
Expand Down Expand Up @@ -1578,6 +1599,12 @@ async fn test_txo_validation() {
height_deleted_at: 0,
block_deleted_in: Vec::new(),
},
QueryDeletedData {
mined_at_height: 1,
block_mined_in: block1_header.hash().to_vec(),
height_deleted_at: 0,
block_deleted_in: Vec::new(),
},
QueryDeletedData {
mined_at_height: 5,
block_mined_in: block5_header.hash().to_vec(),
Expand Down Expand Up @@ -1610,14 +1637,14 @@ async fn test_txo_validation() {
.await
.unwrap();

assert_eq!(utxo_query_calls[0].len(), 3);
assert_eq!(utxo_query_calls[0].len(), 2);

let query_deleted_calls = oms
.base_node_wallet_rpc_mock_state
.wait_pop_query_deleted(1, Duration::from_secs(60))
.await
.unwrap();
assert_eq!(query_deleted_calls[0].hashes.len(), 4);
assert_eq!(query_deleted_calls[0].hashes.len(), 5);

let balance = oms.output_manager_handle.get_balance().await.unwrap();
assert_eq!(
Expand Down Expand Up @@ -1657,15 +1684,15 @@ async fn test_txo_validation() {
.unwrap();

// The spent transaction is not checked during this second validation
assert_eq!(utxo_query_calls[0].len(), 3);
assert_eq!(utxo_query_calls[0].len(), 2);

let query_deleted_calls = oms
.base_node_wallet_rpc_mock_state
.wait_pop_query_deleted(1, Duration::from_secs(60))
.await
.unwrap();

assert_eq!(query_deleted_calls[0].hashes.len(), 4);
assert_eq!(query_deleted_calls[0].hashes.len(), 5);

let balance = oms.output_manager_handle.get_balance().await.unwrap();
assert_eq!(
Expand All @@ -1679,26 +1706,6 @@ async fn test_txo_validation() {
assert_eq!(balance.pending_incoming_balance, MicroMinotari::from(0));
assert_eq!(MicroMinotari::from(0), balance.time_locked_balance.unwrap());

// Trigger another validation and only Output3 should be checked
oms.output_manager_handle.validate_txos().await.unwrap();

let utxo_query_calls = oms
.base_node_wallet_rpc_mock_state
.wait_pop_utxo_query_calls(1, Duration::from_secs(60))
.await
.unwrap();
assert_eq!(utxo_query_calls.len(), 1);
assert_eq!(utxo_query_calls[0].len(), 1);
assert_eq!(
utxo_query_calls[0][0],
output3
.to_transaction_output(&oms.key_manager_handle)
.await
.unwrap()
.hash()
.to_vec()
);

// Now we will create responses that result in a reorg of block 5, keeping block4 the same.
// Output 1: Spent in Block 5 - Unconfirmed
// Output 2: Mined block 1 Confirmed Block 4
Expand Down Expand Up @@ -1730,6 +1737,13 @@ async fn test_txo_validation() {
output_hash: output2_tx_output.hash().to_vec(),
mined_timestamp: 0,
},
UtxoQueryResponse {
output: Some(output3_tx_output.clone().try_into().unwrap()),
mined_at_height: 1,
mined_in_block: block1_header.hash().to_vec(),
output_hash: output3_tx_output.hash().to_vec(),
mined_timestamp: 0,
},
UtxoQueryResponse {
output: Some(output4_tx_output.clone().try_into().unwrap()),
mined_at_height: 5,
Expand Down Expand Up @@ -1765,6 +1779,12 @@ async fn test_txo_validation() {
height_deleted_at: 0,
block_deleted_in: Vec::new(),
},
QueryDeletedData {
mined_at_height: 1,
block_mined_in: block1_header.hash().to_vec(),
height_deleted_at: 0,
block_deleted_in: Vec::new(),
},
QueryDeletedData {
mined_at_height: 5,
block_mined_in: block5_header_reorg.hash().to_vec(),
Expand Down

0 comments on commit 20fbdd8

Please sign in to comment.