|
|
|
@ -18,11 +18,13 @@ package types |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"errors" |
|
|
|
|
"fmt" |
|
|
|
|
"math/big" |
|
|
|
|
"testing" |
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
|
"github.com/ethereum/go-ethereum/crypto" |
|
|
|
|
"github.com/ethereum/go-ethereum/params" |
|
|
|
|
"github.com/ethereum/go-ethereum/rlp" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
@ -136,3 +138,53 @@ func TestChainId(t *testing.T) { |
|
|
|
|
t.Error("expected no error") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type nilSigner struct { |
|
|
|
|
v, r, s *big.Int |
|
|
|
|
Signer |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (ns *nilSigner) SignatureValues(tx *Transaction, sig []byte) (r, s, v *big.Int, err error) { |
|
|
|
|
return ns.v, ns.r, ns.s, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TestNilSigner ensures a faulty Signer implementation does not result in nil signature values or panics.
|
|
|
|
|
func TestNilSigner(t *testing.T) { |
|
|
|
|
key, _ := crypto.GenerateKey() |
|
|
|
|
innerSigner := LatestSignerForChainID(big.NewInt(1)) |
|
|
|
|
for i, signer := range []Signer{ |
|
|
|
|
&nilSigner{v: nil, r: nil, s: nil, Signer: innerSigner}, |
|
|
|
|
&nilSigner{v: big.NewInt(1), r: big.NewInt(1), s: nil, Signer: innerSigner}, |
|
|
|
|
&nilSigner{v: big.NewInt(1), r: nil, s: big.NewInt(1), Signer: innerSigner}, |
|
|
|
|
&nilSigner{v: nil, r: big.NewInt(1), s: big.NewInt(1), Signer: innerSigner}, |
|
|
|
|
} { |
|
|
|
|
t.Run(fmt.Sprintf("signer_%d", i), func(t *testing.T) { |
|
|
|
|
t.Run("legacy", func(t *testing.T) { |
|
|
|
|
legacyTx := createTestLegacyTxInner() |
|
|
|
|
_, err := SignNewTx(key, signer, legacyTx) |
|
|
|
|
if !errors.Is(err, ErrInvalidSig) { |
|
|
|
|
t.Fatal("expected signature values error, no nil result or panic") |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
// test Blob tx specifically, since the signature value types changed
|
|
|
|
|
t.Run("blobtx", func(t *testing.T) { |
|
|
|
|
blobtx := createEmptyBlobTxInner(false) |
|
|
|
|
_, err := SignNewTx(key, signer, blobtx) |
|
|
|
|
if !errors.Is(err, ErrInvalidSig) { |
|
|
|
|
t.Fatal("expected signature values error, no nil result or panic") |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func createTestLegacyTxInner() *LegacyTx { |
|
|
|
|
return &LegacyTx{ |
|
|
|
|
Nonce: uint64(0), |
|
|
|
|
To: nil, |
|
|
|
|
Value: big.NewInt(0), |
|
|
|
|
Gas: params.TxGas, |
|
|
|
|
GasPrice: big.NewInt(params.GWei), |
|
|
|
|
Data: nil, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|