tests: use big int for stAuthorization because eest needs math.HexOrDecimal256 decoding

This commit is contained in:
lightclient 2024-12-06 11:49:52 -07:00
parent 0a129dab19
commit 6505e50d62
No known key found for this signature in database
GPG key ID: 75C916AFEE20183E
2 changed files with 21 additions and 19 deletions

View file

@ -5,10 +5,10 @@ package tests
import (
"encoding/json"
"errors"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/holiman/uint256"
)
var _ = (*stAuthorizationMarshaling)(nil)
@ -17,19 +17,19 @@ var _ = (*stAuthorizationMarshaling)(nil)
func (s stAuthorization) MarshalJSON() ([]byte, error) {
type stAuthorization struct {
ChainID math.HexOrDecimal64
Address common.Address `json:"address" gencodec:"required"`
Nonce math.HexOrDecimal64 `json:"nonce" gencodec:"required"`
V math.HexOrDecimal64 `json:"v" gencodec:"required"`
R uint256.Int `json:"r" gencodec:"required"`
S uint256.Int `json:"s" gencodec:"required"`
Address common.Address `json:"address" gencodec:"required"`
Nonce math.HexOrDecimal64 `json:"nonce" gencodec:"required"`
V math.HexOrDecimal64 `json:"v" gencodec:"required"`
R *math.HexOrDecimal256 `json:"r" gencodec:"required"`
S *math.HexOrDecimal256 `json:"s" gencodec:"required"`
}
var enc stAuthorization
enc.ChainID = math.HexOrDecimal64(s.ChainID)
enc.Address = s.Address
enc.Nonce = math.HexOrDecimal64(s.Nonce)
enc.V = math.HexOrDecimal64(s.V)
enc.R = s.R
enc.S = s.S
enc.R = (*math.HexOrDecimal256)(s.R)
enc.S = (*math.HexOrDecimal256)(s.S)
return json.Marshal(&enc)
}
@ -37,11 +37,11 @@ func (s stAuthorization) MarshalJSON() ([]byte, error) {
func (s *stAuthorization) UnmarshalJSON(input []byte) error {
type stAuthorization struct {
ChainID *math.HexOrDecimal64
Address *common.Address `json:"address" gencodec:"required"`
Nonce *math.HexOrDecimal64 `json:"nonce" gencodec:"required"`
V *math.HexOrDecimal64 `json:"v" gencodec:"required"`
R *uint256.Int `json:"r" gencodec:"required"`
S *uint256.Int `json:"s" gencodec:"required"`
Address *common.Address `json:"address" gencodec:"required"`
Nonce *math.HexOrDecimal64 `json:"nonce" gencodec:"required"`
V *math.HexOrDecimal64 `json:"v" gencodec:"required"`
R *math.HexOrDecimal256 `json:"r" gencodec:"required"`
S *math.HexOrDecimal256 `json:"s" gencodec:"required"`
}
var dec stAuthorization
if err := json.Unmarshal(input, &dec); err != nil {
@ -65,10 +65,10 @@ func (s *stAuthorization) UnmarshalJSON(input []byte) error {
if dec.R == nil {
return errors.New("missing required field 'r' for stAuthorization")
}
s.R = *dec.R
s.R = (*big.Int)(dec.R)
if dec.S == nil {
return errors.New("missing required field 's' for stAuthorization")
}
s.S = *dec.S
s.S = (*big.Int)(dec.S)
return nil
}

View file

@ -144,8 +144,8 @@ type stAuthorization struct {
Address common.Address `json:"address" gencodec:"required"`
Nonce uint64 `json:"nonce" gencodec:"required"`
V uint8 `json:"v" gencodec:"required"`
R uint256.Int `json:"r" gencodec:"required"`
S uint256.Int `json:"s" gencodec:"required"`
R *big.Int `json:"r" gencodec:"required"`
S *big.Int `json:"s" gencodec:"required"`
}
// field type overrides for gencodec
@ -153,6 +153,8 @@ type stAuthorizationMarshaling struct {
ChainID math.HexOrDecimal64
Nonce math.HexOrDecimal64
V math.HexOrDecimal64
R *math.HexOrDecimal256
S *math.HexOrDecimal256
}
// GetChainConfig takes a fork definition and returns a chain config.
@ -448,8 +450,8 @@ func (tx *stTransaction) toMessage(ps stPostState, baseFee *big.Int) (*core.Mess
Address: auth.Address,
Nonce: auth.Nonce,
V: auth.V,
R: auth.R,
S: auth.S,
R: *uint256.MustFromBig(auth.R),
S: *uint256.MustFromBig(auth.S),
}
}
}