mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
eth/protocols/eth: fix tests
This commit is contained in:
parent
fc4e4b3a5b
commit
ad8fe2f675
2 changed files with 43 additions and 36 deletions
|
|
@ -155,9 +155,11 @@ func (rl *ReceiptList69) EncodeForDatabase() []byte {
|
|||
if rl.buf == nil {
|
||||
rl.buf = new(receiptListBuffers)
|
||||
}
|
||||
|
||||
// TODO this is probably wrong
|
||||
var result []byte
|
||||
var b = new(bytes.Buffer)
|
||||
for _, r := range rl.items {
|
||||
var (
|
||||
r = &rl.items[i]
|
||||
bloom = r.bloom(&rl.buf.bloom)
|
||||
w = &rl.buf.enc
|
||||
)
|
||||
|
|
@ -170,11 +172,11 @@ func (rl *ReceiptList69) EncodeForDatabase() []byte {
|
|||
w.Write(r.Logs)
|
||||
w.ListEnd(l)
|
||||
if err := w.Flush(); err != nil {
|
||||
return
|
||||
return []byte{}
|
||||
}
|
||||
// if this is a legacy transaction receipt, we are done.
|
||||
if r.TxType == 0 {
|
||||
return
|
||||
continue
|
||||
}
|
||||
// Otherwise it's a typed transaction receipt, which has the type prefix and
|
||||
// the inner list as a byte-array: tx-type || rlp(list).
|
||||
|
|
@ -183,7 +185,9 @@ func (rl *ReceiptList69) EncodeForDatabase() []byte {
|
|||
w.WriteUint64(uint64(r.TxType))
|
||||
w.WriteBytes(b.Bytes())
|
||||
w.Flush()
|
||||
|
||||
result = append(result, b.Bytes()...)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (rl *ReceiptList69) toReceipts() []*types.Receipt {
|
||||
|
|
@ -202,7 +206,7 @@ func (rl *ReceiptList69) toReceipts() []*types.Receipt {
|
|||
// blockReceiptsToNetwork takes a slice of rlp-encoded receipts, and transactions,
|
||||
// and applies the type-encoding on the receipts (for non-legacy receipts).
|
||||
// e.g. for non-legacy receipts: receipt-data -> {tx-type || receipt-data}
|
||||
func blockReceiptsToNetwork(blockReceipts []byte, txs []*types.Transaction) []byte {
|
||||
func blockReceiptsToNetwork(blockReceipts rlp.RawValue, txs []*types.Transaction) []byte {
|
||||
var (
|
||||
out bytes.Buffer
|
||||
enc = rlp.NewEncoderBuffer(&out)
|
||||
|
|
@ -212,7 +216,7 @@ func blockReceiptsToNetwork(blockReceipts []byte, txs []*types.Transaction) []by
|
|||
for i := 0; it.Next(); i++ {
|
||||
content, _, _ := rlp.SplitList(it.Value())
|
||||
receiptList := enc.List()
|
||||
enc.Write([]byte{txs[i].Type()})
|
||||
enc.WriteUint64(uint64(txs[i].Type()))
|
||||
enc.Write(content)
|
||||
enc.ListEnd(receiptList)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ import (
|
|||
)
|
||||
|
||||
func TestTransformReceipts(t *testing.T) {
|
||||
logs := []*types.Log{{Address: common.Address{1}, Topics: []common.Hash{{1}}}}
|
||||
encLogs, _ := rlp.EncodeToBytes(logs)
|
||||
|
||||
tests := []struct {
|
||||
input []types.ReceiptForStorage
|
||||
txs []*types.Transaction
|
||||
|
|
@ -34,22 +37,22 @@ func TestTransformReceipts(t *testing.T) {
|
|||
{
|
||||
input: []types.ReceiptForStorage{{CumulativeGasUsed: 123, Status: 1, Logs: nil}},
|
||||
txs: []*types.Transaction{types.NewTx(&types.LegacyTx{})},
|
||||
output: []Receipt{{GasUsed: 123, PostStateOrStatus: []byte{1}, Logs: nil}},
|
||||
output: []Receipt{{GasUsed: 123, PostStateOrStatus: []byte{1}, Logs: rlp.EmptyList}},
|
||||
},
|
||||
{
|
||||
input: []types.ReceiptForStorage{{CumulativeGasUsed: 123, Status: 1, Logs: nil}},
|
||||
txs: []*types.Transaction{types.NewTx(&types.DynamicFeeTx{})},
|
||||
output: []Receipt{{GasUsed: 123, PostStateOrStatus: []byte{1}, Logs: nil, TxType: 2}},
|
||||
output: []Receipt{{GasUsed: 123, PostStateOrStatus: []byte{1}, Logs: rlp.EmptyList, TxType: 2}},
|
||||
},
|
||||
{
|
||||
input: []types.ReceiptForStorage{{CumulativeGasUsed: 123, Status: 1, Logs: nil}},
|
||||
txs: []*types.Transaction{types.NewTx(&types.AccessListTx{})},
|
||||
output: []Receipt{{GasUsed: 123, PostStateOrStatus: []byte{1}, Logs: nil, TxType: 1}},
|
||||
output: []Receipt{{GasUsed: 123, PostStateOrStatus: []byte{1}, Logs: rlp.EmptyList, TxType: 1}},
|
||||
},
|
||||
{
|
||||
input: []types.ReceiptForStorage{{CumulativeGasUsed: 123, Status: 1, Logs: []*types.Log{{Address: common.Address{1}, Topics: []common.Hash{{1}}}}}},
|
||||
input: []types.ReceiptForStorage{{CumulativeGasUsed: 123, Status: 1, Logs: logs}},
|
||||
txs: []*types.Transaction{types.NewTx(&types.AccessListTx{})},
|
||||
output: []Receipt{{GasUsed: 123, PostStateOrStatus: []byte{1}, Logs: []*types.Log{{Address: common.Address{1}, Topics: []common.Hash{{1}}}}, Type: 1}},
|
||||
output: []Receipt{{GasUsed: 123, PostStateOrStatus: []byte{1}, Logs: encLogs, TxType: 1}},
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -58,7 +61,7 @@ func TestTransformReceipts(t *testing.T) {
|
|||
have := blockReceiptsToNetwork(in, test.txs)
|
||||
out, _ := rlp.EncodeToBytes(test.output)
|
||||
if !bytes.Equal(have, out) {
|
||||
t.Fatalf("transforming receipt mismatch, test %v: want %v have %v", i, out, have)
|
||||
t.Fatalf("transforming receipt mismatch, test %v: want %v have %v, in %v", i, out, have, in)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue