expand test case to cover blob pool
This commit is contained in:
parent
978d392aa4
commit
768a29e3a4
|
@ -19,6 +19,9 @@ package simulated
|
|||
import (
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"crypto/sha256"
|
||||
"github.com/ethereum/go-ethereum/crypto/kzg4844"
|
||||
"github.com/holiman/uint256"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"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) {
|
||||
client := sim.Client()
|
||||
|
||||
|
@ -66,6 +109,7 @@ func newTx(sim *Backend, key *ecdsa.PrivateKey) (*types.Transaction, error) {
|
|||
Gas: 21000,
|
||||
To: &addr,
|
||||
})
|
||||
|
||||
return types.SignTx(tx, types.LatestSignerForChainID(chainid), key)
|
||||
}
|
||||
|
||||
|
|
|
@ -21,48 +21,33 @@ func TestTransactionRollbackBehavior(t *testing.T) {
|
|||
defer sim.Close()
|
||||
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)
|
||||
})
|
||||
// First transaction gets rolled back
|
||||
_ = testSendSignedTx(t, sim, true)
|
||||
sim.Rollback()
|
||||
|
||||
t.Run("Case 2: Transaction After Rollback (Shows Issue)", func(t *testing.T) {
|
||||
// First transaction gets rolled back
|
||||
_ = testSendSignedTx(t, sim)
|
||||
sim.Rollback()
|
||||
|
||||
// Attempting to process a new transaction immediately after rollback
|
||||
// Currently, this case fails to get a valid receipt
|
||||
tx := testSendSignedTx(t, sim)
|
||||
sim.Commit()
|
||||
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)
|
||||
})
|
||||
// Attempting to process a new transaction immediately after rollback
|
||||
// Currently, this case fails to get a valid receipt
|
||||
tx := testSendSignedTx(t, sim, true)
|
||||
sim.Commit()
|
||||
assertSuccessfulReceipt(t, client, tx)
|
||||
}
|
||||
|
||||
// testSendSignedTx sends a signed transaction to the simulated backend.
|
||||
// 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()
|
||||
client := sim.Client()
|
||||
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 {
|
||||
t.Fatalf("failed to create transaction: %v", err)
|
||||
}
|
||||
|
@ -74,7 +59,7 @@ func testSendSignedTx(t *testing.T, sim *Backend) *types.Transaction {
|
|||
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.
|
||||
func assertSuccessfulReceipt(t *testing.T, client Client, tx *types.Transaction) {
|
||||
t.Helper()
|
||||
|
|
Loading…
Reference in New Issue