From 985332e558e268981ba27cc7c536f513934cafc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CGheisMohammadi=E2=80=9D?= <36589218+GheisMohammadi@users.noreply.github.com> Date: Thu, 6 Jul 2023 01:34:28 +0800 Subject: [PATCH] fix client tests for GetReceipts --- p2p/stream/protocols/sync/chain_test.go | 17 ++++++----------- p2p/stream/protocols/sync/client_test.go | 9 ++++++++- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/p2p/stream/protocols/sync/chain_test.go b/p2p/stream/protocols/sync/chain_test.go index b3d3f463f..8883d7cb5 100644 --- a/p2p/stream/protocols/sync/chain_test.go +++ b/p2p/stream/protocols/sync/chain_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) { diff --git a/p2p/stream/protocols/sync/client_test.go b/p2p/stream/protocols/sync/client_test.go index 9a675fa0d..edfa126d0 100644 --- a/p2p/stream/protocols/sync/client_test.go +++ b/p2p/stream/protocols/sync/client_test.go @@ -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) + } } } }