From 78e77c154e4df5bb8c8bb34fca6534061c018d32 Mon Sep 17 00:00:00 2001 From: Marco Granelli Date: Fri, 30 Aug 2024 16:44:34 +0200 Subject: [PATCH] Fixes integration tests --- crates/node/src/shell/testing/node.rs | 2 +- crates/tests/src/integration/ledger_tests.rs | 29 +++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/crates/node/src/shell/testing/node.rs b/crates/node/src/shell/testing/node.rs index 3d6db6a0d19..df6fb68d49f 100644 --- a/crates/node/src/shell/testing/node.rs +++ b/crates/node/src/shell/testing/node.rs @@ -533,7 +533,7 @@ impl MockNode { let mut tx_results = resp .events .into_iter() - .map(|e| e.read_attribute::>().unwrap()) + .filter_map(|e| e.read_attribute_opt::>().unwrap()) .collect::>(); self.tx_result_codes .lock() diff --git a/crates/tests/src/integration/ledger_tests.rs b/crates/tests/src/integration/ledger_tests.rs index ae7ba59e074..846a39ae603 100644 --- a/crates/tests/src/integration/ledger_tests.rs +++ b/crates/tests/src/integration/ledger_tests.rs @@ -16,6 +16,7 @@ use namada_core::hash::Hash; use namada_core::storage::{DbColFam, Key}; use namada_core::token::NATIVE_MAX_DECIMAL_PLACES; use namada_node::shell::testing::client::run; +use namada_node::shell::testing::node::NodeResults; use namada_node::shell::testing::utils::{Bin, CapturedOutput}; use namada_node::shell::SnapshotSync; use namada_node::storage::DbSnapshot; @@ -1708,8 +1709,28 @@ fn enforce_fee_payment() -> Result<()> { node.clear_results(); node.submit_txs(txs); // If empty than failed in process proposal - assert!(!node.tx_result_codes.lock().unwrap().is_empty()); - node.assert_success(); + let codes = node.tx_result_codes.lock().unwrap(); + assert!(!codes.is_empty()); + + for code in codes.iter() { + assert!(matches!(code, NodeResults::Ok)); + } + + let results = node.tx_results.lock().unwrap(); + // We submitted two batches + assert_eq!(results.len(), 2); + let first_result = &results[0]; + let second_result = &results[1]; + + // The batches should contain a single inner tx each + assert_eq!(first_result.0.len(), 1); + assert_eq!(second_result.0.len(), 1); + + // First transaction pay fees but then fails on the token transfer because + // of a lack of funds + assert!(first_result.are_any_err()); + // Second transaction is correctly applied + assert!(second_result.are_results_successfull()); // Assert balances let captured = CapturedOutput::of(|| { @@ -1728,7 +1749,7 @@ fn enforce_fee_payment() -> Result<()> { ) }); assert!(captured.result.is_ok()); - // This is the result of the two fee payemnts and the successful transfer to + // This is the result of the two fee payments and the successful transfer to // Christel assert!(captured.contains("nam: 1799950")); @@ -1750,7 +1771,7 @@ fn enforce_fee_payment() -> Result<()> { assert!(captured.result.is_ok()); // Bertha must not receive anything because the transaction fails. This is // because we evaluate fee payments before the inner transactions, so by the - // time we execute the transfer, Albert doesn't have enough funds anynmore + // time we execute the transfer, Albert doesn't have enough funds anymore assert!(captured.contains("nam: 2000000")); let captured = CapturedOutput::of(|| {