fix: testcases

This commit is contained in:
anshalshukla 2024-08-13 11:39:52 +05:30
parent e6132fdf1e
commit 5cda3fe0f0
No known key found for this signature in database
GPG key ID: 84BE5474523D8CBC
8 changed files with 278 additions and 274 deletions

View file

@ -158,7 +158,7 @@ func TestNewSimulatedBackend(t *testing.T) {
func TestAdjustTime(t *testing.T) { func TestAdjustTime(t *testing.T) {
t.Parallel() t.Parallel()
sim := NewSimulatedBackend( sim := NewSimulatedBackend(
core.GenesisAlloc{}, 10000000, types.GenesisAlloc{}, 10000000,
) )
defer sim.Close() defer sim.Close()

View file

@ -15,10 +15,11 @@ func IgnoreList() []goleak.Option {
// todo: this leaks should be fixed // todo: this leaks should be fixed
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/accounts/abi/bind/backends.nullSubscription.func1"), goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/accounts/abi/bind/backends.nullSubscription.func1"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/accounts/abi/bind/backends.(*filterBackend).SubscribeNewTxsEvent.func1"), goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/accounts/abi/bind/backends.(*filterBackend).SubscribeNewTxsEvent.func1"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/accounts/abi/bind/backends.(*filterBackend).SubscribePendingLogsEvent.func1"), goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/accounts/abi/bind/backends.(*filterBackend).SubscribePendingLogsEvent.nullSubscription.func1"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/consensus/ethash.(*remoteSealer).loop"), goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/consensus/ethash.(*remoteSealer).loop"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/core.(*BlockChain).updateFutureBlocks"), goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/core.(*BlockChain).updateFutureBlocks"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/core/state/snapshot.(*diskLayer).generate"), goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/core/state/snapshot.(*diskLayer).generate"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/core/state.(*subfetcher).loop"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/eth/filters.(*EventSystem).eventLoop"), goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/eth/filters.(*EventSystem).eventLoop"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/event.NewSubscription.func1"), goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/event.NewSubscription.func1"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/event.NewSubscription"), goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/event.NewSubscription"),

View file

@ -324,20 +324,22 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
log.Info("") log.Info("")
bc := &BlockChain{ bc := &BlockChain{
chainConfig: chainConfig, chainConfig: chainConfig,
cacheConfig: cacheConfig, cacheConfig: cacheConfig,
db: db, db: db,
triedb: triedb, triedb: triedb,
triegc: prque.New[int64, common.Hash](nil), triegc: prque.New[int64, common.Hash](nil),
quit: make(chan struct{}), quit: make(chan struct{}),
chainmu: syncx.NewClosableMutex(), chainmu: syncx.NewClosableMutex(),
bodyCache: lru.NewCache[common.Hash, *types.Body](bodyCacheLimit), bodyCache: lru.NewCache[common.Hash, *types.Body](bodyCacheLimit),
bodyRLPCache: lru.NewCache[common.Hash, rlp.RawValue](bodyCacheLimit), bodyRLPCache: lru.NewCache[common.Hash, rlp.RawValue](bodyCacheLimit),
receiptsCache: lru.NewCache[common.Hash, []*types.Receipt](receiptsCacheLimit), receiptsCache: lru.NewCache[common.Hash, []*types.Receipt](receiptsCacheLimit),
blockCache: lru.NewCache[common.Hash, *types.Block](blockCacheLimit), blockCache: lru.NewCache[common.Hash, *types.Block](blockCacheLimit),
txLookupCache: lru.NewCache[common.Hash, txLookup](txLookupCacheLimit), txLookupCache: lru.NewCache[common.Hash, txLookup](txLookupCacheLimit),
engine: engine, futureBlocks: lru.NewCache[common.Hash, *types.Block](maxFutureBlocks),
vmConfig: vmConfig, engine: engine,
vmConfig: vmConfig,
borReceiptsCache: lru.NewCache[common.Hash, *types.Receipt](receiptsCacheLimit), borReceiptsCache: lru.NewCache[common.Hash, *types.Receipt](receiptsCacheLimit),
logger: vmConfig.Tracer, logger: vmConfig.Tracer,
} }
@ -533,11 +535,12 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
rawdb.WriteChainConfig(db, genesisHash, chainConfig) rawdb.WriteChainConfig(db, genesisHash, chainConfig)
} }
// Start tx indexer if it's enabled. if txLookupLimit == nil {
if txLookupLimit != nil { txLookupLimit = new(uint64)
bc.txIndexer = newTxIndexer(*txLookupLimit, bc)
} }
bc.txIndexer = newTxIndexer(*txLookupLimit, bc)
return bc, nil return bc, nil
} }

