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