Skip to content

Commit

Permalink
feat: use assert_eq for Ok MempoolResult
Browse files Browse the repository at this point in the history
Uses pretty_assertions, colored and formatted output.

commit-id:5dc07b7c
  • Loading branch information
Gilad Chase committed Jun 25, 2024
1 parent 71d556d commit c64d6cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions crates/mempool/src/mempool_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ fn test_add_tx(mut mempool: Mempool) {
let (tx_tip_80_address_2, account3) =
add_tx_input!(Tip(80), TransactionHash(StarkFelt::THREE), contract_address!("0x2"));

assert_matches!(mempool.add_tx(tx_tip_50_address_0.clone(), account1), Ok(()));
assert_matches!(mempool.add_tx(tx_tip_100_address_1.clone(), account2), Ok(()));
assert_matches!(mempool.add_tx(tx_tip_80_address_2.clone(), account3), Ok(()));
assert_eq!(mempool.add_tx(tx_tip_50_address_0.clone(), account1), Ok(()));
assert_eq!(mempool.add_tx(tx_tip_100_address_1.clone(), account2), Ok(()));
assert_eq!(mempool.add_tx(tx_tip_80_address_2.clone(), account3), Ok(()));

assert_eq!(mempool.state.len(), 3);
mempool.state.contains_key(&account1.sender_address);
Expand All @@ -145,7 +145,7 @@ fn test_add_same_tx(mut mempool: Mempool) {
let (tx, account) = add_tx_input!(Tip(50), TransactionHash(StarkFelt::ONE));
let same_tx = tx.clone();

assert_matches!(mempool.add_tx(tx.clone(), account), Ok(()));
assert_eq!(mempool.add_tx(tx.clone(), account), Ok(()));

assert_matches!(
mempool.add_tx(same_tx, account),
Expand All @@ -164,8 +164,8 @@ fn test_add_tx_with_identical_tip_succeeds(mut mempool: Mempool) {
let (tx2, account2) =
add_tx_input!(Tip(1), TransactionHash(StarkFelt::ONE), contract_address!("0x1"));

assert!(mempool.add_tx(tx1.clone(), account1).is_ok());
assert!(mempool.add_tx(tx2.clone(), account2).is_ok());
assert_eq!(mempool.add_tx(tx1.clone(), account1), Ok(()));
assert_eq!(mempool.add_tx(tx2.clone(), account2), Ok(()));

// TODO: currently hash comparison tie-breaks the two. Once more robust tie-breaks are added
// replace this assertion with a dedicated test.
Expand All @@ -181,7 +181,7 @@ fn test_tip_priority_over_tx_hash(mut mempool: Mempool) {
let (tx_small_tip_big_hash, account2) =
add_tx_input!(Tip(1), TransactionHash(StarkFelt::TWO), contract_address!("0x1"));

assert!(mempool.add_tx(tx_big_tip_small_hash.clone(), account1).is_ok());
assert!(mempool.add_tx(tx_small_tip_big_hash.clone(), account2).is_ok());
assert_eq!(mempool.add_tx(tx_big_tip_small_hash.clone(), account1), Ok(()));
assert_eq!(mempool.add_tx(tx_small_tip_big_hash.clone(), account2), Ok(()));
check_mempool_txs_eq(&mempool, &[tx_small_tip_big_hash, tx_big_tip_small_hash])
}
2 changes: 1 addition & 1 deletion crates/mempool_types/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use starknet_api::transaction::TransactionHash;
use thiserror::Error;

#[derive(Clone, Debug, Error)]
#[derive(Clone, Debug, Error, PartialEq, Eq)]
pub enum MempoolError {
#[error("Duplicate transaction, with hash: {tx_hash}")]
DuplicateTransaction { tx_hash: TransactionHash },
Expand Down

0 comments on commit c64d6cc

Please sign in to comment.