Skip to content

Commit

Permalink
Extend integration tests to cover inspect option of checkcommitreadiness
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 Oct 24, 2023
1 parent a7e66b9 commit 697ff15
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
5 changes: 5 additions & 0 deletions integration/nwo/commands/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ type ChaincodeCheckCommitReadiness struct {
SignaturePolicy string
ChannelConfigPolicy string
InitRequired bool
InspectionEnabled bool
CollectionsConfig string
PeerAddresses []string
ClientAuth bool
Expand Down Expand Up @@ -509,6 +510,10 @@ func (c ChaincodeCheckCommitReadiness) Args() []string {
args = append(args, "--init-required")
}

if c.InspectionEnabled {
args = append(args, "--inspect")
}

if c.CollectionsConfig != "" {
args = append(args, "--collections-config", c.CollectionsConfig)
}
Expand Down
44 changes: 43 additions & 1 deletion integration/nwo/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,16 @@ func DeployChaincode(n *Network, channel string, orderer *Orderer, chaincode Cha
// approve for each org
ApproveChaincodeForMyOrg(n, channel, orderer, chaincode, peers...)

// commit definition
// wait for checkcommitreadiness returns ready status
CheckCommitReadinessUntilReady(n, channel, chaincode, n.PeerOrgs(), peers...)

// after the chaincode definition has been correctly approved for each org,
// demonstrate the capability to inspect the discrepancies in the chaincode definitions
// by executing checkcommitreadiness with inspect flag,
// with intentionally altered values for chaincode definition parameters
InspectChaincodeDiscrepancies(n, channel, chaincode, n.PeerOrgs(), peers...)

// commit definition
CommitChaincode(n, channel, orderer, chaincode, peers[0], peers...)

// init the chaincode, if required
Expand Down Expand Up @@ -506,6 +514,40 @@ func checkCommitReadiness(n *Network, peer *Peer, channel string, chaincode Chai
}
}

// InspectChaincodeDiscrepancies inspects the discrepancies in chaincode definitions using the checkcommitreadiness
// command with inspection enabled. This is to verify that the network can detect differences in chaincode definitions,
// particularly when comparing with mismatched parameters from the approved definitions by each organizations.
func InspectChaincodeDiscrepancies(n *Network, channel string, chaincode Chaincode, checkOrgs []*Organization, peers ...*Peer) {
sess, err := n.PeerAdminSession(peers[0], commands.ChaincodeCheckCommitReadiness{
ChannelID: channel,
Name: chaincode.Name,
Version: "mismatched-version", // Intentionally set mismatched version
Sequence: chaincode.Sequence,
EndorsementPlugin: chaincode.EndorsementPlugin,
ValidationPlugin: "mismatched-vscc", // Intentionally set mismatched validation plugin
SignaturePolicy: chaincode.SignaturePolicy,
ChannelConfigPolicy: chaincode.ChannelConfigPolicy,
InitRequired: chaincode.InitRequired,
CollectionsConfig: chaincode.CollectionsConfig,
ClientAuth: n.ClientAuthRequired,
InspectionEnabled: true,
})
Expect(err).NotTo(HaveOccurred())
Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))
output := &lifecycle.CheckCommitReadinessResult{}
err = json.Unmarshal(sess.Out.Contents(), output)
Expect(err).NotTo(HaveOccurred())

for _, org := range checkOrgs {
Expect(output.Mismatches).To(HaveKeyWithValue(org.MSPID, gstruct.PointTo(gstruct.MatchFields(gstruct.IgnoreExtras, gstruct.Fields{
"Items": ConsistOf(
"EndorsementInfo (Check the Version, InitRequired, EndorsementPlugin)",
"ValidationInfo (Check the ValidationParameter, ValidationPlugin)",
),
}))))
}
}

type queryApprovedOutput struct {
Sequence int64 `json:"sequence"`
}
Expand Down

0 comments on commit 697ff15

Please sign in to comment.