Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/types: transaction conditional KnownAccounts fix && HexOrDecimal deser #414

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions core/types/gen_transaction_conditional_json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions core/types/transaction_conditional.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
)

// KnownAccounts represents a set of KnownAccounts
Expand Down Expand Up @@ -42,7 +42,7 @@ func (ka *KnownAccount) UnmarshalJSON(data []byte) error {
}

// MarshalJSON will serialize the KnownAccount into JSON bytes.
func (ka *KnownAccount) MarshalJSON() ([]byte, error) {
func (ka KnownAccount) MarshalJSON() ([]byte, error) {
hamdiallam marked this conversation as resolved.
Show resolved Hide resolved
if ka.StorageRoot != nil {
return json.Marshal(ka.StorageRoot)
}
Expand Down Expand Up @@ -86,10 +86,10 @@ type TransactionConditional struct {

// field type overrides for gencodec
type transactionConditionalMarshalling struct {
BlockNumberMax *hexutil.Big
BlockNumberMin *hexutil.Big
TimestampMin *hexutil.Uint64
TimestampMax *hexutil.Uint64
BlockNumberMax *math.HexOrDecimal256
BlockNumberMin *math.HexOrDecimal256
TimestampMin *math.HexOrDecimal64
TimestampMax *math.HexOrDecimal64
}

// Validate will perform sanity checks on the preconditions. This does not check the aggregate cost of the preconditions.
Expand Down
23 changes: 17 additions & 6 deletions core/types/transaction_conditional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,21 @@ func TestTransactionConditionalSerDeser(t *testing.T) {
},
{
name: "BlockNumberMax",
input: `{"blockNumberMin":"0x1", "blockNumberMax":"0x2"}`,
input: `{"blockNumberMax":"0x2"}`,
mustFail: false,
expected: TransactionConditional{
BlockNumberMin: big.NewInt(1),
BlockNumberMax: big.NewInt(2),
},
},
{
name: "BlockNumber (decimal)",
input: `{"blockNumberMin": 0, "blockNumberMax": 1}`,
mustFail: false,
expected: TransactionConditional{
BlockNumberMin: big.NewInt(0),
BlockNumberMax: big.NewInt(1),
},
},
{
name: "TimestampMin",
input: `{"timestampMin":"0xffff"}`,
Expand All @@ -228,10 +236,13 @@ func TestTransactionConditionalSerDeser(t *testing.T) {
},
},
{
name: "UnknownField",
input: `{"foobarbaz": 1234}`,
mustFail: true,
expected: TransactionConditional{KnownAccounts: nil},
name: "Timestamp (decimal)",
input: `{"timestampMin": 0, "timestampMax": 1}`,
mustFail: false,
expected: TransactionConditional{
TimestampMin: uint64Ptr(0),
TimestampMax: uint64Ptr(1),
},
},
}

Expand Down