Skip to content

Commit

Permalink
Merge pull request ethereum-optimism#414 from ethereum-optimism/trans…
Browse files Browse the repository at this point in the history
…actionCondition.hexordecimal

core/types: transaction conditional KnownAccounts fix && HexOrDecimal deser
  • Loading branch information
hamdiallam authored Oct 29, 2024
2 parents 11064f6 + 6d4a826 commit a52bc72
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 33 deletions.
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) {
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

0 comments on commit a52bc72

Please sign in to comment.