core/txpool/legacypool: add testcase for expensive tx

This commit is contained in:
Martin Holst Swende 2024-02-06 13:41:49 +01:00
parent bab22bc7a8
commit 9f164a6326
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0

View file

@ -17,9 +17,11 @@
package legacypool package legacypool
import ( import (
"math/big"
"math/rand" "math/rand"
"testing" "testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/holiman/uint256" "github.com/holiman/uint256"
@ -51,6 +53,21 @@ func TestStrictListAdd(t *testing.T) {
} }
} }
// TestListAddVeryExpensive tests adding txs which exceed 256 bits in cost. It is
// expected that the list does not panic.
func TestListAddVeryExpensive(t *testing.T) {
key, _ := crypto.GenerateKey()
list := newList(true)
for i := 0; i < 3; i++ {
value := big.NewInt(100)
gasprice, _ := new(big.Int).SetString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 0)
gaslimit := uint64(i)
tx, _ := types.SignTx(types.NewTransaction(uint64(i), common.Address{}, value, gaslimit, gasprice, nil), types.HomesteadSigner{}, key)
t.Logf("cost: %x bitlen: %d\n", tx.Cost(), tx.Cost().BitLen())
list.Add(tx, DefaultConfig.PriceBump)
}
}
func BenchmarkListAdd(b *testing.B) { func BenchmarkListAdd(b *testing.B) {
// Generate a list of transactions to insert // Generate a list of transactions to insert
key, _ := crypto.GenerateKey() key, _ := crypto.GenerateKey()