Skip to content

Commit

Permalink
chore: added test cases for ReapMaxBytesMaxGasMaxTxs
Browse files Browse the repository at this point in the history
  • Loading branch information
iproudhon committed Sep 14, 2021
1 parent f7909ff commit 7541a6d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
12 changes: 11 additions & 1 deletion consensus/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,17 @@ func TestMempoolRmBadTx(t *testing.T) {

// check for the tx
for {
txs := assertMempool(cs.txNotifier).ReapMaxBytesMaxGas(int64(len(txBytes)), -1)
txs := assertMempool(cs.txNotifier).ReapMaxTxs(1)
if len(txs) == 0 {
emptyMempoolCh <- struct{}{}
return
}
txs = assertMempool(cs.txNotifier).ReapMaxBytesMaxGasMaxTxs(int64(len(txBytes)), -1, 1)
if len(txs) == 0 {
emptyMempoolCh <- struct{}{}
return
}
txs = assertMempool(cs.txNotifier).ReapMaxBytesMaxGas(int64(len(txBytes)), -1)
if len(txs) == 0 {
emptyMempoolCh <- struct{}{}
return
Expand Down
41 changes: 25 additions & 16 deletions mempool/clist_mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,26 +114,35 @@ func TestReapMaxBytesMaxGas(t *testing.T) {
maxBytes int64
maxGas int64
expectedNumTxs int
maxTxs int64
}{
{20, -1, -1, 20},
{20, -1, 0, 0},
{20, -1, 10, 10},
{20, -1, 30, 20},
{20, 0, -1, 0},
{20, 0, 10, 0},
{20, 10, 10, 0},
{20, 24, 10, 1},
{20, 240, 5, 5},
{20, 240, -1, 10},
{20, 240, 10, 10},
{20, 240, 15, 10},
{20, 20000, -1, 20},
{20, 20000, 5, 5},
{20, 20000, 30, 20},
{20, -1, -1, 20, 0},
{20, -1, 0, 0, 0},
{20, -1, 10, 10, 0},
{20, -1, 30, 20, 0},
{20, 0, -1, 0, 0},
{20, 0, 10, 0, 0},
{20, 10, 10, 0, 0},
{20, 24, 10, 1, 0},
{20, 240, 5, 5, 0},
{20, 240, -1, 10, 0},
{20, 240, 10, 10, 0},
{20, 240, 15, 10, 0},
{20, 20000, -1, 20, 0},
{20, 20000, 5, 5, 0},
{20, 20000, 30, 20, 0},
{20, 20000, 30, 20, 0},
{20, 20000, 30, 10, 10},
{20, 20000, 30, 20, 100},
}
for tcIndex, tt := range tests {
checkTxs(t, mempool, tt.numTxsToCreate, UnknownPeerID)
got := mempool.ReapMaxBytesMaxGas(tt.maxBytes, tt.maxGas)
var got types.Txs
if tt.maxTxs <= 0 {
got = mempool.ReapMaxBytesMaxGas(tt.maxBytes, tt.maxGas)
} else {
got = mempool.ReapMaxBytesMaxGasMaxTxs(tt.maxBytes, tt.maxGas, tt.maxTxs)
}
assert.Equal(t, tt.expectedNumTxs, len(got), "Got %d txs, expected %d, tc #%d",
len(got), tt.expectedNumTxs, tcIndex)
mempool.Flush()
Expand Down

0 comments on commit 7541a6d

Please sign in to comment.