Skip to content

Commit f7b3336

Browse files
author
Srinivasan Muralidharan
committed
FAB-1230 - use **TEST_CHAINID** for tests and skeleton
https://jira.hyperledger.org/browse/FAB-1230 Orderer sets the stage for multichain by forcing brodcast and deliver clients to specify ChainID. The solo orderer provides a default chain called **TEST_CHAINID** to continue development with. It would have been easy to hard code **TEST_CHAINID** in the lower most utility calls to continue work - basically inside protos/utils/ functions. However, this changeset takes the next step fo moving to using multichain by exposing chainID in core APIs thus forcing higher layers to deal with chains. Currently these high layers are unit tests, CLI and SDK. CLI accepts chain ID via the "-C" param which when not provided defaults to **TEST_CHAINID**. Change-Id: I0d7894c8f17ce8fae6fe075c9865afae58499005 Signed-off-by: Srinivasan Muralidharan <[email protected]>
1 parent af0cd3e commit f7b3336

File tree

16 files changed

+40
-25
lines changed

16 files changed

+40
-25
lines changed

bddtests/chaincode.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ func createProposalForChaincode(ccChaincodeDeploymentSpec *pb.ChaincodeDeploymen
5252
uuid := createPropsalID()
5353

5454
// make proposal
55-
return putils.CreateChaincodeProposal(uuid, lcChaincodeInvocationSpec, creator)
55+
return putils.CreateChaincodeProposal(uuid, util.GetTestChainID(), lcChaincodeInvocationSpec, creator)
5656
}

core/chaincode/exectransaction_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func endTxSimulationCDS(txid string, txsim ledger.TxSimulator, payload []byte, c
128128
return err
129129
}
130130
// get a proposal - we need it to get a transaction
131-
prop, err := putils.CreateProposalFromCDS(txid, cds, ss)
131+
prop, err := putils.CreateProposalFromCDS(txid, util.GetTestChainID(), cds, ss)
132132
if err != nil {
133133
return err
134134
}
@@ -143,7 +143,7 @@ func endTxSimulationCIS(txid string, txsim ledger.TxSimulator, payload []byte, c
143143
return err
144144
}
145145
// get a proposal - we need it to get a transaction
146-
prop, err := putils.CreateProposalFromCIS(txid, cis, ss)
146+
prop, err := putils.CreateProposalFromCIS(txid, util.GetTestChainID(), cis, ss)
147147
if err != nil {
148148
return err
149149
}

core/committer/noopssinglechain/client.go

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/hyperledger/fabric/core/chaincode"
2424
"github.com/hyperledger/fabric/core/committer"
2525
"github.com/hyperledger/fabric/core/ledger/kvledger"
26+
"github.com/hyperledger/fabric/core/util"
2627
"github.com/hyperledger/fabric/protos/common"
2728
"github.com/hyperledger/fabric/protos/orderer"
2829
putils "github.com/hyperledger/fabric/protos/utils"
@@ -194,6 +195,7 @@ func (d *DeliverService) seekOldest() error {
194195
Seek: &orderer.SeekInfo{
195196
Start: orderer.SeekInfo_OLDEST,
196197
WindowSize: d.windowSize,
198+
ChainID: []byte(util.GetTestChainID()),
197199
},
198200
},
199201
})
@@ -206,6 +208,7 @@ func (d *DeliverService) seekLatestFromCommitter(height uint64) error {
206208
Start: orderer.SeekInfo_SPECIFIED,
207209
WindowSize: d.windowSize,
208210
SpecifiedNumber: height,
211+
ChainID: []byte(util.GetTestChainID()),
209212
},
210213
},
211214
})

