本文整理匯總了Golang中github.com/hyperledger/fabric/core/util.GetTestChainID函數的典型用法代碼示例。如果您正苦於以下問題:Golang GetTestChainID函數的具體用法?Golang GetTestChainID怎麽用?Golang GetTestChainID使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GetTestChainID函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ConstructTransaction
// ConstructTransaction constructs a transaction for testing
func ConstructTransaction(t *testing.T, simulationResults []byte, sign bool) (*common.Envelope, string, error) {
ccName := "foo"
txID := util.GenerateUUID()
var txEnv *common.Envelope
var err error
if sign {
txEnv, err = ptestutils.ConstructSingedTxEnvWithDefaultSigner(txID, util.GetTestChainID(), ccName, simulationResults, nil, nil)
} else {
txEnv, err = ptestutils.ConstructUnsingedTxEnv(txID, util.GetTestChainID(), ccName, simulationResults, nil, nil)
}
return txEnv, txID, err
}
示例2: TestExecuteInvokeTransaction
func TestExecuteInvokeTransaction(t *testing.T) {
chainID := util.GetTestChainID()
lis, err := initPeer(chainID)
if err != nil {
t.Fail()
t.Logf("Error creating peer: %s", err)
}
defer finitPeer(lis, chainID)
var ctxt = context.Background()
cccid := NewCCContext(chainID, "example02", "", "", false, nil)
url := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
chaincodeID := &pb.ChaincodeID{Name: "example02", Path: url}
args := []string{"a", "b", "10"}
err = invokeExample02Transaction(ctxt, cccid, chaincodeID, args, true)
if err != nil {
t.Fail()
t.Logf("Error invoking transaction: %s", err)
} else {
fmt.Printf("Invoke test passed\n")
t.Logf("Invoke test passed")
}
theChaincodeSupport.Stop(ctxt, cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID}})
}
示例3: TestRedeploy
//TestRedeploy - deploy two times, second time should fail but example02 should remain deployed
func TestRedeploy(t *testing.T) {
chainID := util.GetTestChainID()
//invalid arguments
spec := &pb.ChaincodeSpec{Type: 1, ChaincodeID: &pb.ChaincodeID{Name: "ex02", Path: "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"}, CtorMsg: &pb.ChaincodeInput{Args: [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")}}}
cccid := chaincode.NewCCContext(chainID, "ex02", "", "", false, nil)
_, _, err := deploy(endorserServer, chainID, spec, nil)
if err != nil {
t.Fail()
t.Logf("error in endorserServer.ProcessProposal %s", err)
chaincode.GetChain().Stop(context.Background(), cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
return
}
//second time should not fail as we are just simulating
_, _, err = deploy(endorserServer, chainID, spec, nil)
if err != nil {
t.Fail()
t.Logf("error in endorserServer.ProcessProposal %s", err)
chaincode.GetChain().Stop(context.Background(), cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
return
}
chaincode.GetChain().Stop(context.Background(), cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
}
示例4: TestGetMSPManagerFromBlock
func TestGetMSPManagerFromBlock(t *testing.T) {
conf, err := msp.GetLocalMspConfig("../../../msp/sampleconfig/")
if err != nil {
t.Fatalf("GetLocalMspConfig failed, err %s", err)
}
block, err := msptestutils.GetTestBlockFromMspConfig(conf)
if err != nil {
t.Fatalf("getTestBlockFromMspConfig failed, err %s", err)
}
mgr, err := GetMSPManagerFromBlock(block)
if err != nil {
t.Fatalf("GetMSPManagerFromBlock failed, err %s", err)
} else if mgr == nil {
t.Fatalf("Returned nil manager")
}
msps, err := mgr.GetMSPs()
if err != nil {
t.Fatalf("EnlistedMSPs failed, err %s", err)
}
if msps == nil || len(msps) == 0 {
t.Fatalf("There are no MSPS in the manager for chain %s", util.GetTestChainID())
}
}
示例5: TestGopathExecuteDeployTransaction
// Test deploy of a transaction with a GOPATH with multiple elements
func TestGopathExecuteDeployTransaction(t *testing.T) {
chainID := util.GetTestChainID()
// add a trailing slash to GOPATH
// and a couple of elements - it doesn't matter what they are
os.Setenv("GOPATH", os.Getenv("GOPATH")+string(os.PathSeparator)+string(os.PathListSeparator)+"/tmp/foo"+string(os.PathListSeparator)+"/tmp/bar")
executeDeployTransaction(t, chainID, "example01", "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example01")
}
示例6: TestHTTPExecuteDeployTransaction
// Test deploy of a transaction with a chaincode over HTTP.
func TestHTTPExecuteDeployTransaction(t *testing.T) {
chainID := util.GetTestChainID()
// The chaincode used here cannot be from the fabric repo
// itself or it won't be downloaded because it will be found
// in GOPATH, which would defeat the test
executeDeployTransaction(t, chainID, "example01", "http://gopkg.in/mastersingh24/fabric-test-resources.v1")
}
示例7: getProposal
func getProposal() (*peer.Proposal, error) {
cis := &peer.ChaincodeInvocationSpec{
ChaincodeSpec: &peer.ChaincodeSpec{
ChaincodeID: &peer.ChaincodeID{Name: "foo"},
Type: peer.ChaincodeSpec_GOLANG}}
uuid := util.GenerateUUID()
return utils.CreateProposalFromCIS(uuid, util.GetTestChainID(), cis, signerSerialized)
}
示例8: TestFakeSetup
// TODO: as soon as proper per-chain MSP support is developed, this test will no longer be required
func TestFakeSetup(t *testing.T) {
err := LoadFakeSetupWithLocalMspAndTestChainMsp("../../../msp/sampleconfig/")
if err != nil {
t.Fatalf("LoadLocalMsp failed, err %s", err)
}
_, err = GetLocalMSP().GetDefaultSigningIdentity()
if err != nil {
t.Fatalf("GetDefaultSigningIdentity failed, err %s", err)
}
msps, err := GetManagerForChain(util.GetTestChainID()).GetMSPs()
if err != nil {
t.Fatalf("EnlistedMSPs failed, err %s", err)
}
if msps == nil || len(msps) == 0 {
t.Fatalf("There are no MSPS in the manager for chain %s", util.GetTestChainID())
}
}
示例9: TestDeployAndUpgrade
// TestUpgradeAndInvoke deploys chaincode_example01, upgrade it with chaincode_example02, then invoke it
func TestDeployAndUpgrade(t *testing.T) {
chainID := util.GetTestChainID()
var ctxt = context.Background()
url1 := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example01"
url2 := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
chaincodeID1 := &pb.ChaincodeID{Path: url1, Name: "upgradeex01"}
chaincodeID2 := &pb.ChaincodeID{Path: url2, Name: "upgradeex01"}
f := "init"
argsDeploy := util.ToChaincodeArgs(f, "a", "100", "b", "200")
spec := &pb.ChaincodeSpec{Type: 1, ChaincodeID: chaincodeID1, CtorMsg: &pb.ChaincodeInput{Args: argsDeploy}}
cccid1 := chaincode.NewCCContext(chainID, "upgradeex01", "", "", false, nil)
cccid2 := chaincode.NewCCContext(chainID, "upgradeex02", "", "", false, nil)
resp, prop, err := deploy(endorserServer, chainID, spec, nil)
chaincodeName := spec.ChaincodeID.Name
if err != nil {
t.Fail()
chaincode.GetChain().Stop(ctxt, cccid1, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID1}})
chaincode.GetChain().Stop(ctxt, cccid2, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID2}})
t.Logf("Error deploying <%s>: %s", chaincodeName, err)
return
}
err = endorserServer.(*Endorser).commitTxSimulation(prop, chainID, signer, resp)
if err != nil {
t.Fail()
chaincode.GetChain().Stop(ctxt, cccid1, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID1}})
chaincode.GetChain().Stop(ctxt, cccid2, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID2}})
t.Logf("Error committing <%s>: %s", chaincodeName, err)
return
}
argsUpgrade := util.ToChaincodeArgs(f, "a", "150", "b", "300")
spec = &pb.ChaincodeSpec{Type: 1, ChaincodeID: chaincodeID2, CtorMsg: &pb.ChaincodeInput{Args: argsUpgrade}}
resp, prop, err = upgrade(endorserServer, chainID, spec, nil)
if err != nil {
t.Fail()
chaincode.GetChain().Stop(ctxt, cccid1, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID1}})
chaincode.GetChain().Stop(ctxt, cccid2, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID2}})
t.Logf("Error upgrading <%s>: %s", chaincodeName, err)
return
}
fmt.Printf("Upgrade test passed\n")
t.Logf("Upgrade test passed")
chaincode.GetChain().Stop(ctxt, cccid1, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID1}})
chaincode.GetChain().Stop(ctxt, cccid2, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID2}})
}
示例10: TestRangeQuery
// Test the invocation of a transaction.
func TestRangeQuery(t *testing.T) {
//TODO enable after ledger enables RangeQuery
t.Skip()
chainID := util.GetTestChainID()
lis, err := initPeer(chainID)
if err != nil {
t.Fail()
t.Logf("Error creating peer: %s", err)
}
defer finitPeer(lis, chainID)
var ctxt = context.Background()
url := "github.com/hyperledger/fabric/examples/chaincode/go/map"
cID := &pb.ChaincodeID{Name: "tmap", Path: url}
f := "init"
args := util.ToChaincodeArgs(f)
spec := &pb.ChaincodeSpec{Type: 1, ChaincodeID: cID, CtorMsg: &pb.ChaincodeInput{Args: args}}
cccid := NewCCContext(chainID, "tmap", "", "", false, nil)
_, err = deploy(ctxt, cccid, spec)
chaincodeID := spec.ChaincodeID.Name
if err != nil {
t.Fail()
t.Logf("Error initializing chaincode %s(%s)", chaincodeID, err)
theChaincodeSupport.Stop(ctxt, cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
return
}
// Invoke second chaincode, which will inturn invoke the first chaincode
f = "keys"
args = util.ToChaincodeArgs(f)
spec = &pb.ChaincodeSpec{Type: 1, ChaincodeID: cID, CtorMsg: &pb.ChaincodeInput{Args: args}}
_, _, _, err = invoke(ctxt, chainID, spec)
if err != nil {
t.Fail()
t.Logf("Error invoking <%s>: %s", chaincodeID, err)
theChaincodeSupport.Stop(ctxt, cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
return
}
theChaincodeSupport.Stop(ctxt, cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
}
示例11: createProposalForChaincode
// createChaincodeDeploymentSpec Returns a deployment proposal of chaincode type
func createProposalForChaincode(ccChaincodeDeploymentSpec *pb.ChaincodeDeploymentSpec, creator []byte) (proposal *pb.Proposal, err error) {
var ccDeploymentSpecBytes []byte
if ccDeploymentSpecBytes, err = proto.Marshal(ccChaincodeDeploymentSpec); err != nil {
return nil, fmt.Errorf("Error creating proposal from ChaincodeDeploymentSpec: %s", err)
}
lcChaincodeSpec := &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_GOLANG,
ChaincodeID: &pb.ChaincodeID{Name: "lccc"},
CtorMsg: &pb.ChaincodeInput{Args: [][]byte{[]byte("deploy"), []byte("default"), ccDeploymentSpecBytes}}}
lcChaincodeInvocationSpec := &pb.ChaincodeInvocationSpec{ChaincodeSpec: lcChaincodeSpec}
uuid := createProposalID()
// make proposal
return putils.CreateChaincodeProposal(uuid, util.GetTestChainID(), lcChaincodeInvocationSpec, creator)
}
示例12: TestDeploy
//TestDeploy deploy chaincode example01
func TestDeploy(t *testing.T) {
chainID := util.GetTestChainID()
spec := &pb.ChaincodeSpec{Type: 1, ChaincodeID: &pb.ChaincodeID{Name: "ex01", Path: "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example01"}, CtorMsg: &pb.ChaincodeInput{Args: [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")}}}
cccid := chaincode.NewCCContext(chainID, "ex01", "", "", false, nil)
_, _, err := deploy(endorserServer, chainID, spec, nil)
if err != nil {
t.Fail()
t.Logf("Deploy-error in deploy %s", err)
chaincode.GetChain().Stop(context.Background(), cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
return
}
chaincode.GetChain().Stop(context.Background(), cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
}
示例13: TestDeployAndInvoke
// TestDeployAndInvoke deploys and invokes chaincode_example01
func TestDeployAndInvoke(t *testing.T) {
chainID := util.GetTestChainID()
var ctxt = context.Background()
url := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example01"
chaincodeID := &pb.ChaincodeID{Path: url, Name: "ex01"}
args := []string{"10"}
f := "init"
argsDeploy := util.ToChaincodeArgs(f, "a", "100", "b", "200")
spec := &pb.ChaincodeSpec{Type: 1, ChaincodeID: chaincodeID, CtorMsg: &pb.ChaincodeInput{Args: argsDeploy}}
cccid := chaincode.NewCCContext(chainID, "ex01", "", "", false, nil)
resp, prop, err := deploy(endorserServer, chainID, spec, nil)
chaincodeID1 := spec.ChaincodeID.Name
if err != nil {
t.Fail()
t.Logf("Error deploying <%s>: %s", chaincodeID1, err)
chaincode.GetChain().Stop(ctxt, cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID}})
return
}
err = endorserServer.(*Endorser).commitTxSimulation(prop, chainID, signer, resp)
if err != nil {
t.Fail()
t.Logf("Error committing <%s>: %s", chaincodeID1, err)
chaincode.GetChain().Stop(ctxt, cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID}})
return
}
f = "invoke"
invokeArgs := append([]string{f}, args...)
spec = &pb.ChaincodeSpec{Type: 1, ChaincodeID: chaincodeID, CtorMsg: &pb.ChaincodeInput{Args: util.ToChaincodeArgs(invokeArgs...)}}
resp, err = invoke(chainID, spec)
if err != nil {
t.Fail()
t.Logf("Error invoking transaction: %s", err)
chaincode.GetChain().Stop(ctxt, cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID}})
return
}
fmt.Printf("Invoke test passed\n")
t.Logf("Invoke test passed")
chaincode.GetChain().Stop(ctxt, cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID}})
}
示例14: createTx
func createTx() (*common.Envelope, error) {
cis := &peer.ChaincodeInvocationSpec{ChaincodeSpec: &peer.ChaincodeSpec{ChaincodeID: &peer.ChaincodeID{Name: "foo"}}}
uuid := util.GenerateUUID()
prop, err := utils.CreateProposalFromCIS(uuid, util.GetTestChainID(), cis, sid)
if err != nil {
return nil, err
}
presp, err := utils.CreateProposalResponse(prop.Header, prop.Payload, []byte("res"), nil, nil, id)
if err != nil {
return nil, err
}
return utils.CreateSignedTx(prop, id, presp)
}
示例15: TestDeployBadPayload
//TestDeployBadPayload set payload to nil and do a deploy. It should fail and example02 should not be deployed
func TestDeployBadPayload(t *testing.T) {
chainID := util.GetTestChainID()
//invalid arguments
spec := &pb.ChaincodeSpec{Type: 1, ChaincodeID: &pb.ChaincodeID{Name: "ex02", Path: "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"}, CtorMsg: &pb.ChaincodeInput{Args: [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")}}}
cccid := chaincode.NewCCContext(chainID, "ex02", "", "", false, nil)
f := func(cds *pb.ChaincodeDeploymentSpec) {
cds.CodePackage = nil
}
_, _, err := deploy(endorserServer, chainID, spec, f)
if err == nil {
t.Fail()
t.Log("DeployBadPayload-expected error in deploy but succeeded")
chaincode.GetChain().Stop(context.Background(), cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
return
}
chaincode.GetChain().Stop(context.Background(), cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
}