|
9 | 9 |
|
10 | 10 | "github.com/stretchr/testify/require"
|
11 | 11 |
|
| 12 | + abci "github.com/tendermint/tendermint/abci/types" |
12 | 13 | "github.com/tendermint/tendermint/config"
|
13 | 14 | "github.com/tendermint/tendermint/types"
|
14 | 15 | )
|
@@ -304,3 +305,60 @@ func TestPendingTxsPopTxsBad(t *testing.T) {
|
304 | 305 | // duplicate
|
305 | 306 | require.Panics(t, func() { pendingTxs.popTxsAtIndices([]int{2, 2}) })
|
306 | 307 | }
|
| 308 | + |
| 309 | +func TestPendingTxs_InsertCondition(t *testing.T) { |
| 310 | + mempoolCfg := config.TestMempoolConfig() |
| 311 | + |
| 312 | + // First test exceeding number of txs |
| 313 | + mempoolCfg.PendingSize = 2 |
| 314 | + |
| 315 | + pendingTxs := NewPendingTxs(mempoolCfg) |
| 316 | + |
| 317 | + // Transaction setup |
| 318 | + tx1 := &WrappedTx{ |
| 319 | + tx: types.Tx("tx1_data"), |
| 320 | + priority: 1, |
| 321 | + } |
| 322 | + tx1Size := tx1.Size() |
| 323 | + |
| 324 | + tx2 := &WrappedTx{ |
| 325 | + tx: types.Tx("tx2_data"), |
| 326 | + priority: 2, |
| 327 | + } |
| 328 | + tx2Size := tx2.Size() |
| 329 | + |
| 330 | + err := pendingTxs.Insert(tx1, &abci.ResponseCheckTxV2{}, TxInfo{}) |
| 331 | + require.Nil(t, err) |
| 332 | + |
| 333 | + err = pendingTxs.Insert(tx2, &abci.ResponseCheckTxV2{}, TxInfo{}) |
| 334 | + require.Nil(t, err) |
| 335 | + |
| 336 | + // Should fail due to pending store size limit |
| 337 | + tx3 := &WrappedTx{ |
| 338 | + tx: types.Tx("tx3_data_exceeding_pending_size"), |
| 339 | + priority: 3, |
| 340 | + } |
| 341 | + |
| 342 | + err = pendingTxs.Insert(tx3, &abci.ResponseCheckTxV2{}, TxInfo{}) |
| 343 | + require.NotNil(t, err) |
| 344 | + |
| 345 | + // Second test exceeding byte size condition |
| 346 | + mempoolCfg.PendingSize = 5 |
| 347 | + pendingTxs = NewPendingTxs(mempoolCfg) |
| 348 | + mempoolCfg.MaxPendingTxsBytes = int64(tx1Size + tx2Size) |
| 349 | + |
| 350 | + err = pendingTxs.Insert(tx1, &abci.ResponseCheckTxV2{}, TxInfo{}) |
| 351 | + require.Nil(t, err) |
| 352 | + |
| 353 | + err = pendingTxs.Insert(tx2, &abci.ResponseCheckTxV2{}, TxInfo{}) |
| 354 | + require.Nil(t, err) |
| 355 | + |
| 356 | + // Should fail due to exceeding max pending transaction bytes |
| 357 | + tx3 = &WrappedTx{ |
| 358 | + tx: types.Tx("tx3_small_but_exceeds_byte_limit"), |
| 359 | + priority: 3, |
| 360 | + } |
| 361 | + |
| 362 | + err = pendingTxs.Insert(tx3, &abci.ResponseCheckTxV2{}, TxInfo{}) |
| 363 | + require.NotNil(t, err) |
| 364 | +} |
0 commit comments