@@ -11,31 +11,31 @@ use starknet_mempool_types::mempool_types::{Account, ThinTransaction};
11
11
12
12
use crate :: mempool:: { Mempool , MempoolInput , TransactionReference } ;
13
13
14
- /// Creates a valid input for mempool's `add_tx` with optional default value for
15
- /// `sender_address`.
14
+ /// Creates a valid input for mempool's `add_tx` with optional default values.
16
15
/// Usage:
17
- /// 1. add_tx_input!(tip, tx_hash, address, nonce)
18
- /// 2. add_tx_input!(tip, tx_hash, address)
19
- /// 3. add_tx_input!(tip, tx_hash)
16
+ /// 1. add_tx_input!(tip: 1 , tx_hash: StarkFelt::TWO , address: "0x3" , nonce: 4 )
17
+ /// 2. add_tx_input!(tip: 1 , tx_hash: StarkFelt::TWO , address: "0x3" )
18
+ /// 3. add_tx_input!(tip:1 , tx_hash: StarkFelt::TWO )
20
19
macro_rules! add_tx_input {
21
- // Pattern for all four arguments
22
- ( $tip: expr, $tx_hash: expr, $sender_address: expr, $nonce: expr) => { {
23
- let account = Account { sender_address: $sender_address, ..Default :: default ( ) } ;
20
+ // Pattern for all four arguments with keyword arguments.
21
+ ( tip: $tip: expr, tx_hash: $tx_hash: expr, sender_address: $sender_address: expr, nonce: $nonce: expr) => { {
22
+ let sender_address = contract_address!( $sender_address) ;
23
+ let account = Account { sender_address, ..Default :: default ( ) } ;
24
24
let tx = ThinTransaction {
25
- tip: $tip,
26
- tx_hash: $tx_hash,
27
- sender_address: $sender_address ,
28
- nonce: $nonce,
25
+ tip: Tip ( $tip) ,
26
+ tx_hash: TransactionHash ( $tx_hash) ,
27
+ sender_address,
28
+ nonce: Nonce :: from ( $nonce) ,
29
29
} ;
30
30
MempoolInput { tx, account }
31
31
} } ;
32
- // Pattern for three arguments: tip, tx_hash, address
33
- ( $tip: expr, $tx_hash: expr, $address : expr) => {
34
- add_tx_input!( $tip, $tx_hash, $address , Nonce :: default ( ) )
32
+ // Pattern for three arguments.
33
+ ( tip : $tip: expr, tx_hash : $tx_hash: expr, sender_address : $sender_address : expr) => {
34
+ add_tx_input!( tip : $tip, tx_hash : $tx_hash, sender_address : $sender_address , nonce : Nonce :: default ( ) )
35
35
} ;
36
- // Pattern for two arguments: tip, tx_hash
37
- ( $tip: expr, $tx_hash: expr) => {
38
- add_tx_input!( $tip, $tx_hash, ContractAddress :: default ( ) , Nonce :: default ( ) )
36
+ // Pattern for two arguments.
37
+ ( tip : $tip: expr, tx_hash : $tx_hash: expr) => {
38
+ add_tx_input!( tip : $tip, tx_hash : $tx_hash, sender_address : ContractAddress :: default ( ) , nonce : Nonce :: default ( ) )
39
39
} ;
40
40
}
41
41
@@ -63,11 +63,11 @@ fn check_mempool_txs_eq(mempool: &Mempool, expected_txs: &[ThinTransaction]) {
63
63
#[ case( 5 ) ] // Requesting more transactions than are in the queue
64
64
#[ case( 2 ) ] // Requesting fewer transactions than are in the queue
65
65
fn test_get_txs ( #[ case] requested_txs : usize ) {
66
- let input_tip_50_address_0 = add_tx_input ! ( Tip ( 50 ) , TransactionHash ( StarkFelt :: ONE ) ) ;
66
+ let input_tip_50_address_0 = add_tx_input ! ( tip : 50 , tx_hash : StarkFelt :: ONE ) ;
67
67
let input_tip_100_address_1 =
68
- add_tx_input ! ( Tip ( 100 ) , TransactionHash ( StarkFelt :: TWO ) , contract_address! ( "0x1" ) ) ;
68
+ add_tx_input ! ( tip : 100 , tx_hash : StarkFelt :: TWO , sender_address : "0x1" ) ;
69
69
let input_tip_10_address_2 =
70
- add_tx_input ! ( Tip ( 10 ) , TransactionHash ( StarkFelt :: THREE ) , contract_address! ( "0x2" ) ) ;
70
+ add_tx_input ! ( tip : 10 , tx_hash : StarkFelt :: THREE , sender_address : "0x2" ) ;
71
71
72
72
let mut mempool = Mempool :: new ( [
73
73
input_tip_50_address_0. clone ( ) ,
@@ -94,11 +94,11 @@ fn test_get_txs(#[case] requested_txs: usize) {
94
94
95
95
#[ rstest]
96
96
fn test_add_tx ( mut mempool : Mempool ) {
97
- let input_tip_50_address_0 = add_tx_input ! ( Tip ( 50 ) , TransactionHash ( StarkFelt :: ONE ) ) ;
97
+ let input_tip_50_address_0 = add_tx_input ! ( tip : 50 , tx_hash : StarkFelt :: ONE ) ;
98
98
let input_tip_100_address_1 =
99
- add_tx_input ! ( Tip ( 100 ) , TransactionHash ( StarkFelt :: TWO ) , contract_address! ( "0x1" ) ) ;
99
+ add_tx_input ! ( tip : 100 , tx_hash : StarkFelt :: TWO , sender_address : "0x1" ) ;
100
100
let input_tip_80_address_2 =
101
- add_tx_input ! ( Tip ( 80 ) , TransactionHash ( StarkFelt :: THREE ) , contract_address! ( "0x2" ) ) ;
101
+ add_tx_input ! ( tip : 80 , tx_hash : StarkFelt :: THREE , sender_address : "0x2" ) ;
102
102
103
103
assert_eq ! ( mempool. add_tx( input_tip_50_address_0. clone( ) ) , Ok ( ( ) ) ) ;
104
104
assert_eq ! ( mempool. add_tx( input_tip_100_address_1. clone( ) ) , Ok ( ( ) ) ) ;
@@ -111,7 +111,7 @@ fn test_add_tx(mut mempool: Mempool) {
111
111
112
112
#[ rstest]
113
113
fn test_add_same_tx ( mut mempool : Mempool ) {
114
- let input = add_tx_input ! ( Tip ( 50 ) , TransactionHash ( StarkFelt :: ONE ) ) ;
114
+ let input = add_tx_input ! ( tip : 50 , tx_hash : StarkFelt :: ONE ) ;
115
115
let same_input = input. clone ( ) ;
116
116
117
117
assert_eq ! ( mempool. add_tx( input) , Ok ( ( ) ) ) ;
@@ -126,11 +126,11 @@ fn test_add_same_tx(mut mempool: Mempool) {
126
126
127
127
#[ rstest]
128
128
fn test_add_tx_with_identical_tip_succeeds ( mut mempool : Mempool ) {
129
- let input1 = add_tx_input ! ( Tip ( 1 ) , TransactionHash ( StarkFelt :: TWO ) ) ;
129
+ let input1 = add_tx_input ! ( tip : 1 , tx_hash : StarkFelt :: TWO ) ;
130
130
131
131
// Create a transaction with identical tip, it should be allowed through since the priority
132
132
// queue tie-breaks identical tips by other tx-unique identifiers (for example tx hash).
133
- let input2 = add_tx_input ! ( Tip ( 1 ) , TransactionHash ( StarkFelt :: ONE ) , contract_address! ( "0x1" ) ) ;
133
+ let input2 = add_tx_input ! ( tip : 1 , tx_hash : StarkFelt :: ONE , sender_address : "0x1" ) ;
134
134
135
135
assert_eq ! ( mempool. add_tx( input1. clone( ) ) , Ok ( ( ) ) ) ;
136
136
assert_eq ! ( mempool. add_tx( input2. clone( ) ) , Ok ( ( ) ) ) ;
@@ -142,12 +142,12 @@ fn test_add_tx_with_identical_tip_succeeds(mut mempool: Mempool) {
142
142
143
143
#[ rstest]
144
144
fn test_tip_priority_over_tx_hash ( mut mempool : Mempool ) {
145
- let input_big_tip_small_hash = add_tx_input ! ( Tip ( 2 ) , TransactionHash ( StarkFelt :: ONE ) ) ;
145
+ let input_big_tip_small_hash = add_tx_input ! ( tip : 2 , tx_hash : StarkFelt :: ONE ) ;
146
146
147
147
// Create a transaction with identical tip, it should be allowed through since the priority
148
148
// queue tie-breaks identical tips by other tx-unique identifiers (for example tx hash).
149
149
let input_small_tip_big_hash =
150
- add_tx_input ! ( Tip ( 1 ) , TransactionHash ( StarkFelt :: TWO ) , contract_address! ( "0x1" ) ) ;
150
+ add_tx_input ! ( tip : 1 , tx_hash : StarkFelt :: TWO , sender_address : "0x1" ) ;
151
151
152
152
assert_eq ! ( mempool. add_tx( input_big_tip_small_hash. clone( ) ) , Ok ( ( ) ) ) ;
153
153
assert_eq ! ( mempool. add_tx( input_small_tip_big_hash. clone( ) ) , Ok ( ( ) ) ) ;
0 commit comments