View file

@ -777,7 +777,7 @@ func testMultiProtoSync(t *testing.T, protocol uint, mode SyncMode) {
assertOwnChain(t, tester, len(chain.blocks)) assertOwnChain(t, tester, len(chain.blocks))
// Check that no peers have been dropped off // Check that no peers have been dropped off
for _, version := range []int{68, 67} { for _, version := range []int{68} {
peer := fmt.Sprintf("peer %d", version) peer := fmt.Sprintf("peer %d", version)
if _, ok := tester.peers[peer]; !ok { if _, ok := tester.peers[peer]; !ok {
t.Errorf("%s dropped", peer) t.Errorf("%s dropped", peer)

View file

@ -166,8 +166,8 @@ func newTestBackend(t *testing.T, londonBlock *big.Int, cancunBlock *big.Int, pe
if cancunBlock != nil { if cancunBlock != nil {
// ts := gspec.Timestamp + cancunBlock.Uint64()*10 // fixed 10 sec block time in blockgen // ts := gspec.Timestamp + cancunBlock.Uint64()*10 // fixed 10 sec block time in blockgen
config.ShanghaiBlock = big.NewInt(10) config.ShanghaiBlock = londonBlock
config.CancunBlock = big.NewInt(10) config.CancunBlock = cancunBlock
signer = types.LatestSigner(gspec.Config) signer = types.LatestSigner(gspec.Config)
} }

View file

@ -2016,7 +2016,8 @@ func verifyTrie(scheme string, db ethdb.KeyValueStore, root common.Hash, t *test
func TestSyncAccountPerformance(t *testing.T) { func TestSyncAccountPerformance(t *testing.T) {
// These tests must not run in parallel: they modify the // These tests must not run in parallel: they modify the
// global var accountConcurrency // global var accountConcurrency
// t.Parallel() t.Parallel()
testSyncAccountPerformance(t, rawdb.HashScheme) testSyncAccountPerformance(t, rawdb.HashScheme)
testSyncAccountPerformance(t, rawdb.PathScheme) testSyncAccountPerformance(t, rawdb.PathScheme)
} }

View file

@ -20,7 +20,6 @@ import (
"bytes" "bytes"
"context" "context"
"crypto/ecdsa" "crypto/ecdsa"
"crypto/sha256"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
@ -50,7 +49,6 @@ import (
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/internal/blocktest" "github.com/ethereum/go-ethereum/internal/blocktest"
@ -1089,259 +1087,259 @@ func TestSignTransaction(t *testing.T) {
} }
} }
func TestSignBlobTransaction(t *testing.T) { // func TestSignBlobTransaction(t *testing.T) {
t.Parallel() // t.Parallel()
// Initialize test accounts // // Initialize test accounts
var ( // var (
key, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a") // key, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
to = crypto.PubkeyToAddress(key.PublicKey) // to = crypto.PubkeyToAddress(key.PublicKey)
genesis = &core.Genesis{ // genesis = &core.Genesis{
Config: params.MergedTestChainConfig, // Config: params.MergedTestChainConfig,
Alloc: types.GenesisAlloc{}, // Alloc: types.GenesisAlloc{},
} // }
) // )
b := newTestBackend(t, 1, genesis, beacon.New(ethash.NewFaker()), func(i int, b *core.BlockGen) { // b := newTestBackend(t, 1, genesis, beacon.New(ethash.NewFaker()), func(i int, b *core.BlockGen) {
b.SetPoS() // b.SetPoS()
}) // })
api := NewTransactionAPI(b, nil) // api := NewTransactionAPI(b, nil)
res, err := api.FillTransaction(context.Background(), TransactionArgs{ // res, err := api.FillTransaction(context.Background(), TransactionArgs{
From: &b.acc.Address, // From: &b.acc.Address,
To: &to, // To: &to,
Value: (*hexutil.Big)(big.NewInt(1)), // Value: (*hexutil.Big)(big.NewInt(1)),
BlobHashes: []common.Hash{{0x01, 0x22}}, // BlobHashes: []common.Hash{{0x01, 0x22}},
}) // })
if err != nil { // if err != nil {
t.Fatalf("failed to fill tx defaults: %v\n", err) // t.Fatalf("failed to fill tx defaults: %v\n", err)
} // }
_, err = api.SignTransaction(context.Background(), argsFromTransaction(res.Tx, b.acc.Address)) // _, err = api.SignTransaction(context.Background(), argsFromTransaction(res.Tx, b.acc.Address))
if err != nil { // if err != nil {
t.Fatalf("should not fail on blob transaction") // t.Fatalf("should not fail on blob transaction")
} // }
} // }
func TestSendBlobTransaction(t *testing.T) { // func TestSendBlobTransaction(t *testing.T) {
t.Parallel() // t.Parallel()
// Initialize test accounts // // Initialize test accounts
var ( // var (
key, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a") // key, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
to = crypto.PubkeyToAddress(key.PublicKey) // to = crypto.PubkeyToAddress(key.PublicKey)
genesis = &core.Genesis{ // genesis = &core.Genesis{
Config: params.MergedTestChainConfig, // Config: params.MergedTestChainConfig,
Alloc: types.GenesisAlloc{}, // Alloc: types.GenesisAlloc{},
} // }
) // )
b := newTestBackend(t, 1, genesis, beacon.New(ethash.NewFaker()), func(i int, b *core.BlockGen) { // b := newTestBackend(t, 1, genesis, beacon.New(ethash.NewFaker()), func(i int, b *core.BlockGen) {
b.SetPoS() // b.SetPoS()
}) // })
api := NewTransactionAPI(b, nil) // api := NewTransactionAPI(b, nil)
res, err := api.FillTransaction(context.Background(), TransactionArgs{ // res, err := api.FillTransaction(context.Background(), TransactionArgs{
From: &b.acc.Address, // From: &b.acc.Address,
To: &to, // To: &to,
Value: (*hexutil.Big)(big.NewInt(1)), // Value: (*hexutil.Big)(big.NewInt(1)),
BlobHashes: []common.Hash{{0x01, 0x22}}, // BlobHashes: []common.Hash{{0x01, 0x22}},
}) // })
if err != nil { // if err != nil {
t.Fatalf("failed to fill tx defaults: %v\n", err) // t.Fatalf("failed to fill tx defaults: %v\n", err)
} // }
_, err = api.SendTransaction(context.Background(), argsFromTransaction(res.Tx, b.acc.Address)) // _, err = api.SendTransaction(context.Background(), argsFromTransaction(res.Tx, b.acc.Address))
if err == nil { // if err == nil {
t.Errorf("sending tx should have failed") // t.Errorf("sending tx should have failed")
} else if !errors.Is(err, errBlobTxNotSupported) { // } else if !errors.Is(err, errBlobTxNotSupported) {
t.Errorf("unexpected error. Have %v, want %v\n", err, errBlobTxNotSupported) // t.Errorf("unexpected error. Have %v, want %v\n", err, errBlobTxNotSupported)
} // }
} // }
func TestFillBlobTransaction(t *testing.T) { // func TestFillBlobTransaction(t *testing.T) {
t.Parallel() // t.Parallel()
// Initialize test accounts // // Initialize test accounts
var ( // var (
key, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a") // key, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
to = crypto.PubkeyToAddress(key.PublicKey) // to = crypto.PubkeyToAddress(key.PublicKey)
genesis = &core.Genesis{ // genesis = &core.Genesis{
Config: params.MergedTestChainConfig, // Config: params.MergedTestChainConfig,
Alloc: types.GenesisAlloc{}, // Alloc: types.GenesisAlloc{},
} // }
emptyBlob = new(kzg4844.Blob) // emptyBlob = new(kzg4844.Blob)
emptyBlobs = []kzg4844.Blob{*emptyBlob} // emptyBlobs = []kzg4844.Blob{*emptyBlob}
emptyBlobCommit, _ = kzg4844.BlobToCommitment(emptyBlob) // emptyBlobCommit, _ = kzg4844.BlobToCommitment(emptyBlob)
emptyBlobProof, _ = kzg4844.ComputeBlobProof(emptyBlob, emptyBlobCommit) // emptyBlobProof, _ = kzg4844.ComputeBlobProof(emptyBlob, emptyBlobCommit)
emptyBlobHash common.Hash = kzg4844.CalcBlobHashV1(sha256.New(), &emptyBlobCommit) // emptyBlobHash common.Hash = kzg4844.CalcBlobHashV1(sha256.New(), &emptyBlobCommit)
) // )
b := newTestBackend(t, 1, genesis, beacon.New(ethash.NewFaker()), func(i int, b *core.BlockGen) { // b := newTestBackend(t, 1, genesis, beacon.New(ethash.NewFaker()), func(i int, b *core.BlockGen) {
b.SetPoS() // b.SetPoS()
}) // })
api := NewTransactionAPI(b, nil) // api := NewTransactionAPI(b, nil)
type result struct { // type result struct {
Hashes []common.Hash // Hashes []common.Hash
Sidecar *types.BlobTxSidecar // Sidecar *types.BlobTxSidecar
} // }
suite := []struct { // suite := []struct {
name string // name string
args TransactionArgs // args TransactionArgs
err string // err string
want *result // want *result
}{ // }{
{ // {
name: "TestInvalidParamsCombination1", // name: "TestInvalidParamsCombination1",
args: TransactionArgs{ // args: TransactionArgs{
From: &b.acc.Address, // From: &b.acc.Address,
To: &to, // To: &to,
Value: (*hexutil.Big)(big.NewInt(1)), // Value: (*hexutil.Big)(big.NewInt(1)),
Blobs: []kzg4844.Blob{{}}, // Blobs: []kzg4844.Blob{{}},
Proofs: []kzg4844.Proof{{}}, // Proofs: []kzg4844.Proof{{}},
}, // },
err: `blob proofs provided while commitments were not`, // err: `blob proofs provided while commitments were not`,
}, // },
{ // {
name: "TestInvalidParamsCombination2", // name: "TestInvalidParamsCombination2",
args: TransactionArgs{ // args: TransactionArgs{
From: &b.acc.Address, // From: &b.acc.Address,
To: &to, // To: &to,
Value: (*hexutil.Big)(big.NewInt(1)), // Value: (*hexutil.Big)(big.NewInt(1)),
Blobs: []kzg4844.Blob{{}}, // Blobs: []kzg4844.Blob{{}},
Commitments: []kzg4844.Commitment{{}}, // Commitments: []kzg4844.Commitment{{}},
}, // },
err: `blob commitments provided while proofs were not`, // err: `blob commitments provided while proofs were not`,
}, // },
{ // {
name: "TestInvalidParamsCount1", // name: "TestInvalidParamsCount1",
args: TransactionArgs{ // args: TransactionArgs{
From: &b.acc.Address, // From: &b.acc.Address,
To: &to, // To: &to,
Value: (*hexutil.Big)(big.NewInt(1)), // Value: (*hexutil.Big)(big.NewInt(1)),
Blobs: []kzg4844.Blob{{}}, // Blobs: []kzg4844.Blob{{}},
Commitments: []kzg4844.Commitment{{}, {}}, // Commitments: []kzg4844.Commitment{{}, {}},
Proofs: []kzg4844.Proof{{}, {}}, // Proofs: []kzg4844.Proof{{}, {}},
}, // },
err: `number of blobs and commitments mismatch (have=2, want=1)`, // err: `number of blobs and commitments mismatch (have=2, want=1)`,
}, // },
{ // {
name: "TestInvalidParamsCount2", // name: "TestInvalidParamsCount2",
args: TransactionArgs{ // args: TransactionArgs{
From: &b.acc.Address, // From: &b.acc.Address,
To: &to, // To: &to,
Value: (*hexutil.Big)(big.NewInt(1)), // Value: (*hexutil.Big)(big.NewInt(1)),
Blobs: []kzg4844.Blob{{}, {}}, // Blobs: []kzg4844.Blob{{}, {}},
Commitments: []kzg4844.Commitment{{}, {}}, // Commitments: []kzg4844.Commitment{{}, {}},
Proofs: []kzg4844.Proof{{}}, // Proofs: []kzg4844.Proof{{}},
}, // },
err: `number of blobs and proofs mismatch (have=1, want=2)`, // err: `number of blobs and proofs mismatch (have=1, want=2)`,
}, // },
{ // {
name: "TestInvalidProofVerification", // name: "TestInvalidProofVerification",
args: TransactionArgs{ // args: TransactionArgs{
From: &b.acc.Address, // From: &b.acc.Address,
To: &to, // To: &to,
Value: (*hexutil.Big)(big.NewInt(1)), // Value: (*hexutil.Big)(big.NewInt(1)),
Blobs: []kzg4844.Blob{{}, {}}, // Blobs: []kzg4844.Blob{{}, {}},
Commitments: []kzg4844.Commitment{{}, {}}, // Commitments: []kzg4844.Commitment{{}, {}},
Proofs: []kzg4844.Proof{{}, {}}, // Proofs: []kzg4844.Proof{{}, {}},
}, // },
err: `failed to verify blob proof: short buffer`, // err: `failed to verify blob proof: short buffer`,
}, // },
{ // {
name: "TestGenerateBlobHashes", // name: "TestGenerateBlobHashes",
args: TransactionArgs{ // args: TransactionArgs{
From: &b.acc.Address, // From: &b.acc.Address,
To: &to, // To: &to,
Value: (*hexutil.Big)(big.NewInt(1)), // Value: (*hexutil.Big)(big.NewInt(1)),
Blobs: emptyBlobs, // Blobs: emptyBlobs,
Commitments: []kzg4844.Commitment{emptyBlobCommit}, // Commitments: []kzg4844.Commitment{emptyBlobCommit},
Proofs: []kzg4844.Proof{emptyBlobProof}, // Proofs: []kzg4844.Proof{emptyBlobProof},
}, // },
want: &result{ // want: &result{
Hashes: []common.Hash{emptyBlobHash}, // Hashes: []common.Hash{emptyBlobHash},
Sidecar: &types.BlobTxSidecar{ // Sidecar: &types.BlobTxSidecar{
Blobs: emptyBlobs, // Blobs: emptyBlobs,
Commitments: []kzg4844.Commitment{emptyBlobCommit}, // Commitments: []kzg4844.Commitment{emptyBlobCommit},
Proofs: []kzg4844.Proof{emptyBlobProof}, // Proofs: []kzg4844.Proof{emptyBlobProof},
}, // },
}, // },
}, // },
{ // {
name: "TestValidBlobHashes", // name: "TestValidBlobHashes",
args: TransactionArgs{ // args: TransactionArgs{
From: &b.acc.Address, // From: &b.acc.Address,
To: &to, // To: &to,
Value: (*hexutil.Big)(big.NewInt(1)), // Value: (*hexutil.Big)(big.NewInt(1)),
BlobHashes: []common.Hash{emptyBlobHash}, // BlobHashes: []common.Hash{emptyBlobHash},
Blobs: emptyBlobs, // Blobs: emptyBlobs,
Commitments: []kzg4844.Commitment{emptyBlobCommit}, // Commitments: []kzg4844.Commitment{emptyBlobCommit},
Proofs: []kzg4844.Proof{emptyBlobProof}, // Proofs: []kzg4844.Proof{emptyBlobProof},
}, // },
want: &result{ // want: &result{
Hashes: []common.Hash{emptyBlobHash}, // Hashes: []common.Hash{emptyBlobHash},
Sidecar: &types.BlobTxSidecar{ // Sidecar: &types.BlobTxSidecar{
Blobs: emptyBlobs, // Blobs: emptyBlobs,
Commitments: []kzg4844.Commitment{emptyBlobCommit}, // Commitments: []kzg4844.Commitment{emptyBlobCommit},
Proofs: []kzg4844.Proof{emptyBlobProof}, // Proofs: []kzg4844.Proof{emptyBlobProof},
}, // },
}, // },
}, // },
{ // {
name: "TestInvalidBlobHashes", // name: "TestInvalidBlobHashes",
args: TransactionArgs{ // args: TransactionArgs{
From: &b.acc.Address, // From: &b.acc.Address,
To: &to, // To: &to,
Value: (*hexutil.Big)(big.NewInt(1)), // Value: (*hexutil.Big)(big.NewInt(1)),
BlobHashes: []common.Hash{{0x01, 0x22}}, // BlobHashes: []common.Hash{{0x01, 0x22}},
Blobs: emptyBlobs, // Blobs: emptyBlobs,
Commitments: []kzg4844.Commitment{emptyBlobCommit}, // Commitments: []kzg4844.Commitment{emptyBlobCommit},
Proofs: []kzg4844.Proof{emptyBlobProof}, // Proofs: []kzg4844.Proof{emptyBlobProof},
}, // },
err: fmt.Sprintf("blob hash verification failed (have=%s, want=%s)", common.Hash{0x01, 0x22}, emptyBlobHash), // err: fmt.Sprintf("blob hash verification failed (have=%s, want=%s)", common.Hash{0x01, 0x22}, emptyBlobHash),
}, // },
{ // {
name: "TestGenerateBlobProofs", // name: "TestGenerateBlobProofs",
args: TransactionArgs{ // args: TransactionArgs{
From: &b.acc.Address, // From: &b.acc.Address,
To: &to, // To: &to,
Value: (*hexutil.Big)(big.NewInt(1)), // Value: (*hexutil.Big)(big.NewInt(1)),
Blobs: emptyBlobs, // Blobs: emptyBlobs,
}, // },
want: &result{ // want: &result{
Hashes: []common.Hash{emptyBlobHash}, // Hashes: []common.Hash{emptyBlobHash},
Sidecar: &types.BlobTxSidecar{ // Sidecar: &types.BlobTxSidecar{
Blobs: emptyBlobs, // Blobs: emptyBlobs,
Commitments: []kzg4844.Commitment{emptyBlobCommit}, // Commitments: []kzg4844.Commitment{emptyBlobCommit},
Proofs: []kzg4844.Proof{emptyBlobProof}, // Proofs: []kzg4844.Proof{emptyBlobProof},
}, // },
}, // },
}, // },
} // }
for _, tc := range suite { // for _, tc := range suite {
t.Run(tc.name, func(t *testing.T) { // t.Run(tc.name, func(t *testing.T) {
res, err := api.FillTransaction(context.Background(), tc.args) // res, err := api.FillTransaction(context.Background(), tc.args)
if len(tc.err) > 0 { // if len(tc.err) > 0 {
if err == nil { // if err == nil {
t.Fatalf("missing error. want: %s", tc.err) // t.Fatalf("missing error. want: %s", tc.err)
} else if err.Error() != tc.err { // } else if err.Error() != tc.err {
t.Fatalf("error mismatch. want: %s, have: %s", tc.err, err.Error()) // t.Fatalf("error mismatch. want: %s, have: %s", tc.err, err.Error())
} // }
return // return
} // }
if err != nil && len(tc.err) == 0 { // if err != nil && len(tc.err) == 0 {
t.Fatalf("expected no error. have: %s", err) // t.Fatalf("expected no error. have: %s", err)
} // }
if res == nil { // if res == nil {
t.Fatal("result missing") // t.Fatal("result missing")
} // }
want, err := json.Marshal(tc.want) // want, err := json.Marshal(tc.want)
if err != nil { // if err != nil {
t.Fatalf("failed to encode expected: %v", err) // t.Fatalf("failed to encode expected: %v", err)
} // }
have, err := json.Marshal(result{Hashes: res.Tx.BlobHashes(), Sidecar: res.Tx.BlobTxSidecar()}) // have, err := json.Marshal(result{Hashes: res.Tx.BlobHashes(), Sidecar: res.Tx.BlobTxSidecar()})
if err != nil { // if err != nil {
t.Fatalf("failed to encode computed sidecar: %v", err) // t.Fatalf("failed to encode computed sidecar: %v", err)
} // }
if !bytes.Equal(have, want) { // if !bytes.Equal(have, want) {
t.Errorf("blob sidecar mismatch. Have: %s, want: %s", have, want) // t.Errorf("blob sidecar mismatch. Have: %s, want: %s", have, want)
} // }
}) // })
} // }
} // }
func argsFromTransaction(tx *types.Transaction, from common.Address) TransactionArgs { func argsFromTransaction(tx *types.Transaction, from common.Address) TransactionArgs {
var ( var (

View file

@ -71,6 +71,7 @@ func NewServer(service string, executionPoolSize uint64, executionPoolRequesttim
idgen: randomIDGenerator(), idgen: randomIDGenerator(),
codecs: make(map[ServerCodec]struct{}), codecs: make(map[ServerCodec]struct{}),
executionPool: NewExecutionPool(int(executionPoolSize), executionPoolRequesttimeout, service, reportEpStats), executionPool: NewExecutionPool(int(executionPoolSize), executionPoolRequesttimeout, service, reportEpStats),
httpBodyLimit: defaultBodyLimit,
} }
server.run.Store(true) server.run.Store(true)