core/endorser/endorser_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func closeListenerAndSleep(l net.Listener) {
123123
//Currently supported only for Invokes (Queries still go through devops client)
124124
func getProposal(cis *pb.ChaincodeInvocationSpec, creator []byte) (*pb.Proposal, error) {
125125
uuid := util.GenerateUUID()
126-
return pbutils.CreateChaincodeProposal(uuid, cis, creator)
126+
return pbutils.CreateChaincodeProposal(uuid, util.GetTestChainID(), cis, creator)
127127
}
128128

129129
//getDeployProposal gets the proposal for the chaincode deployment

core/ledger/kvledger/example/app.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (app *App) QueryBalances(accounts []string) ([]int, error) {
114114
}
115115

116116
func constructTransaction(simulationResults []byte) *common.Envelope {
117-
txEnv, _ := ptestutils.ConstructSingedTxEnvWithDefaultSigner(util.GenerateUUID(), "foo", simulationResults, nil, nil)
117+
txEnv, _ := ptestutils.ConstructSingedTxEnvWithDefaultSigner(util.GenerateUUID(), util.GetTestChainID(), "foo", simulationResults, nil, nil)
118118
return txEnv
119119
}
120120

core/ledger/testutil/test_helper.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ func ConstructTestTransaction(t *testing.T, simulationResults []byte, sign bool)
6363
ccName := "foo"
6464
txID := util.GenerateUUID()
6565
if sign {
66-
return ptestutils.ConstructSingedTxEnvWithDefaultSigner(txID, ccName, simulationResults, nil, nil)
66+
return ptestutils.ConstructSingedTxEnvWithDefaultSigner(txID, util.GetTestChainID(), ccName, simulationResults, nil, nil)
6767
}
68-
return ptestutils.ConstructUnsingedTxEnv(txID, ccName, simulationResults, nil, nil)
68+
return ptestutils.ConstructUnsingedTxEnv(txID, util.GetTestChainID(), ccName, simulationResults, nil, nil)
6969
}
7070

7171
// ComputeBlockHash computes the crypto-hash of a block

core/peer/fullflow_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func getProposal() (*peer.Proposal, error) {
3939

4040
uuid := util.GenerateUUID()
4141

42-
return utils.CreateProposalFromCIS(uuid, cis, signerSerialized)
42+
return utils.CreateProposalFromCIS(uuid, util.GetTestChainID(), cis, signerSerialized)
4343
}
4444

