@@ -20,7 +20,6 @@ import (
2020 "bytes"
2121 "math"
2222 "math/big"
23- "reflect"
2423 "testing"
2524
2625 "github.com/ethereum/go-ethereum/common"
@@ -38,128 +37,6 @@ func TestDecodeEmptyTypedReceipt(t *testing.T) {
3837 }
3938}
4039
41- func TestLegacyReceiptDecoding (t * testing.T ) {
42- tests := []struct {
43- name string
44- encode func (* Receipt ) ([]byte , error )
45- }{
46- {
47- "StoredReceiptRLP" ,
48- encodeAsStoredReceiptRLP ,
49- },
50- {
51- "V4StoredReceiptRLP" ,
52- encodeAsV4StoredReceiptRLP ,
53- },
54- {
55- "V3StoredReceiptRLP" ,
56- encodeAsV3StoredReceiptRLP ,
57- },
58- }
59-
60- tx := NewTransaction (1 , common .HexToAddress ("0x1" ), big .NewInt (1 ), 1 , big .NewInt (1 ), nil )
61- receipt := & Receipt {
62- Status : ReceiptStatusFailed ,
63- CumulativeGasUsed : 1 ,
64- Logs : []* Log {
65- {
66- Address : common .BytesToAddress ([]byte {0x11 }),
67- Topics : []common.Hash {common .HexToHash ("dead" ), common .HexToHash ("beef" )},
68- Data : []byte {0x01 , 0x00 , 0xff },
69- },
70- {
71- Address : common .BytesToAddress ([]byte {0x01 , 0x11 }),
72- Topics : []common.Hash {common .HexToHash ("dead" ), common .HexToHash ("beef" )},
73- Data : []byte {0x01 , 0x00 , 0xff },
74- },
75- },
76- TxHash : tx .Hash (),
77- ContractAddress : common .BytesToAddress ([]byte {0x01 , 0x11 , 0x11 }),
78- GasUsed : 111111 ,
79- }
80- receipt .Bloom = CreateBloom (Receipts {receipt })
81-
82- for _ , tc := range tests {
83- t .Run (tc .name , func (t * testing.T ) {
84- enc , err := tc .encode (receipt )
85- if err != nil {
86- t .Fatalf ("Error encoding receipt: %v" , err )
87- }
88- var dec ReceiptForStorage
89- if err := rlp .DecodeBytes (enc , & dec ); err != nil {
90- t .Fatalf ("Error decoding RLP receipt: %v" , err )
91- }
92- // Check whether all consensus fields are correct.
93- if dec .Status != receipt .Status {
94- t .Fatalf ("Receipt status mismatch, want %v, have %v" , receipt .Status , dec .Status )
95- }
96- if dec .CumulativeGasUsed != receipt .CumulativeGasUsed {
97- t .Fatalf ("Receipt CumulativeGasUsed mismatch, want %v, have %v" , receipt .CumulativeGasUsed , dec .CumulativeGasUsed )
98- }
99- if dec .Bloom != receipt .Bloom {
100- t .Fatalf ("Bloom data mismatch, want %v, have %v" , receipt .Bloom , dec .Bloom )
101- }
102- if len (dec .Logs ) != len (receipt .Logs ) {
103- t .Fatalf ("Receipt log number mismatch, want %v, have %v" , len (receipt .Logs ), len (dec .Logs ))
104- }
105- for i := 0 ; i < len (dec .Logs ); i ++ {
106- if dec .Logs [i ].Address != receipt .Logs [i ].Address {
107- t .Fatalf ("Receipt log %d address mismatch, want %v, have %v" , i , receipt .Logs [i ].Address , dec .Logs [i ].Address )
108- }
109- if ! reflect .DeepEqual (dec .Logs [i ].Topics , receipt .Logs [i ].Topics ) {
110- t .Fatalf ("Receipt log %d topics mismatch, want %v, have %v" , i , receipt .Logs [i ].Topics , dec .Logs [i ].Topics )
111- }
112- if ! bytes .Equal (dec .Logs [i ].Data , receipt .Logs [i ].Data ) {
113- t .Fatalf ("Receipt log %d data mismatch, want %v, have %v" , i , receipt .Logs [i ].Data , dec .Logs [i ].Data )
114- }
115- }
116- })
117- }
118- }
119-
120- func encodeAsStoredReceiptRLP (want * Receipt ) ([]byte , error ) {
121- stored := & storedReceiptRLP {
122- PostStateOrStatus : want .statusEncoding (),
123- CumulativeGasUsed : want .CumulativeGasUsed ,
124- Logs : make ([]* LogForStorage , len (want .Logs )),
125- }
126- for i , log := range want .Logs {
127- stored .Logs [i ] = (* LogForStorage )(log )
128- }
129- return rlp .EncodeToBytes (stored )
130- }
131-
132- func encodeAsV4StoredReceiptRLP (want * Receipt ) ([]byte , error ) {
133- stored := & v4StoredReceiptRLP {
134- PostStateOrStatus : want .statusEncoding (),
135- CumulativeGasUsed : want .CumulativeGasUsed ,
136- TxHash : want .TxHash ,
137- ContractAddress : want .ContractAddress ,
138- Logs : make ([]* LogForStorage , len (want .Logs )),
139- GasUsed : want .GasUsed ,
140- }
141- for i , log := range want .Logs {
142- stored .Logs [i ] = (* LogForStorage )(log )
143- }
144- return rlp .EncodeToBytes (stored )
145- }
146-
147- func encodeAsV3StoredReceiptRLP (want * Receipt ) ([]byte , error ) {
148- stored := & v3StoredReceiptRLP {
149- PostStateOrStatus : want .statusEncoding (),
150- CumulativeGasUsed : want .CumulativeGasUsed ,
151- Bloom : want .Bloom ,
152- TxHash : want .TxHash ,
153- ContractAddress : want .ContractAddress ,
154- Logs : make ([]* LogForStorage , len (want .Logs )),
155- GasUsed : want .GasUsed ,
156- }
157- for i , log := range want .Logs {
158- stored .Logs [i ] = (* LogForStorage )(log )
159- }
160- return rlp .EncodeToBytes (stored )
161- }
162-
16340// Tests that receipt data can be correctly derived from the contextual infos
16441func TestDeriveFields (t * testing.T ) {
16542 // Create a few transactions to have receipts for
0 commit comments