|
1 | 1 | package syncer
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "fmt" |
5 |
| - "io/ioutil" |
6 |
| - "math/big" |
7 | 4 | "testing"
|
8 | 5 |
|
9 |
| - "github.com/ethereum/go-ethereum/common" |
10 |
| - gethTypes "github.com/ethereum/go-ethereum/core/types" |
11 | 6 | "github.com/prysmaticlabs/prysm/client/mainchain"
|
12 | 7 | "github.com/prysmaticlabs/prysm/client/params"
|
13 |
| - "github.com/prysmaticlabs/prysm/client/types" |
14 |
| - pb "github.com/prysmaticlabs/prysm/proto/sharding/p2p/v1" |
15 | 8 | "github.com/prysmaticlabs/prysm/shared"
|
16 | 9 | "github.com/prysmaticlabs/prysm/shared/database"
|
17 | 10 | "github.com/prysmaticlabs/prysm/shared/p2p"
|
18 |
| - "github.com/sirupsen/logrus" |
19 | 11 | logTest "github.com/sirupsen/logrus/hooks/test"
|
20 | 12 | )
|
21 | 13 |
|
22 | 14 | var _ = shared.Service(&Syncer{})
|
23 | 15 |
|
24 |
| -func init() { |
25 |
| - logrus.SetLevel(logrus.DebugLevel) |
26 |
| - logrus.SetOutput(ioutil.Discard) |
27 |
| -} |
28 |
| - |
29 | 16 | func TestStop(t *testing.T) {
|
30 | 17 | hook := logTest.NewGlobal()
|
31 | 18 |
|
@@ -63,77 +50,3 @@ func TestStop(t *testing.T) {
|
63 | 50 | }
|
64 | 51 | hook.Reset()
|
65 | 52 | }
|
66 |
| - |
67 |
| -// This test checks the proper functioning of the handleCollationBodyRequests goroutine |
68 |
| -// by listening to the responseSent channel which occurs after successful |
69 |
| -// construction and sending of a response via p2p. |
70 |
| -func TestHandleCollationBodyRequests(t *testing.T) { |
71 |
| - hook := logTest.NewGlobal() |
72 |
| - |
73 |
| - config := &database.DBConfig{Name: "", DataDir: "", InMemory: true} |
74 |
| - shardChainDB, err := database.NewDB(config) |
75 |
| - if err != nil { |
76 |
| - t.Fatalf("unable to setup db: %v", err) |
77 |
| - } |
78 |
| - server, err := p2p.NewServer() |
79 |
| - if err != nil { |
80 |
| - t.Fatalf("Unable to setup p2p server: %v", err) |
81 |
| - } |
82 |
| - |
83 |
| - body := []byte{1, 2, 3, 4, 5} |
84 |
| - shardID := big.NewInt(0) |
85 |
| - chunkRoot := gethTypes.DeriveSha(types.Chunks(body)) |
86 |
| - period := big.NewInt(0) |
87 |
| - proposerAddress := common.BytesToAddress([]byte{}) |
88 |
| - |
89 |
| - header := types.NewCollationHeader(shardID, &chunkRoot, period, &proposerAddress, [32]byte{}) |
90 |
| - // Stores the collation into the inmemory kv store shardChainDB. |
91 |
| - collation := types.NewCollation(header, body, nil) |
92 |
| - |
93 |
| - shard := types.NewShard(shardID, shardChainDB.DB()) |
94 |
| - |
95 |
| - if err := shard.SaveCollation(collation); err != nil { |
96 |
| - t.Fatalf("Could not store collation in shardChainDB: %v", err) |
97 |
| - } |
98 |
| - |
99 |
| - syncer, err := NewSyncer(params.DefaultConfig(), &mainchain.SMCClient{}, server, shardChainDB, 0) |
100 |
| - if err != nil { |
101 |
| - t.Fatalf("Unable to setup syncer service: %v", err) |
102 |
| - } |
103 |
| - syncer.Start() |
104 |
| - syncer.collationBodyBuf = make(chan p2p.Message) |
105 |
| - |
106 |
| - doneChan := make(chan struct{}) |
107 |
| - exitRoutine := make(chan bool) |
108 |
| - |
109 |
| - go func() { |
110 |
| - syncer.run(doneChan) |
111 |
| - <-exitRoutine |
112 |
| - }() |
113 |
| - |
114 |
| - msg := p2p.Message{ |
115 |
| - Peer: p2p.Peer{}, |
116 |
| - Data: &pb.CollationBodyRequest{ |
117 |
| - ChunkRoot: chunkRoot.Bytes(), |
118 |
| - ShardId: shardID.Uint64(), |
119 |
| - Period: period.Uint64(), |
120 |
| - ProposerAddress: proposerAddress.Bytes(), |
121 |
| - }, |
122 |
| - } |
123 |
| - syncer.collationBodyBuf <- msg |
124 |
| - doneChan <- struct{}{} |
125 |
| - exitRoutine <- true |
126 |
| - |
127 |
| - logMsg := hook.Entries[1].Message |
128 |
| - want := fmt.Sprintf("Received p2p request of type: %T", &pb.CollationBodyRequest{}) |
129 |
| - if logMsg != want { |
130 |
| - t.Errorf("incorrect log, expected %s, got %s", want, logMsg) |
131 |
| - } |
132 |
| - |
133 |
| - logMsg = hook.Entries[4].Message |
134 |
| - want = fmt.Sprintf("Responding to p2p collation request") |
135 |
| - if logMsg != want { |
136 |
| - t.Errorf("incorrect log, expected %s, got %s", want, logMsg) |
137 |
| - } |
138 |
| - hook.Reset() |
139 |
| -} |
0 commit comments