fix client tests for GetReceipts

pull/4452/head
“GheisMohammadi” 1 year ago
parent a4d6ffc0e0
commit 985332e558
No known key found for this signature in database
GPG Key ID: 15073AED3829FE90
  1. 17
      p2p/stream/protocols/sync/chain_test.go
  2. 9
      p2p/stream/protocols/sync/client_test.go

@ -51,12 +51,11 @@ func (tch *testChainHelper) getNodeData(hs []common.Hash) ([][]byte, error) {
return data, nil
}
func (tch *testChainHelper) getReceipts(hs []common.Hash) ([][]byte, error) {
func (tch *testChainHelper) getReceipts(hs []common.Hash) ([]types.Receipts, error) {
testReceipts := makeTestReceipts(len(hs), 3)
receipts := make([][]byte, 0, len(hs)*3)
for _, r := range testReceipts {
receiptByes, _ := rlp.EncodeToBytes(r)
receipts = append(receipts, receiptByes)
receipts := make([]types.Receipts, len(hs)*3)
for i, _ := range hs {
receipts[i] = testReceipts
}
return receipts, nil
}
@ -115,7 +114,7 @@ func makeTestNodeData(n int) [][]byte {
}
// makeTestReceipts creates fake receipts
func makeTestReceipts(n int, nPerBlock int) []types.Receipts {
func makeTestReceipts(n int, nPerBlock int) []*types.Receipt {
receipts := make([]*types.Receipt, nPerBlock)
for i := 0; i < nPerBlock; i++ {
receipts[i] = &types.Receipt{
@ -124,11 +123,7 @@ func makeTestReceipts(n int, nPerBlock int) []types.Receipts {
Logs: make([]*types.Log, 5),
}
}
allReceipts := make([]types.Receipts, n)
for i := 0; i < n; i++ {
allReceipts[i] = receipts
}
return allReceipts
return receipts
}
func decodeBlocksBytes(bbs [][]byte) ([]*types.Block, error) {

@ -15,6 +15,7 @@ import (
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/p2p/stream/common/ratelimiter"
"github.com/harmony-one/harmony/p2p/stream/common/streammanager"
"github.com/harmony-one/harmony/p2p/stream/protocols/sync/message"
syncpb "github.com/harmony-one/harmony/p2p/stream/protocols/sync/message"
sttypes "github.com/harmony-one/harmony/p2p/stream/types"
)
@ -59,7 +60,10 @@ var (
testBlocksByHashesResponse = syncpb.MakeGetBlocksByHashesResponse(0, [][]byte{testBlockBytes}, make([][]byte, 1))
testReceiptResponse = syncpb.MakeGetReceiptsResponse(0, [][]byte{testReceiptBytes})
testReceipsMap = map[uint64]*message.Receipts{
0: {ReceiptBytes: [][]byte{testReceiptBytes}},
}
testReceiptResponse = syncpb.MakeGetReceiptsResponse(0, testReceipsMap)
testNodeDataResponse = syncpb.MakeGetNodeDataResponse(0, [][]byte{testNodeDataBytes})
@ -358,6 +362,9 @@ func TestProtocol_GetReceipts(t *testing.T) {
if len(receipts) != 1 {
t.Errorf("Test %v: size not 1", i)
}
if len(receipts[0]) != 1 {
t.Errorf("Test %v: block receipts size not 1", i)
}
}
}
}

Loading…
Cancel
Save