add gongxianghua test function explain

parent 8c67d27a
This diff is collapsed.
......@@ -88,9 +88,9 @@ client:
# [Optional]. Client key and cert for TLS handshake with peers and orderers
client:
key:
path: /opt/gopath/src/github.com/fabric-sdk-sample/fabric-sdk-go/${CRYPTOCONFIG_FIXTURES_PATH}/peerOrganizations/org2.example.com/users/User1@org2.example.com/tls/client.key
path: /opt/gopath/src/github.com/fabric-sdk-sample/fabric-sdk-go/${CRYPTOCONFIG_FIXTURES_PATH}/peerOrganizations/org2.example.com/users/User2@org2.example.com/tls/client.key
cert:
path: /opt/gopath/src/github.com/fabric-sdk-sample/fabric-sdk-go/${CRYPTOCONFIG_FIXTURES_PATH}/peerOrganizations/org2.example.com/users/User1@org2.example.com/tls/client.crt
path: /opt/gopath/src/github.com/fabric-sdk-sample/fabric-sdk-go/${CRYPTOCONFIG_FIXTURES_PATH}/peerOrganizations/org2.example.com/users/User2@org2.example.com/tls/client.crt
#
# [Optional]. But most apps would have this section so that channel objects can be constructed
......@@ -414,9 +414,9 @@ certificateAuthorities:
# Client key and cert for SSL handshake with Fabric CA
client:
key:
path: /opt/gopath/src/github.com/fabric-sdk-sample/fabric-sdk-go/${CRYPTOCONFIG_FIXTURES_PATH}/peerOrganizations/org1.example.com/users/User1@org1.example.com/tls/client.key
path: /opt/gopath/src/github.com/fabric-sdk-sample/fabric-sdk-go/${CRYPTOCONFIG_FIXTURES_PATH}/peerOrganizations/org1.example.com/users/User2@org1.example.com/tls/client.key
cert:
path: /opt/gopath/src/github.com/fabric-sdk-sample/fabric-sdk-go/${CRYPTOCONFIG_FIXTURES_PATH}/peerOrganizations/org1.example.com/users/User1@org1.example.com/tls/client.crt
path: /opt/gopath/src/github.com/fabric-sdk-sample/fabric-sdk-go/${CRYPTOCONFIG_FIXTURES_PATH}/peerOrganizations/org1.example.com/users/User2@org1.example.com/tls/client.crt
# Fabric-CA supports dynamic user enrollment via REST APIs. A "root" user, a.k.a registrar, is
# needed to enroll and invoke new users.
......
......@@ -87,7 +87,7 @@ func CcCreate(){
//prepare context
adminContext := sdk.Context(fabsdk.WithUser(orgAdmin), fabsdk.WithOrg("Org2"))
adminContext := sdk.Context(fabsdk.WithUser(orgAdmin), fabsdk.WithOrg("Org1"))
// Org resource management client
orgResMgmt, err := resmgmt.New(adminContext)
......@@ -253,29 +253,34 @@ func upgradeCc(userName,orgName,chaincodePath ,ccID, version string,args [][]by
func createCc( orgResMgmt *resmgmt.Client) *resmgmt.InstantiateCCResponse {
peerFilter := &PeerFilter{URl:[]string{"39.98.194.244:7251"}}
CcAddress := "/opt/gopath/src/github.com/fabric-sdk-sample/fabric-sdk-go/test/fixtures/testdata"
ccPkg, err := packager.NewCCPackage("github.com/example_cc", CcAddress)
if err != nil {
fmt.Printf("createCc happen err: %s", err)
return nil
fmt.Printf("createCc happen err NewCCPackage: %s", err)
return nil
}
// Install example cc to org peers
installCCReq := resmgmt.InstallCCRequest{Name: ccID, Path: "github.com/example_cc", Version: "0", Package: ccPkg}
_, err = orgResMgmt.InstallCC(installCCReq, resmgmt.WithRetry(retry.DefaultResMgmtOpts))//install 是依赖orgId 的peer
//Install example cc to org peers
installCCReq := resmgmt.InstallCCRequest{Name: "testcc", Path: "github.com/example_cc", Version: "1.0", Package: ccPkg}
_, err = orgResMgmt.InstallCC(installCCReq, resmgmt.WithRetry(retry.DefaultResMgmtOpts),)//install 是依赖orgId 的peer
if err != nil {
fmt.Printf("createCc happen err: %s", err)
fmt.Printf("createCc happen err InstallCC: %s", err)
return nil
}
return nil
// Set up chaincode policy
ccPolicy := cauthdsl.SignedByAnyMember([]string{"Org1MSP"}) //注册chaincode policy
// Org resource manager will instantiate 'example_cc' on channel
resp, err := orgResMgmt.InstantiateCC( //InstantiateCC 实例instantiataCC 却是从channels 获取peer
channelID,
resmgmt.InstantiateCCRequest{Name: ccID, Path: "github.com/example_cc", Version: "0", Args: integration.ExampleCCInitArgs(), Policy: ccPolicy},
resmgmt.InstantiateCCRequest{Name: "testcc", Path: "github.com/chaincode/chaincode_example02/go", Version: "1.0", Args: integration.ExampleCCInitArgs(), Policy: ccPolicy},
resmgmt.WithRetry(retry.DefaultResMgmtOpts),
resmgmt.WithTargetFilter(peerFilter),
)
if err!=nil{
fmt.Printf("createCc happen err: %s", err)
fmt.Printf("createCc happen err InstantiateCC: %s", err)
return nil
}
return &resp
......
......@@ -47,21 +47,35 @@ func TestCcCreate(t *testing.T){
func TestInstallCc(t *testing.T){
userName := "Admin"
orgName:= "Org1"
chaincodePath:="github.com/example_cc"
goPath := "/opt/gopath/src/github.com/fabric-sdk-sample/fabric-sdk-go/test/fixtures/testdata"
//chaincodePath:="github.com/example_cc"
//goPath := "/opt/gopath/src/github.com/fabric-sdk-sample/fabric-sdk-go/test/fixtures/testdata/src"
chaincodePath:="github.com/gongxianghui"
goPath:= "/opt/gopath/src/github.com/hyperledger/chaincode"
peerFilter := &PeerFilter{URl:[]string{"39.98.194.244:7151"}}
ccID:="testCC"
version:= "0"
ccID:="gongxianghui"
version:= "1"
installCc(userName,orgName,chaincodePath,goPath,ccID,version,peerFilter)
}
func TestInstantiateCc(t *testing.T){
userName := "Admin"
orgName:= "Org1"
//chaincodePath:="github.com/example_cc"
//goPath := "/opt/gopath/src/github.com/fabric-sdk-sample/fabric-sdk-go/test/fixtures/testdata/src"
chaincodePath:="github.com/gongxianghui"
//goPath:= "/opt/gopath/src/github.com/hyperledger/chaincode"
peerFilter := &PeerFilter{URl:[]string{"39.98.194.244:7251"}}
ccID:="gongxianghui"
version:= "1"
instantiateCc(userName,orgName,chaincodePath,ccID,version,nil,nil,peerFilter)
}
func TestUpgradeCc(t *testing.T){
userName := "Admin"
orgName:= "Org1"
chaincodePath:="github.com/example_cc"
//peerFilter := &PeerFilter{URl:[]string{"39.98.194.244:7151"}}
ccID:="example_cc_e2e"
chaincodePath:="gongxianghui"
peerFilter := &PeerFilter{URl:[]string{"39.98.194.244:7251"}}
ccID:="testCC"
version:= "0"
upgradeCc(userName,orgName,chaincodePath,ccID,version,nil,nil,nil)
upgradeCc(userName,orgName,chaincodePath,ccID,version,nil,nil,peerFilter)
}
\ No newline at end of file
......@@ -10,7 +10,7 @@ import (
*/
func TestCcQuery(t *testing.T) {
res,err := CcQuery("mycc","get",[][]byte{[]byte("alibusi"),[]byte(`{"id":"1"}`)}) //共享汇table query
res,err := CcQuery("mycc","cert",nil) //共享汇table query
if err!=nil{
fmt.Println("CcQuery execute err: ",err)
}else{
......@@ -18,12 +18,12 @@ func TestCcQuery(t *testing.T) {
}
fmt.Println("===============================schema get query==================================================")
fmt.Println("")
resSchema,errSchema := CcQuery("mycc","schema",[][]byte{[]byte("get"),[]byte("alibusi")}) //共享汇table query
if err!=nil{
fmt.Println("CcQuery execute err: ",errSchema)
}else{
fmt.Printf("Invoke status %d and payload %s \n",resSchema.ChaincodeStatus,string(resSchema.Payload))
}
//resSchema,errSchema := CcQuery("mycc","schema",[][]byte{[]byte("get"),[]byte("alibusi")}) //共享汇table query
//if err!=nil{
// fmt.Println("CcQuery execute err: ",errSchema)
//}else{
// fmt.Printf("Invoke status %d and payload %s \n",resSchema.ChaincodeStatus,string(resSchema.Payload))
//}
}
var input = `{"id":"1","aname":"aaa","atype":"aaa","alinkman":"cc","aader":"aader","amob":"1234567890","backup":{"id":"1","aname":"alibusi","atype":"type","alinkman":"aaa","aader":"aader","amob":"1234567890"}}`
......@@ -76,4 +76,104 @@ func TestCcInvoke(t *testing.T) {
}
}
/*
共享慧chaincode测试说明:
当前共享慧共有两部分内容:
1:schema 部分。
分为三个操作function
(1)put:存储表结构,用于table put(具体表数据存储时) or update(具体表数据结构更新)时进行table 结构校验。每条schema 数据由table name 为key。
args[0]区分是schema 的操作类型,分为put,update,get 三种.args[1],代表table name,唯一值不可重复。args[2]具体的table struct
(2)update:更新表结构
args[0]区分是schema 的操作类型,分为put,update,get 三种.args[1],代表table name,唯一值不可重复。args[2]具体update的table struct
(3)get :获得表结构
args[0]区分是schema 的操作类型,分为put,update,get 三种.args[1],代表table name,唯一值不可重复。
2:table data 部分(数据存储部分,数据存在表结构,所以在进行table data 操作前,需要存在对应的table schema)
(1)put:存储具体的表数据,支持批量存储。
put 操作时,args[0] 表示table name,我们会根据table name,查询对应的schema 数据,用于对table data 进行格式校验。所以我们在进行put 操作前,一定要提前进行对应的
schema table struct put operation.args[1],表示具体的存储表数据,args[1]可以是批量表数据,也可以是单条表数据。每条数据除了必须满足对应的表结构,必须存在id 字段
id 字段是一条数据的唯一key.不能重复。
(2)update :修改表数据,不支持批量数据
update 操作时,args[0] 表示table name,args[1]表示要修改的数据,同样必须存在id 字段
(3)get :根据表id字段查询表数据
get操作时,args[0] 表示table name,args[1],表示要查询数据的id
*/
/*
一个新表格数据完整的测试顺序
1:Schema,put
2:Data put
3:Data get
*/
/*
我们常遇到的错误:
1:重复执行同一张表的schema put 操作。
解决方法修改args[1] 的table name
error message:the parameter ** already exists and cannot be added
2:重复执行同一张表的Data put 操作。
解决方法,更新args[1]的存储数据的id 字段值
error message: ** data already exist
3:直接执行表的Data put 操作,而没有执行对应表结构的Schema put操作。
error message: GetSchema data fail,please check your parameters
解决方法,先执行对应表结构的Schema put操作
*/
func TestSchemaPut(t *testing.T){
resSchema,errSchema := CcInvoke("mycc","schema",[][]byte{[]byte("put"),[]byte("alibusi"),[]byte(input)})
if errSchema!=nil{
fmt.Println("CcInvoke execute err: ",errSchema)
}else{
fmt.Printf("Invoke status %d and payload %s \n",resSchema.ChaincodeStatus,string(resSchema.Payload))
}
}
func TestSchemaGet(t *testing.T){
resSchema,errSchema := CcQuery("mycc","schema",[][]byte{[]byte("get"),[]byte("alibusi")})
if errSchema!=nil{
fmt.Println("CcQuery execute err: ",errSchema)
}else{
fmt.Printf("Query status %d and payload %s \n",resSchema.ChaincodeStatus,string(resSchema.Payload))
}
}
/*
update Schema 只对新数据格式是否符合map[string]interface{} 的格式,以及更新的数据是否存在
*/
func TestSchemaUpdate(t *testing.T){
resSchema,errSchema := CcInvoke("mycc","schema",[][]byte{[]byte("get"),[]byte("alibusi"),[]byte(input)})
if errSchema!=nil{
fmt.Println("CcInvoke execute err: ",errSchema)
}else{
fmt.Printf("Invoke status %d and payload %s \n",resSchema.ChaincodeStatus,string(resSchema.Payload))
}
}
/*
----------------------------------------------------------Data Operation------------------------------------------------------------
*/
func TestDataPut(t *testing.T){
resSchema,errSchema := CcInvoke("mycc","schema",[][]byte{[]byte("put"),[]byte("alibusi"),[]byte(input)})
if errSchema!=nil{
fmt.Println("CcInvoke execute err: ",errSchema)
}else{
fmt.Printf("Invoke status %d and payload %s \n",resSchema.ChaincodeStatus,string(resSchema.Payload))
}
}
func TestDataGet(t *testing.T){
resSchema,errSchema := CcQuery("mycc","schema",[][]byte{[]byte("get"),[]byte("alibusi"),[]byte(`{"id":"1"}`)})
if errSchema!=nil{
fmt.Println("CcQuery execute err: ",errSchema)
}else{
fmt.Printf("Query status %d and payload %s \n",resSchema.ChaincodeStatus,string(resSchema.Payload))
}
}
func TestDataUpdate(t *testing.T){
resSchema,errSchema := CcInvoke("mycc","schema",[][]byte{[]byte("get"),[]byte("alibusi"),[]byte(inputUp)})
if errSchema!=nil{
fmt.Println("CcInvoke execute err: ",errSchema)
}else{
fmt.Printf("Invoke status %d and payload %s \n",resSchema.ChaincodeStatus,string(resSchema.Payload))
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment