(t *testing.T, n, c int)
| 178 | } |
| 179 | |
| 180 | func 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 | } |
no test coverage detected