|
|
|
@ -29,6 +29,59 @@ import ( |
|
|
|
|
"github.com/ethereum/go-ethereum/rlp" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
|
legacyReceipt = &Receipt{ |
|
|
|
|
Status: ReceiptStatusFailed, |
|
|
|
|
CumulativeGasUsed: 1, |
|
|
|
|
Logs: []*Log{ |
|
|
|
|
{ |
|
|
|
|
Address: common.BytesToAddress([]byte{0x11}), |
|
|
|
|
Topics: []common.Hash{common.HexToHash("dead"), common.HexToHash("beef")}, |
|
|
|
|
Data: []byte{0x01, 0x00, 0xff}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
Address: common.BytesToAddress([]byte{0x01, 0x11}), |
|
|
|
|
Topics: []common.Hash{common.HexToHash("dead"), common.HexToHash("beef")}, |
|
|
|
|
Data: []byte{0x01, 0x00, 0xff}, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
accessListReceipt = &Receipt{ |
|
|
|
|
Status: ReceiptStatusFailed, |
|
|
|
|
CumulativeGasUsed: 1, |
|
|
|
|
Logs: []*Log{ |
|
|
|
|
{ |
|
|
|
|
Address: common.BytesToAddress([]byte{0x11}), |
|
|
|
|
Topics: []common.Hash{common.HexToHash("dead"), common.HexToHash("beef")}, |
|
|
|
|
Data: []byte{0x01, 0x00, 0xff}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
Address: common.BytesToAddress([]byte{0x01, 0x11}), |
|
|
|
|
Topics: []common.Hash{common.HexToHash("dead"), common.HexToHash("beef")}, |
|
|
|
|
Data: []byte{0x01, 0x00, 0xff}, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
Type: AccessListTxType, |
|
|
|
|
} |
|
|
|
|
eip1559Receipt = &Receipt{ |
|
|
|
|
Status: ReceiptStatusFailed, |
|
|
|
|
CumulativeGasUsed: 1, |
|
|
|
|
Logs: []*Log{ |
|
|
|
|
{ |
|
|
|
|
Address: common.BytesToAddress([]byte{0x11}), |
|
|
|
|
Topics: []common.Hash{common.HexToHash("dead"), common.HexToHash("beef")}, |
|
|
|
|
Data: []byte{0x01, 0x00, 0xff}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
Address: common.BytesToAddress([]byte{0x01, 0x11}), |
|
|
|
|
Topics: []common.Hash{common.HexToHash("dead"), common.HexToHash("beef")}, |
|
|
|
|
Data: []byte{0x01, 0x00, 0xff}, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
Type: DynamicFeeTxType, |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func TestDecodeEmptyTypedReceipt(t *testing.T) { |
|
|
|
|
input := []byte{0x80} |
|
|
|
|
var r Receipt |
|
|
|
@ -312,6 +365,105 @@ func TestTypedReceiptEncodingDecoding(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestReceiptMarshalBinary(t *testing.T) { |
|
|
|
|
// Legacy Receipt
|
|
|
|
|
legacyReceipt.Bloom = CreateBloom(Receipts{legacyReceipt}) |
|
|
|
|
have, err := legacyReceipt.MarshalBinary() |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("marshal binary error: %v", err) |
|
|
|
|
} |
|
|
|
|
legacyReceipts := Receipts{legacyReceipt} |
|
|
|
|
buf := new(bytes.Buffer) |
|
|
|
|
legacyReceipts.EncodeIndex(0, buf) |
|
|
|
|
haveEncodeIndex := buf.Bytes() |
|
|
|
|
if !bytes.Equal(have, haveEncodeIndex) { |
|
|
|
|
t.Errorf("BinaryMarshal and EncodeIndex mismatch, got %x want %x", have, haveEncodeIndex) |
|
|
|
|
} |
|
|
|
|
buf.Reset() |
|
|
|
|
if err := legacyReceipt.EncodeRLP(buf); err != nil { |
|
|
|
|
t.Fatalf("encode rlp error: %v", err) |
|
|
|
|
} |
|
|
|
|
haveRLPEncode := buf.Bytes() |
|
|
|
|
if !bytes.Equal(have, haveRLPEncode) { |
|
|
|
|
t.Errorf("BinaryMarshal and EncodeRLP mismatch for legacy tx, got %x want %x", have, haveRLPEncode) |
|
|
|
|
} |
|
|
|
|
legacyWant := common.FromHex("f901c58001b9010000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000010000080000000000000000000004000000000000000000000000000040000000000000000000000000000800000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000f8bef85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100fff85d940000000000000000000000000000000000000111f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff") |
|
|
|
|
if !bytes.Equal(have, legacyWant) { |
|
|
|
|
t.Errorf("encoded RLP mismatch, got %x want %x", have, legacyWant) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 2930 Receipt
|
|
|
|
|
buf.Reset() |
|
|
|
|
accessListReceipt.Bloom = CreateBloom(Receipts{accessListReceipt}) |
|
|
|
|
have, err = accessListReceipt.MarshalBinary() |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("marshal binary error: %v", err) |
|
|
|
|
} |
|
|
|
|
accessListReceipts := Receipts{accessListReceipt} |
|
|
|
|
accessListReceipts.EncodeIndex(0, buf) |
|
|
|
|
haveEncodeIndex = buf.Bytes() |
|
|
|
|
if !bytes.Equal(have, haveEncodeIndex) { |
|
|
|
|
t.Errorf("BinaryMarshal and EncodeIndex mismatch, got %x want %x", have, haveEncodeIndex) |
|
|
|
|
} |
|
|
|
|
accessListWant := common.FromHex("01f901c58001b9010000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000010000080000000000000000000004000000000000000000000000000040000000000000000000000000000800000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000f8bef85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100fff85d940000000000000000000000000000000000000111f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff") |
|
|
|
|
if !bytes.Equal(have, accessListWant) { |
|
|
|
|
t.Errorf("encoded RLP mismatch, got %x want %x", have, accessListWant) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 1559 Receipt
|
|
|
|
|
buf.Reset() |
|
|
|
|
eip1559Receipt.Bloom = CreateBloom(Receipts{eip1559Receipt}) |
|
|
|
|
have, err = eip1559Receipt.MarshalBinary() |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("marshal binary error: %v", err) |
|
|
|
|
} |
|
|
|
|
eip1559Receipts := Receipts{eip1559Receipt} |
|
|
|
|
eip1559Receipts.EncodeIndex(0, buf) |
|
|
|
|
haveEncodeIndex = buf.Bytes() |
|
|
|
|
if !bytes.Equal(have, haveEncodeIndex) { |
|
|
|
|
t.Errorf("BinaryMarshal and EncodeIndex mismatch, got %x want %x", have, haveEncodeIndex) |
|
|
|
|
} |
|
|
|
|
eip1559Want := common.FromHex("02f901c58001b9010000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000010000080000000000000000000004000000000000000000000000000040000000000000000000000000000800000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000f8bef85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100fff85d940000000000000000000000000000000000000111f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff") |
|
|
|
|
if !bytes.Equal(have, eip1559Want) { |
|
|
|
|
t.Errorf("encoded RLP mismatch, got %x want %x", have, eip1559Want) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestReceiptUnmarshalBinary(t *testing.T) { |
|
|
|
|
// Legacy Receipt
|
|
|
|
|
legacyBinary := common.FromHex("f901c58001b9010000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000010000080000000000000000000004000000000000000000000000000040000000000000000000000000000800000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000f8bef85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100fff85d940000000000000000000000000000000000000111f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff") |
|
|
|
|
gotLegacyReceipt := new(Receipt) |
|
|
|
|
if err := gotLegacyReceipt.UnmarshalBinary(legacyBinary); err != nil { |
|
|
|
|
t.Fatalf("unmarshal binary error: %v", err) |
|
|
|
|
} |
|
|
|
|
legacyReceipt.Bloom = CreateBloom(Receipts{legacyReceipt}) |
|
|
|
|
if !reflect.DeepEqual(gotLegacyReceipt, legacyReceipt) { |
|
|
|
|
t.Errorf("receipt unmarshalled from binary mismatch, got %v want %v", gotLegacyReceipt, legacyReceipt) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 2930 Receipt
|
|
|
|
|
accessListBinary := common.FromHex("01f901c58001b9010000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000010000080000000000000000000004000000000000000000000000000040000000000000000000000000000800000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000f8bef85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100fff85d940000000000000000000000000000000000000111f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff") |
|
|
|
|
gotAccessListReceipt := new(Receipt) |
|
|
|
|
if err := gotAccessListReceipt.UnmarshalBinary(accessListBinary); err != nil { |
|
|
|
|
t.Fatalf("unmarshal binary error: %v", err) |
|
|
|
|
} |
|
|
|
|
accessListReceipt.Bloom = CreateBloom(Receipts{accessListReceipt}) |
|
|
|
|
if !reflect.DeepEqual(gotAccessListReceipt, accessListReceipt) { |
|
|
|
|
t.Errorf("receipt unmarshalled from binary mismatch, got %v want %v", gotAccessListReceipt, accessListReceipt) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 1559 Receipt
|
|
|
|
|
eip1559RctBinary := common.FromHex("02f901c58001b9010000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000010000080000000000000000000004000000000000000000000000000040000000000000000000000000000800000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000f8bef85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100fff85d940000000000000000000000000000000000000111f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff") |
|
|
|
|
got1559Receipt := new(Receipt) |
|
|
|
|
if err := got1559Receipt.UnmarshalBinary(eip1559RctBinary); err != nil { |
|
|
|
|
t.Fatalf("unmarshal binary error: %v", err) |
|
|
|
|
} |
|
|
|
|
eip1559Receipt.Bloom = CreateBloom(Receipts{eip1559Receipt}) |
|
|
|
|
if !reflect.DeepEqual(got1559Receipt, eip1559Receipt) { |
|
|
|
|
t.Errorf("receipt unmarshalled from binary mismatch, got %v want %v", got1559Receipt, eip1559Receipt) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func clearComputedFieldsOnReceipts(t *testing.T, receipts Receipts) { |
|
|
|
|
t.Helper() |
|
|
|
|
|
|
|
|
|