@@ -226,3 +226,83 @@ def test_tx_replacement(cronos_mempool):
226226 },
227227 )
228228 assert "has already been mined" in str (exc )
229+
230+
231+ @pytest .mark .flaky (max_runs = 3 )
232+ def test_multiple_tx_replacement (cronos_mempool ):
233+ w3 = cronos_mempool .w3
234+ cli = cronos_mempool .cosmos_cli ()
235+ base_fee = w3 .eth .get_block ("latest" )["baseFeePerGas" ]
236+ priority_fee = w3 .eth .max_priority_fee
237+ user1_nonce = get_account_nonce (w3 , key = KEYS ["validator" ])
238+ user2_nonce = get_account_nonce (w3 , key = KEYS ["validator2" ])
239+ user3_nonce = get_account_nonce (w3 , key = KEYS ["validator3" ])
240+ initial_balance = w3 .eth .get_balance (ADDRS ["community" ])
241+
242+ tx1 = {
243+ "to" : ADDRS ["community" ],
244+ "value" : 1 ,
245+ "maxFeePerGas" : base_fee + priority_fee ,
246+ "maxPriorityFeePerGas" : priority_fee ,
247+ "nonce" : user1_nonce ,
248+ "from" : ADDRS ["validator" ],
249+ }
250+ tx1_signed = sign_transaction (w3 , tx1 , key = KEYS ["validator" ])
251+ tx1_replaced = {
252+ "to" : ADDRS ["community" ],
253+ "value" : 2 ,
254+ "maxFeePerGas" : int ((base_fee + priority_fee ) * 1.15 ),
255+ "maxPriorityFeePerGas" : int (priority_fee * 1.15 ),
256+ "nonce" : user1_nonce ,
257+ "from" : ADDRS ["validator" ],
258+ }
259+ tx1_replaced_signed = sign_transaction (w3 , tx1_replaced , key = KEYS ["validator" ])
260+ tx1_replaced_again = {
261+ "to" : ADDRS ["community" ],
262+ "value" : 3 ,
263+ "maxFeePerGas" : int ((base_fee + priority_fee ) * 2 ),
264+ "maxPriorityFeePerGas" : int (priority_fee * 2 ),
265+ "nonce" : user1_nonce ,
266+ "from" : ADDRS ["validator" ],
267+ }
268+ tx1_replaced_again_signed = sign_transaction (
269+ w3 , tx1_replaced_again , key = KEYS ["validator" ]
270+ )
271+
272+ tx2 = {
273+ "to" : ADDRS ["community" ],
274+ "value" : 10 ,
275+ "maxFeePerGas" : base_fee + priority_fee ,
276+ "maxPriorityFeePerGas" : priority_fee ,
277+ "nonce" : user2_nonce ,
278+ "from" : ADDRS ["validator2" ],
279+ }
280+ tx2_signed = sign_transaction (w3 , tx2 , key = KEYS ["validator2" ])
281+ tx2_replaced = {
282+ "to" : ADDRS ["community" ],
283+ "value" : 11 ,
284+ "maxFeePerGas" : int ((base_fee + priority_fee ) * 2 ),
285+ "maxPriorityFeePerGas" : int (priority_fee * 2 ),
286+ "nonce" : user2_nonce ,
287+ "from" : ADDRS ["validator2" ],
288+ }
289+ tx2_replaced_signed = sign_transaction (w3 , tx2_replaced , key = KEYS ["validator2" ])
290+
291+ tx3 = {
292+ "to" : ADDRS ["community" ],
293+ "value" : 20 ,
294+ "maxFeePerGas" : base_fee + priority_fee ,
295+ "maxPriorityFeePerGas" : priority_fee ,
296+ "nonce" : user3_nonce ,
297+ "from" : ADDRS ["validator3" ],
298+ }
299+ tx3_signed = sign_transaction (w3 , tx3 , key = KEYS ["validator3" ])
300+
301+ w3 .eth .send_raw_transaction (tx1_signed .raw_transaction )
302+ w3 .eth .send_raw_transaction (tx1_replaced_signed .raw_transaction )
303+ w3 .eth .send_raw_transaction (tx1_replaced_again_signed .raw_transaction )
304+ w3 .eth .send_raw_transaction (tx2_signed .raw_transaction )
305+ w3 .eth .send_raw_transaction (tx2_replaced_signed .raw_transaction )
306+ w3 .eth .send_raw_transaction (tx3_signed .raw_transaction )
307+ wait_for_new_blocks (cli , 1 )
308+ assert w3 .eth .get_balance (ADDRS ["community" ]) == initial_balance + 34
0 commit comments