mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
fail on signTransaction
This commit is contained in:
parent
711802fac3
commit
841f324d6f
2 changed files with 48 additions and 15 deletions
|
|
@ -497,8 +497,8 @@ func (s *PersonalAccountAPI) SignTransaction(ctx context.Context, args Transacti
|
|||
if args.GasPrice == nil && (args.MaxFeePerGas == nil || args.MaxPriorityFeePerGas == nil) {
|
||||
return nil, errors.New("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas")
|
||||
}
|
||||
if args.IsEIP4844() && (args.BlobVersionedHashes == nil || args.MaxFeePerBlobGas == nil) {
|
||||
return nil, errors.New("missing maxFeePerBlobGas or blobVersionedHashes")
|
||||
if args.IsEIP4844() {
|
||||
return nil, errBlobTxNotSupported
|
||||
}
|
||||
if args.Nonce == nil {
|
||||
return nil, errors.New("nonce not specified")
|
||||
|
|
@ -1905,8 +1905,8 @@ func (s *TransactionAPI) SignTransaction(ctx context.Context, args TransactionAr
|
|||
if args.GasPrice == nil && (args.MaxPriorityFeePerGas == nil || args.MaxFeePerGas == nil) {
|
||||
return nil, errors.New("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas")
|
||||
}
|
||||
if args.IsEIP4844() && (args.BlobVersionedHashes == nil || args.MaxFeePerBlobGas == nil) {
|
||||
return nil, errors.New("missing maxFeePerBlobGas or blobVersionedHashes")
|
||||
if args.IsEIP4844() {
|
||||
return nil, errBlobTxNotSupported
|
||||
}
|
||||
if args.Nonce == nil {
|
||||
return nil, errors.New("nonce not specified")
|
||||
|
|
|
|||
|
|
@ -974,6 +974,44 @@ func TestCall(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestSignTransaction(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: core.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)),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to fill tx defaults: %v\n", err)
|
||||
}
|
||||
|
||||
res, err = api.SignTransaction(context.Background(), argsFromTransaction(res.Tx, b.acc.Address))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to sign tx: %v\n", err)
|
||||
}
|
||||
tx, err := json.Marshal(res.Tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
expect := `{"type":"0x2","chainId":"0x1","nonce":"0x0","to":"0x703c4b2bd70c169f5717101caee543299fc946c7","gas":"0x5208","gasPrice":null,"maxPriorityFeePerGas":"0x0","maxFeePerGas":"0x684ee180","value":"0x1","input":"0x","accessList":[],"v":"0x0","r":"0x8fabeb142d585dd9247f459f7e6fe77e2520c88d50ba5d220da1533cea8b34e1","s":"0x582dd68b21aef36ba23f34e49607329c20d981d30404daf749077f5606785ce7","yParity":"0x0","hash":"0x93927839207cfbec395da84b8a2bc38b7b65d2cb2819e9fef1f091f5b1d4cc8f"}`
|
||||
if !bytes.Equal(tx, []byte(expect)) {
|
||||
t.Errorf("result mismatch. Have:\n%s\nWant:\n%s\n", tx, expect)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSignBlobTransaction(t *testing.T) {
|
||||
t.Parallel()
|
||||
// Initialize test accounts
|
||||
|
|
@ -993,23 +1031,18 @@ func TestSignBlobTransaction(t *testing.T) {
|
|||
From: &b.acc.Address,
|
||||
To: &to,
|
||||
Value: (*hexutil.Big)(big.NewInt(1)),
|
||||
BlobVersionedHashes: []common.Hash{common.Hash{0x01, 0x22}},
|
||||
BlobVersionedHashes: []common.Hash{{0x01, 0x22}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to fill tx defaults: %v\n", err)
|
||||
}
|
||||
|
||||
res, err = api.SignTransaction(context.Background(), argsFromTransaction(res.Tx, b.acc.Address))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to sign tx: %v\n", err)
|
||||
_, err = api.SignTransaction(context.Background(), argsFromTransaction(res.Tx, b.acc.Address))
|
||||
if err == nil {
|
||||
t.Fatalf("should fail on blob-tx")
|
||||
}
|
||||
tx, err := json.Marshal(res.Tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
expect := `{"type":"0x3","chainId":"0x1","nonce":"0x0","to":"0x703c4b2bd70c169f5717101caee543299fc946c7","gas":"0x5208","gasPrice":null,"maxPriorityFeePerGas":"0x0","maxFeePerGas":"0x684ee180","maxFeePerBlobGas":"0x2","value":"0x1","input":"0x","accessList":[],"blobVersionedHashes":["0x0122000000000000000000000000000000000000000000000000000000000000"],"v":"0x1","r":"0x94e52c0d77144ec96d0e52c65195b3b574d3184b788d44b80c1cac9c43495924","s":"0x17ee5cdc420360a221df4ac805030ecf4a2f0bb292ced555267f54a76e0400b6","yParity":"0x1","hash":"0xe4c90a797ceae5e2cd7f32ca27134e72d3a2db5eac755333c8fa20da537f4f25"}`
|
||||
if !bytes.Equal(tx, []byte(expect)) {
|
||||
t.Errorf("result mismatch. Have:\n%s\nWant:\n%s\n", tx, expect)
|
||||
if !errors.Is(err, errBlobTxNotSupported) {
|
||||
t.Errorf("error mismatch. Have: %v, want: %v", err, errBlobTxNotSupported)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue