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


Golang shim.MockStub類代碼示例

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


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

示例1: checkInit

func checkInit(t *testing.T, scc *SimpleChaincode, stub *shim.MockStub, args [][]byte) {
	_, err := stub.MockInit("1", args)
	if err != nil {
		fmt.Println("Init failed", err)
		t.FailNow()
	}
}
開發者ID:hyperledger,項目名稱:fabric,代碼行數:7,代碼來源:chaincode_example03_test.go

示例2: checkInvoke

func checkInvoke(t *testing.T, stub *shim.MockStub, args [][]byte) {
	_, err := stub.MockInvoke("1", args)
	if err != nil {
		fmt.Println("Invoke", args, "failed", err)
		t.FailNow()
	}
}
開發者ID:hyperledger,項目名稱:fabric,代碼行數:7,代碼來源:chaincode_example05_test.go

示例3: checkInvoke

func checkInvoke(t *testing.T, scc *SimpleChaincode, stub *shim.MockStub, args []string) {
	_, err := stub.MockInvoke("1", "query", args)
	if err != nil {
		fmt.Println("Invoke", args, "failed", err)
		t.FailNow()
	}
}
開發者ID:yoshiharay,項目名稱:fabric,代碼行數:7,代碼來源:chaincode_example03_test.go

示例4: checkInit

func checkInit(t *testing.T, stub *shim.MockStub, args []string) {
	_, err := stub.MockInit("1", "init", args)
	if err != nil {
		fmt.Println("Init failed", err)
		t.FailNow()
	}
}
開發者ID:yoshiharay,項目名稱:fabric,代碼行數:7,代碼來源:chaincode_example04_test.go

示例5: register

func register(stub *shim.MockStub, ccname string) error {
	args := [][]byte{[]byte("register"), []byte(ccname)}
	if _, err := stub.MockInvoke("1", args); err != nil {
		return err
	}
	return nil
}
開發者ID:hyperledger,項目名稱:fabric,代碼行數:7,代碼來源:lccc_test.go

示例6: checkQuery

func checkQuery(t *testing.T, stub *shim.MockStub, args [][]byte, expect string) {
	bytes, err := stub.MockInvoke("1", args)
	if err != nil {
		fmt.Println("Query", args, "failed", err)
		t.FailNow()
	}
	if bytes == nil {
		fmt.Println("Query", args, "failed to get result")
		t.FailNow()
	}
	if string(bytes) != expect {
		fmt.Println("Query result ", string(bytes), "was not", expect, "as expected")
		t.FailNow()
	}
}
開發者ID:hyperledger,項目名稱:fabric,代碼行數:15,代碼來源:chaincode_example05_test.go

示例7: checkQuery

func checkQuery(t *testing.T, stub *shim.MockStub, name string, value string) {
	bytes, err := stub.MockInvoke("1", [][]byte{[]byte("query"), []byte(name)})
	if err != nil {
		fmt.Println("Query", name, "failed", err)
		t.FailNow()
	}
	if bytes == nil {
		fmt.Println("Query", name, "failed to get value")
		t.FailNow()
	}
	if string(bytes) != value {
		fmt.Println("Query value", name, "was not", value, "as expected")
		t.FailNow()
	}
}
開發者ID:hyperledger,項目名稱:fabric,代碼行數:15,代碼來源:chaincode_example04_test.go

示例8: checkInit

func checkInit(t *testing.T, stub *shim.MockStub, args [][]byte, retval []byte) {
	result, err := stub.MockInit("1", args)
	if err != nil {
		fmt.Println("Init failed", err)
		t.FailNow()
	}
	if retval != nil {
		if result == nil {
			fmt.Printf("Init returned nil, expected %s", string(retval))
			t.FailNow()
		}
		if string(result) != string(retval) {
			fmt.Printf("Init returned %s, expected %s", string(result), string(retval))
			t.FailNow()
		}
	}
}
開發者ID:hyperledger,項目名稱:fabric,代碼行數:17,代碼來源:invokereturnsvalue_test.go

示例9: checkQuery

func checkQuery(t *testing.T, scc *SimpleChaincode, stub *shim.MockStub, args [][]byte) {
	_, err := stub.MockInit("1", args)
	bytes, err := scc.Invoke(stub)
	if err != nil {
		// expected failure
		fmt.Println("Query below is expected to fail")
		fmt.Println("Query failed", err)
		fmt.Println("Query above is expected to fail")

		if err.Error() != "{\"Error\":\"Cannot put state within chaincode query\"}" {
			fmt.Println("Failure was not the expected \"Cannot put state within chaincode query\" : ", err)
			t.FailNow()
		}

	} else {
		fmt.Println("Query did not fail as expected (PutState within Query)!", bytes, err)
		t.FailNow()
	}
}
開發者ID:hyperledger,項目名稱:fabric,代碼行數:19,代碼來源:chaincode_example03_test.go


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