4545
func TestGoodPath(t *testing.T) {

core/system_chaincode/escc/endorser_onevalidsignature_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func TestInvoke(t *testing.T) {
117117

118118
uuid := util.GenerateUUID()
119119

120-
proposal, err := putils.CreateChaincodeProposal(uuid, cis, sIdBytes)
120+
proposal, err := putils.CreateChaincodeProposal(uuid, util.GetTestChainID(), cis, sIdBytes)
121121
if err != nil {
122122
t.Fail()
123123
t.Fatalf("couldn't generate chaincode proposal: err %s", err)

core/system_chaincode/vscc/validator_onevalidsignature_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func createTx() (*common.Envelope, error) {
3535

3636
uuid := util.GenerateUUID()
3737

38-
prop, err := utils.CreateProposalFromCIS(uuid, cis, sid)
38+
prop, err := utils.CreateProposalFromCIS(uuid, util.GetTestChainID(), cis, sid)
3939
if err != nil {
4040
return nil, err
4141
}

core/util/utils.go

+7
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,10 @@ func ArrayToChaincodeArgs(args []string) [][]byte {
140140
}
141141
return bargs
142142
}
143+
144+
const testchainid = "**TEST_CHAINID**"
145+
146+
//GetTestChainID returns the CHAINID constant in use by orderer
147+
func GetTestChainID() string {
148+
return testchainid
149+
}

peer/chaincode/chaincode.go

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package chaincode
1919
import (
2020
"fmt"
2121

22+
"github.com/hyperledger/fabric/core/util"
2223
"github.com/hyperledger/fabric/peer/common"
2324
"github.com/op/go-logging"
2425
"github.com/spf13/cobra"
@@ -48,6 +49,8 @@ func Cmd() *cobra.Command {
4849
fmt.Sprint("Username for chaincode operations when security is enabled"))
4950
flags.StringVarP(&customIDGenAlg, "tid", "t", common.UndefinedParamValue,
5051
fmt.Sprint("Name of a custom ID generation algorithm (hashing and decoding) e.g. sha256base64"))
52+
flags.StringVarP(&chainID, "chainID", "C", util.GetTestChainID(),
53+
fmt.Sprint("The chain on which this command should be executed"))
5154

5255
chaincodeCmd.AddCommand(deployCmd())
5356
chaincodeCmd.AddCommand(invokeCmd())
@@ -67,6 +70,7 @@ var (
6770
chaincodeQueryHex bool
6871
chaincodeAttributesJSON string
6972
customIDGenAlg string
73+
chainID string
7074
)
7175

7276
var chaincodeCmd = &cobra.Command{

peer/chaincode/common.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func chaincodeInvokeOrQuery(cmd *cobra.Command, args []string, invoke bool) (err
191191
uuid := cutil.GenerateUUID()
192192

193193
var prop *pb.Proposal
194-
prop, err = putils.CreateProposalFromCIS(uuid, invocation, creator)
194+
prop, err = putils.CreateProposalFromCIS(uuid, chainID, invocation, creator)
195195
if err != nil {
196196
return fmt.Errorf("Error creating proposal %s: %s\n", chainFuncName, err)
197197
}

peer/chaincode/deploy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func deploy(cmd *cobra.Command) (*protcommon.Envelope, error) {
8080

8181
uuid := util.GenerateUUID()
8282

83-
prop, err := utils.CreateProposalFromCDS(uuid, cds, creator)
83+
prop, err := utils.CreateProposalFromCDS(uuid, chainID, cds, creator)
8484
if err != nil {
8585
return nil, fmt.Errorf("Error creating proposal %s: %s\n", chainFuncName, err)
8686
}

protos/testutils/txtestutils.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,18 @@ func getMSPMgrConfigFile() (string, error) {
7979

8080
// ConstructSingedTxEnvWithDefaultSigner constructs a transaction envelop for tests with a default signer.
8181
// This method helps other modules to construct a transaction with supplied parameters
82-
func ConstructSingedTxEnvWithDefaultSigner(txid string, ccName string, simulationResults []byte, events []byte, visibility []byte) (*common.Envelope, error) {
83-
return ConstructSingedTxEnv(txid, ccName, simulationResults, events, visibility, signer)
82+
func ConstructSingedTxEnvWithDefaultSigner(txid string, chainID, ccName string, simulationResults []byte, events []byte, visibility []byte) (*common.Envelope, error) {
83+
return ConstructSingedTxEnv(txid, chainID, ccName, simulationResults, events, visibility, signer)
8484
}
8585

8686
// ConstructSingedTxEnv constructs a transaction envelop for tests
87-
func ConstructSingedTxEnv(txid string, ccName string, simulationResults []byte, events []byte, visibility []byte, signer msp.SigningIdentity) (*common.Envelope, error) {
87+
func ConstructSingedTxEnv(txid string, chainID string, ccName string, simulationResults []byte, events []byte, visibility []byte, signer msp.SigningIdentity) (*common.Envelope, error) {
8888
ss, err := signer.Serialize()
8989
if err != nil {
9090
return nil, err
9191
}
9292

93-
prop, err := putils.CreateChaincodeProposal(txid, &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: &pb.ChaincodeID{Name: ccName}}}, ss)
93+
prop, err := putils.CreateChaincodeProposal(txid, chainID, &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: &pb.ChaincodeID{Name: ccName}}}, ss)
9494
if err != nil {
9595
return nil, err
9696
}
@@ -108,8 +108,8 @@ func ConstructSingedTxEnv(txid string, ccName string, simulationResults []byte,
108108
}
109109

110110
// ConstructUnsingedTxEnv creates a Transaction envelope from given inputs
111-
func ConstructUnsingedTxEnv(txid string, ccName string, simulationResults []byte, events []byte, visibility []byte) (*common.Envelope, error) {
112-
prop, err := putils.CreateChaincodeProposal(txid, &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: &pb.ChaincodeID{Name: ccName}}}, nil)
111+
func ConstructUnsingedTxEnv(txid string, chainID string, ccName string, simulationResults []byte, events []byte, visibility []byte) (*common.Envelope, error) {
112+
prop, err := putils.CreateChaincodeProposal(txid, chainID, &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: &pb.ChaincodeID{Name: ccName}}}, nil)
113113
if err != nil {
114114
return nil, err
115115
}

protos/utils/proputils.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func GetEnvelope(bytes []byte) (*common.Envelope, error) {
196196
}
197197

198198
// CreateChaincodeProposal creates a proposal from given input
199-
func CreateChaincodeProposal(txid string, cis *peer.ChaincodeInvocationSpec, creator []byte) (*peer.Proposal, error) {
199+
func CreateChaincodeProposal(txid string, chainID string, cis *peer.ChaincodeInvocationSpec, creator []byte) (*peer.Proposal, error) {
200200
ccHdrExt := &peer.ChaincodeHeaderExtension{ChaincodeID: cis.ChaincodeSpec.ChaincodeID}
201201
ccHdrExtBytes, err := proto.Marshal(ccHdrExt)
202202
if err != nil {
@@ -222,6 +222,7 @@ func CreateChaincodeProposal(txid string, cis *peer.ChaincodeInvocationSpec, cre
222222

223223
hdr := &common.Header{ChainHeader: &common.ChainHeader{Type: int32(common.HeaderType_ENDORSER_TRANSACTION),
224224
TxID: txid,
225+
ChainID: []byte(chainID),
225226
Extension: ccHdrExtBytes},
226227
SignatureHeader: &common.SignatureHeader{Nonce: nonce, Creator: creator}}
227228

@@ -372,12 +373,12 @@ func GetActionFromEnvelope(envBytes []byte) (*peer.ChaincodeAction, error) {
372373
}
373374

374375
// CreateProposalFromCIS returns a proposal given a serialized identity and a ChaincodeInvocationSpec
375-
func CreateProposalFromCIS(txid string, cis *peer.ChaincodeInvocationSpec, creator []byte) (*peer.Proposal, error) {
376-
return CreateChaincodeProposal(txid, cis, creator)
376+
func CreateProposalFromCIS(txid string, chainID string, cis *peer.ChaincodeInvocationSpec, creator []byte) (*peer.Proposal, error) {
377+
return CreateChaincodeProposal(txid, chainID, cis, creator)
377378
}
378379

379380
// CreateProposalFromCDS returns a proposal given a serialized identity and a ChaincodeDeploymentSpec
380-
func CreateProposalFromCDS(txid string, cds *peer.ChaincodeDeploymentSpec, creator []byte) (*peer.Proposal, error) {
381+
func CreateProposalFromCDS(txid string, chainID string, cds *peer.ChaincodeDeploymentSpec, creator []byte) (*peer.Proposal, error) {
381382
b, err := proto.Marshal(cds)
382383
if err != nil {
383384
return nil, err
@@ -391,5 +392,5 @@ func CreateProposalFromCDS(txid string, cds *peer.ChaincodeDeploymentSpec, creat
391392
CtorMsg: &peer.ChaincodeInput{Args: [][]byte{[]byte("deploy"), []byte("default"), b}}}}
392393

393394
//...and get the proposal for it
394-
return CreateProposalFromCIS(txid, lcccSpec, creator)
395+
return CreateProposalFromCIS(txid, chainID, lcccSpec, creator)
395396
}

protos/utils/proputils_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func createCIS() *pb.ChaincodeInvocationSpec {
4444
func TestProposal(t *testing.T) {
4545
uuid := util.GenerateUUID()
4646
// create a proposal from a ChaincodeInvocationSpec
47-
prop, err := CreateChaincodeProposal(uuid, createCIS(), []byte("creator"))
47+
prop, err := CreateChaincodeProposal(uuid, util.GetTestChainID(), createCIS(), []byte("creator"))
4848
if err != nil {
4949
t.Fatalf("Could not create chaincode proposal, err %s\n", err)
5050
return
@@ -198,7 +198,7 @@ func TestProposalResponse(t *testing.T) {
198198
func TestEnvelope(t *testing.T) {
199199
// create a proposal from a ChaincodeInvocationSpec
200200
uuid := util.GenerateUUID()
201-
prop, err := CreateChaincodeProposal(uuid, createCIS(), signerSerialized)
201+
prop, err := CreateChaincodeProposal(uuid, util.GetTestChainID(), createCIS(), signerSerialized)
202202
if err != nil {
203203
t.Fatalf("Could not create chaincode proposal, err %s\n", err)
204204
return

0 commit comments

Comments
 (0)