From 9f164a63263f08beecf9923682181f9b82aa0f6d Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Tue, 6 Feb 2024 13:41:49 +0100 Subject: [PATCH] core/txpool/legacypool: add testcase for expensive tx --- core/txpool/legacypool/list_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core/txpool/legacypool/list_test.go b/core/txpool/legacypool/list_test.go index b96bf9b45a..67256f63b7 100644 --- a/core/txpool/legacypool/list_test.go +++ b/core/txpool/legacypool/list_test.go @@ -17,9 +17,11 @@ package legacypool import ( + "math/big" "math/rand" "testing" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "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) { // Generate a list of transactions to insert key, _ := crypto.GenerateKey()