github.com/EgonCoin/EgonChain@v1.10.16/core/types/receipt_test.go (about) 1 // Copyright 2019 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package types 18 19 import ( 20 "bytes" 21 "math" 22 "math/big" 23 "reflect" 24 "testing" 25 26 "github.com/EgonCoin/EgonChain/common" 27 "github.com/EgonCoin/EgonChain/crypto" 28 "github.com/EgonCoin/EgonChain/params" 29 "github.com/EgonCoin/EgonChain/rlp" 30 ) 31 32 var ( 33 legacyReceipt = &Receipt{ 34 Status: ReceiptStatusFailed, 35 CumulativeGasUsed: 1, 36 Logs: []*Log{ 37 { 38 Address: common.BytesToAddress([]byte{0x11}), 39 Topics: []common.Hash{common.HexToHash("dead"), common.HexToHash("beef")}, 40 Data: []byte{0x01, 0x00, 0xff}, 41 }, 42 { 43 Address: common.BytesToAddress([]byte{0x01, 0x11}), 44 Topics: []common.Hash{common.HexToHash("dead"), common.HexToHash("beef")}, 45 Data: []byte{0x01, 0x00, 0xff}, 46 }, 47 }, 48 } 49 accessListReceipt = &Receipt{ 50 Status: ReceiptStatusFailed, 51 CumulativeGasUsed: 1, 52 Logs: []*Log{ 53 { 54 Address: common.BytesToAddress([]byte{0x11}), 55 Topics: []common.Hash{common.HexToHash("dead"), common.HexToHash("beef")}, 56 Data: []byte{0x01, 0x00, 0xff}, 57 }, 58 { 59 Address: common.BytesToAddress([]byte{0x01, 0x11}), 60 Topics: []common.Hash{common.HexToHash("dead"), common.HexToHash("beef")}, 61 Data: []byte{0x01, 0x00, 0xff}, 62 }, 63 }, 64 Type: AccessListTxType, 65 } 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 } 83 ) 84 85 func TestDecodeEmptyTypedReceipt(t *testing.T) { 86 input := []byte{0x80} 87 var r Receipt 88 err := rlp.DecodeBytes(input, &r) 89 if err != errEmptyTypedReceipt { 90 t.Fatal("wrong error:", err) 91 } 92 } 93 94 func TestLegacyReceiptDecoding(t *testing.T) { 95 tests := []struct { 96 name string 97 encode func(*Receipt) ([]byte, error) 98 }{ 99 { 100 "StoredReceiptRLP", 101 encodeAsStoredReceiptRLP, 102 }, 103 { 104 "V4StoredReceiptRLP", 105 encodeAsV4StoredReceiptRLP, 106 }, 107 { 108 "V3StoredReceiptRLP", 109 encodeAsV3StoredReceiptRLP, 110 }, 111 } 112 113 tx := NewTransaction(1, common.HexToAddress("0x1"), big.NewInt(1), 1, big.NewInt(1), nil) 114 receipt := &Receipt{ 115 Status: ReceiptStatusFailed, 116 CumulativeGasUsed: 1, 117 Logs: []*Log{ 118 { 119 Address: common.BytesToAddress([]byte{0x11}), 120 Topics: []common.Hash{common.HexToHash("dead"), common.HexToHash("beef")}, 121 Data: []byte{0x01, 0x00, 0xff}, 122 }, 123 { 124 Address: common.BytesToAddress([]byte{0x01, 0x11}), 125 Topics: []common.Hash{common.HexToHash("dead"), common.HexToHash("beef")}, 126 Data: []byte{0x01, 0x00, 0xff}, 127 }, 128 }, 129 TxHash: tx.Hash(), 130 ContractAddress: common.BytesToAddress([]byte{0x01, 0x11, 0x11}), 131 GasUsed: 111111, 132 } 133 receipt.Bloom = CreateBloom(Receipts{receipt}) 134 135 for _, tc := range tests { 136 t.Run(tc.name, func(t *testing.T) { 137 enc, err := tc.encode(receipt) 138 if err != nil { 139 t.Fatalf("Error encoding receipt: %v", err) 140 } 141 var dec ReceiptForStorage 142 if err := rlp.DecodeBytes(enc, &dec); err != nil { 143 t.Fatalf("Error decoding RLP receipt: %v", err) 144 } 145 // Check whether all consensus fields are correct. 146 if dec.Status != receipt.Status { 147 t.Fatalf("Receipt status mismatch, want %v, have %v", receipt.Status, dec.Status) 148 } 149 if dec.CumulativeGasUsed != receipt.CumulativeGasUsed { 150 t.Fatalf("Receipt CumulativeGasUsed mismatch, want %v, have %v", receipt.CumulativeGasUsed, dec.CumulativeGasUsed) 151 } 152 if dec.Bloom != receipt.Bloom { 153 t.Fatalf("Bloom data mismatch, want %v, have %v", receipt.Bloom, dec.Bloom) 154 } 155 if len(dec.Logs) != len(receipt.Logs) { 156 t.Fatalf("Receipt log number mismatch, want %v, have %v", len(receipt.Logs), len(dec.Logs)) 157 } 158 for i := 0; i < len(dec.Logs); i++ { 159 if dec.Logs[i].Address != receipt.Logs[i].Address { 160 t.Fatalf("Receipt log %d address mismatch, want %v, have %v", i, receipt.Logs[i].Address, dec.Logs[i].Address) 161 } 162 if !reflect.DeepEqual(dec.Logs[i].Topics, receipt.Logs[i].Topics) { 163 t.Fatalf("Receipt log %d topics mismatch, want %v, have %v", i, receipt.Logs[i].Topics, dec.Logs[i].Topics) 164 } 165 if !bytes.Equal(dec.Logs[i].Data, receipt.Logs[i].Data) { 166 t.Fatalf("Receipt log %d data mismatch, want %v, have %v", i, receipt.Logs[i].Data, dec.Logs[i].Data) 167 } 168 } 169 }) 170 } 171 } 172 173 func encodeAsStoredReceiptRLP(want *Receipt) ([]byte, error) { 174 stored := &storedReceiptRLP{ 175 PostStateOrStatus: want.statusEncoding(), 176 CumulativeGasUsed: want.CumulativeGasUsed, 177 Logs: make([]*LogForStorage, len(want.Logs)), 178 } 179 for i, log := range want.Logs { 180 stored.Logs[i] = (*LogForStorage)(log) 181 } 182 return rlp.EncodeToBytes(stored) 183 } 184 185 func encodeAsV4StoredReceiptRLP(want *Receipt) ([]byte, error) { 186 stored := &v4StoredReceiptRLP{ 187 PostStateOrStatus: want.statusEncoding(), 188 CumulativeGasUsed: want.CumulativeGasUsed, 189 TxHash: want.TxHash, 190 ContractAddress: want.ContractAddress, 191 Logs: make([]*LogForStorage, len(want.Logs)), 192 GasUsed: want.GasUsed, 193 } 194 for i, log := range want.Logs { 195 stored.Logs[i] = (*LogForStorage)(log) 196 } 197 return rlp.EncodeToBytes(stored) 198 } 199 200 func encodeAsV3StoredReceiptRLP(want *Receipt) ([]byte, error) { 201 stored := &v3StoredReceiptRLP{ 202 PostStateOrStatus: want.statusEncoding(), 203 CumulativeGasUsed: want.CumulativeGasUsed, 204 Bloom: want.Bloom, 205 TxHash: want.TxHash, 206 ContractAddress: want.ContractAddress, 207 Logs: make([]*LogForStorage, len(want.Logs)), 208 GasUsed: want.GasUsed, 209 } 210 for i, log := range want.Logs { 211 stored.Logs[i] = (*LogForStorage)(log) 212 } 213 return rlp.EncodeToBytes(stored) 214 } 215 216 // Tests that receipt data can be correctly derived from the contextual infos 217 func TestDeriveFields(t *testing.T) { 218 // Create a few transactions to have receipts for 219 to2 := common.HexToAddress("0x2") 220 to3 := common.HexToAddress("0x3") 221 txs := Transactions{ 222 NewTx(&LegacyTx{ 223 Nonce: 1, 224 Value: big.NewInt(1), 225 Gas: 1, 226 GasPrice: big.NewInt(1), 227 }), 228 NewTx(&LegacyTx{ 229 To: &to2, 230 Nonce: 2, 231 Value: big.NewInt(2), 232 Gas: 2, 233 GasPrice: big.NewInt(2), 234 }), 235 NewTx(&AccessListTx{ 236 To: &to3, 237 Nonce: 3, 238 Value: big.NewInt(3), 239 Gas: 3, 240 GasPrice: big.NewInt(3), 241 }), 242 } 243 // Create the corresponding receipts 244 receipts := Receipts{ 245 &Receipt{ 246 Status: ReceiptStatusFailed, 247 CumulativeGasUsed: 1, 248 Logs: []*Log{ 249 {Address: common.BytesToAddress([]byte{0x11})}, 250 {Address: common.BytesToAddress([]byte{0x01, 0x11})}, 251 }, 252 TxHash: txs[0].Hash(), 253 ContractAddress: common.BytesToAddress([]byte{0x01, 0x11, 0x11}), 254 GasUsed: 1, 255 }, 256 &Receipt{ 257 PostState: common.Hash{2}.Bytes(), 258 CumulativeGasUsed: 3, 259 Logs: []*Log{ 260 {Address: common.BytesToAddress([]byte{0x22})}, 261 {Address: common.BytesToAddress([]byte{0x02, 0x22})}, 262 }, 263 TxHash: txs[1].Hash(), 264 ContractAddress: common.BytesToAddress([]byte{0x02, 0x22, 0x22}), 265 GasUsed: 2, 266 }, 267 &Receipt{ 268 Type: AccessListTxType, 269 PostState: common.Hash{3}.Bytes(), 270 CumulativeGasUsed: 6, 271 Logs: []*Log{ 272 {Address: common.BytesToAddress([]byte{0x33})}, 273 {Address: common.BytesToAddress([]byte{0x03, 0x33})}, 274 }, 275 TxHash: txs[2].Hash(), 276 ContractAddress: common.BytesToAddress([]byte{0x03, 0x33, 0x33}), 277 GasUsed: 3, 278 }, 279 } 280 // Clear all the computed fields and re-derive them 281 number := big.NewInt(1) 282 hash := common.BytesToHash([]byte{0x03, 0x14}) 283 284 clearComputedFieldsOnReceipts(t, receipts) 285 if err := receipts.DeriveFields(params.TestChainConfig, hash, number.Uint64(), txs); err != nil { 286 t.Fatalf("DeriveFields(...) = %v, want <nil>", err) 287 } 288 // Iterate over all the computed fields and check that they're correct 289 signer := MakeSigner(params.TestChainConfig, number) 290 291 logIndex := uint(0) 292 for i := range receipts { 293 if receipts[i].Type != txs[i].Type() { 294 t.Errorf("receipts[%d].Type = %d, want %d", i, receipts[i].Type, txs[i].Type()) 295 } 296 if receipts[i].TxHash != txs[i].Hash() { 297 t.Errorf("receipts[%d].TxHash = %s, want %s", i, receipts[i].TxHash.String(), txs[i].Hash().String()) 298 } 299 if receipts[i].BlockHash != hash { 300 t.Errorf("receipts[%d].BlockHash = %s, want %s", i, receipts[i].BlockHash.String(), hash.String()) 301 } 302 if receipts[i].BlockNumber.Cmp(number) != 0 { 303 t.Errorf("receipts[%c].BlockNumber = %s, want %s", i, receipts[i].BlockNumber.String(), number.String()) 304 } 305 if receipts[i].TransactionIndex != uint(i) { 306 t.Errorf("receipts[%d].TransactionIndex = %d, want %d", i, receipts[i].TransactionIndex, i) 307 } 308 if receipts[i].GasUsed != txs[i].Gas() { 309 t.Errorf("receipts[%d].GasUsed = %d, want %d", i, receipts[i].GasUsed, txs[i].Gas()) 310 } 311 if txs[i].To() != nil && receipts[i].ContractAddress != (common.Address{}) { 312 t.Errorf("receipts[%d].ContractAddress = %s, want %s", i, receipts[i].ContractAddress.String(), (common.Address{}).String()) 313 } 314 from, _ := Sender(signer, txs[i]) 315 contractAddress := crypto.CreateAddress(from, txs[i].Nonce()) 316 if txs[i].To() == nil && receipts[i].ContractAddress != contractAddress { 317 t.Errorf("receipts[%d].ContractAddress = %s, want %s", i, receipts[i].ContractAddress.String(), contractAddress.String()) 318 } 319 for j := range receipts[i].Logs { 320 if receipts[i].Logs[j].BlockNumber != number.Uint64() { 321 t.Errorf("receipts[%d].Logs[%d].BlockNumber = %d, want %d", i, j, receipts[i].Logs[j].BlockNumber, number.Uint64()) 322 } 323 if receipts[i].Logs[j].BlockHash != hash { 324 t.Errorf("receipts[%d].Logs[%d].BlockHash = %s, want %s", i, j, receipts[i].Logs[j].BlockHash.String(), hash.String()) 325 } 326 if receipts[i].Logs[j].TxHash != txs[i].Hash() { 327 t.Errorf("receipts[%d].Logs[%d].TxHash = %s, want %s", i, j, receipts[i].Logs[j].TxHash.String(), txs[i].Hash().String()) 328 } 329 if receipts[i].Logs[j].TxIndex != uint(i) { 330 t.Errorf("receipts[%d].Logs[%d].TransactionIndex = %d, want %d", i, j, receipts[i].Logs[j].TxIndex, i) 331 } 332 if receipts[i].Logs[j].Index != logIndex { 333 t.Errorf("receipts[%d].Logs[%d].Index = %d, want %d", i, j, receipts[i].Logs[j].Index, logIndex) 334 } 335 logIndex++ 336 } 337 } 338 } 339 340 // TestTypedReceiptEncodingDecoding reproduces a flaw that existed in the receipt 341 // rlp decoder, which failed due to a shadowing error. 342 func TestTypedReceiptEncodingDecoding(t *testing.T) { 343 var payload = common.FromHex("f9043eb9010c01f90108018262d4b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0b9010c01f901080182cd14b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0b9010d01f901090183013754b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0b9010d01f90109018301a194b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0") 344 check := func(bundle []*Receipt) { 345 t.Helper() 346 for i, receipt := range bundle { 347 if got, want := receipt.Type, uint8(1); got != want { 348 t.Fatalf("bundle %d: got %x, want %x", i, got, want) 349 } 350 } 351 } 352 { 353 var bundle []*Receipt 354 rlp.DecodeBytes(payload, &bundle) 355 check(bundle) 356 } 357 { 358 var bundle []*Receipt 359 r := bytes.NewReader(payload) 360 s := rlp.NewStream(r, uint64(len(payload))) 361 if err := s.Decode(&bundle); err != nil { 362 t.Fatal(err) 363 } 364 check(bundle) 365 } 366 } 367 368 func TestReceiptMarshalBinary(t *testing.T) { 369 // Legacy Receipt 370 legacyReceipt.Bloom = CreateBloom(Receipts{legacyReceipt}) 371 have, err := legacyReceipt.MarshalBinary() 372 if err != nil { 373 t.Fatalf("marshal binary error: %v", err) 374 } 375 legacyReceipts := Receipts{legacyReceipt} 376 buf := new(bytes.Buffer) 377 legacyReceipts.EncodeIndex(0, buf) 378 haveEncodeIndex := buf.Bytes() 379 if !bytes.Equal(have, haveEncodeIndex) { 380 t.Errorf("BinaryMarshal and EncodeIndex mismatch, got %x want %x", have, haveEncodeIndex) 381 } 382 buf.Reset() 383 if err := legacyReceipt.EncodeRLP(buf); err != nil { 384 t.Fatalf("encode rlp error: %v", err) 385 } 386 haveRLPEncode := buf.Bytes() 387 if !bytes.Equal(have, haveRLPEncode) { 388 t.Errorf("BinaryMarshal and EncodeRLP mismatch for legacy tx, got %x want %x", have, haveRLPEncode) 389 } 390 legacyWant := common.FromHex("f901c58001b9010000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000010000080000000000000000000004000000000000000000000000000040000000000000000000000000000800000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000f8bef85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100fff85d940000000000000000000000000000000000000111f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff") 391 if !bytes.Equal(have, legacyWant) { 392 t.Errorf("encoded RLP mismatch, got %x want %x", have, legacyWant) 393 } 394 395 // 2930 Receipt 396 buf.Reset() 397 accessListReceipt.Bloom = CreateBloom(Receipts{accessListReceipt}) 398 have, err = accessListReceipt.MarshalBinary() 399 if err != nil { 400 t.Fatalf("marshal binary error: %v", err) 401 } 402 accessListReceipts := Receipts{accessListReceipt} 403 accessListReceipts.EncodeIndex(0, buf) 404 haveEncodeIndex = buf.Bytes() 405 if !bytes.Equal(have, haveEncodeIndex) { 406 t.Errorf("BinaryMarshal and EncodeIndex mismatch, got %x want %x", have, haveEncodeIndex) 407 } 408 accessListWant := common.FromHex("01f901c58001b9010000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000010000080000000000000000000004000000000000000000000000000040000000000000000000000000000800000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000f8bef85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100fff85d940000000000000000000000000000000000000111f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff") 409 if !bytes.Equal(have, accessListWant) { 410 t.Errorf("encoded RLP mismatch, got %x want %x", have, accessListWant) 411 } 412 413 // 1559 Receipt 414 buf.Reset() 415 eip1559Receipt.Bloom = CreateBloom(Receipts{eip1559Receipt}) 416 have, err = eip1559Receipt.MarshalBinary() 417 if err != nil { 418 t.Fatalf("marshal binary error: %v", err) 419 } 420 eip1559Receipts := Receipts{eip1559Receipt} 421 eip1559Receipts.EncodeIndex(0, buf) 422 haveEncodeIndex = buf.Bytes() 423 if !bytes.Equal(have, haveEncodeIndex) { 424 t.Errorf("BinaryMarshal and EncodeIndex mismatch, got %x want %x", have, haveEncodeIndex) 425 } 426 eip1559Want := common.FromHex("02f901c58001b9010000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000010000080000000000000000000004000000000000000000000000000040000000000000000000000000000800000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000f8bef85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100fff85d940000000000000000000000000000000000000111f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff") 427 if !bytes.Equal(have, eip1559Want) { 428 t.Errorf("encoded RLP mismatch, got %x want %x", have, eip1559Want) 429 } 430 } 431 432 func TestReceiptUnmarshalBinary(t *testing.T) { 433 // Legacy Receipt 434 legacyBinary := common.FromHex("f901c58001b9010000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000010000080000000000000000000004000000000000000000000000000040000000000000000000000000000800000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000f8bef85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100fff85d940000000000000000000000000000000000000111f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff") 435 gotLegacyReceipt := new(Receipt) 436 if err := gotLegacyReceipt.UnmarshalBinary(legacyBinary); err != nil { 437 t.Fatalf("unmarshal binary error: %v", err) 438 } 439 legacyReceipt.Bloom = CreateBloom(Receipts{legacyReceipt}) 440 if !reflect.DeepEqual(gotLegacyReceipt, legacyReceipt) { 441 t.Errorf("receipt unmarshalled from binary mismatch, got %v want %v", gotLegacyReceipt, legacyReceipt) 442 } 443 444 // 2930 Receipt 445 accessListBinary := common.FromHex("01f901c58001b9010000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000010000080000000000000000000004000000000000000000000000000040000000000000000000000000000800000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000f8bef85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100fff85d940000000000000000000000000000000000000111f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff") 446 gotAccessListReceipt := new(Receipt) 447 if err := gotAccessListReceipt.UnmarshalBinary(accessListBinary); err != nil { 448 t.Fatalf("unmarshal binary error: %v", err) 449 } 450 accessListReceipt.Bloom = CreateBloom(Receipts{accessListReceipt}) 451 if !reflect.DeepEqual(gotAccessListReceipt, accessListReceipt) { 452 t.Errorf("receipt unmarshalled from binary mismatch, got %v want %v", gotAccessListReceipt, accessListReceipt) 453 } 454 455 // 1559 Receipt 456 eip1559RctBinary := common.FromHex("02f901c58001b9010000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000010000080000000000000000000004000000000000000000000000000040000000000000000000000000000800000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000f8bef85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100fff85d940000000000000000000000000000000000000111f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff") 457 got1559Receipt := new(Receipt) 458 if err := got1559Receipt.UnmarshalBinary(eip1559RctBinary); err != nil { 459 t.Fatalf("unmarshal binary error: %v", err) 460 } 461 eip1559Receipt.Bloom = CreateBloom(Receipts{eip1559Receipt}) 462 if !reflect.DeepEqual(got1559Receipt, eip1559Receipt) { 463 t.Errorf("receipt unmarshalled from binary mismatch, got %v want %v", got1559Receipt, eip1559Receipt) 464 } 465 } 466 467 func clearComputedFieldsOnReceipts(t *testing.T, receipts Receipts) { 468 t.Helper() 469 470 for _, receipt := range receipts { 471 clearComputedFieldsOnReceipt(t, receipt) 472 } 473 } 474 475 func clearComputedFieldsOnReceipt(t *testing.T, receipt *Receipt) { 476 t.Helper() 477 478 receipt.TxHash = common.Hash{} 479 receipt.BlockHash = common.Hash{} 480 receipt.BlockNumber = big.NewInt(math.MaxUint32) 481 receipt.TransactionIndex = math.MaxUint32 482 receipt.ContractAddress = common.Address{} 483 receipt.GasUsed = 0 484 485 clearComputedFieldsOnLogs(t, receipt.Logs) 486 } 487 488 func clearComputedFieldsOnLogs(t *testing.T, logs []*Log) { 489 t.Helper() 490 491 for _, log := range logs { 492 clearComputedFieldsOnLog(t, log) 493 } 494 } 495 496 func clearComputedFieldsOnLog(t *testing.T, log *Log) { 497 t.Helper() 498 499 log.BlockNumber = math.MaxUint32 500 log.BlockHash = common.Hash{} 501 log.TxHash = common.Hash{} 502 log.TxIndex = math.MaxUint32 503 log.Index = math.MaxUint32 504 }