Skip to content

Commit

Permalink
fix receipt json marshaling/unmarshaling
Browse files Browse the repository at this point in the history
Signed-off-by: Roberto Bayardo <roberto.bayardo@coinbase.com>
  • Loading branch information
roberto-bayardo committed Oct 25, 2023
1 parent 29cd9a3 commit 5177cb8
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 47 deletions.
92 changes: 50 additions & 42 deletions core/types/gen_receipt_json.go

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

12 changes: 7 additions & 5 deletions core/types/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ type receiptMarshaling struct {
BlockNumber *hexutil.Big
TransactionIndex hexutil.Uint

// Optimism: extend receipts with their L1 price (if a rollup tx)
L1GasPrice *hexutil.Big
L1GasUsed *hexutil.Big
L1Fee *hexutil.Big
FeeScalar *big.Float
// Optimism
L1GasPrice *hexutil.Big
L1GasUsed *hexutil.Big
L1Fee *hexutil.Big
FeeScalar *big.Float
DepositNonce *hexutil.Uint64
DepositReceiptVersion *hexutil.Uint64
}

// receiptRLP is the consensus encoding of a receipt.
Expand Down
23 changes: 23 additions & 0 deletions core/types/receipt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,29 @@ func TestReceiptJSON(t *testing.T) {
t.Fatal("error unmarshaling receipt from json:", err)
}
}

// Test that deposit tx fields are appropriately preserved across marshal/unmarshal
b, err := depositReceiptWithNonceAndVersion.MarshalJSON()
if err != nil {
t.Fatal("error marshaling receipt to json:", err)
}
r := Receipt{}
err = r.UnmarshalJSON(b)
if err != nil {
t.Fatal("error unmarshaling receipt from json:", err)
}
if r.DepositNonce == nil {
t.Fatal("expected non nil deposit nonce")
}
if r.DepositReceiptVersion == nil {
t.Fatal("expected non nil deposit nonce")
}
if *r.DepositNonce != *depositReceiptWithNonceAndVersion.DepositNonce {
t.Fatal("Deposit nonces don't match", r.DepositNonce, depositReceiptWithNonceAndVersion.DepositNonce)
}
if *r.DepositReceiptVersion != *depositReceiptWithNonceAndVersion.DepositReceiptVersion {
t.Fatal("Deposit receipt versions don't match", r.DepositReceiptVersion, depositReceiptWithNonceAndVersion.DepositReceiptVersion)
}
}

// Test we can still parse receipt without EffectiveGasPrice for backwards compatibility, even
Expand Down

0 comments on commit 5177cb8

Please sign in to comment.