(t *testing.T)
| 215 | } |
| 216 | |
| 217 | func TestCreateChannelBySnapshot(t *testing.T) { |
| 218 | peerInstance, cleanup := NewTestPeer(t) |
| 219 | defer cleanup() |
| 220 | |
| 221 | var initArg string |
| 222 | waitCh := make(chan struct{}) |
| 223 | peerInstance.Initialize( |
| 224 | func(cid string) { |
| 225 | <-waitCh |
| 226 | initArg = cid |
| 227 | }, |
| 228 | nil, |
| 229 | plugin.MapBasedMapper(map[string]validation.PluginFactory{}), |
| 230 | &ledgermocks.DeployedChaincodeInfoProvider{}, |
| 231 | nil, |
| 232 | nil, |
| 233 | runtime.NumCPU(), |
| 234 | ) |
| 235 | |
| 236 | testChannelID := "createchannelbysnapshot" |
| 237 | |
| 238 | // create a temp dir to store snapshot |
| 239 | tempdir := t.TempDir() |
| 240 | |
| 241 | snapshotDir := ledgermgmttest.CreateSnapshotWithGenesisBlock(t, tempdir, testChannelID, &ConfigTxProcessor{}) |
| 242 | err := peerInstance.CreateChannelFromSnapshot(snapshotDir, &ledgermocks.DeployedChaincodeInfoProvider{}, nil, nil) |
| 243 | require.NoError(t, err) |
| 244 | |
| 245 | expectedStatus := &pb.JoinBySnapshotStatus{InProgress: true, BootstrappingSnapshotDir: snapshotDir} |
| 246 | require.Equal(t, expectedStatus, peerInstance.JoinBySnapshotStatus()) |
| 247 | |
| 248 | // write a msg to waitCh to unblock channel init func |
| 249 | waitCh <- struct{}{} |
| 250 | |
| 251 | // wait until ledger creation is done |
| 252 | ledgerCreationDone := func() bool { |
| 253 | return !peerInstance.JoinBySnapshotStatus().InProgress |
| 254 | } |
| 255 | require.Eventually(t, ledgerCreationDone, time.Minute, time.Second) |
| 256 | |
| 257 | // verify channel init func is called |
| 258 | require.Equal(t, testChannelID, initArg) |
| 259 | |
| 260 | // verify ledger created |
| 261 | ledger := peerInstance.GetLedger(testChannelID) |
| 262 | require.NotNil(t, ledger) |
| 263 | |
| 264 | bcInfo, err := ledger.GetBlockchainInfo() |
| 265 | require.NoError(t, err) |
| 266 | require.Equal(t, uint64(1), bcInfo.GetHeight()) |
| 267 | |
| 268 | expectedStatus = &pb.JoinBySnapshotStatus{InProgress: false, BootstrappingSnapshotDir: ""} |
| 269 | require.Equal(t, expectedStatus, peerInstance.JoinBySnapshotStatus()) |
| 270 | |
| 271 | // Bad ledger |
| 272 | ledger = peerInstance.GetLedger("BogusChain") |
| 273 | require.Nil(t, ledger) |
| 274 |
nothing calls this directly
no test coverage detected