Skip to content

Commit 8f79ea1

Browse files
committed
[FAB-10336] assertions & validation in instantiate
This baby step should keep the callers from polling. Change-Id: I45f4f089e0d0903324fd7c7e3d722f6dec539c40 Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent 59d29f8 commit 8f79ea1

File tree

3 files changed

+17
-37
lines changed

3 files changed

+17
-37
lines changed

integration/runner/peer.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,24 @@ func (p *Peer) InstallChaincode(name, version, path string) {
176176
Expect(sess).To(gbytes.Say(fmt.Sprintf("Name: %s, Version: %s,", name, version)))
177177
}
178178

179-
func (p *Peer) InstantiateChaincode(name string, version string, orderer string, channel string, args string, policy string) *ginkgomon.Runner {
179+
func (p *Peer) InstantiateChaincode(name, version, orderer, channel, args, policy string) {
180180
cmd := exec.Command(p.Path, "chaincode", "instantiate", "-n", name, "-v", version, "-o", orderer, "-C", channel, "-c", args, "-P", policy)
181181
p.setupEnvironment(cmd)
182182

183-
r := ginkgomon.New(ginkgomon.Config{
184-
Name: "instantiate",
185-
AnsiColorCode: "4;35m",
186-
Command: cmd,
187-
})
183+
sess, err := helpers.StartSession(cmd, "instantiate", "4;35m")
184+
ExpectWithOffset(1, err).NotTo(HaveOccurred())
185+
EventuallyWithOffset(1, sess, time.Minute).Should(gexec.Exit(0))
188186

189-
return r
187+
listInstantiated := func() *gbytes.Buffer {
188+
cmd := exec.Command(p.Path, "chaincode", "list", "--instantiated", "-C", channel)
189+
p.setupEnvironment(cmd)
190+
191+
sess, err := helpers.StartSession(cmd, "list instantiated", "4;34m")
192+
ExpectWithOffset(1, err).NotTo(HaveOccurred())
193+
EventuallyWithOffset(1, sess, 10*time.Second).Should(gexec.Exit(0))
194+
return sess.Buffer()
195+
}
196+
EventuallyWithOffset(1, listInstantiated, time.Minute).Should(gbytes.Say(fmt.Sprintf("Name: %s, Version: %s,", name, version)))
190197
}
191198

192199
func (p *Peer) QueryChaincode(name string, channel string, args string) *ginkgomon.Runner {

integration/runner/peer_test.go

+2-18
Original file line numberDiff line numberDiff line change
@@ -194,29 +194,13 @@ var _ = Describe("Peer", func() {
194194
Eventually(liProcess.Wait(), 10*time.Second).Should(Receive(BeNil()))
195195
Expect(liRunner).To(gbytes.Say("Name: mytest, Version: 1.0,"))
196196

197-
By("instantiate channel")
197+
By("instantiate chaincode")
198198
instantiateCC := components.Peer()
199199
instantiateCC.ConfigDir = tempDir
200200
instantiateCC.MSPConfigPath = filepath.Join(cryptoDir, "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp")
201-
instRunner := instantiateCC.InstantiateChaincode("mytest", "1.0", "127.0.0.1:8050", "mychan", `{"Args":["init","a","100","b","200"]}`, "")
202-
instProcess := ifrit.Invoke(instRunner)
203-
Eventually(instProcess.Ready(), 10*time.Second).Should(BeClosed())
204-
Eventually(instProcess.Wait(), 10*time.Second).ShouldNot(Receive(BeNil()))
201+
instantiateCC.InstantiateChaincode("mytest", "1.0", "127.0.0.1:8050", "mychan", `{"Args":["init","a","100","b","200"]}`, "")
205202

206203
By("list instantiated chaincode")
207-
listInstantiated := func() *gbytes.Buffer {
208-
listInstan := components.Peer()
209-
listInstan.ConfigDir = tempDir
210-
listInstan.MSPConfigPath = filepath.Join(cryptoDir, "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp")
211-
linstRunner := listInstan.ChaincodeListInstantiated("mychan")
212-
err := execute(linstRunner)
213-
if err != nil {
214-
return nil
215-
}
216-
return linstRunner.Buffer()
217-
}
218-
Eventually(listInstantiated, 90*time.Second, 500*time.Millisecond).Should(gbytes.Say("Name: mytest, Version: 1.0,"))
219-
220204
listInstan := components.Peer()
221205
listInstan.ConfigDir = tempDir
222206
listInstan.MSPConfigPath = filepath.Join(cryptoDir, "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp")

integration/world/config.go

+1-12
Original file line numberDiff line numberDiff line change
@@ -424,18 +424,7 @@ func (w *World) SetupChannel(d Deployment, peers []string) error {
424424
p = w.Components.Peer()
425425
p.ConfigDir = filepath.Join(w.Rootpath, "peer0.org1.example.com")
426426
p.MSPConfigPath = filepath.Join(w.Rootpath, "crypto", "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp")
427-
adminRunner = p.InstantiateChaincode(d.Chaincode.Name, d.Chaincode.Version, d.Orderer, d.Channel, d.InitArgs, d.Policy)
428-
execute(adminRunner)
429-
430-
listInstantiated := func() bool {
431-
p = w.Components.Peer()
432-
p.ConfigDir = filepath.Join(w.Rootpath, "peer0.org1.example.com")
433-
p.MSPConfigPath = filepath.Join(w.Rootpath, "crypto", "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp")
434-
adminRunner = p.ChaincodeListInstantiated(d.Channel)
435-
execute(adminRunner)
436-
return strings.Contains(string(adminRunner.Buffer().Contents()), fmt.Sprintf("Path: %s", d.Chaincode.Path))
437-
}
438-
Eventually(listInstantiated, 90*time.Second, 500*time.Millisecond).Should(BeTrue())
427+
p.InstantiateChaincode(d.Chaincode.Name, d.Chaincode.Version, d.Orderer, d.Channel, d.InitArgs, d.Policy)
439428

440429
return nil
441430
}

0 commit comments

Comments
 (0)