diff --git a/docs/source/chaincode4noah.rst b/docs/source/chaincode4noah.rst index f42dd68a7fd..b05ad0ff752 100644 --- a/docs/source/chaincode4noah.rst +++ b/docs/source/chaincode4noah.rst @@ -325,30 +325,23 @@ Which shows output similar to the example below: install Package the specified chaincode into a deployment spec and save it on the peer's path. instantiate Deploy the specified chaincode to the network. invoke Invoke the specified chaincode. + list Get the instantiated chaincodes on a channel or installed chaincodes on a peer. package Package the specified chaincode into a deployment spec. query Query using the specified chaincode. signpackage Sign the specified chaincode package upgrade Upgrade chaincode. Flags: - --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint - -C, --chainID string The chain on which this command should be executed (default "testchainid") - -c, --ctor string Constructor message for the chaincode in JSON format (default "{}") - -E, --escc string The name of the endorsement system chaincode to be used for this chaincode - -l, --lang string Language the chaincode is written in (default "golang") - -n, --name string Name of the chaincode - -o, --orderer string Ordering service endpoint - -p, --path string Path to chaincode - -P, --policy string The endorsement policy associated to this chaincode - -t, --tid string Name of a custom ID generation algorithm (hashing and decoding) e.g. sha256base64 - --tls Use TLS when communicating with the orderer endpoint - -u, --username string Username for chaincode operations when security is enabled - -v, --version string Version of the chaincode specified in install/instantiate/upgrade commands - -V, --vscc string The name of the verification system chaincode to be used for this chaincode - - Global Flags: - --logging-level string Default logging level and overrides, see core.yaml for full syntax - --test.coverprofile string Done (default "coverage.cov") + --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint + -h, --help help for chaincode + -o, --orderer string Ordering service endpoint + --tls Use TLS when communicating with the orderer endpoint + --transient string Transient map of arguments in JSON encoding + +Global Flags: + --logging-level string Default logging level and overrides, see core.yaml for full syntax + --test.coverprofile string Done (default "coverage.cov") + -v, --version Use "peer chaincode [command] --help" for more information about a command. diff --git a/docs/source/peer-chaincode-devmode.rst b/docs/source/peer-chaincode-devmode.rst index 28113ab4b08..c1bd3f8d3df 100644 --- a/docs/source/peer-chaincode-devmode.rst +++ b/docs/source/peer-chaincode-devmode.rst @@ -7,9 +7,8 @@ during chaincode development phase for rapid code/build/run/debug cycle turnaround. To keep this a realistic “dev” environment, we are going to keep it “out -of the box” - with one exception: we create two channels instead of -using the default ``testchainid`` channel to show how the single running -instance can be accessed from multiple channels. +of the box” - with one exception: we create two channels to show how the +single running instance can be accessed from multiple channels. - Note: Make sure peer is not using TLS when running in dev mode. diff --git a/peer/chaincode/chaincode.go b/peer/chaincode/chaincode.go index de2459b4f9f..888ec3c0068 100644 --- a/peer/chaincode/chaincode.go +++ b/peer/chaincode/chaincode.go @@ -10,7 +10,6 @@ import ( "fmt" "github.com/hyperledger/fabric/common/flogging" - "github.com/hyperledger/fabric/common/util" "github.com/hyperledger/fabric/peer/common" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -59,7 +58,7 @@ var ( chaincodeQueryRaw bool chaincodeQueryHex bool customIDGenAlg string - chainID string + channelID string chaincodeVersion string policy string escc string @@ -101,7 +100,7 @@ func resetFlags() { fmt.Sprint("Username for chaincode operations when security is enabled")) flags.StringVarP(&customIDGenAlg, "tid", "t", common.UndefinedParamValue, fmt.Sprint("Name of a custom ID generation algorithm (hashing and decoding) e.g. sha256base64")) - flags.StringVarP(&chainID, "channelID", "C", util.GetTestChainID(), + flags.StringVarP(&channelID, "channelID", "C", "", fmt.Sprint("The channel on which this command should be executed")) flags.StringVarP(&policy, "policy", "P", common.UndefinedParamValue, fmt.Sprint("The endorsement policy associated to this chaincode")) diff --git a/peer/chaincode/common.go b/peer/chaincode/common.go index 6b64feda9cb..e07a28a38f0 100644 --- a/peer/chaincode/common.go +++ b/peer/chaincode/common.go @@ -99,7 +99,7 @@ func chaincodeInvokeOrQuery(cmd *cobra.Command, args []string, invoke bool, cf * proposalResp, err := ChaincodeInvokeOrQuery( spec, - chainID, + channelID, invoke, cf.Signer, cf.EndorserClient, @@ -246,14 +246,14 @@ func InitCmdFactory(isEndorserRequired, isOrdererRequired bool) (*ChaincodeCmdFa var broadcastClient common.BroadcastClient if isOrdererRequired { if len(orderingEndpoint) == 0 { - orderingEndpoints, err := common.GetOrdererEndpointOfChainFnc(chainID, signer, endorserClient) + orderingEndpoints, err := common.GetOrdererEndpointOfChainFnc(channelID, signer, endorserClient) if err != nil { - return nil, fmt.Errorf("Error getting (%s) orderer endpoint: %s", chainID, err) + return nil, fmt.Errorf("Error getting (%s) orderer endpoint: %s", channelID, err) } if len(orderingEndpoints) == 0 { - return nil, fmt.Errorf("Error no orderer endpoint got for %s", chainID) + return nil, fmt.Errorf("Error no orderer endpoint got for %s", channelID) } - logger.Infof("Get chain(%s) orderer endpoint: %s", chainID, orderingEndpoints[0]) + logger.Infof("Get chain(%s) orderer endpoint: %s", channelID, orderingEndpoints[0]) orderingEndpoint = orderingEndpoints[0] } diff --git a/peer/chaincode/instantiate.go b/peer/chaincode/instantiate.go index 06c32c249d6..e967a44ff2c 100644 --- a/peer/chaincode/instantiate.go +++ b/peer/chaincode/instantiate.go @@ -17,6 +17,7 @@ limitations under the License. package chaincode import ( + "errors" "fmt" protcommon "github.com/hyperledger/fabric/protos/common" @@ -75,7 +76,7 @@ func instantiate(cmd *cobra.Command, cf *ChaincodeCmdFactory) (*protcommon.Envel return nil, fmt.Errorf("Error serializing identity for %s: %s", cf.Signer.GetIdentifier(), err) } - prop, _, err := utils.CreateDeployProposalFromCDS(chainID, cds, creator, policyMarshalled, []byte(escc), []byte(vscc)) + prop, _, err := utils.CreateDeployProposalFromCDS(channelID, cds, creator, policyMarshalled, []byte(escc), []byte(vscc)) if err != nil { return nil, fmt.Errorf("Error creating proposal %s: %s", chainFuncName, err) } @@ -108,6 +109,9 @@ func instantiate(cmd *cobra.Command, cf *ChaincodeCmdFactory) (*protcommon.Envel // (hash) is printed to STDOUT for use by subsequent chaincode-related CLI // commands. func chaincodeDeploy(cmd *cobra.Command, args []string, cf *ChaincodeCmdFactory) error { + if channelID == "" { + return errors.New("The required parameter 'channelID' is empty. Rerun the command with -C flag") + } var err error if cf == nil { cf, err = InitCmdFactory(true, true) diff --git a/peer/chaincode/instantiate_test.go b/peer/chaincode/instantiate_test.go index 93c748de34a..d4579c1a81e 100644 --- a/peer/chaincode/instantiate_test.go +++ b/peer/chaincode/instantiate_test.go @@ -37,7 +37,7 @@ func TestInstantiateCmd(t *testing.T) { }{ { name: "successful", - args: []string{"-n", "example02", "-v", "anotherversion", "-c", "{\"Args\": [\"init\",\"a\",\"100\",\"b\",\"200\"]}"}, + args: []string{"-n", "example02", "-v", "anotherversion", "-C", "mychannel", "-c", "{\"Args\": [\"init\",\"a\",\"100\",\"b\",\"200\"]}"}, errorExpected: false, errMsg: "Run chaincode instantiate cmd error", }, @@ -49,19 +49,25 @@ func TestInstantiateCmd(t *testing.T) { }, { name: "missing version", - args: []string{"-n", "example02", "-c", "{\"Args\": [\"init\",\"a\",\"100\",\"b\",\"200\"]}"}, + args: []string{"-n", "example02", "-C", "mychannel", "-c", "{\"Args\": [\"init\",\"a\",\"100\",\"b\",\"200\"]}"}, errorExpected: true, errMsg: "Expected error executing instantiate command without the -v option", }, { name: "missing name", - args: []string{"-v", "anotherversion", "-c", "{\"Args\": [\"init\",\"a\",\"100\",\"b\",\"200\"]}"}, + args: []string{"-v", "anotherversion", "-C", "mychannel", "-c", "{\"Args\": [\"init\",\"a\",\"100\",\"b\",\"200\"]}"}, errorExpected: true, errMsg: "Expected error executing instantiate command without the -n option", }, + { + name: "missing channelID", + args: []string{"-n", "example02", "-v", "anotherversion", "-c", "{\"Args\": [\"init\",\"a\",\"100\",\"b\",\"200\"]}"}, + errorExpected: true, + errMsg: "Expected error executing instantiate command without the -C option", + }, { name: "missing ctor", - args: []string{"-n", "example02", "-v", "anotherversion"}, + args: []string{"-n", "example02", "-C", "mychannel", "-v", "anotherversion"}, errorExpected: true, errMsg: "Expected error executing instantiate command without the -c option", }, diff --git a/peer/chaincode/invoke.go b/peer/chaincode/invoke.go index deb4521c67c..6756fc8931d 100644 --- a/peer/chaincode/invoke.go +++ b/peer/chaincode/invoke.go @@ -17,6 +17,7 @@ limitations under the License. package chaincode import ( + "errors" "fmt" "github.com/spf13/cobra" @@ -46,6 +47,9 @@ func invokeCmd(cf *ChaincodeCmdFactory) *cobra.Command { } func chaincodeInvoke(cmd *cobra.Command, args []string, cf *ChaincodeCmdFactory) error { + if channelID == "" { + return errors.New("The required parameter 'channelID' is empty. Rerun the command with -C flag") + } var err error if cf == nil { cf, err = InitCmdFactory(true, true) diff --git a/peer/chaincode/invoke_test.go b/peer/chaincode/invoke_test.go index 83780db74a2..6ac5eed9513 100644 --- a/peer/chaincode/invoke_test.go +++ b/peer/chaincode/invoke_test.go @@ -37,12 +37,23 @@ func TestInvokeCmd(t *testing.T) { InitMSP() mockCF, err := getMockChaincodeCmdFactory() assert.NoError(t, err, "Error getting mock chaincode command factory") + // reset channelID, it might have been set by previous test + channelID = "" + // Error case 0: no channelID specified cmd := invokeCmd(mockCF) addFlags(cmd) args := []string{"-n", "example02", "-c", "{\"Args\": [\"invoke\",\"a\",\"b\",\"10\"]}"} cmd.SetArgs(args) err = cmd.Execute() + assert.Error(t, err, "'peer chaincode invoke' command should have returned error when called without -C flag") + + // Success case + cmd = invokeCmd(mockCF) + addFlags(cmd) + args = []string{"-n", "example02", "-c", "{\"Args\": [\"invoke\",\"a\",\"b\",\"10\"]}", "-C", "mychannel"} + cmd.SetArgs(args) + err = cmd.Execute() assert.NoError(t, err, "Run chaincode invoke cmd error") // Error case 1: no orderer endpoints @@ -65,7 +76,7 @@ func TestInvokeCmd(t *testing.T) { } cmd = invokeCmd(nil) addFlags(cmd) - args = []string{"-n", "example02", "-c", "{\"Args\": [\"invoke\",\"a\",\"b\",\"10\"]}"} + args = []string{"-n", "example02", "-c", "{\"Args\": [\"invoke\",\"a\",\"b\",\"10\"]}", "-C", "mychannel"} cmd.SetArgs(args) err = cmd.Execute() assert.Error(t, err) @@ -128,7 +139,7 @@ func TestInvokeCmdEndorsementError(t *testing.T) { cmd := invokeCmd(mockCF) addFlags(cmd) - args := []string{"-n", "example02", "-c", "{\"Args\": [\"invoke\",\"a\",\"b\",\"10\"]}"} + args := []string{"-n", "example02", "-C", "mychannel", "-c", "{\"Args\": [\"invoke\",\"a\",\"b\",\"10\"]}"} cmd.SetArgs(args) err = cmd.Execute() assert.Error(t, err, "Expected error executing invoke command") diff --git a/peer/chaincode/list.go b/peer/chaincode/list.go index 9aaf95fa746..6adc95358d0 100644 --- a/peer/chaincode/list.go +++ b/peer/chaincode/list.go @@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0 package chaincode import ( + "errors" "fmt" "github.com/golang/protobuf/proto" @@ -45,6 +46,9 @@ func listCmd(cf *ChaincodeCmdFactory) *cobra.Command { } func getChaincodes(cmd *cobra.Command, cf *ChaincodeCmdFactory) error { + if channelID == "" { + return errors.New("The required parameter 'channelID' is empty. Rerun the command with -C flag") + } var err error if cf == nil { cf, err = InitCmdFactory(true, false) @@ -62,7 +66,7 @@ func getChaincodes(cmd *cobra.Command, cf *ChaincodeCmdFactory) error { if getInstalledChaincodes && (!getInstantiatedChaincodes) { prop, _, err = utils.CreateGetInstalledChaincodesProposal(creator) } else if getInstantiatedChaincodes && (!getInstalledChaincodes) { - prop, _, err = utils.CreateGetChaincodesProposal(chainID, creator) + prop, _, err = utils.CreateGetChaincodesProposal(channelID, creator) } else { return fmt.Errorf("Must explicitly specify \"--installed\" or \"--instantiated\"") } @@ -91,7 +95,7 @@ func getChaincodes(cmd *cobra.Command, cf *ChaincodeCmdFactory) error { if getInstalledChaincodes { fmt.Println("Get installed chaincodes on peer:") } else { - fmt.Printf("Get instantiated chaincodes on channel %s:\n", chainID) + fmt.Printf("Get instantiated chaincodes on channel %s:\n", channelID) } for _, chaincode := range cqr.Chaincodes { fmt.Printf("%v\n", chaincode) diff --git a/peer/chaincode/list_test.go b/peer/chaincode/list_test.go index 9a5c25a5c62..0ac632546d4 100644 --- a/peer/chaincode/list_test.go +++ b/peer/chaincode/list_test.go @@ -13,6 +13,7 @@ import ( "github.com/golang/protobuf/proto" "github.com/hyperledger/fabric/peer/common" pb "github.com/hyperledger/fabric/protos/peer" + "github.com/stretchr/testify/assert" ) func TestChaincodeListCmd(t *testing.T) { @@ -48,13 +49,19 @@ func TestChaincodeListCmd(t *testing.T) { Signer: signer, BroadcastClient: mockBroadcastClient, } + // reset channelID, it might have been set by previous test + channelID = "" // Get installed chaincodes installedChaincodesCmd := listCmd(mockCF) args := []string{"--installed"} installedChaincodesCmd.SetArgs(args) + err = installedChaincodesCmd.Execute() + assert.Error(t, err, "Run chaincode list cmd to get installed chaincodes should fail if invoked without -C flag") + args = []string{"--installed", "-C", "mychannel"} + installedChaincodesCmd.SetArgs(args) if err := installedChaincodesCmd.Execute(); err != nil { t.Errorf("Run chaincode list cmd to get installed chaincodes error:%v", err) } @@ -63,10 +70,13 @@ func TestChaincodeListCmd(t *testing.T) { // Get instantiated chaincodes instantiatedChaincodesCmd := listCmd(mockCF) - args = []string{"--instantiated"} instantiatedChaincodesCmd.SetArgs(args) + err = instantiatedChaincodesCmd.Execute() + assert.Error(t, err, "Run chaincode list cmd to get instantiated chaincodes should fail if invoked without -C flag") + args = []string{"--instantiated", "-C", "mychannel"} + instantiatedChaincodesCmd.SetArgs(args) if err := instantiatedChaincodesCmd.Execute(); err != nil { t.Errorf("Run chaincode list cmd to get instantiated chaincodes error:%v", err) } @@ -75,10 +85,13 @@ func TestChaincodeListCmd(t *testing.T) { // Wrong case: Set both "--installed" and "--instantiated" Cmd := listCmd(mockCF) - args = []string{"--installed", "--instantiated"} Cmd.SetArgs(args) + err = Cmd.Execute() + assert.Error(t, err, "Run chaincode list cmd to get instantiated/installed chaincodes should fail if invoked without -C flag") + args = []string{"--installed", "--instantiated", "-C", "mychannel"} + Cmd.SetArgs(args) expectErr := fmt.Errorf("Must explicitly specify \"--installed\" or \"--instantiated\"") if err := Cmd.Execute(); err == nil || err.Error() != expectErr.Error() { t.Errorf("Expect error: %s", expectErr) @@ -89,7 +102,7 @@ func TestChaincodeListCmd(t *testing.T) { // Wrong case: Miss "--intsalled" and "--instantiated" nilCmd := listCmd(mockCF) - args = []string{} + args = []string{"-C", "mychannel"} nilCmd.SetArgs(args) expectErr = fmt.Errorf("Must explicitly specify \"--installed\" or \"--instantiated\"") diff --git a/peer/chaincode/query.go b/peer/chaincode/query.go index 12d1cd45904..0e884625f73 100644 --- a/peer/chaincode/query.go +++ b/peer/chaincode/query.go @@ -17,6 +17,7 @@ limitations under the License. package chaincode import ( + "errors" "fmt" "github.com/spf13/cobra" @@ -52,6 +53,9 @@ func queryCmd(cf *ChaincodeCmdFactory) *cobra.Command { } func chaincodeQuery(cmd *cobra.Command, args []string, cf *ChaincodeCmdFactory) error { + if channelID == "" { + return errors.New("The required parameter 'channelID' is empty. Rerun the command with -C flag") + } var err error if cf == nil { cf, err = InitCmdFactory(true, false) diff --git a/peer/chaincode/query_test.go b/peer/chaincode/query_test.go index 7d8eea3c9a9..08eb85863a5 100644 --- a/peer/chaincode/query_test.go +++ b/peer/chaincode/query_test.go @@ -27,35 +27,46 @@ func TestQueryCmd(t *testing.T) { mockCF, err := getMockChaincodeCmdFactory() assert.NoError(t, err, "Error getting mock chaincode command factory") + // reset channelID, it might have been set by previous test + channelID = "" - // Success case: run query command with -r option + // Success case: run query command without -C option cmd := queryCmd(mockCF) addFlags(cmd) - args := []string{"-r", "-n", "example02", "-c", "{\"Args\": [\"query\",\"a\"]}"} + args := []string{"-n", "example02", "-c", "{\"Args\": [\"query\",\"a\"]}"} + cmd.SetArgs(args) + err = cmd.Execute() + assert.Error(t, err, "'peer chaincode query' command should have failed without -C flag") + + // Success case: run query command without -r or -x option + cmd = queryCmd(mockCF) + addFlags(cmd) + args = []string{"-C", "mychannel", "-n", "example02", "-c", "{\"Args\": [\"query\",\"a\"]}"} cmd.SetArgs(args) err = cmd.Execute() assert.NoError(t, err, "Run chaincode query cmd error") - // Success case: run query command with -x option + // Success case: run query command with -r option cmd = queryCmd(mockCF) addFlags(cmd) - args = []string{"-x", "-n", "example02", "-c", "{\"Args\": [\"query\",\"a\"]}"} + args = []string{"-r", "-C", "mychannel", "-n", "example02", "-c", "{\"Args\": [\"query\",\"a\"]}"} cmd.SetArgs(args) err = cmd.Execute() assert.NoError(t, err, "Run chaincode query cmd error") + chaincodeQueryRaw = false - // Success case: run query command with out -r or -x option + // Success case: run query command with -x option cmd = queryCmd(mockCF) addFlags(cmd) - args = []string{"-n", "example02", "-c", "{\"Args\": [\"query\",\"a\"]}"} + args = []string{"-x", "-C", "mychannel", "-n", "example02", "-c", "{\"Args\": [\"query\",\"a\"]}"} cmd.SetArgs(args) err = cmd.Execute() - assert.NoError(t, err, "Expected error executing query command") + assert.NoError(t, err, "Run chaincode query cmd error") // Failure case: run query command with both -x and -r options cmd = queryCmd(mockCF) addFlags(cmd) - args = []string{"-r", "-x", "-n", "example02", "-c", "{\"Args\": [\"query\",\"a\"]}"} + args = []string{"-r", "-x", "-C", "mychannel", "-n", "example02", "-c", "{\"Args\": [\"query\",\"a\"]}"} cmd.SetArgs(args) err = cmd.Execute() assert.Error(t, err, "Expected error executing query command with both -r and -x options") @@ -68,5 +79,5 @@ func TestQueryCmd(t *testing.T) { args = []string{"-r", "-n", "example02", "-c", "{\"Args\": [\"query\",\"a\"]}"} cmd.SetArgs(args) err = cmd.Execute() - assert.Error(t, err, "Expected error executing query command with both -r and -x options") + assert.Error(t, err, "Expected error executing query command") } diff --git a/peer/chaincode/upgrade.go b/peer/chaincode/upgrade.go index 3b7ccf9dc30..6e56c81f29a 100644 --- a/peer/chaincode/upgrade.go +++ b/peer/chaincode/upgrade.go @@ -17,6 +17,7 @@ limitations under the License. package chaincode import ( + "errors" "fmt" protcommon "github.com/hyperledger/fabric/protos/common" @@ -59,6 +60,9 @@ func upgradeCmd(cf *ChaincodeCmdFactory) *cobra.Command { //upgrade the command via Endorser func upgrade(cmd *cobra.Command, cf *ChaincodeCmdFactory) (*protcommon.Envelope, error) { + if channelID == "" { + return nil, errors.New("The required parameter 'channelID' is empty. Rerun the command with -C flag") + } spec, err := getChaincodeSpec(cmd) if err != nil { return nil, err @@ -74,7 +78,7 @@ func upgrade(cmd *cobra.Command, cf *ChaincodeCmdFactory) (*protcommon.Envelope, return nil, fmt.Errorf("Error serializing identity for %s: %s", cf.Signer.GetIdentifier(), err) } - prop, _, err := utils.CreateUpgradeProposalFromCDS(chainID, cds, creator, policyMarshalled, []byte(escc), []byte(vscc)) + prop, _, err := utils.CreateUpgradeProposalFromCDS(channelID, cds, creator, policyMarshalled, []byte(escc), []byte(vscc)) if err != nil { return nil, fmt.Errorf("Error creating proposal %s: %s", chainFuncName, err) } diff --git a/peer/chaincode/upgrade_test.go b/peer/chaincode/upgrade_test.go index 9950ce0c335..00423dfca89 100644 --- a/peer/chaincode/upgrade_test.go +++ b/peer/chaincode/upgrade_test.go @@ -25,6 +25,7 @@ import ( "github.com/hyperledger/fabric/msp/mgmt/testtools" "github.com/hyperledger/fabric/peer/common" pb "github.com/hyperledger/fabric/protos/peer" + "github.com/stretchr/testify/assert" ) var once sync.Once @@ -63,6 +64,8 @@ func TestUpgradeCmd(t *testing.T) { Signer: signer, BroadcastClient: mockBroadcastClient, } + // reset channelID, it might have been set by previous test + channelID = "" cmd := upgradeCmd(mockCF) addFlags(cmd) @@ -70,10 +73,14 @@ func TestUpgradeCmd(t *testing.T) { args := []string{"-n", "example02", "-p", "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02", "-v", "anotherversion", "-c", "{\"Function\":\"init\",\"Args\": [\"param\",\"1\"]}"} cmd.SetArgs(args) + err = cmd.Execute() + assert.Error(t, err, "'peer chaincode upgrade' command should have failed without -C flag") - if err := cmd.Execute(); err != nil { - t.Errorf("Run chaincode upgrade cmd error:%v", err) - } + args = []string{"-C", "mychannel", "-n", "example02", "-p", "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02", + "-v", "anotherversion", "-c", "{\"Function\":\"init\",\"Args\": [\"param\",\"1\"]}"} + cmd.SetArgs(args) + err = cmd.Execute() + assert.NoError(t, err, "'peer chaincode upgrade' command failed") } func TestUpgradeCmdEndorseFail(t *testing.T) { @@ -101,7 +108,7 @@ func TestUpgradeCmdEndorseFail(t *testing.T) { cmd := upgradeCmd(mockCF) addFlags(cmd) - args := []string{"-n", "example02", "-p", "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02", + args := []string{"-C", "mychannel", "-n", "example02", "-p", "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02", "-v", "anotherversion", "-c", "{\"Function\":\"init\",\"Args\": [\"param\",\"1\"]}"} cmd.SetArgs(args) @@ -142,7 +149,7 @@ func TestUpgradeCmdSendTXFail(t *testing.T) { cmd := upgradeCmd(mockCF) addFlags(cmd) - args := []string{"-n", "example02", "-p", "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02", "-v", "anotherversion", "-c", "{\"Function\":\"init\",\"Args\": [\"param\",\"1\"]}"} + args := []string{"-C", "mychannel", "-n", "example02", "-p", "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02", "-v", "anotherversion", "-c", "{\"Function\":\"init\",\"Args\": [\"param\",\"1\"]}"} cmd.SetArgs(args) expectErrMsg := sendErr.Error() diff --git a/peer/node/start.go b/peer/node/start.go index c28228c3cb8..88853136e76 100644 --- a/peer/node/start.go +++ b/peer/node/start.go @@ -60,7 +60,6 @@ const ( type ccEndpointFunc func() (*pb.PeerEndpoint, error) var chaincodeDevMode bool -var peerDefaultChain bool var orderingEndpoint string // XXXDefaultChannelMSPID should not be defined in production code @@ -74,8 +73,6 @@ func startCmd() *cobra.Command { flags := nodeStartCmd.Flags() flags.BoolVarP(&chaincodeDevMode, "peer-chaincodedev", "", false, "Whether peer in chaincode development mode") - flags.BoolVarP(&peerDefaultChain, "peer-defaultchain", "", false, - "Whether to start peer with chain testchainid") flags.StringVarP(&orderingEndpoint, "orderer", "o", "orderer:7050", "Ordering service endpoint") return nodeStartCmd