@@ -25,6 +25,7 @@ import (
25
25
. "github.com/onsi/ginkgo"
26
26
. "github.com/onsi/gomega"
27
27
"github.com/onsi/gomega/gbytes"
28
+ "github.com/onsi/gomega/gexec"
28
29
"github.com/tedsuo/ifrit"
29
30
yaml "gopkg.in/yaml.v2"
30
31
)
@@ -395,17 +396,24 @@ func (w *World) peerNetwork() {
395
396
func (w * World ) SetupChannel (d Deployment , peers []string ) {
396
397
var p * runner.Peer
397
398
398
- p = w .Components .Peer ()
399
- p .ConfigDir = filepath .Join (w .Rootpath , "peer0.org1.example.com" )
400
- p .MSPConfigPath = filepath .Join (w .Rootpath , "crypto" , "peerOrganizations" , "org1.example.com" , "users" , "Admin@org1.example.com" , "msp" )
399
+ if len (peers ) == 0 {
400
+ return
401
+ }
402
+
403
+ setupPeerRunner := func (peerID string ) * runner.Peer {
404
+ p = w .Components .Peer ()
405
+ peerOrg := strings .SplitN (peerID , "." , 2 )[1 ]
406
+ p .ConfigDir = filepath .Join (w .Rootpath , peerID )
407
+ p .MSPConfigPath = filepath .Join (w .Rootpath , "crypto" , "peerOrganizations" , peerOrg , "users" , fmt .Sprintf ("Admin@%s" , peerOrg ), "msp" )
408
+ return p
409
+ }
410
+
411
+ p = setupPeerRunner (peers [0 ])
401
412
adminRunner := p .CreateChannel (d .Channel , filepath .Join (w .Rootpath , fmt .Sprintf ("%s_tx.pb" , d .Channel )), d .Orderer )
402
413
execute (adminRunner )
403
414
404
415
for _ , peer := range peers {
405
- p = w .Components .Peer ()
406
- peerOrg := strings .SplitN (peer , "." , 2 )[1 ]
407
- p .ConfigDir = filepath .Join (w .Rootpath , peer )
408
- p .MSPConfigPath = filepath .Join (w .Rootpath , "crypto" , "peerOrganizations" , peerOrg , "users" , fmt .Sprintf ("Admin@%s" , peerOrg ), "msp" )
416
+ p = setupPeerRunner (peer )
409
417
adminRunner = p .FetchChannel (d .Channel , filepath .Join (w .Rootpath , peer , fmt .Sprintf ("%s_block.pb" , d .Channel )), "0" , d .Orderer )
410
418
execute (adminRunner )
411
419
ExpectWithOffset (1 , adminRunner .Err ()).To (gbytes .Say ("Received block: 0" ))
@@ -419,10 +427,21 @@ func (w *World) SetupChannel(d Deployment, peers []string) {
419
427
p .InstallChaincode (d .Chaincode .Name , d .Chaincode .Version , d .Chaincode .Path )
420
428
}
421
429
422
- p = w .Components .Peer ()
423
- p .ConfigDir = filepath .Join (w .Rootpath , "peer0.org1.example.com" )
424
- p .MSPConfigPath = filepath .Join (w .Rootpath , "crypto" , "peerOrganizations" , "org1.example.com" , "users" , "Admin@org1.example.com" , "msp" )
430
+ p = setupPeerRunner (peers [0 ])
425
431
p .InstantiateChaincode (d .Chaincode .Name , d .Chaincode .Version , d .Orderer , d .Channel , d .InitArgs , d .Policy )
432
+
433
+ for _ , peer := range peers [1 :] {
434
+ p = setupPeerRunner (peer )
435
+ listInstantiated := func () * gbytes.Buffer {
436
+ adminRunner = p .ChaincodeListInstantiated (d .Channel )
437
+
438
+ sess , err := helpers .StartSession (adminRunner .Command , "list instantiated" , "4;34m" )
439
+ ExpectWithOffset (1 , err ).NotTo (HaveOccurred ())
440
+ EventuallyWithOffset (1 , sess , 10 * time .Second ).Should (gexec .Exit (0 ))
441
+ return sess .Buffer ()
442
+ }
443
+ EventuallyWithOffset (1 , listInstantiated , time .Minute ).Should (gbytes .Say (fmt .Sprintf ("Name: %s, Version: %s," , d .Chaincode .Name , d .Chaincode .Version )))
444
+ }
426
445
}
427
446
428
447
func (w * World ) PeerIDs () []string {
0 commit comments