@@ -13,45 +13,42 @@ func TestTxsReplacement(t *testing.T) {
1313 testCases := []struct {
1414 name string
1515 actions []func (s TestSuite )
16- bypass bool
1716 }{
1817 {
1918 name : "single pending tx submitted to same nodes %s" ,
2019 actions : []func (s TestSuite ){
2120 func (s TestSuite ) {
2221 _ , err := s .SendTx (t , s .Node (0 ), "acc0" , 0 , s .BaseFee (), nil )
2322 require .NoError (t , err , "failed to send tx" )
24- tx2 , err := s .SendTx (t , s .Node (0 ), "acc0" , 0 , s .BaseFeeX2 (), big .NewInt (1 ))
23+ tx2 , err := s .SendTx (t , s .Node (1 ), "acc0" , 0 , s .BaseFeeX2 (), big .NewInt (1 ))
2524 require .NoError (t , err , "failed to send tx" )
2625
2726 s .SetExpPendingTxs (tx2 )
2827 },
2928 },
30- bypass : true ,
3129 },
3230 {
3331 name : "multiple pending txs submitted to same nodes %s" ,
3432 actions : []func (s TestSuite ){
3533 func (s TestSuite ) {
3634 _ , err := s .SendTx (t , s .Node (0 ), "acc0" , 0 , s .BaseFee (), nil )
3735 require .NoError (t , err , "failed to send tx" )
38- tx2 , err := s .SendTx (t , s .Node (0 ), "acc0" , 0 , s .BaseFeeX2 (), big .NewInt (1 ))
36+ tx2 , err := s .SendTx (t , s .Node (1 ), "acc0" , 0 , s .BaseFeeX2 (), big .NewInt (1 ))
3937 require .NoError (t , err , "failed to send tx" )
4038
41- _ , err = s .SendTx (t , s .Node (1 ), "acc0" , 1 , s .BaseFee (), nil )
39+ _ , err = s .SendTx (t , s .Node (0 ), "acc0" , 1 , s .BaseFee (), nil )
4240 require .NoError (t , err , "failed to send tx" )
4341 tx4 , err := s .SendTx (t , s .Node (1 ), "acc0" , 1 , s .BaseFeeX2 (), big .NewInt (1 ))
4442 require .NoError (t , err , "failed to send tx" )
4543
46- _ , err = s .SendTx (t , s .Node (2 ), "acc0" , 2 , s .BaseFee (), nil )
44+ _ , err = s .SendTx (t , s .Node (0 ), "acc0" , 2 , s .BaseFee (), nil )
4745 require .NoError (t , err , "failed to send tx" )
48- tx6 , err := s .SendTx (t , s .Node (2 ), "acc0" , 2 , s .BaseFeeX2 (), big .NewInt (1 ))
46+ tx6 , err := s .SendTx (t , s .Node (1 ), "acc0" , 2 , s .BaseFeeX2 (), big .NewInt (1 ))
4947 require .NoError (t , err , "failed to send tx" )
5048
5149 s .SetExpPendingTxs (tx2 , tx4 , tx6 )
5250 },
5351 },
54- bypass : true ,
5552 },
5653 {
5754 name : "single queued tx %s" ,
@@ -116,11 +113,6 @@ func TestTxsReplacement(t *testing.T) {
116113 TxType : suite .TxTypeEVM ,
117114 IsDynamicFeeTx : true ,
118115 },
119- {
120- Description : "Cosmos LegacyTx" ,
121- TxType : suite .TxTypeCosmos ,
122- IsDynamicFeeTx : false ,
123- },
124116 }
125117
126118 s := suite .NewSystemTestSuite (t )
@@ -131,10 +123,105 @@ func TestTxsReplacement(t *testing.T) {
131123 for _ , tc := range testCases {
132124 testName := fmt .Sprintf (tc .name , to .Description )
133125 t .Run (testName , func (t * testing.T ) {
134- if tc .bypass {
135- return
126+ s .BeforeEachCase (t )
127+ for _ , action := range tc .actions {
128+ action (s )
129+ s .AfterEachAction (t )
136130 }
131+ s .AfterEachCase (t )
132+ })
133+ }
134+ }
135+ }
136+
137+ func TestTxsReplacementWithCosmosTx (t * testing.T ) {
138+ testCases := []struct {
139+ name string
140+ actions []func (s TestSuite )
141+ }{
142+ {
143+ name : "single pending tx submitted to same nodes %s" ,
144+ actions : []func (s TestSuite ){
145+ func (s TestSuite ) {
146+ s .AwaitNBlocks (t , 2 )
147+
148+ // NOTE: Currently EVMD cannot handle tx reordering correctly when cosmos tx is used.
149+ // It is because of CheckTxHandler cannot handle errors from SigVerificationDecorator properly.
150+ // After modifying CheckTxHandler, we can also modify this test case
151+ // : high prio cosmos tx should replace low prio evm tx.
152+ tx1 , err := s .SendTx (t , s .Node (0 ), "acc0" , 0 , s .BaseFee (), nil )
153+ require .NoError (t , err , "failed to send tx" )
154+ _ , err = s .SendTx (t , s .Node (1 ), "acc0" , 0 , s .BaseFeeX2 (), big .NewInt (1 ))
155+ require .NoError (t , err , "failed to send tx" )
156+
157+ s .SetExpPendingTxs (tx1 )
158+ },
159+ },
160+ },
161+ {
162+ name : "multiple pending txs submitted to same nodes %s" ,
163+ actions : []func (s TestSuite ){
164+ func (s TestSuite ) {
165+ s .AwaitNBlocks (t , 2 )
166+
167+ // NOTE: Currently EVMD cannot handle tx reordering correctly when cosmos tx is used.
168+ // It is because of CheckTxHandler cannot handle errors from SigVerificationDecorator properly.
169+ // After modifying CheckTxHandler, we can also modify this test case
170+ // : high prio cosmos tx should replace low prio evm tx.
171+ tx1 , err := s .SendTx (t , s .Node (0 ), "acc0" , 0 , s .BaseFee (), nil )
172+ require .NoError (t , err , "failed to send tx" )
173+ _ , err = s .SendTx (t , s .Node (1 ), "acc0" , 0 , s .BaseFeeX2 (), big .NewInt (1 ))
174+ require .NoError (t , err , "failed to send tx" )
175+
176+ tx3 , err := s .SendTx (t , s .Node (0 ), "acc0" , 1 , s .BaseFee (), nil )
177+ require .NoError (t , err , "failed to send tx" )
178+ _ , err = s .SendTx (t , s .Node (1 ), "acc0" , 1 , s .BaseFeeX2 (), big .NewInt (1 ))
179+ require .NoError (t , err , "failed to send tx" )
180+
181+ tx5 , err := s .SendTx (t , s .Node (0 ), "acc0" , 2 , s .BaseFee (), nil )
182+ require .NoError (t , err , "failed to send tx" )
183+ _ , err = s .SendTx (t , s .Node (1 ), "acc0" , 2 , s .BaseFeeX2 (), big .NewInt (1 ))
184+ require .NoError (t , err , "failed to send tx" )
137185
186+ s .SetExpPendingTxs (tx1 , tx3 , tx5 )
187+ },
188+ },
189+ },
190+ {
191+ name : "single queued tx %s" ,
192+ actions : []func (s TestSuite ){
193+ func (s TestSuite ) {
194+ // Cosmos txs are not queued in local mempool
195+ _ , err := s .SendTx (t , s .Node (0 ), "acc0" , 1 , s .BaseFee (), nil )
196+ require .NoError (t , err , "failed to send tx" )
197+ _ , err = s .SendTx (t , s .Node (0 ), "acc0" , 1 , s .BaseFeeX2 (), big .NewInt (1 ))
198+ require .NoError (t , err , "failed to send tx" )
199+ },
200+ func (s TestSuite ) {
201+ txHash , err := s .SendTx (t , s .Node (1 ), "acc0" , 0 , s .BaseFee (), nil )
202+ require .NoError (t , err , "failed to send tx" )
203+
204+ s .SetExpPendingTxs (txHash )
205+ },
206+ },
207+ },
208+ }
209+
210+ testOptions := []* suite.TestOptions {
211+ {
212+ Description : "Cosmos LegacyTx" ,
213+ TxType : suite .TxTypeCosmos ,
214+ },
215+ }
216+
217+ s := suite .NewSystemTestSuite (t )
218+ s .SetupTest (t )
219+
220+ for _ , to := range testOptions {
221+ s .SetOptions (to )
222+ for _ , tc := range testCases {
223+ testName := fmt .Sprintf (tc .name , to .Description )
224+ t .Run (testName , func (t * testing.T ) {
138225 s .BeforeEachCase (t )
139226 for _ , action := range tc .actions {
140227 action (s )
@@ -150,63 +237,63 @@ func TestMixedTxsReplacementEVMAndCosmos(t *testing.T) {
150237 testCases := []struct {
151238 name string
152239 actions []func (s TestSuite )
153- bypass bool
154240 }{
155241 {
156242 name : "single pending tx (low prio evm tx first) %s" ,
157243 actions : []func (s TestSuite ){
158244 func (s TestSuite ) {
159- _ , err := s .SendEthTx (t , s .Node (0 ), "acc0" , 0 , s .BaseFee (), nil )
245+ s .AwaitNBlocks (t , 2 )
246+
247+ tx1 , err := s .SendEthTx (t , s .Node (0 ), "acc0" , 0 , s .BaseFee (), s .BaseFee ())
160248 require .NoError (t , err , "failed to send tx" )
161- tx2 , err := s .SendCosmosTx (t , s .Node (0 ), "acc0" , 0 , s .BaseFeeX2 (), big .NewInt (1 ))
249+
250+ baseFeeX20 := new (big.Int ).Mul (s .BaseFeeX2 (), big .NewInt (1000000000000000000 ))
251+ _ , err = s .SendCosmosTx (t , s .Node (1 ), "acc0" , 0 , baseFeeX20 , nil )
162252 require .NoError (t , err , "failed to send tx" )
163253
164- s .SetExpPendingTxs (tx2 )
254+ s .SetExpPendingTxs (tx1 )
165255 },
166256 },
167- bypass : true ,
168257 },
169258 {
170259 name : "single pending tx (high prio evm tx first) %s" ,
171260 actions : []func (s TestSuite ){
172261 func (s TestSuite ) {
173- tx1 , err := s .SendEthTx (t , s .Node (0 ), "acc0" , 0 , s .BaseFeeX2 (), big . NewInt ( 1 ))
262+ tx1 , err := s .SendEthTx (t , s .Node (0 ), "acc0" , 0 , s .BaseFeeX2 (), s . BaseFeeX2 ( ))
174263 require .NoError (t , err , "failed to send tx" )
175- _ , err = s .SendCosmosTx (t , s .Node (0 ), "acc0" , 0 , s .BaseFee (), nil )
264+ _ , err = s .SendCosmosTx (t , s .Node (1 ), "acc0" , 0 , s .BaseFee (), nil )
176265 require .NoError (t , err , "failed to send tx" )
177266
178267 s .SetExpPendingTxs (tx1 )
179268 },
180269 },
181- bypass : true ,
182270 },
183271 {
184272 name : "single pending tx (low prio cosmos tx first) %s" ,
185273 actions : []func (s TestSuite ){
186274 func (s TestSuite ) {
187275 _ , err := s .SendCosmosTx (t , s .Node (0 ), "acc0" , 0 , s .BaseFee (), nil )
188276 require .NoError (t , err , "failed to send tx" )
189- tx2 , err := s .SendEthTx (t , s .Node (0 ), "acc0" , 0 , s .BaseFeeX2 (), big . NewInt ( 1 ))
277+ tx2 , err := s .SendEthTx (t , s .Node (1 ), "acc0" , 0 , s .BaseFeeX2 (), s . BaseFeeX2 ( ))
190278 require .NoError (t , err , "failed to send tx" )
191279
192280 s .SetExpPendingTxs (tx2 )
193281 },
194282 },
195- bypass : true ,
196283 },
197284 {
198285 name : "single pending tx (high prio cosmos tx first) %s" ,
199286 actions : []func (s TestSuite ){
200287 func (s TestSuite ) {
201- tx1 , err := s .SendCosmosTx (t , s .Node (0 ), "acc0" , 0 , s .BaseFeeX2 (), big .NewInt (1 ))
288+ baseFeeX20 := new (big.Int ).Mul (s .BaseFeeX2 (), big .NewInt (10 ))
289+ tx1 , err := s .SendCosmosTx (t , s .Node (0 ), "acc0" , 0 , baseFeeX20 , nil )
202290 require .NoError (t , err , "failed to send tx" )
203291 _ , err = s .SendEthTx (t , s .Node (0 ), "acc0" , 0 , s .BaseFee (), nil )
204292 require .NoError (t , err , "failed to send tx" )
205293
206294 s .SetExpPendingTxs (tx1 )
207295 },
208296 },
209- bypass : true ,
210297 },
211298 {
212299 name : "single queued tx (low prio evm tx first) %s" ,
@@ -256,7 +343,7 @@ func TestMixedTxsReplacementEVMAndCosmos(t *testing.T) {
256343 func (s TestSuite ) {
257344 _ , err := s .SendCosmosTx (t , s .Node (0 ), "acc0" , 1 , s .BaseFee (), nil )
258345 require .NoError (t , err , "failed to send tx" )
259- tx2 , err := s .SendEthTx (t , s .Node (0 ), "acc0" , 1 , s .BaseFeeX2 (), big . NewInt ( 1 ))
346+ tx2 , err := s .SendEthTx (t , s .Node (0 ), "acc0" , 1 , s .BaseFeeX2 (), s . BaseFeeX2 ( ))
260347 require .NoError (t , err , "failed to send tx" )
261348
262349 // CosmosTx is not queued in local mempool
@@ -312,10 +399,6 @@ func TestMixedTxsReplacementEVMAndCosmos(t *testing.T) {
312399 for _ , tc := range testCases {
313400 testName := fmt .Sprintf (tc .name , to .Description )
314401 t .Run (testName , func (t * testing.T ) {
315- if tc .bypass {
316- return
317- }
318-
319402 s .BeforeEachCase (t )
320403 for _ , action := range tc .actions {
321404 action (s )
@@ -331,7 +414,6 @@ func TestMixedTxsReplacementLegacyAndDynamicFee(t *testing.T) {
331414 testCases := []struct {
332415 name string
333416 actions []func (s TestSuite )
334- bypass bool
335417 }{
336418 {
337419 name : "dynamic fee tx should not replace legacy tx" ,
@@ -410,10 +492,6 @@ func TestMixedTxsReplacementLegacyAndDynamicFee(t *testing.T) {
410492
411493 for _ , tc := range testCases {
412494 t .Run (tc .name , func (t * testing.T ) {
413- if tc .bypass {
414- return
415- }
416-
417495 s .BeforeEachCase (t )
418496 for _ , action := range tc .actions {
419497 action (s )
0 commit comments