mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 05:36:46 +00:00
BRG4-15: error out early if nil pubkey provided when creating PoL tx
This commit is contained in:
parent
9d70186ec4
commit
1301bf6f44
2 changed files with 24 additions and 5 deletions
|
|
@ -18,6 +18,7 @@ package types
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
||||
|
|
@ -145,14 +146,11 @@ var (
|
|||
|
||||
// getDistributeForData returns the tx data for the `distributeFor(bytes pubkey)` method.
|
||||
func getDistributeForData(pubkey *common.Pubkey) ([]byte, error) {
|
||||
var pubkeyBytes []byte
|
||||
if pubkey == nil {
|
||||
pubkeyBytes = common.Pubkey{}.Bytes()
|
||||
} else {
|
||||
pubkeyBytes = pubkey.Bytes()
|
||||
return nil, errors.New("pubkey cannot be nil for PoL transaction")
|
||||
}
|
||||
|
||||
arguments, err := distributeForMethod.Inputs.Pack(pubkeyBytes)
|
||||
arguments, err := distributeForMethod.Inputs.Pack(pubkey.Bytes())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,27 @@ func TestNewPoLTx_DataPacking(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestNewPoLTx_NilPubkey verifies that NewPoLTx returns an error when pubkey is nil.
|
||||
func TestNewPoLTx_NilPubkey(t *testing.T) {
|
||||
chainID := big.NewInt(1)
|
||||
distributor := common.HexToAddress("0x000000000000000000000000000000000000dEaD")
|
||||
blockNum := big.NewInt(123)
|
||||
baseFee := big.NewInt(1000000000)
|
||||
|
||||
// Call NewPoLTx with nil pubkey
|
||||
tx, err := NewPoLTx(chainID, distributor, blockNum, params.PoLTxGasLimit, baseFee, nil)
|
||||
if err == nil {
|
||||
t.Fatalf("expected error for nil pubkey, but got nil")
|
||||
}
|
||||
if tx != nil {
|
||||
t.Fatalf("expected nil transaction when error occurs, but got %v", tx)
|
||||
}
|
||||
expectedErr := "pubkey cannot be nil for PoL transaction"
|
||||
if err.Error() != expectedErr {
|
||||
t.Fatalf("error message mismatch: have %q, want %q", err.Error(), expectedErr)
|
||||
}
|
||||
}
|
||||
|
||||
// TestNewPoLTx_NegativeBlockNumber ensures negative block numbers are handled
|
||||
// without panicking (uint64 wrap-around is expected).
|
||||
func TestNewPoLTx_NegativeBlockNumber(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue