當前位置: 首頁>>代碼示例>>Golang>>正文


Golang shim.NewMockStub函數代碼示例

本文整理匯總了Golang中github.com/hyperledger/fabric/core/chaincode/shim.NewMockStub函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewMockStub函數的具體用法?Golang NewMockStub怎麽用?Golang NewMockStub使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewMockStub函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestExample04_Invoke

func TestExample04_Invoke(t *testing.T) {
	scc := new(SimpleChaincode)
	stub := shim.NewMockStub("ex05", scc)

	ccEx2 := new(ex02.SimpleChaincode)
	stubEx2 := shim.NewMockStub("ex02", ccEx2)
	checkInit(t, stubEx2, [][]byte{[]byte("init"), []byte("a"), []byte("222"), []byte("b"), []byte("333")})
	stub.MockPeerChaincode(example02Url, stubEx2)

	checkInit(t, stub, [][]byte{[]byte("init"), []byte("sumStoreName"), []byte("0")})

	// a + b = 222 + 333 = 555
	checkInvoke(t, stub, [][]byte{[]byte("invoke"), []byte(example02Url), []byte("sumStoreName")})
	checkQuery(t, stub, [][]byte{[]byte("query"), []byte(example02Url), []byte("sumStoreName")}, "555") // example05 doesn't return JSON?
	checkQuery(t, stubEx2, [][]byte{[]byte("query"), []byte("a")}, "222")
	checkQuery(t, stubEx2, [][]byte{[]byte("query"), []byte("b")}, "333")

	// update A-=10 and B+=10
	checkInvoke(t, stubEx2, [][]byte{[]byte("invoke"), []byte("a"), []byte("b"), []byte("10")})

	// a + b = 212 + 343 = 555
	checkInvoke(t, stub, [][]byte{[]byte("invoke"), []byte(example02Url), []byte("sumStoreName")})
	checkQuery(t, stub, [][]byte{[]byte("query"), []byte(example02Url), []byte("sumStoreName")}, "555") // example05 doesn't return JSON?
	checkQuery(t, stubEx2, [][]byte{[]byte("query"), []byte("a")}, "212")
	checkQuery(t, stubEx2, [][]byte{[]byte("query"), []byte("b")}, "343")
}
開發者ID:hyperledger,項目名稱:fabric,代碼行數:26,代碼來源:chaincode_example05_test.go

示例2: TestExample04_Invoke

func TestExample04_Invoke(t *testing.T) {
	scc := new(SimpleChaincode)
	stub := shim.NewMockStub("ex05", scc)

	ccEx2 := new(ex02.SimpleChaincode)
	stubEx2 := shim.NewMockStub("ex02", ccEx2)
	checkInit(t, stubEx2, []string{"a", "222", "b", "333"})
	stub.MockPeerChaincode(example02Url, stubEx2)

	checkInit(t, stub, []string{"sumStoreName", "0"})

	// a + b = 222 + 333 = 555
	checkInvoke(t, stub, []string{example02Url, "sumStoreName"})
	checkQuery(t, stub, []string{example02Url, "sumStoreName"}, "555") // example05 doesn't return JSON?
	checkQuery(t, stubEx2, []string{"a"}, "222")
	checkQuery(t, stubEx2, []string{"b"}, "333")

	// update A-=10 and B+=10
	checkInvoke(t, stubEx2, []string{"a", "b", "10"})

	// a + b = 212 + 343 = 555
	checkInvoke(t, stub, []string{example02Url, "sumStoreName"})
	checkQuery(t, stub, []string{example02Url, "sumStoreName"}, "555") // example05 doesn't return JSON?
	checkQuery(t, stubEx2, []string{"a"}, "212")
	checkQuery(t, stubEx2, []string{"b"}, "343")
}
開發者ID:yoshiharay,項目名稱:fabric,代碼行數:26,代碼來源:chaincode_example05_test.go

示例3: TestExample04_Invoke

