From fe8aea421656e467f2054fc778e4691a81154991 Mon Sep 17 00:00:00 2001 From: brentstone Date: Mon, 24 Jun 2024 22:33:45 -0700 Subject: [PATCH] fixup! Merge branch 'tiago/uniquely-identify-inner-txs' (#3416) --- crates/node/src/shell/finalize_block.rs | 28 +++++-------------------- crates/tx/src/data/mod.rs | 18 ++++++++++++++++ 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/crates/node/src/shell/finalize_block.rs b/crates/node/src/shell/finalize_block.rs index 15c3f257f2..baa91e6b76 100644 --- a/crates/node/src/shell/finalize_block.rs +++ b/crates/node/src/shell/finalize_block.rs @@ -5911,16 +5911,10 @@ mod test_finalize_block { // multiple tx results (2) let tx_results = event.read_attribute::>().unwrap(); - assert_eq!(tx_results.batch_results.0.len(), 2); + assert_eq!(tx_results.batch_results.len(), 2); // all txs should have succeeded - assert!( - tx_results - .batch_results - .0 - .values() - .all(|result| result.is_ok()) - ); + assert!(tx_results.batch_results.are_results_ok()); } #[test] @@ -5990,22 +5984,10 @@ mod test_finalize_block { // multiple tx results (2) let tx_results = event.read_attribute::>().unwrap(); - assert_eq!(tx_results.batch_results.0.len(), 2); + assert_eq!(tx_results.batch_results.len(), 2); // check one succeeded and the other failed - assert!( - tx_results - .batch_results - .0 - .values() - .any(|result| result.is_ok()) - ); - assert!( - tx_results - .batch_results - .0 - .values() - .any(|result| result.is_err()) - ); + assert!(tx_results.batch_results.are_any_ok()); + assert!(tx_results.batch_results.are_any_err()); } } diff --git a/crates/tx/src/data/mod.rs b/crates/tx/src/data/mod.rs index 0f33d73930..6792acc83c 100644 --- a/crates/tx/src/data/mod.rs +++ b/crates/tx/src/data/mod.rs @@ -221,6 +221,24 @@ impl BatchResults { pub fn is_empty(&self) -> bool { self.0.is_empty() } + + /// Check if the collecction of inner tx results contains no errors. + #[inline] + pub fn are_results_ok(&self) -> bool { + self.iter().all(|(_, res)| res.is_ok()) + } + + /// Check if the collecction of inner tx results contains any ok results. + #[inline] + pub fn are_any_ok(&self) -> bool { + self.iter().any(|(_, res)| res.is_ok()) + } + + /// Check if the collecction of inner tx results contains any errors. + #[inline] + pub fn are_any_err(&self) -> bool { + self.iter().any(|(_, res)| res.is_err()) + } } /// Compute the hash of the some inner tx in a batch.