Skip to content

Commit

Permalink
Add integration tests for calculatepackageid command
Browse files Browse the repository at this point in the history
Signed-off-by: Tatsuya Sato <tatsuya.sato.so@hitachi.com>
  • Loading branch information
satota2 authored and denyeart committed Nov 1, 2021
1 parent abdb330 commit 70ace58
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
22 changes: 22 additions & 0 deletions integration/nwo/commands/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,28 @@ func (c ChaincodePackageLegacy) Args() []string {
return args
}

type ChaincodeCalculatePackageID struct {
PackageFile string
ClientAuth bool
}

func (c ChaincodeCalculatePackageID) SessionName() string {
return "peer-lifecycle-chaincode-calculatepackageid"
}

func (c ChaincodeCalculatePackageID) Args() []string {
args := []string{
"lifecycle", "chaincode", "calculatepackageid",
c.PackageFile,
}

if c.ClientAuth {
args = append(args, "--clientauth")
}

return args
}

type ChaincodeInstall struct {
PackageFile string
PeerAddresses []string
Expand Down
10 changes: 10 additions & 0 deletions integration/nwo/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ func PackageChaincodeLegacy(n *Network, chaincode Chaincode, peer *Peer) {
Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))
}

func CheckPackageID(n *Network, packageFile string, packageID string, peer *Peer) {
sess, err := n.PeerAdminSession(peer, commands.ChaincodeCalculatePackageID{
PackageFile: packageFile,
ClientAuth: n.ClientAuthRequired,
})
Expect(err).NotTo(HaveOccurred())
Eventually(sess, n.EventuallyTimeout).Should(gbytes.Say(fmt.Sprintf(`\QPackage ID: %s\E`, packageID)))
}

func InstallChaincode(n *Network, chaincode Chaincode, peers ...*Peer) {
// Ensure 'jq' exists in path, because we need it to build chaincode
if _, err := exec.LookPath("jq"); err != nil {
Expand All @@ -189,6 +198,7 @@ func InstallChaincode(n *Network, chaincode Chaincode, peers ...*Peer) {
EventuallyWithOffset(1, sess, n.EventuallyTimeout).Should(gexec.Exit())

EnsureInstalled(n, chaincode.Label, chaincode.PackageID, p)
CheckPackageID(n, chaincode.PackageFile, chaincode.PackageID, p)
}
}

Expand Down

0 comments on commit 70ace58

Please sign in to comment.