MCPcopy
hub / github.com/hyperledger/fabric / TestCreateChannelBySnapshot

Function TestCreateChannelBySnapshot

core/peer/peer_test.go:217–285  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

215}
216
217func 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

Callers

nothing calls this directly

Calls 12

MapBasedMapperTypeAlias · 0.92
NewTestPeerFunction · 0.85
cleanupFunction · 0.85
GetPolicyManagerMethod · 0.80
GetChannelsInfoMethod · 0.80
InitializeMethod · 0.65
GetLedgerMethod · 0.65
GetBlockchainInfoMethod · 0.65
EqualMethod · 0.45
JoinBySnapshotStatusMethod · 0.45

Tested by

no test coverage detected