core: fix benchmark tests (#23803)

Fixes crashes in various benchmarks in the core package
This commit is contained in:
Martin Holst Swende
2021-10-27 13:08:51 +02:00
committed by GitHub
parent 526c3f6b9e
commit eab4d898fd
4 changed files with 51 additions and 20 deletions

View File

@ -51,7 +51,7 @@ func TestStrictTxListAdd(t *testing.T) {
}
}
func BenchmarkTxListAdd(t *testing.B) {
func BenchmarkTxListAdd(b *testing.B) {
// Generate a list of transactions to insert
key, _ := crypto.GenerateKey()
@ -60,11 +60,13 @@ func BenchmarkTxListAdd(t *testing.B) {
txs[i] = transaction(uint64(i), 0, key)
}
// Insert the transactions in a random order
list := newTxList(true)
priceLimit := big.NewInt(int64(DefaultTxPoolConfig.PriceLimit))
t.ResetTimer()
for _, v := range rand.Perm(len(txs)) {
list.Add(txs[v], DefaultTxPoolConfig.PriceBump)
list.Filter(priceLimit, DefaultTxPoolConfig.PriceBump)
b.ResetTimer()
for i := 0; i < b.N; i++ {
list := newTxList(true)
for _, v := range rand.Perm(len(txs)) {
list.Add(txs[v], DefaultTxPoolConfig.PriceBump)
list.Filter(priceLimit, DefaultTxPoolConfig.PriceBump)
}
}
}