func TestExample04_Invoke(t *testing.T) {
	scc := new(SimpleChaincode)
	stub := shim.NewMockStub("ex04", scc)

	chaincodeToInvoke := "ex02"

	ccEx2 := new(ex02.SimpleChaincode)
	stubEx2 := shim.NewMockStub(chaincodeToInvoke, ccEx2)
	checkInit(t, stubEx2, [][]byte{[]byte("init"), []byte("a"), []byte("111"), []byte("b"), []byte("222")})
	stub.MockPeerChaincode(chaincodeToInvoke, stubEx2)

	// Init A=567 B=678
	checkInit(t, stub, [][]byte{[]byte("init"), []byte("Event"), []byte("1")})

	// Invoke A->B for 10 via Example04's chaincode
	checkInvoke(t, stub, [][]byte{[]byte("invoke"), []byte(chaincodeToInvoke), []byte("Event"), []byte("1")})
	checkQuery(t, stub, "Event", eventResponse)
	checkQuery(t, stubEx2, "a", "101")
	checkQuery(t, stubEx2, "b", "232")

	// Invoke A->B for 10 via Example04's chaincode
	checkInvoke(t, stub, [][]byte{[]byte("invoke"), []byte(chaincodeToInvoke), []byte("Event"), []byte("1")})
	checkQuery(t, stub, "Event", eventResponse)
	checkQuery(t, stubEx2, "a", "91")
	checkQuery(t, stubEx2, "b", "242")
}
開發者ID:hyperledger,項目名稱:fabric,代碼行數:26,代碼來源:chaincode_example04_test.go

示例4: TestExample04_Query

func TestExample04_Query(t *testing.T) {
	scc := new(SimpleChaincode)
	stub := shim.NewMockStub("ex05", scc)

	ccEx2 := new(ex02.SimpleChaincode)
	stubEx2 := shim.NewMockStub("ex02", ccEx2)
	checkInit(t, stubEx2, []string{"a", "111", "b", "222"})
	stub.MockPeerChaincode(example02Url, stubEx2)

	checkInit(t, stub, []string{"sumStoreName", "0"})

	// a + b = 111 + 222 = 333
	checkQuery(t, stub, []string{example02Url, "sumStoreName"}, "333") // example05 doesn't return JSON?
}
開發者ID:yoshiharay,項目名稱:fabric,代碼行數:14,代碼來源:chaincode_example05_test.go

示例5: TestExample04_Query

func TestExample04_Query(t *testing.T) {
	scc := new(SimpleChaincode)
	stub := shim.NewMockStub("ex05", scc)

	ccEx2 := new(ex02.SimpleChaincode)
	stubEx2 := shim.NewMockStub("ex02", ccEx2)
	checkInit(t, stubEx2, [][]byte{[]byte("init"), []byte("a"), []byte("111"), []byte("b"), []byte("222")})
	stub.MockPeerChaincode(example02Url, stubEx2)

	checkInit(t, stub, [][]byte{[]byte("init"), []byte("sumStoreName"), []byte("0")})

	// a + b = 111 + 222 = 333
	checkQuery(t, stub, [][]byte{[]byte("query"), []byte(example02Url), []byte("sumStoreName")}, "333") // example05 doesn't return JSON?
}
開發者ID:hyperledger,項目名稱:fabric,代碼行數:14,代碼來源:chaincode_example05_test.go

示例6: TestUpgradeNonExistChaincode

