Skip to content

Commit

Permalink
[FAB-10689] add collection config to peer runner
Browse files Browse the repository at this point in the history
this change set adds the collection config path to peer structs,
and adds the collection config in instantiate and upgrade functions.

Change-Id: I5338485c7e0e7a9cf27b221428f5e2623b950175
Signed-off-by: nirro <[email protected]>
  • Loading branch information
nirrozenbaum committed Jul 1, 2018
1 parent 74ee0ff commit 32c05bd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion integration/runner/discovery_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ var _ bool = Describe("DiscoveryService", func() {
instantiateCC := components.Peer()
instantiateCC.ConfigDir = tempDir
instantiateCC.MSPConfigPath = filepath.Join(cryptoDir, "peerOrganizations", "org1.example.com", "users", "[email protected]", "msp")
instantiateCC.InstantiateChaincode("mytest", "1.0", "127.0.0.1:8050", "mychan", `{"Args":["init","a","100","b","200"]}`, "")
instantiateCC.InstantiateChaincode("mytest", "1.0", "127.0.0.1:8050", "mychan", `{"Args":["init","a","100","b","200"]}`, "", "")

By("list instantiated chaincode")
listInstan := components.Peer()
Expand Down
21 changes: 18 additions & 3 deletions integration/runner/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,29 @@ func (p *Peer) InstallChaincode(name, version, path string) {
Expect(sess).To(gbytes.Say(fmt.Sprintf("Name: %s, Version: %s,", name, version)))
}

func (p *Peer) InstantiateChaincode(name, version, orderer, channel, args, policy string) {
cmd := exec.Command(p.Path, "chaincode", "instantiate", "-n", name, "-v", version, "-o", orderer, "-C", channel, "-c", args, "-P", policy)
func (p *Peer) InstantiateChaincode(name, version, orderer, channel, args, policy string, collectionsConfigPath string) {
cmd := exec.Command(p.Path, "chaincode", "instantiate", "-n", name, "-v", version, "-o", orderer, "-C", channel, "-c", args, "-P", policy, "--collections-config", collectionsConfigPath)
p.setupEnvironment(cmd)

sess, err := helpers.StartSession(cmd, "instantiate", "4;35m")
ExpectWithOffset(1, err).NotTo(HaveOccurred())
EventuallyWithOffset(1, sess, time.Minute).Should(gexec.Exit(0))

p.VerifyChaincodeIsInstantiated(name, version, channel, time.Minute)
}

func (p *Peer) UpgradeChaincode(name string, version string, orderer string, channel string, args string, policy string, collectionsConfigPath string) {
cmd := exec.Command(p.Path, "chaincode", "upgrade", "-n", name, "-v", version, "-o", orderer, "-C", channel, "-c", args, "-P", policy, "--collections-config", collectionsConfigPath)
p.setupEnvironment(cmd)

sess, err := helpers.StartSession(cmd, "upgrade", "4;35m")
ExpectWithOffset(1, err).NotTo(HaveOccurred())
EventuallyWithOffset(1, sess, time.Minute).Should(gexec.Exit(0))

p.VerifyChaincodeIsInstantiated(name, version, channel, time.Minute)
}

func (p *Peer) VerifyChaincodeIsInstantiated(chaincodeName string, version string, channel string, timeout time.Duration) {
listInstantiated := func() *gbytes.Buffer {
cmd := exec.Command(p.Path, "chaincode", "list", "--instantiated", "-C", channel)
p.setupEnvironment(cmd)
Expand All @@ -206,7 +221,7 @@ func (p *Peer) InstantiateChaincode(name, version, orderer, channel, args, polic
EventuallyWithOffset(1, sess, 10*time.Second).Should(gexec.Exit(0))
return sess.Buffer()
}
EventuallyWithOffset(1, listInstantiated, time.Minute).Should(gbytes.Say(fmt.Sprintf("Name: %s, Version: %s,", name, version)))
EventuallyWithOffset(1, listInstantiated, timeout).Should(gbytes.Say(fmt.Sprintf("Name: %s, Version: %s,", chaincodeName, version)))
}

func (p *Peer) QueryChaincode(name string, channel string, args string) *ginkgomon.Runner {
Expand Down
2 changes: 1 addition & 1 deletion integration/runner/peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ var _ = Describe("Peer", func() {
instantiateCC := components.Peer()
instantiateCC.ConfigDir = tempDir
instantiateCC.MSPConfigPath = filepath.Join(cryptoDir, "peerOrganizations", "org1.example.com", "users", "[email protected]", "msp")
instantiateCC.InstantiateChaincode("mytest", "1.0", "127.0.0.1:8050", "mychan", `{"Args":["init","a","100","b","200"]}`, "")
instantiateCC.InstantiateChaincode("mytest", "1.0", "127.0.0.1:8050", "mychan", `{"Args":["init","a","100","b","200"]}`, "", "")

By("list instantiated chaincode")
listInstan := components.Peer()
Expand Down
24 changes: 8 additions & 16 deletions integration/world/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec"
"github.com/tedsuo/ifrit"
yaml "gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -75,11 +74,12 @@ type World struct {
}

type Chaincode struct {
Name string
Path string
Version string
GoPath string
ExecPath string
Name string
Path string
Version string
GoPath string
ExecPath string
CollectionsConfigPath string
}

type Deployment struct {
Expand Down Expand Up @@ -428,19 +428,11 @@ func (w *World) SetupChannel(d Deployment, peers []string) {
}

p = setupPeerRunner(peers[0])
p.InstantiateChaincode(d.Chaincode.Name, d.Chaincode.Version, d.Orderer, d.Channel, d.InitArgs, d.Policy)
p.InstantiateChaincode(d.Chaincode.Name, d.Chaincode.Version, d.Orderer, d.Channel, d.InitArgs, d.Policy, d.Chaincode.CollectionsConfigPath)

for _, peer := range peers[1:] {
p = setupPeerRunner(peer)
listInstantiated := func() *gbytes.Buffer {
adminRunner = p.ChaincodeListInstantiated(d.Channel)

sess, err := helpers.StartSession(adminRunner.Command, "list instantiated", "4;34m")
ExpectWithOffset(1, err).NotTo(HaveOccurred())
EventuallyWithOffset(1, sess, 10*time.Second).Should(gexec.Exit(0))
return sess.Buffer()
}
EventuallyWithOffset(1, listInstantiated, time.Minute).Should(gbytes.Say(fmt.Sprintf("Name: %s, Version: %s,", d.Chaincode.Name, d.Chaincode.Version)))
p.VerifyChaincodeIsInstantiated(d.Chaincode.Name, d.Chaincode.Version, d.Channel, time.Minute)
}
}

Expand Down

0 comments on commit 32c05bd

Please sign in to comment.