mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 01:43:47 +00:00
expand test case to cover blob pool
This commit is contained in:
parent
978d392aa4
commit
768a29e3a4
2 changed files with 63 additions and 34 deletions
|
|
@ -19,6 +19,9 @@ package simulated
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
|
"crypto/sha256"
|
||||||
|
"github.com/ethereum/go-ethereum/crypto/kzg4844"
|
||||||
|
"github.com/holiman/uint256"
|
||||||
"math/big"
|
"math/big"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -46,6 +49,46 @@ func simTestBackend(testAddr common.Address) *Backend {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newBlobTx(sim *Backend, key *ecdsa.PrivateKey) (*types.Transaction, error) {
|
||||||
|
client := sim.Client()
|
||||||
|
|
||||||
|
testBlob := &kzg4844.Blob{0x00}
|
||||||
|
testBlobCommit, _ := kzg4844.BlobToCommitment(testBlob)
|
||||||
|
testBlobProof, _ := kzg4844.ComputeBlobProof(testBlob, testBlobCommit)
|
||||||
|
testBlobVHash := kzg4844.CalcBlobHashV1(sha256.New(), &testBlobCommit)
|
||||||
|
|
||||||
|
head, _ := client.HeaderByNumber(context.Background(), nil) // Should be child's, good enough
|
||||||
|
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(params.GWei))
|
||||||
|
gasPriceU256, _ := uint256.FromBig(gasPrice)
|
||||||
|
gasTipCapU256, _ := uint256.FromBig(big.NewInt(params.GWei))
|
||||||
|
|
||||||
|
addr := crypto.PubkeyToAddress(key.PublicKey)
|
||||||
|
chainid, _ := client.ChainID(context.Background())
|
||||||
|
nonce, err := client.PendingNonceAt(context.Background(), addr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
chainidU256, _ := uint256.FromBig(chainid)
|
||||||
|
tx := types.NewTx(&types.BlobTx{
|
||||||
|
ChainID: chainidU256,
|
||||||
|
GasTipCap: gasTipCapU256,
|
||||||
|
GasFeeCap: gasPriceU256,
|
||||||
|
BlobFeeCap: uint256.NewInt(1),
|
||||||
|
Gas: 21000,
|
||||||
|
Nonce: nonce,
|
||||||
|
To: addr,
|
||||||
|
AccessList: nil,
|
||||||
|
BlobHashes: []common.Hash{testBlobVHash},
|
||||||
|
Sidecar: &types.BlobTxSidecar{
|
||||||
|
Blobs: []kzg4844.Blob{*testBlob},
|
||||||
|
Commitments: []kzg4844.Commitment{testBlobCommit},
|
||||||
|
Proofs: []kzg4844.Proof{testBlobProof},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return types.SignTx(tx, types.LatestSignerForChainID(chainid), key)
|
||||||
|
}
|
||||||
|
|
||||||
func newTx(sim *Backend, key *ecdsa.PrivateKey) (*types.Transaction, error) {
|
func newTx(sim *Backend, key *ecdsa.PrivateKey) (*types.Transaction, error) {
|
||||||
client := sim.Client()
|
client := sim.Client()
|
||||||
|
|
||||||
|
|
@ -66,6 +109,7 @@ func newTx(sim *Backend, key *ecdsa.PrivateKey) (*types.Transaction, error) {
|
||||||
Gas: 21000,
|
Gas: 21000,
|
||||||
To: &addr,
|
To: &addr,
|
||||||
})
|
})
|
||||||
|
|
||||||
return types.SignTx(tx, types.LatestSignerForChainID(chainid), key)
|
return types.SignTx(tx, types.LatestSignerForChainID(chainid), key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,48 +21,33 @@ func TestTransactionRollbackBehavior(t *testing.T) {
|
||||||
defer sim.Close()
|
defer sim.Close()
|
||||||
client := sim.Client()
|
client := sim.Client()
|
||||||
|
|
||||||
t.Run("Case 1: Basic Transaction (Control Case)", func(t *testing.T) {
|
|
||||||
// Demonstrates normal transaction processing works as expected
|
|
||||||
tx := testSendSignedTx(t, sim)
|
|
||||||
sim.Commit()
|
|
||||||
assertSuccessfulReceipt(t, client, tx)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("Case 2: Transaction After Rollback (Shows Issue)", func(t *testing.T) {
|
|
||||||
// First transaction gets rolled back
|
// First transaction gets rolled back
|
||||||
_ = testSendSignedTx(t, sim)
|
_ = testSendSignedTx(t, sim, true)
|
||||||
sim.Rollback()
|
sim.Rollback()
|
||||||
|
|
||||||
// Attempting to process a new transaction immediately after rollback
|
// Attempting to process a new transaction immediately after rollback
|
||||||
// Currently, this case fails to get a valid receipt
|
// Currently, this case fails to get a valid receipt
|
||||||
tx := testSendSignedTx(t, sim)
|
tx := testSendSignedTx(t, sim, true)
|
||||||
sim.Commit()
|
sim.Commit()
|
||||||
assertSuccessfulReceipt(t, client, tx)
|
assertSuccessfulReceipt(t, client, tx)
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("Case 3: Transaction After Rollback with Empty Block (Workaround)", func(t *testing.T) {
|
|
||||||
// First transaction gets rolled back
|
|
||||||
_ = testSendSignedTx(t, sim)
|
|
||||||
sim.Rollback()
|
|
||||||
|
|
||||||
// Workaround: Commit an empty block after rollback
|
|
||||||
sim.Commit()
|
|
||||||
|
|
||||||
// Now the new transaction succeeds
|
|
||||||
tx := testSendSignedTx(t, sim)
|
|
||||||
sim.Commit()
|
|
||||||
assertSuccessfulReceipt(t, client, tx)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// testSendSignedTx sends a signed transaction to the simulated backend.
|
// testSendSignedTx sends a signed transaction to the simulated backend.
|
||||||
// It does not commit the block.
|
// It does not commit the block.
|
||||||
func testSendSignedTx(t *testing.T, sim *Backend) *types.Transaction {
|
func testSendSignedTx(t *testing.T, sim *Backend, isBlobTx bool) *types.Transaction {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
client := sim.Client()
|
client := sim.Client()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
signedTx, err := newTx(sim, testKey)
|
var (
|
||||||
|
err error
|
||||||
|
signedTx *types.Transaction
|
||||||
|
)
|
||||||
|
if isBlobTx {
|
||||||
|
signedTx, err = newBlobTx(sim, testKey)
|
||||||
|
} else {
|
||||||
|
signedTx, err = newTx(sim, testKey)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create transaction: %v", err)
|
t.Fatalf("failed to create transaction: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -74,7 +59,7 @@ func testSendSignedTx(t *testing.T, sim *Backend) *types.Transaction {
|
||||||
return signedTx
|
return signedTx
|
||||||
}
|
}
|
||||||
|
|
||||||
// assertSuccessfulReceipt verifies that a transaction was successfully processed
|
// assertSuccessfulReceipt verifies that a transaction was successfully included as of the pending state
|
||||||
// by checking its receipt status.
|
// by checking its receipt status.
|
||||||
func assertSuccessfulReceipt(t *testing.T, client Client, tx *types.Transaction) {
|
func assertSuccessfulReceipt(t *testing.T, client Client, tx *types.Transaction) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue