MCPcopy Create free account
hub / github.com/DNAProject/DNA / testCalcParticipantPeers

Function testCalcParticipantPeers

consensus/vbft/node_utils_test.go:180–232  ·  view source on GitHub ↗
(t *testing.T, n, c int)

Source from the content-addressed store, hash-verified

178}
179
180func testCalcParticipantPeers(t *testing.T, n, c int) {
181 server := constructServer()
182
183 pos := make([]uint32, 0)
184 for i := 0; i < n; i++ {
185 for j := 0; j < 4; j++ {
186 pos = append(pos, uint32(i))
187 }
188 }
189
190 chainCfg := server.config
191 chainCfg.N = uint32(n)
192 chainCfg.C = uint32(c)
193 chainCfg.PosTable = pos
194 chainCfg.Peers = make([]*vconfig.PeerConfig, 0)
195 for i := 0; i < n; i++ {
196 chainCfg.Peers = append(chainCfg.Peers, &vconfig.PeerConfig{
197 Index: uint32(i),
198 ID: fmt.Sprintf("test-%d", i)})
199 }
200
201 cfg := &BlockParticipantConfig{
202 BlockNum: 100,
203 Vrf: newTestVrfValue(),
204 ChainConfig: chainCfg,
205 }
206
207 pp, pe, pc := calcParticipantPeers(cfg, chainCfg)
208 if len(pp) != c+1 {
209 t.Fatalf("invalid proposal peer(%d, %d): %v, %v, %v", n, c, pp, pe, pc)
210 }
211 if len(pe) < 2*c {
212 t.Fatalf("invalid endorse peer(%d, %d): %v, %v, %v", n, c, pp, pe, pc)
213 }
214 if len(pc) < 2*c {
215 t.Fatalf("invalid commit peer(%d, %d): %v, %v, %v", n, c, pp, pe, pc)
216 }
217
218 // check how many peers are selected
219 peers := make(map[uint32]bool)
220 for _, p := range pp {
221 peers[p] = true
222 }
223 for _, p := range pe {
224 peers[p] = true
225 }
226 for _, p := range pc {
227 peers[p] = true
228 }
229 if len(peers) < 2*c+1 {
230 t.Fatalf("peers(%d, %d, %d, %d, %d, %d): %v, %v, %v", n, c, len(peers), len(pp), len(pe), len(pc), pp, pe, pc)
231 }
232}

Callers 1

TestCalcParticipantPeersFunction · 0.85

Calls 4

constructServerFunction · 0.85
newTestVrfValueFunction · 0.85
calcParticipantPeersFunction · 0.85
FatalfMethod · 0.80

Tested by

no test coverage detected