eth: fix test

This commit is contained in:
Gary Rong 2025-04-14 20:04:43 +08:00
parent eb25e657e7
commit 492003943f

View file

@ -20,9 +20,7 @@ import (
"context" "context"
"crypto/ecdsa" "crypto/ecdsa"
"errors" "errors"
"fmt"
"math/big" "math/big"
"path/filepath"
"testing" "testing"
"time" "time"
@ -68,8 +66,7 @@ func initBackend(t *testing.T, withLocal bool) *EthAPIBackend {
txconfig := legacypool.DefaultConfig txconfig := legacypool.DefaultConfig
txconfig.Journal = "" // Don't litter the disk with test journals txconfig.Journal = "" // Don't litter the disk with test journals
dir := filepath.Join(t.TempDir(), fmt.Sprintf("withLocal%t", withLocal)) blobPool := blobpool.New(blobpool.Config{Datadir: t.TempDir()}, chain, nil)
blobPool := blobpool.New(blobpool.Config{Datadir: dir}, chain, nil)
legacyPool := legacypool.New(txconfig, chain) legacyPool := legacypool.New(txconfig, chain)
txpool, _ := txpool.New(txconfig.PriceLimit, chain, []txpool.SubPool{legacyPool, blobPool}) txpool, _ := txpool.New(txconfig.PriceLimit, chain, []txpool.SubPool{legacyPool, blobPool})
@ -129,29 +126,32 @@ func pricedSetCodeTxWithAuth(nonce uint64, gaslimit uint64, gasFee, tip *uint256
}) })
} }
func TestLocalTxSend(t *testing.T) { func TestSendTx(t *testing.T) {
for _, withLocal := range []bool{false, true} { testSendTx(t, false)
b := initBackend(t, withLocal) testSendTx(t, true)
}
txA := pricedSetCodeTx(0, 250000, uint256.NewInt(params.GWei), uint256.NewInt(params.GWei), key, []unsignedAuth{ func testSendTx(t *testing.T, withLocal bool) {
{ b := initBackend(t, withLocal)
nonce: 0,
key: key,
},
})
b.SendTx(context.Background(), txA)
txB := makeTx(1, nil, nil, key) txA := pricedSetCodeTx(0, 250000, uint256.NewInt(params.GWei), uint256.NewInt(params.GWei), key, []unsignedAuth{
err := b.SendTx(context.Background(), txB) {
nonce: 0,
key: key,
},
})
b.SendTx(context.Background(), txA)
if withLocal { txB := makeTx(1, nil, nil, key)
if err != nil { err := b.SendTx(context.Background(), txB)
t.Fatalf("Unexpected error sending tx: %v", err)
} if withLocal {
} else { if err != nil {
if !errors.Is(err, txpool.ErrInflightTxLimitReached) { t.Fatalf("Unexpected error sending tx: %v", err)
t.Fatalf("Unexpected error, want: %v, got: %v", txpool.ErrInflightTxLimitReached, err) }
} } else {
if !errors.Is(err, txpool.ErrInflightTxLimitReached) {
t.Fatalf("Unexpected error, want: %v, got: %v", txpool.ErrInflightTxLimitReached, err)
} }
} }
} }