//TestUpgradeNonExistChaincode tests upgrade non exist chaincode
func TestUpgradeNonExistChaincode(t *testing.T) {
	initialize()

	scc := new(LifeCycleSysCC)
	stub := shim.NewMockStub("lccc", scc)

	cds, err := constructDeploymentSpec("example02", "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02", [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")})
	var b []byte
	if b, err = proto.Marshal(cds); err != nil || b == nil {
		t.Fatalf("Marshal DeploymentSpec failed")
	}

	args := [][]byte{[]byte(DEPLOY), []byte("test"), b}
	if _, err := stub.MockInvoke("1", args); err != nil {
		t.Fatalf("Deploy chaincode error: %v", err)
	}

	newCds, err := constructDeploymentSpec("example03", "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02", [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")})
	var newb []byte
	if newb, err = proto.Marshal(newCds); err != nil || newb == nil {
		t.Fatalf("Marshal DeploymentSpec failed")
	}

	args = [][]byte{[]byte(UPGRADE), []byte("test"), newb}
	_, err = stub.MockInvoke("1", args)
	if _, ok := err.(NotFoundErr); !ok {
		t.FailNow()
	}
}
開發者ID:hyperledger,項目名稱:fabric,代碼行數:30,代碼來源:lccc_test.go

示例7: TestUpgrade

//TestUpgrade tests the upgrade function
func TestUpgrade(t *testing.T) {
	initialize()

	scc := new(LifeCycleSysCC)
	stub := shim.NewMockStub("lccc", scc)

	cds, err := constructDeploymentSpec("example02", "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02", [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")})
	var b []byte
	if b, err = proto.Marshal(cds); err != nil || b == nil {
		t.Fatalf("Marshal DeploymentSpec failed")
	}

	args := [][]byte{[]byte(DEPLOY), []byte("test"), b}
	if _, err := stub.MockInvoke("1", args); err != nil {
		t.Fatalf("Deploy chaincode error: %v", err)
	}

	newCds, err := constructDeploymentSpec("example02", "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02", [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")})
	var newb []byte
	if newb, err = proto.Marshal(newCds); err != nil || newb == nil {
		t.Fatalf("Marshal DeploymentSpec failed")
	}

	args = [][]byte{[]byte(UPGRADE), []byte("test"), newb}
	version, err := stub.MockInvoke("1", args)
	if err != nil {
		t.Fatalf("Upgrade chaincode error: %v", err)
	}

	expectVer := "1"
	newVer := string(version)
	if newVer != expectVer {
		t.Fatalf("Upgrade chaincode version error, expected %s, got %s", expectVer, newVer)
	}
}
開發者ID:hyperledger,項目名稱:fabric,代碼行數:36,代碼來源:lccc_test.go

示例8: TestInit

func TestInit(t *testing.T) {
	v := new(ValidatorOneValidSignature)
	stub := shim.NewMockStub("validatoronevalidsignature", v)

	if _, err := stub.MockInit("1", nil); err != nil {
		t.Fatalf("vscc init failed with %v", err)
	}
}
開發者ID:hyperledger,項目名稱:fabric,代碼行數:8,代碼來源:validator_onevalidsignature_test.go

示例9: TestInit

func TestInit(t *testing.T) {
	e := new(PeerConfiger)
	stub := shim.NewMockStub("PeerConfiger", e)

	if _, err := stub.MockInit("1", nil); err != nil {
		fmt.Println("Init failed", err)
		t.FailNow()
	}
}
開發者ID:hyperledger,項目名稱:fabric,代碼行數:9,代碼來源:peer_configer_test.go

示例10: TestExample03_Init

func TestExample03_Init(t *testing.T) {
	scc := new(SimpleChaincode)
	stub := shim.NewMockStub("ex03", scc)

	// Init A=123 B=234
	checkInit(t, scc, stub, [][]byte{[]byte("init"), []byte("A"), []byte("123")})

	checkState(t, stub, "A", "123")
}
開發者ID:hyperledger,項目名稱:fabric,代碼行數:9,代碼來源:chaincode_example03_test.go

示例11: TestExample04_Init

func TestExample04_Init(t *testing.T) {
	scc := new(SimpleChaincode)
	stub := shim.NewMockStub("ex04", scc)

	// Init A=123 B=234
	checkInit(t, stub, []string{"Event", "123"})

	checkState(t, stub, "Event", "123")
}
開發者ID:yoshiharay,項目名稱:fabric,代碼行數:9,代碼來源:chaincode_example04_test.go

示例12: TestExample04_Init

func TestExample04_Init(t *testing.T) {
	scc := new(SimpleChaincode)
	stub := shim.NewMockStub("ex05", scc)

	// Init A=123 B=234
	checkInit(t, stub, [][]byte{[]byte("init"), []byte("sumStoreName"), []byte("432")})

	checkState(t, stub, "sumStoreName", "432")
}
開發者ID:hyperledger,項目名稱:fabric,代碼行數:9,代碼來源:chaincode_example05_test.go

示例13: TestExample04_Query

func TestExample04_Query(t *testing.T) {
	scc := new(SimpleChaincode)
	stub := shim.NewMockStub("ex04", scc)

	// Init A=345 B=456
	checkInit(t, stub, [][]byte{[]byte("init"), []byte("Event"), []byte("1")})

	// Query A
	checkQuery(t, stub, "Event", eventResponse)
}
開發者ID:hyperledger,項目名稱:fabric,代碼行數:10,代碼來源:chaincode_example04_test.go

示例14: TestExample03_Query

func TestExample03_Query(t *testing.T) {
	scc := new(SimpleChaincode)
	stub := shim.NewMockStub("ex03", scc)

	// Init A=345 B=456
	checkInit(t, scc, stub, [][]byte{[]byte("init"), []byte("A"), []byte("345")})

	// Query A
	checkQuery(t, scc, stub, [][]byte{[]byte("query"), []byte("A"), []byte("345")})
}
開發者ID:hyperledger,項目名稱:fabric,代碼行數:10,代碼來源:chaincode_example03_test.go

示例15: TestExample03_Query

func TestExample03_Query(t *testing.T) {
	scc := new(SimpleChaincode)
	stub := shim.NewMockStub("ex03", scc)

	// Init A=345 B=456
	checkInit(t, scc, stub, []string{"A", "345"})

	// Query A
	checkQuery(t, scc, stub, []string{"A", "345"}, "345")
}
開發者ID:yoshiharay,項目名稱:fabric,代碼行數:10,代碼來源:chaincode_example03_test.go


注:本文中的github.com/hyperledger/fabric/core/chaincode/shim.NewMockStub函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。