Skip to content

Commit 40d644c

Browse files
committed
rebase and support 1559 tx type
1 parent da442c9 commit 40d644c

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

core/types/receipt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,13 @@ func (r *Receipt) decodeTyped(b []byte) error {
207207
return errEmptyTypedReceipt
208208
}
209209
switch b[0] {
210-
case AccessListTxType:
210+
case DynamicFeeTxType, AccessListTxType:
211211
var data receiptRLP
212212
err := rlp.DecodeBytes(b[1:], &data)
213213
if err != nil {
214214
return err
215215
}
216-
r.Type = AccessListTxType
216+
r.Type = b[0]
217217
return r.setFromRLP(data)
218218
default:
219219
return ErrTxTypeNotSupported

core/types/receipt_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,23 @@ var (
6363
},
6464
Type: AccessListTxType,
6565
}
66+
eip1559Receipt = &Receipt{
67+
Status: ReceiptStatusFailed,
68+
CumulativeGasUsed: 1,
69+
Logs: []*Log{
70+
{
71+
Address: common.BytesToAddress([]byte{0x11}),
72+
Topics: []common.Hash{common.HexToHash("dead"), common.HexToHash("beef")},
73+
Data: []byte{0x01, 0x00, 0xff},
74+
},
75+
{
76+
Address: common.BytesToAddress([]byte{0x01, 0x11}),
77+
Topics: []common.Hash{common.HexToHash("dead"), common.HexToHash("beef")},
78+
Data: []byte{0x01, 0x00, 0xff},
79+
},
80+
},
81+
Type: DynamicFeeTxType,
82+
}
6683
)
6784

6885
func TestDecodeEmptyTypedReceipt(t *testing.T) {
@@ -273,6 +290,24 @@ func TestReceiptMarshalBinary(t *testing.T) {
273290
if !bytes.Equal(have, accessListWant) {
274291
t.Errorf("encoded RLP mismatch, got %x want %x", have, accessListWant)
275292
}
293+
294+
// 1559 Receipt
295+
buf.Reset()
296+
eip1559Receipt.Bloom = CreateBloom(Receipts{eip1559Receipt})
297+
have, err = eip1559Receipt.MarshalBinary()
298+
if err != nil {
299+
t.Fatalf("marshal binary error: %v", err)
300+
}
301+
eip1559Receipts := Receipts{eip1559Receipt}
302+
eip1559Receipts.EncodeIndex(0, buf)
303+
haveEncodeIndex = buf.Bytes()
304+
if !bytes.Equal(have, haveEncodeIndex) {
305+
t.Errorf("BinaryMarshal and EncodeIndex mismatch, got %x want %x", have, haveEncodeIndex)
306+
}
307+
eip1559Want := common.FromHex("02f901c58001b9010000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000010000080000000000000000000004000000000000000000000000000040000000000000000000000000000800000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000f8bef85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100fff85d940000000000000000000000000000000000000111f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff")
308+
if !bytes.Equal(have, eip1559Want) {
309+
t.Errorf("encoded RLP mismatch, got %x want %x", have, eip1559Want)
310+
}
276311
}
277312

278313
func TestReceiptUnmarshalBinary(t *testing.T) {
@@ -297,6 +332,17 @@ func TestReceiptUnmarshalBinary(t *testing.T) {
297332
if !reflect.DeepEqual(gotAccessListReceipt, accessListReceipt) {
298333
t.Errorf("receipt unmarshalled from binary mismatch, got %v want %v", gotAccessListReceipt, accessListReceipt)
299334
}
335+
336+
// 1559 Receipt
337+
eip1559RctBinary := common.FromHex("02f901c58001b9010000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000010000080000000000000000000004000000000000000000000000000040000000000000000000000000000800000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000f8bef85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100fff85d940000000000000000000000000000000000000111f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff")
338+
got1559Receipt := new(Receipt)
339+
if err := got1559Receipt.UnmarshalBinary(eip1559RctBinary); err != nil {
340+
t.Fatalf("unmarshal binary error: %v", err)
341+
}
342+
eip1559Receipt.Bloom = CreateBloom(Receipts{eip1559Receipt})
343+
if !reflect.DeepEqual(got1559Receipt, eip1559Receipt) {
344+
t.Errorf("receipt unmarshalled from binary mismatch, got %v want %v", got1559Receipt, eip1559Receipt)
345+
}
300346
}
301347

302348
func clearComputedFieldsOnReceipts(t *testing.T, receipts Receipts) {

0 commit comments

Comments
 (0)