mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-26 03:25:09 +00:00
Adding golang application for asset-transfer-basic sample. (#211)
Signed-off-by: Chongxin Luo <Chongxin.Luo@ibm.com> Improved private data Go Chaincode in idiomatic go. Adding go chaincode unit tests Signed-off-by: Sijo Cherian <sijo@ibm.com>
This commit is contained in:
parent
026217db9a
commit
eadb98493f
13 changed files with 4488 additions and 29 deletions
4
asset-transfer-basic/application-go/.gitignore
vendored
Executable file
4
asset-transfer-basic/application-go/.gitignore
vendored
Executable file
|
|
@ -0,0 +1,4 @@
|
||||||
|
wallet
|
||||||
|
!wallet/.gitkeep
|
||||||
|
|
||||||
|
keystore
|
||||||
146
asset-transfer-basic/application-go/assetTransfer.go
Normal file
146
asset-transfer-basic/application-go/assetTransfer.go
Normal file
|
|
@ -0,0 +1,146 @@
|
||||||
|
/*
|
||||||
|
Copyright 2020 IBM All Rights Reserved.
|
||||||
|
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
|
||||||
|
"github.com/hyperledger/fabric-sdk-go/pkg/gateway"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println("============ application-golang starts ============")
|
||||||
|
|
||||||
|
os.Setenv("DISCOVERY_AS_LOCALHOST", "true")
|
||||||
|
wallet, err := gateway.NewFileSystemWallet("wallet")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("failed to create wallet: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !wallet.Exists("appUser") {
|
||||||
|
err = populateWallet(wallet)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("failed to populate wallet contents: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ccpPath := filepath.Join(
|
||||||
|
"..",
|
||||||
|
"..",
|
||||||
|
"test-network",
|
||||||
|
"organizations",
|
||||||
|
"peerOrganizations",
|
||||||
|
"org1.example.com",
|
||||||
|
"connection-org1.yaml",
|
||||||
|
)
|
||||||
|
|
||||||
|
gw, err := gateway.Connect(
|
||||||
|
gateway.WithConfig(config.FromFile(filepath.Clean(ccpPath))),
|
||||||
|
gateway.WithIdentity(wallet, "appUser"),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("failed to connect to gateway: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
defer gw.Close()
|
||||||
|
|
||||||
|
network, err := gw.GetNetwork("mychannel")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("failed to get network: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
contract := network.GetContract("basic")
|
||||||
|
|
||||||
|
result, err := contract.EvaluateTransaction("GetAllAssets")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("failed to evaluate transaction: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fmt.Println(string(result))
|
||||||
|
|
||||||
|
result, err = contract.SubmitTransaction("CreateAsset", "asset13", "yellow", "Tom", "5", "1300")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("failed to submit transaction: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fmt.Println(string(result))
|
||||||
|
|
||||||
|
result, err = contract.EvaluateTransaction("ReadAsset", "asset4")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("failed to evaluate transaction: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fmt.Println(string(result))
|
||||||
|
|
||||||
|
_, err = contract.SubmitTransaction("TransferAsset", "asset1", "Tom")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Failed to submit transaction: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err = contract.EvaluateTransaction("ReadAsset", "asset1")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("failed to evaluate transaction: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fmt.Println(string(result))
|
||||||
|
fmt.Println("============ application-golang ends ============")
|
||||||
|
}
|
||||||
|
|
||||||
|
func populateWallet(wallet *gateway.Wallet) error {
|
||||||
|
fmt.Println("============ populate wallet starts ============")
|
||||||
|
credPath := filepath.Join(
|
||||||
|
"..",
|
||||||
|
"..",
|
||||||
|
"test-network",
|
||||||
|
"organizations",
|
||||||
|
"peerOrganizations",
|
||||||
|
"org1.example.com",
|
||||||
|
"users",
|
||||||
|
"User1@org1.example.com",
|
||||||
|
"msp",
|
||||||
|
)
|
||||||
|
|
||||||
|
certPath := filepath.Join(credPath, "signcerts", "cert.pem")
|
||||||
|
// read the certificate pem
|
||||||
|
cert, err := ioutil.ReadFile(filepath.Clean(certPath))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
keyDir := filepath.Join(credPath, "keystore")
|
||||||
|
// there's a single file in this dir containing the private key
|
||||||
|
files, err := ioutil.ReadDir(keyDir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(files) != 1 {
|
||||||
|
return errors.New("keystore folder should have contain one file")
|
||||||
|
}
|
||||||
|
keyPath := filepath.Join(keyDir, files[0].Name())
|
||||||
|
key, err := ioutil.ReadFile(filepath.Clean(keyPath))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
identity := gateway.NewX509Identity("Org1MSP", string(cert), string(key))
|
||||||
|
|
||||||
|
err = wallet.Put("appUser", identity)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Println("============ populate wallet ends ============")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
5
asset-transfer-basic/application-go/go.mod
Normal file
5
asset-transfer-basic/application-go/go.mod
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
module asset-transfer-basic
|
||||||
|
|
||||||
|
go 1.14
|
||||||
|
|
||||||
|
require github.com/hyperledger/fabric-sdk-go v1.0.0-beta2
|
||||||
127
asset-transfer-basic/application-go/go.sum
Normal file
127
asset-transfer-basic/application-go/go.sum
Normal file
|
|
@ -0,0 +1,127 @@
|
||||||
|
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
|
github.com/Knetic/govaluate v3.0.0+incompatible h1:7o6+MAPhYTCF0+fdvoz1xDedhRb4f6s9Tn1Tt7/WTEg=
|
||||||
|
github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
|
||||||
|
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
|
||||||
|
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0=
|
||||||
|
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||||
|
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||||
|
github.com/cloudflare/cfssl v0.0.0-20180223231731-4e2dcbde5004 h1:lkAMpLVBDaj17e85keuznYcH5rqI438v41pKcBl4ZxQ=
|
||||||
|
github.com/cloudflare/cfssl v0.0.0-20180223231731-4e2dcbde5004/go.mod h1:yMWuSON2oQp+43nFtAV/uvKQIFpSPerB57DCt9t8sSA=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||||
|
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||||
|
github.com/go-kit/kit v0.8.0 h1:Wz+5lgoB0kkuqLEc6NVmwRknTKP6dTGbSqvhZtBI/j0=
|
||||||
|
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||||
|
github.com/go-logfmt/logfmt v0.4.0 h1:MP4Eh7ZCb31lleYCFuwm0oe4/YGak+5l1vA2NOE80nA=
|
||||||
|
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
||||||
|
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||||
|
github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo=
|
||||||
|
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||||
|
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||||
|
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||||
|
github.com/golang/mock v1.2.0 h1:28o5sBqPkBsMGnC6b4MvE2TzSr5/AT4c/1fLqVGIwlk=
|
||||||
|
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||||
|
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
|
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
|
||||||
|
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
|
github.com/google/certificate-transparency-go v0.0.0-20180222191210-5ab67e519c93 h1:qdfmdGwtm13OVx+AxguOWUTbgmXGn2TbdUHipo3chMg=
|
||||||
|
github.com/google/certificate-transparency-go v0.0.0-20180222191210-5ab67e519c93/go.mod h1:QeJfpSbVSfYc7RgB3gJFj9cbuQMMchQxrWXz8Ruopmg=
|
||||||
|
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||||
|
github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce h1:xdsDDbiBDQTKASoGEZ+pEmF1OnWuu8AQ9I8iNbHNeno=
|
||||||
|
github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce/go.mod h1:oZtUIOe8dh44I2q6ScRibXws4Ajl+d+nod3AaR9vL5w=
|
||||||
|
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||||
|
github.com/hyperledger/fabric-lib-go v1.0.0 h1:UL1w7c9LvHZUSkIvHTDGklxFv2kTeva1QI2emOVc324=
|
||||||
|
github.com/hyperledger/fabric-lib-go v1.0.0/go.mod h1:H362nMlunurmHwkYqR5uHL2UDWbQdbfz74n8kbCFsqc=
|
||||||
|
github.com/hyperledger/fabric-protos-go v0.0.0-20191121202242-f5500d5e3e85 h1:bNgEcCg5NVRWs/T+VUEfhgh5Olx/N4VB+0+ybW+oSuA=
|
||||||
|
github.com/hyperledger/fabric-protos-go v0.0.0-20191121202242-f5500d5e3e85/go.mod h1:xVYTjK4DtZRBxZ2D9aE4y6AbLaPwue2o/criQyQbVD0=
|
||||||
|
github.com/hyperledger/fabric-sdk-go v1.0.0-beta1.0.20200526155846-219a09aadc0f h1:eAkJx0+8PBbfP6xZxVRD2agk9W7oDbqllxO+ERgnKJk=
|
||||||
|
github.com/hyperledger/fabric-sdk-go v1.0.0-beta1.0.20200526155846-219a09aadc0f/go.mod h1:/s224b8NLvOJOCIqBvWd9O6u7GE33iuIOT6OfcTE1OE=
|
||||||
|
github.com/hyperledger/fabric-sdk-go v1.0.0-beta2 h1:FBYygns0Qga+mQ4PXycyTU5m4N9KAZM+Ttf7agiV7M8=
|
||||||
|
github.com/hyperledger/fabric-sdk-go v1.0.0-beta2/go.mod h1:/s224b8NLvOJOCIqBvWd9O6u7GE33iuIOT6OfcTE1OE=
|
||||||
|
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 h1:T+h1c/A9Gawja4Y9mFVWj2vyii2bbUNDw3kt9VxK2EY=
|
||||||
|
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||||
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
|
github.com/magiconair/properties v1.7.6 h1:U+1DqNen04MdEPgFiIwdOUiqZ8qPa37xgogX/sd3+54=
|
||||||
|
github.com/magiconair/properties v1.7.6/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||||
|
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||||
|
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||||
|
github.com/miekg/pkcs11 v0.0.0-20190329070431-55f3fac3af27/go.mod h1:WCBAbTOdfhHhz7YXujeZMF7owC4tPb1naKFsgfUISjo=
|
||||||
|
github.com/mitchellh/mapstructure v0.0.0-20180220230111-00c29f56e238 h1:+MZW2uvHgN8kYvksEN3f7eFL2wpzk0GxmlFsMybWc7E=
|
||||||
|
github.com/mitchellh/mapstructure v0.0.0-20180220230111-00c29f56e238/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||||
|
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
|
github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||||
|
github.com/pelletier/go-toml v1.1.0 h1:cmiOvKzEunMsAxyhXSzpL5Q1CRKpVv0KQsnAIcSEVYM=
|
||||||
|
github.com/pelletier/go-toml v1.1.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||||
|
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||||
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/prometheus/client_golang v0.8.0 h1:1921Yw9Gc3iSc4VQh3PIoOqgPCZS7G/4xQNVUp8Mda8=
|
||||||
|
github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||||
|
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 h1:idejC8f05m9MGOsuEi1ATq9shN03HrxNkD/luQvxCv8=
|
||||||
|
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||||
|
github.com/prometheus/common v0.0.0-20180518154759-7600349dcfe1 h1:osmNoEW2SCW3L7EX0km2LYM8HKpNWRiouxjE3XHkyGc=
|
||||||
|
github.com/prometheus/common v0.0.0-20180518154759-7600349dcfe1/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
|
||||||
|
github.com/prometheus/procfs v0.0.0-20180705121852-ae68e2d4c00f h1:c9M4CCa6g8WURSsbrl3lb/w/G1Z5xZpYvhhjdcVDOkE=
|
||||||
|
github.com/prometheus/procfs v0.0.0-20180705121852-ae68e2d4c00f/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||||
|
github.com/spf13/afero v1.1.0 h1:bopulORc2JeYaxfHLvJa5NzxviA9PoWhpiiJkru7Ji4=
|
||||||
|
github.com/spf13/afero v1.1.0/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
|
||||||
|
github.com/spf13/cast v1.2.0 h1:HHl1DSRbEQN2i8tJmtS6ViPyHx35+p51amrdsiTCrkg=
|
||||||
|
github.com/spf13/cast v1.2.0/go.mod h1:r2rcYCSwa1IExKTDiTfzaxqT2FNHs8hODu4LnUfgKEg=
|
||||||
|
github.com/spf13/jwalterweatherman v0.0.0-20180109140146-7c0cea34c8ec h1:2ZXvIUGghLpdTVHR1UfvfrzoVlZaE/yOWC5LueIHZig=
|
||||||
|
github.com/spf13/jwalterweatherman v0.0.0-20180109140146-7c0cea34c8ec/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
|
||||||
|
github.com/spf13/pflag v1.0.1 h1:aCvUg6QPl3ibpQUxyLkrEkCHtPqYJL4x9AuhqVqFis4=
|
||||||
|
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||||
|
github.com/spf13/viper v1.0.2 h1:Ncr3ZIuJn322w2k1qmzXDnkLAdQMlJqBa9kfAH+irso=
|
||||||
|
github.com/spf13/viper v1.0.2/go.mod h1:A8kyI5cUJhb8N+3pkfONlcEcZbueH6nhAm0Fq7SrnBM=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||||
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
|
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||||
|
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||||
|
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
|
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=
|
||||||
|
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
|
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||||
|
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
|
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||||
|
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||||
|
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||||
|
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||||
|
google.golang.org/genproto v0.0.0-20190327125643-d831d65fe17d h1:XB2jc5XQ9uhizGTS2vWcN01bc4dI6z3C4KY5MQm8SS8=
|
||||||
|
google.golang.org/genproto v0.0.0-20190327125643-d831d65fe17d/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||||
|
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||||
|
google.golang.org/grpc v1.23.0 h1:AzbTB6ux+okLTzP8Ru1Xs41C303zdcfEht7MQnYJt5A=
|
||||||
|
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||||
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||||
|
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
|
||||||
|
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
|
@ -4,7 +4,7 @@ Copyright IBM Corp. All Rights Reserved.
|
||||||
SPDX-License-Identifier: Apache-2.0
|
SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package chaincode
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
@ -20,7 +20,7 @@ func (s *SmartContract) ReadAsset(ctx contractapi.TransactionContextInterface, a
|
||||||
log.Printf("ReadAsset: collection %v, ID %v", assetCollection, assetID)
|
log.Printf("ReadAsset: collection %v, ID %v", assetCollection, assetID)
|
||||||
assetJSON, err := ctx.GetStub().GetPrivateData(assetCollection, assetID) //get the asset from chaincode state
|
assetJSON, err := ctx.GetStub().GetPrivateData(assetCollection, assetID) //get the asset from chaincode state
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read from asset %v", err)
|
return nil, fmt.Errorf("failed to read asset: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//No Asset found, return empty response
|
//No Asset found, return empty response
|
||||||
|
|
@ -44,7 +44,7 @@ func (s *SmartContract) ReadAssetPrivateDetails(ctx contractapi.TransactionConte
|
||||||
log.Printf("ReadAssetPrivateDetails: collection %v, ID %v", collection, assetID)
|
log.Printf("ReadAssetPrivateDetails: collection %v, ID %v", collection, assetID)
|
||||||
assetDetailsJSON, err := ctx.GetStub().GetPrivateData(collection, assetID) // Get the asset from chaincode state
|
assetDetailsJSON, err := ctx.GetStub().GetPrivateData(collection, assetID) // Get the asset from chaincode state
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read from asset details %v", err)
|
return nil, fmt.Errorf("failed to read asset details: %v", err)
|
||||||
}
|
}
|
||||||
if assetDetailsJSON == nil {
|
if assetDetailsJSON == nil {
|
||||||
log.Printf("AssetPrivateDetails for %v does not exist in collection %v", assetID, collection)
|
log.Printf("AssetPrivateDetails for %v does not exist in collection %v", assetID, collection)
|
||||||
|
|
@ -147,7 +147,6 @@ func (s *SmartContract) QueryAssetByOwner(ctx contractapi.TransactionContextInte
|
||||||
return queryResults, nil
|
return queryResults, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// QueryAssets uses a query string to perform a query for assets.
|
// QueryAssets uses a query string to perform a query for assets.
|
||||||
// Query string matching state database syntax is passed in and executed as is.
|
// Query string matching state database syntax is passed in and executed as is.
|
||||||
// Supports ad hoc queries that can be defined at runtime by the client.
|
// Supports ad hoc queries that can be defined at runtime by the client.
|
||||||
|
|
@ -4,7 +4,7 @@ Copyright IBM Corp. All Rights Reserved.
|
||||||
SPDX-License-Identifier: Apache-2.0
|
SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package chaincode
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
@ -19,6 +19,11 @@ import (
|
||||||
const assetCollection = "assetCollection"
|
const assetCollection = "assetCollection"
|
||||||
const transferAgreementObjectType = "transferAgreement"
|
const transferAgreementObjectType = "transferAgreement"
|
||||||
|
|
||||||
|
// SmartContract of this fabric sample
|
||||||
|
type SmartContract struct {
|
||||||
|
contractapi.Contract
|
||||||
|
}
|
||||||
|
|
||||||
// Asset describes main asset details that are visible to all organizations
|
// Asset describes main asset details that are visible to all organizations
|
||||||
type Asset struct {
|
type Asset struct {
|
||||||
Type string `json:"objectType"` //Type is used to distinguish the various types of objects in state database
|
Type string `json:"objectType"` //Type is used to distinguish the various types of objects in state database
|
||||||
|
|
@ -40,11 +45,6 @@ type TransferAgreement struct {
|
||||||
BuyerID string `json:"buyerID"`
|
BuyerID string `json:"buyerID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SmartContract of this fabric sample
|
|
||||||
type SmartContract struct {
|
|
||||||
contractapi.Contract
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateAsset creates a new asset by placing the main asset details in the assetCollection
|
// CreateAsset creates a new asset by placing the main asset details in the assetCollection
|
||||||
// that can be read by both organizations. The appraisal value is stored in the owners org specific collection.
|
// that can be read by both organizations. The appraisal value is stored in the owners org specific collection.
|
||||||
func (s *SmartContract) CreateAsset(ctx contractapi.TransactionContextInterface) error {
|
func (s *SmartContract) CreateAsset(ctx contractapi.TransactionContextInterface) error {
|
||||||
|
|
@ -273,9 +273,11 @@ func (s *SmartContract) TransferAsset(ctx contractapi.TransactionContextInterfac
|
||||||
// Read asset from the private data collection
|
// Read asset from the private data collection
|
||||||
asset, err := s.ReadAsset(ctx, assetTransferInput.ID)
|
asset, err := s.ReadAsset(ctx, assetTransferInput.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get asset: %v", err)
|
return fmt.Errorf("error reading asset: %v", err)
|
||||||
|
}
|
||||||
|
if asset == nil {
|
||||||
|
return fmt.Errorf("%v does not exist", assetTransferInput.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that the client is submitting request to peer in their organization
|
// Verify that the client is submitting request to peer in their organization
|
||||||
err = verifyClientOrgMatchesPeerOrg(ctx)
|
err = verifyClientOrgMatchesPeerOrg(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -561,17 +563,3 @@ func verifyClientOrgMatchesPeerOrg(ctx contractapi.TransactionContextInterface)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
|
||||||
|
|
||||||
chaincode, err := contractapi.NewChaincode(new(SmartContract))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Panicf("error creating the chaincode: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := chaincode.Start(); err != nil {
|
|
||||||
log.Panicf("error starting the chaincode: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,493 @@
|
||||||
|
package chaincode_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hyperledger/fabric-chaincode-go/pkg/cid"
|
||||||
|
"github.com/hyperledger/fabric-chaincode-go/shim"
|
||||||
|
"github.com/hyperledger/fabric-contract-api-go/contractapi"
|
||||||
|
|
||||||
|
"github.com/hyperledger/fabric-samples/asset-transfer-private-data/chaincode-go/chaincode"
|
||||||
|
"github.com/hyperledger/fabric-samples/asset-transfer-private-data/chaincode-go/chaincode/mocks"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
These unit tests use mocks to simulate chaincode-api & fabric interactions
|
||||||
|
The mocks are generated using counterfeiter directives in the comments (starting with "go:generate counterfeiter")
|
||||||
|
All files in mocks/* are generated by running following, in the directory with your directive:
|
||||||
|
`go generate`
|
||||||
|
*/
|
||||||
|
|
||||||
|
//go:generate counterfeiter -o mocks/transaction.go -fake-name TransactionContext . transactionContext
|
||||||
|
type transactionContext interface {
|
||||||
|
contractapi.TransactionContextInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
//go:generate counterfeiter -o mocks/chaincodestub.go -fake-name ChaincodeStub . chaincodeStub
|
||||||
|
type chaincodeStub interface {
|
||||||
|
shim.ChaincodeStubInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
//go:generate counterfeiter -o mocks/statequeryiterator.go -fake-name StateQueryIterator . stateQueryIterator
|
||||||
|
type stateQueryIterator interface {
|
||||||
|
shim.StateQueryIteratorInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
//go:generate counterfeiter -o mocks/clientIdentity.go -fake-name ClientIdentity . clientIdentity
|
||||||
|
type clientIdentity interface {
|
||||||
|
cid.ClientIdentity
|
||||||
|
}
|
||||||
|
|
||||||
|
const assetCollectionName = "assetCollection"
|
||||||
|
const transferAgreementObjectType = "transferAgreement"
|
||||||
|
const myOrg1Msp = "Org1Testmsp"
|
||||||
|
const myOrg1Clientid = "myOrg1Userid"
|
||||||
|
const myOrg1PrivCollection = "Org1TestmspPrivateCollection"
|
||||||
|
const myOrg2Msp = "Org2Testmsp"
|
||||||
|
const myOrg2Clientid = "myOrg2Userid"
|
||||||
|
const myOrg2PrivCollection = "Org2TestmspPrivateCollection"
|
||||||
|
|
||||||
|
type assetTransientInput struct {
|
||||||
|
Type string `json:"objectType"`
|
||||||
|
ID string `json:"assetID"`
|
||||||
|
Color string `json:"color"`
|
||||||
|
Size int `json:"size"`
|
||||||
|
AppraisedValue int `json:"appraisedValue"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type assetTransferTransientInput struct {
|
||||||
|
ID string `json:"assetID"`
|
||||||
|
BuyerMSP string `json:"buyerMSP"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCreateAssetBadInput(t *testing.T) {
|
||||||
|
transactionContext, chaincodeStub := prepMocksAsOrg1()
|
||||||
|
assetTransferCC := chaincode.SmartContract{}
|
||||||
|
|
||||||
|
// No transient map
|
||||||
|
err := assetTransferCC.CreateAsset(transactionContext)
|
||||||
|
require.EqualError(t, err, "asset not found in the transient map input")
|
||||||
|
|
||||||
|
// transient map with incomplete asset data
|
||||||
|
assetPropMap := map[string][]byte{
|
||||||
|
"asset_properties": []byte("ill formatted property"),
|
||||||
|
}
|
||||||
|
chaincodeStub.GetTransientReturns(assetPropMap, nil)
|
||||||
|
err = assetTransferCC.CreateAsset(transactionContext)
|
||||||
|
require.Error(t, err, "Expected error: transient map with incomplete asset data")
|
||||||
|
require.Contains(t, err.Error(), "failed to unmarshal JSON")
|
||||||
|
|
||||||
|
testAsset := &assetTransientInput{
|
||||||
|
Type: "testfulasset",
|
||||||
|
}
|
||||||
|
setReturnAssetPropsInTransientMap(t, chaincodeStub, testAsset)
|
||||||
|
err = assetTransferCC.CreateAsset(transactionContext)
|
||||||
|
require.EqualError(t, err, "assetID field must be a non-empty string")
|
||||||
|
|
||||||
|
testAsset = &assetTransientInput{
|
||||||
|
ID: "id1",
|
||||||
|
Color: "gray",
|
||||||
|
}
|
||||||
|
setReturnAssetPropsInTransientMap(t, chaincodeStub, testAsset)
|
||||||
|
err = assetTransferCC.CreateAsset(transactionContext)
|
||||||
|
require.EqualError(t, err, "objectType field must be a non-empty string")
|
||||||
|
|
||||||
|
// case when asset exists, GetPrivateData returns a valid data from ledger
|
||||||
|
testAsset = &assetTransientInput{
|
||||||
|
ID: "id1",
|
||||||
|
Type: "testfulasset",
|
||||||
|
Color: "gray",
|
||||||
|
Size: 7,
|
||||||
|
AppraisedValue: 500,
|
||||||
|
}
|
||||||
|
setReturnAssetPropsInTransientMap(t, chaincodeStub, testAsset)
|
||||||
|
chaincodeStub.GetPrivateDataReturns([]byte{}, nil)
|
||||||
|
err = assetTransferCC.CreateAsset(transactionContext)
|
||||||
|
require.EqualError(t, err, "this asset already exists: id1")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCreateAssetSuccessful(t *testing.T) {
|
||||||
|
transactionContext, chaincodeStub := prepMocksAsOrg1()
|
||||||
|
assetTransferCC := chaincode.SmartContract{}
|
||||||
|
testAsset := &assetTransientInput{
|
||||||
|
ID: "id1",
|
||||||
|
Type: "testfulasset",
|
||||||
|
Color: "gray",
|
||||||
|
Size: 7,
|
||||||
|
AppraisedValue: 500,
|
||||||
|
}
|
||||||
|
setReturnAssetPropsInTransientMap(t, chaincodeStub, testAsset)
|
||||||
|
err := assetTransferCC.CreateAsset(transactionContext)
|
||||||
|
require.NoError(t, err)
|
||||||
|
//Validate PutPrivateData calls
|
||||||
|
calledCollection, calledId, _ := chaincodeStub.PutPrivateDataArgsForCall(0)
|
||||||
|
require.Equal(t, assetCollectionName, calledCollection)
|
||||||
|
require.Equal(t, "id1", calledId)
|
||||||
|
|
||||||
|
expectedPrivateDetails := &chaincode.AssetPrivateDetails{
|
||||||
|
ID: "id1",
|
||||||
|
AppraisedValue: 500,
|
||||||
|
}
|
||||||
|
assetBytes, err := json.Marshal(expectedPrivateDetails)
|
||||||
|
calledCollection, calledId, calledAssetBytes := chaincodeStub.PutPrivateDataArgsForCall(1)
|
||||||
|
require.Equal(t, myOrg1PrivCollection, calledCollection)
|
||||||
|
require.Equal(t, "id1", calledId)
|
||||||
|
require.Equal(t, assetBytes, calledAssetBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestReadAsset(t *testing.T) {
|
||||||
|
transactionContext, chaincodeStub := prepMocksAsOrg1()
|
||||||
|
assetTransferCC := chaincode.SmartContract{}
|
||||||
|
|
||||||
|
assetBytes, err := assetTransferCC.ReadAsset(transactionContext, "id1")
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Nil(t, assetBytes)
|
||||||
|
|
||||||
|
chaincodeStub.GetPrivateDataReturns(nil, fmt.Errorf("unable to retrieve asset"))
|
||||||
|
assetBytes, err = assetTransferCC.ReadAsset(transactionContext, "id1")
|
||||||
|
require.EqualError(t, err, "failed to read asset: unable to retrieve asset")
|
||||||
|
|
||||||
|
testAsset := &chaincode.Asset{
|
||||||
|
ID: "id1",
|
||||||
|
Type: "testfulasset",
|
||||||
|
Color: "gray",
|
||||||
|
Size: 7,
|
||||||
|
Owner: myOrg1Clientid,
|
||||||
|
}
|
||||||
|
setReturnPrivateDataInStub(t, chaincodeStub, testAsset)
|
||||||
|
assetRead, err := assetTransferCC.ReadAsset(transactionContext, "id1")
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, testAsset, assetRead)
|
||||||
|
}
|
||||||
|
|
||||||
|
//todo
|
||||||
|
// ReadAssetPrivateDetails
|
||||||
|
// AgreeToTransfer
|
||||||
|
|
||||||
|
func TestTransferAsset(t *testing.T) {
|
||||||
|
transactionContext, chaincodeStub := prepMocksAsOrg1()
|
||||||
|
assetTransferCC := chaincode.SmartContract{}
|
||||||
|
assetNewOwner := &assetTransferTransientInput{
|
||||||
|
ID: "id1",
|
||||||
|
BuyerMSP: myOrg2Msp,
|
||||||
|
}
|
||||||
|
setReturnAssetOwnerInTransientMap(t, chaincodeStub, assetNewOwner)
|
||||||
|
origAsset := chaincode.Asset{
|
||||||
|
ID: "id1",
|
||||||
|
Type: "testfulasset",
|
||||||
|
Color: "gray",
|
||||||
|
Size: 7,
|
||||||
|
Owner: myOrg1Clientid,
|
||||||
|
}
|
||||||
|
setReturnPrivateDataInStub(t, chaincodeStub, &origAsset)
|
||||||
|
//to ensure we pass data hash verification
|
||||||
|
chaincodeStub.GetPrivateDataHashReturns([]byte("datahash"), nil)
|
||||||
|
//to ensure that ReadTransferAgreement call returns org2 client ID
|
||||||
|
chaincodeStub.GetPrivateDataReturnsOnCall(1, []byte(myOrg2Clientid), nil)
|
||||||
|
chaincodeStub.CreateCompositeKeyReturns(transferAgreementObjectType+"id1", nil)
|
||||||
|
|
||||||
|
err := assetTransferCC.TransferAsset(transactionContext)
|
||||||
|
require.NoError(t, err)
|
||||||
|
//Validate PutPrivateData calls
|
||||||
|
expectedNewAsset := origAsset
|
||||||
|
expectedNewAsset.Owner = myOrg2Clientid
|
||||||
|
expectedNewAssetBytes, err := json.Marshal(expectedNewAsset)
|
||||||
|
require.NoError(t, err)
|
||||||
|
calledCollection, calledId, calledWithAssetBytes := chaincodeStub.PutPrivateDataArgsForCall(0)
|
||||||
|
require.Equal(t, assetCollectionName, calledCollection)
|
||||||
|
require.Equal(t, "id1", calledId)
|
||||||
|
require.Equal(t, expectedNewAssetBytes, calledWithAssetBytes)
|
||||||
|
calledCollection, calledId = chaincodeStub.DelPrivateDataArgsForCall(0)
|
||||||
|
require.Equal(t, myOrg1PrivCollection, calledCollection)
|
||||||
|
require.Equal(t, "id1", calledId)
|
||||||
|
|
||||||
|
calledCollection, calledId = chaincodeStub.DelPrivateDataArgsForCall(1)
|
||||||
|
require.Equal(t, assetCollectionName, calledCollection)
|
||||||
|
require.Equal(t, transferAgreementObjectType+"id1", calledId)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTransferAssetByNonOwner(t *testing.T) {
|
||||||
|
transactionContext, chaincodeStub := prepMocksAsOrg1()
|
||||||
|
assetTransferCC := chaincode.SmartContract{}
|
||||||
|
assetNewOwner := &assetTransferTransientInput{
|
||||||
|
ID: "id1",
|
||||||
|
BuyerMSP: myOrg1Msp,
|
||||||
|
}
|
||||||
|
setReturnAssetOwnerInTransientMap(t, chaincodeStub, assetNewOwner)
|
||||||
|
//Try to transfer asset owned by Org2
|
||||||
|
org2Asset := chaincode.Asset{
|
||||||
|
ID: "id1",
|
||||||
|
Type: "testfulasset",
|
||||||
|
Color: "gray",
|
||||||
|
Size: 7,
|
||||||
|
Owner: myOrg2Clientid,
|
||||||
|
}
|
||||||
|
setReturnPrivateDataInStub(t, chaincodeStub, &org2Asset)
|
||||||
|
err := assetTransferCC.TransferAsset(transactionContext)
|
||||||
|
require.EqualError(t, err, "failed transfer verification: error: submitting client identity does not own asset")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTransferAssetWithoutAnAgreement(t *testing.T) {
|
||||||
|
transactionContext, chaincodeStub := prepMocksAsOrg1()
|
||||||
|
assetTransferCC := chaincode.SmartContract{}
|
||||||
|
assetNewOwner := &assetTransferTransientInput{
|
||||||
|
ID: "id1",
|
||||||
|
BuyerMSP: myOrg1Msp,
|
||||||
|
}
|
||||||
|
setReturnAssetOwnerInTransientMap(t, chaincodeStub, assetNewOwner)
|
||||||
|
orgAsset := chaincode.Asset{
|
||||||
|
ID: "id1",
|
||||||
|
Type: "testfulasset",
|
||||||
|
Color: "gray",
|
||||||
|
Size: 7,
|
||||||
|
Owner: myOrg1Clientid,
|
||||||
|
}
|
||||||
|
setReturnPrivateDataInStub(t, chaincodeStub, &orgAsset)
|
||||||
|
//to ensure we pass data hash verification
|
||||||
|
chaincodeStub.GetPrivateDataHashReturns([]byte("datahash"), nil)
|
||||||
|
chaincodeStub.CreateCompositeKeyReturns(transferAgreementObjectType+"id1", nil)
|
||||||
|
//ReadTransferAgreement call returns no buyer client ID
|
||||||
|
chaincodeStub.GetPrivateDataReturnsOnCall(1, []byte{}, nil)
|
||||||
|
|
||||||
|
err := assetTransferCC.TransferAsset(transactionContext)
|
||||||
|
require.EqualError(t, err, "BuyerID not found in TransferAgreement for id1")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTransferAssetBadInput(t *testing.T) {
|
||||||
|
transactionContext, chaincodeStub := prepMocksAsOrg1()
|
||||||
|
assetTransferCC := chaincode.SmartContract{}
|
||||||
|
|
||||||
|
assetNewOwner := &assetTransferTransientInput{
|
||||||
|
ID: "id1",
|
||||||
|
BuyerMSP: "",
|
||||||
|
}
|
||||||
|
setReturnAssetOwnerInTransientMap(t, chaincodeStub, assetNewOwner)
|
||||||
|
setReturnPrivateDataInStub(t, chaincodeStub, &chaincode.Asset{})
|
||||||
|
err := assetTransferCC.TransferAsset(transactionContext)
|
||||||
|
require.EqualError(t, err, "buyerMSP field must be a non-empty string")
|
||||||
|
|
||||||
|
assetNewOwner = &assetTransferTransientInput{
|
||||||
|
ID: "id1",
|
||||||
|
BuyerMSP: myOrg2Msp,
|
||||||
|
}
|
||||||
|
setReturnAssetOwnerInTransientMap(t, chaincodeStub, assetNewOwner)
|
||||||
|
//asset does not exist
|
||||||
|
setReturnPrivateDataInStub(t, chaincodeStub, nil)
|
||||||
|
err = assetTransferCC.TransferAsset(transactionContext)
|
||||||
|
require.EqualError(t, err, "id1 does not exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTransferAssetNonMatchingAppraisalValue(t *testing.T) {
|
||||||
|
transactionContext, chaincodeStub := prepMocksAsOrg1()
|
||||||
|
assetTransferCC := chaincode.SmartContract{}
|
||||||
|
assetNewOwner := &assetTransferTransientInput{
|
||||||
|
ID: "id1",
|
||||||
|
BuyerMSP: myOrg2Msp,
|
||||||
|
}
|
||||||
|
setReturnAssetOwnerInTransientMap(t, chaincodeStub, assetNewOwner)
|
||||||
|
|
||||||
|
orgAsset := chaincode.Asset{
|
||||||
|
ID: "id1",
|
||||||
|
Type: "testfulasset",
|
||||||
|
Color: "gray",
|
||||||
|
Size: 7,
|
||||||
|
Owner: myOrg1Clientid,
|
||||||
|
}
|
||||||
|
setReturnPrivateDataInStub(t, chaincodeStub, &orgAsset)
|
||||||
|
chaincodeStub.CreateCompositeKeyReturns(transferAgreementObjectType+"id1", nil)
|
||||||
|
//data hash different in each collection
|
||||||
|
chaincodeStub.GetPrivateDataHashReturnsOnCall(0, []byte("datahash1"), nil)
|
||||||
|
chaincodeStub.GetPrivateDataHashReturnsOnCall(1, []byte("datahash2"), nil)
|
||||||
|
|
||||||
|
err := assetTransferCC.TransferAsset(transactionContext)
|
||||||
|
require.Error(t, err, "Expected failed hash verification")
|
||||||
|
require.Contains(t, err.Error(), "failed transfer verification: hash for appraised value")
|
||||||
|
}
|
||||||
|
|
||||||
|
func prepMocksAsOrg1() (*mocks.TransactionContext, *mocks.ChaincodeStub) {
|
||||||
|
return prepMocks(myOrg1Msp, myOrg1Clientid)
|
||||||
|
}
|
||||||
|
func prepMocksAsOrg2() (*mocks.TransactionContext, *mocks.ChaincodeStub) {
|
||||||
|
return prepMocks(myOrg2Msp, myOrg2Clientid)
|
||||||
|
}
|
||||||
|
func prepMocks(orgMSP, clientId string) (*mocks.TransactionContext, *mocks.ChaincodeStub) {
|
||||||
|
chaincodeStub := &mocks.ChaincodeStub{}
|
||||||
|
transactionContext := &mocks.TransactionContext{}
|
||||||
|
transactionContext.GetStubReturns(chaincodeStub)
|
||||||
|
|
||||||
|
clientIdentity := &mocks.ClientIdentity{}
|
||||||
|
clientIdentity.GetMSPIDReturns(orgMSP, nil)
|
||||||
|
clientIdentity.GetIDReturns(clientId, nil)
|
||||||
|
//set matching msp ID using peer shim env variable
|
||||||
|
os.Setenv("CORE_PEER_LOCALMSPID", orgMSP)
|
||||||
|
transactionContext.GetClientIdentityReturns(clientIdentity)
|
||||||
|
return transactionContext, chaincodeStub
|
||||||
|
}
|
||||||
|
|
||||||
|
func setReturnAssetOwnerInTransientMap(t *testing.T, chaincodeStub *mocks.ChaincodeStub, assetOwner *assetTransferTransientInput) []byte {
|
||||||
|
assetOwnerBytes := []byte{}
|
||||||
|
if assetOwner != nil {
|
||||||
|
var err error
|
||||||
|
assetOwnerBytes, err = json.Marshal(assetOwner)
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
assetPropMap := map[string][]byte{
|
||||||
|
"asset_owner": assetOwnerBytes,
|
||||||
|
}
|
||||||
|
chaincodeStub.GetTransientReturns(assetPropMap, nil)
|
||||||
|
return assetOwnerBytes
|
||||||
|
}
|
||||||
|
|
||||||
|
func setReturnAssetPropsInTransientMap(t *testing.T, chaincodeStub *mocks.ChaincodeStub, testAsset *assetTransientInput) []byte {
|
||||||
|
assetBytes := []byte{}
|
||||||
|
if testAsset != nil {
|
||||||
|
var err error
|
||||||
|
assetBytes, err = json.Marshal(testAsset)
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
assetPropMap := map[string][]byte{
|
||||||
|
"asset_properties": assetBytes,
|
||||||
|
}
|
||||||
|
chaincodeStub.GetTransientReturns(assetPropMap, nil)
|
||||||
|
return assetBytes
|
||||||
|
}
|
||||||
|
|
||||||
|
func setReturnPrivateDataInStub(t *testing.T, chaincodeStub *mocks.ChaincodeStub, testAsset *chaincode.Asset) []byte {
|
||||||
|
assetBytes := []byte{}
|
||||||
|
if testAsset != nil {
|
||||||
|
var err error
|
||||||
|
assetBytes, err = json.Marshal(testAsset)
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
chaincodeStub.GetPrivateDataReturns(assetBytes, nil)
|
||||||
|
return assetBytes
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
func TestReadAsset(t *testing.T) {
|
||||||
|
chaincodeStub := &mocks.ChaincodeStub{}
|
||||||
|
transactionContext := &mocks.TransactionContext{}
|
||||||
|
transactionContext.GetStubReturns(chaincodeStub)
|
||||||
|
|
||||||
|
expectedAsset := &chaincode.Asset{ID: "asset1"}
|
||||||
|
bytes, err := json.Marshal(expectedAsset)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
chaincodeStub.GetStateReturns(bytes, nil)
|
||||||
|
assetTransferCC := chaincode.SmartContract{}
|
||||||
|
asset, err := assetTransferCC.ReadAsset(transactionContext, "")
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, expectedAsset, asset)
|
||||||
|
|
||||||
|
chaincodeStub.GetStateReturns(nil, fmt.Errorf("unable to retrieve asset"))
|
||||||
|
_, err = assetTransferCC.ReadAsset(transactionContext, "")
|
||||||
|
require.EqualError(t, err, "failed to read from world state: unable to retrieve asset")
|
||||||
|
|
||||||
|
chaincodeStub.GetStateReturns(nil, nil)
|
||||||
|
asset, err = assetTransferCC.ReadAsset(transactionContext, "asset1")
|
||||||
|
require.EqualError(t, err, "the asset asset1 does not exist")
|
||||||
|
require.Nil(t, asset)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUpdateAsset(t *testing.T) {
|
||||||
|
chaincodeStub := &mocks.ChaincodeStub{}
|
||||||
|
transactionContext := &mocks.TransactionContext{}
|
||||||
|
transactionContext.GetStubReturns(chaincodeStub)
|
||||||
|
|
||||||
|
expectedAsset := &chaincode.Asset{ID: "asset1"}
|
||||||
|
bytes, err := json.Marshal(expectedAsset)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
chaincodeStub.GetStateReturns(bytes, nil)
|
||||||
|
assetTransferCC := chaincode.SmartContract{}
|
||||||
|
err = assetTransferCC.UpdateAsset(transactionContext, "", "", 0, "", 0)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
chaincodeStub.GetStateReturns(nil, nil)
|
||||||
|
err = assetTransferCC.UpdateAsset(transactionContext, "asset1", "", 0, "", 0)
|
||||||
|
require.EqualError(t, err, "the asset asset1 does not exist")
|
||||||
|
|
||||||
|
chaincodeStub.GetStateReturns(nil, fmt.Errorf("unable to retrieve asset"))
|
||||||
|
err = assetTransferCC.UpdateAsset(transactionContext, "asset1", "", 0, "", 0)
|
||||||
|
require.EqualError(t, err, "failed to read from world state: unable to retrieve asset")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDeleteAsset(t *testing.T) {
|
||||||
|
chaincodeStub := &mocks.ChaincodeStub{}
|
||||||
|
transactionContext := &mocks.TransactionContext{}
|
||||||
|
transactionContext.GetStubReturns(chaincodeStub)
|
||||||
|
|
||||||
|
asset := &chaincode.Asset{ID: "asset1"}
|
||||||
|
bytes, err := json.Marshal(asset)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
chaincodeStub.GetStateReturns(bytes, nil)
|
||||||
|
chaincodeStub.DelStateReturns(nil)
|
||||||
|
assetTransferCC := chaincode.SmartContract{}
|
||||||
|
err = assetTransferCC.DeleteAsset(transactionContext, "")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
chaincodeStub.GetStateReturns(nil, nil)
|
||||||
|
err = assetTransferCC.DeleteAsset(transactionContext, "asset1")
|
||||||
|
require.EqualError(t, err, "the asset asset1 does not exist")
|
||||||
|
|
||||||
|
chaincodeStub.GetStateReturns(nil, fmt.Errorf("unable to retrieve asset"))
|
||||||
|
err = assetTransferCC.DeleteAsset(transactionContext, "")
|
||||||
|
require.EqualError(t, err, "failed to read from world state: unable to retrieve asset")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTransferAsset(t *testing.T) {
|
||||||
|
chaincodeStub := &mocks.ChaincodeStub{}
|
||||||
|
transactionContext := &mocks.TransactionContext{}
|
||||||
|
transactionContext.GetStubReturns(chaincodeStub)
|
||||||
|
|
||||||
|
asset := &chaincode.Asset{ID: "asset1"}
|
||||||
|
bytes, err := json.Marshal(asset)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
chaincodeStub.GetStateReturns(bytes, nil)
|
||||||
|
assetTransferCC := chaincode.SmartContract{}
|
||||||
|
err = assetTransferCC.TransferAsset(transactionContext, "", "")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
chaincodeStub.GetStateReturns(nil, fmt.Errorf("unable to retrieve asset"))
|
||||||
|
err = assetTransferCC.TransferAsset(transactionContext, "", "")
|
||||||
|
require.EqualError(t, err, "failed to read from world state: unable to retrieve asset")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetAllAssets(t *testing.T) {
|
||||||
|
asset := &chaincode.Asset{ID: "asset1"}
|
||||||
|
bytes, err := json.Marshal(asset)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
iterator := &mocks.StateQueryIterator{}
|
||||||
|
iterator.HasNextReturnsOnCall(0, true)
|
||||||
|
iterator.HasNextReturnsOnCall(1, false)
|
||||||
|
iterator.NextReturns(&queryresult.KV{Value: bytes}, nil)
|
||||||
|
|
||||||
|
chaincodeStub := &mocks.ChaincodeStub{}
|
||||||
|
transactionContext := &mocks.TransactionContext{}
|
||||||
|
transactionContext.GetStubReturns(chaincodeStub)
|
||||||
|
|
||||||
|
chaincodeStub.GetStateByRangeReturns(iterator, nil)
|
||||||
|
assetTransferCC := &chaincode.SmartContract{}
|
||||||
|
assets, err := assetTransferCC.GetAllAssets(transactionContext)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, []*chaincode.Asset{asset}, assets)
|
||||||
|
|
||||||
|
iterator.HasNextReturns(true)
|
||||||
|
iterator.NextReturns(nil, fmt.Errorf("failed retrieving next item"))
|
||||||
|
assets, err = assetTransferCC.GetAllAssets(transactionContext)
|
||||||
|
require.EqualError(t, err, "failed retrieving next item")
|
||||||
|
require.Nil(t, assets)
|
||||||
|
|
||||||
|
chaincodeStub.GetStateByRangeReturns(nil, fmt.Errorf("failed retrieving all assets"))
|
||||||
|
assets, err = assetTransferCC.GetAllAssets(transactionContext)
|
||||||
|
require.EqualError(t, err, "failed retrieving all assets")
|
||||||
|
require.Nil(t, assets)
|
||||||
|
}*/
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,399 @@
|
||||||
|
// Code generated by counterfeiter. DO NOT EDIT.
|
||||||
|
package mocks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/x509"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ClientIdentity struct {
|
||||||
|
AssertAttributeValueStub func(string, string) error
|
||||||
|
assertAttributeValueMutex sync.RWMutex
|
||||||
|
assertAttributeValueArgsForCall []struct {
|
||||||
|
arg1 string
|
||||||
|
arg2 string
|
||||||
|
}
|
||||||
|
assertAttributeValueReturns struct {
|
||||||
|
result1 error
|
||||||
|
}
|
||||||
|
assertAttributeValueReturnsOnCall map[int]struct {
|
||||||
|
result1 error
|
||||||
|
}
|
||||||
|
GetAttributeValueStub func(string) (string, bool, error)
|
||||||
|
getAttributeValueMutex sync.RWMutex
|
||||||
|
getAttributeValueArgsForCall []struct {
|
||||||
|
arg1 string
|
||||||
|
}
|
||||||
|
getAttributeValueReturns struct {
|
||||||
|
result1 string
|
||||||
|
result2 bool
|
||||||
|
result3 error
|
||||||
|
}
|
||||||
|
getAttributeValueReturnsOnCall map[int]struct {
|
||||||
|
result1 string
|
||||||
|
result2 bool
|
||||||
|
result3 error
|
||||||
|
}
|
||||||
|
GetIDStub func() (string, error)
|
||||||
|
getIDMutex sync.RWMutex
|
||||||
|
getIDArgsForCall []struct {
|
||||||
|
}
|
||||||
|
getIDReturns struct {
|
||||||
|
result1 string
|
||||||
|
result2 error
|
||||||
|
}
|
||||||
|
getIDReturnsOnCall map[int]struct {
|
||||||
|
result1 string
|
||||||
|
result2 error
|
||||||
|
}
|
||||||
|
GetMSPIDStub func() (string, error)
|
||||||
|
getMSPIDMutex sync.RWMutex
|
||||||
|
getMSPIDArgsForCall []struct {
|
||||||
|
}
|
||||||
|
getMSPIDReturns struct {
|
||||||
|
result1 string
|
||||||
|
result2 error
|
||||||
|
}
|
||||||
|
getMSPIDReturnsOnCall map[int]struct {
|
||||||
|
result1 string
|
||||||
|
result2 error
|
||||||
|
}
|
||||||
|
GetX509CertificateStub func() (*x509.Certificate, error)
|
||||||
|
getX509CertificateMutex sync.RWMutex
|
||||||
|
getX509CertificateArgsForCall []struct {
|
||||||
|
}
|
||||||
|
getX509CertificateReturns struct {
|
||||||
|
result1 *x509.Certificate
|
||||||
|
result2 error
|
||||||
|
}
|
||||||
|
getX509CertificateReturnsOnCall map[int]struct {
|
||||||
|
result1 *x509.Certificate
|
||||||
|
result2 error
|
||||||
|
}
|
||||||
|
invocations map[string][][]interface{}
|
||||||
|
invocationsMutex sync.RWMutex
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) AssertAttributeValue(arg1 string, arg2 string) error {
|
||||||
|
fake.assertAttributeValueMutex.Lock()
|
||||||
|
ret, specificReturn := fake.assertAttributeValueReturnsOnCall[len(fake.assertAttributeValueArgsForCall)]
|
||||||
|
fake.assertAttributeValueArgsForCall = append(fake.assertAttributeValueArgsForCall, struct {
|
||||||
|
arg1 string
|
||||||
|
arg2 string
|
||||||
|
}{arg1, arg2})
|
||||||
|
fake.recordInvocation("AssertAttributeValue", []interface{}{arg1, arg2})
|
||||||
|
fake.assertAttributeValueMutex.Unlock()
|
||||||
|
if fake.AssertAttributeValueStub != nil {
|
||||||
|
return fake.AssertAttributeValueStub(arg1, arg2)
|
||||||
|
}
|
||||||
|
if specificReturn {
|
||||||
|
return ret.result1
|
||||||
|
}
|
||||||
|
fakeReturns := fake.assertAttributeValueReturns
|
||||||
|
return fakeReturns.result1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) AssertAttributeValueCallCount() int {
|
||||||
|
fake.assertAttributeValueMutex.RLock()
|
||||||
|
defer fake.assertAttributeValueMutex.RUnlock()
|
||||||
|
return len(fake.assertAttributeValueArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) AssertAttributeValueCalls(stub func(string, string) error) {
|
||||||
|
fake.assertAttributeValueMutex.Lock()
|
||||||
|
defer fake.assertAttributeValueMutex.Unlock()
|
||||||
|
fake.AssertAttributeValueStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) AssertAttributeValueArgsForCall(i int) (string, string) {
|
||||||
|
fake.assertAttributeValueMutex.RLock()
|
||||||
|
defer fake.assertAttributeValueMutex.RUnlock()
|
||||||
|
argsForCall := fake.assertAttributeValueArgsForCall[i]
|
||||||
|
return argsForCall.arg1, argsForCall.arg2
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) AssertAttributeValueReturns(result1 error) {
|
||||||
|
fake.assertAttributeValueMutex.Lock()
|
||||||
|
defer fake.assertAttributeValueMutex.Unlock()
|
||||||
|
fake.AssertAttributeValueStub = nil
|
||||||
|
fake.assertAttributeValueReturns = struct {
|
||||||
|
result1 error
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) AssertAttributeValueReturnsOnCall(i int, result1 error) {
|
||||||
|
fake.assertAttributeValueMutex.Lock()
|
||||||
|
defer fake.assertAttributeValueMutex.Unlock()
|
||||||
|
fake.AssertAttributeValueStub = nil
|
||||||
|
if fake.assertAttributeValueReturnsOnCall == nil {
|
||||||
|
fake.assertAttributeValueReturnsOnCall = make(map[int]struct {
|
||||||
|
result1 error
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fake.assertAttributeValueReturnsOnCall[i] = struct {
|
||||||
|
result1 error
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) GetAttributeValue(arg1 string) (string, bool, error) {
|
||||||
|
fake.getAttributeValueMutex.Lock()
|
||||||
|
ret, specificReturn := fake.getAttributeValueReturnsOnCall[len(fake.getAttributeValueArgsForCall)]
|
||||||
|
fake.getAttributeValueArgsForCall = append(fake.getAttributeValueArgsForCall, struct {
|
||||||
|
arg1 string
|
||||||
|
}{arg1})
|
||||||
|
fake.recordInvocation("GetAttributeValue", []interface{}{arg1})
|
||||||
|
fake.getAttributeValueMutex.Unlock()
|
||||||
|
if fake.GetAttributeValueStub != nil {
|
||||||
|
return fake.GetAttributeValueStub(arg1)
|
||||||
|
}
|
||||||
|
if specificReturn {
|
||||||
|
return ret.result1, ret.result2, ret.result3
|
||||||
|
}
|
||||||
|
fakeReturns := fake.getAttributeValueReturns
|
||||||
|
return fakeReturns.result1, fakeReturns.result2, fakeReturns.result3
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) GetAttributeValueCallCount() int {
|
||||||
|
fake.getAttributeValueMutex.RLock()
|
||||||
|
defer fake.getAttributeValueMutex.RUnlock()
|
||||||
|
return len(fake.getAttributeValueArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) GetAttributeValueCalls(stub func(string) (string, bool, error)) {
|
||||||
|
fake.getAttributeValueMutex.Lock()
|
||||||
|
defer fake.getAttributeValueMutex.Unlock()
|
||||||
|
fake.GetAttributeValueStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) GetAttributeValueArgsForCall(i int) string {
|
||||||
|
fake.getAttributeValueMutex.RLock()
|
||||||
|
defer fake.getAttributeValueMutex.RUnlock()
|
||||||
|
argsForCall := fake.getAttributeValueArgsForCall[i]
|
||||||
|
return argsForCall.arg1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) GetAttributeValueReturns(result1 string, result2 bool, result3 error) {
|
||||||
|
fake.getAttributeValueMutex.Lock()
|
||||||
|
defer fake.getAttributeValueMutex.Unlock()
|
||||||
|
fake.GetAttributeValueStub = nil
|
||||||
|
fake.getAttributeValueReturns = struct {
|
||||||
|
result1 string
|
||||||
|
result2 bool
|
||||||
|
result3 error
|
||||||
|
}{result1, result2, result3}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) GetAttributeValueReturnsOnCall(i int, result1 string, result2 bool, result3 error) {
|
||||||
|
fake.getAttributeValueMutex.Lock()
|
||||||
|
defer fake.getAttributeValueMutex.Unlock()
|
||||||
|
fake.GetAttributeValueStub = nil
|
||||||
|
if fake.getAttributeValueReturnsOnCall == nil {
|
||||||
|
fake.getAttributeValueReturnsOnCall = make(map[int]struct {
|
||||||
|
result1 string
|
||||||
|
result2 bool
|
||||||
|
result3 error
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fake.getAttributeValueReturnsOnCall[i] = struct {
|
||||||
|
result1 string
|
||||||
|
result2 bool
|
||||||
|
result3 error
|
||||||
|
}{result1, result2, result3}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) GetID() (string, error) {
|
||||||
|
fake.getIDMutex.Lock()
|
||||||
|
ret, specificReturn := fake.getIDReturnsOnCall[len(fake.getIDArgsForCall)]
|
||||||
|
fake.getIDArgsForCall = append(fake.getIDArgsForCall, struct {
|
||||||
|
}{})
|
||||||
|
fake.recordInvocation("GetID", []interface{}{})
|
||||||
|
fake.getIDMutex.Unlock()
|
||||||
|
if fake.GetIDStub != nil {
|
||||||
|
return fake.GetIDStub()
|
||||||
|
}
|
||||||
|
if specificReturn {
|
||||||
|
return ret.result1, ret.result2
|
||||||
|
}
|
||||||
|
fakeReturns := fake.getIDReturns
|
||||||
|
return fakeReturns.result1, fakeReturns.result2
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) GetIDCallCount() int {
|
||||||
|
fake.getIDMutex.RLock()
|
||||||
|
defer fake.getIDMutex.RUnlock()
|
||||||
|
return len(fake.getIDArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) GetIDCalls(stub func() (string, error)) {
|
||||||
|
fake.getIDMutex.Lock()
|
||||||
|
defer fake.getIDMutex.Unlock()
|
||||||
|
fake.GetIDStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) GetIDReturns(result1 string, result2 error) {
|
||||||
|
fake.getIDMutex.Lock()
|
||||||
|
defer fake.getIDMutex.Unlock()
|
||||||
|
fake.GetIDStub = nil
|
||||||
|
fake.getIDReturns = struct {
|
||||||
|
result1 string
|
||||||
|
result2 error
|
||||||
|
}{result1, result2}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) GetIDReturnsOnCall(i int, result1 string, result2 error) {
|
||||||
|
fake.getIDMutex.Lock()
|
||||||
|
defer fake.getIDMutex.Unlock()
|
||||||
|
fake.GetIDStub = nil
|
||||||
|
if fake.getIDReturnsOnCall == nil {
|
||||||
|
fake.getIDReturnsOnCall = make(map[int]struct {
|
||||||
|
result1 string
|
||||||
|
result2 error
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fake.getIDReturnsOnCall[i] = struct {
|
||||||
|
result1 string
|
||||||
|
result2 error
|
||||||
|
}{result1, result2}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) GetMSPID() (string, error) {
|
||||||
|
fake.getMSPIDMutex.Lock()
|
||||||
|
ret, specificReturn := fake.getMSPIDReturnsOnCall[len(fake.getMSPIDArgsForCall)]
|
||||||
|
fake.getMSPIDArgsForCall = append(fake.getMSPIDArgsForCall, struct {
|
||||||
|
}{})
|
||||||
|
fake.recordInvocation("GetMSPID", []interface{}{})
|
||||||
|
fake.getMSPIDMutex.Unlock()
|
||||||
|
if fake.GetMSPIDStub != nil {
|
||||||
|
return fake.GetMSPIDStub()
|
||||||
|
}
|
||||||
|
if specificReturn {
|
||||||
|
return ret.result1, ret.result2
|
||||||
|
}
|
||||||
|
fakeReturns := fake.getMSPIDReturns
|
||||||
|
return fakeReturns.result1, fakeReturns.result2
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) GetMSPIDCallCount() int {
|
||||||
|
fake.getMSPIDMutex.RLock()
|
||||||
|
defer fake.getMSPIDMutex.RUnlock()
|
||||||
|
return len(fake.getMSPIDArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) GetMSPIDCalls(stub func() (string, error)) {
|
||||||
|
fake.getMSPIDMutex.Lock()
|
||||||
|
defer fake.getMSPIDMutex.Unlock()
|
||||||
|
fake.GetMSPIDStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) GetMSPIDReturns(result1 string, result2 error) {
|
||||||
|
fake.getMSPIDMutex.Lock()
|
||||||
|
defer fake.getMSPIDMutex.Unlock()
|
||||||
|
fake.GetMSPIDStub = nil
|
||||||
|
fake.getMSPIDReturns = struct {
|
||||||
|
result1 string
|
||||||
|
result2 error
|
||||||
|
}{result1, result2}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) GetMSPIDReturnsOnCall(i int, result1 string, result2 error) {
|
||||||
|
fake.getMSPIDMutex.Lock()
|
||||||
|
defer fake.getMSPIDMutex.Unlock()
|
||||||
|
fake.GetMSPIDStub = nil
|
||||||
|
if fake.getMSPIDReturnsOnCall == nil {
|
||||||
|
fake.getMSPIDReturnsOnCall = make(map[int]struct {
|
||||||
|
result1 string
|
||||||
|
result2 error
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fake.getMSPIDReturnsOnCall[i] = struct {
|
||||||
|
result1 string
|
||||||
|
result2 error
|
||||||
|
}{result1, result2}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) GetX509Certificate() (*x509.Certificate, error) {
|
||||||
|
fake.getX509CertificateMutex.Lock()
|
||||||
|
ret, specificReturn := fake.getX509CertificateReturnsOnCall[len(fake.getX509CertificateArgsForCall)]
|
||||||
|
fake.getX509CertificateArgsForCall = append(fake.getX509CertificateArgsForCall, struct {
|
||||||
|
}{})
|
||||||
|
fake.recordInvocation("GetX509Certificate", []interface{}{})
|
||||||
|
fake.getX509CertificateMutex.Unlock()
|
||||||
|
if fake.GetX509CertificateStub != nil {
|
||||||
|
return fake.GetX509CertificateStub()
|
||||||
|
}
|
||||||
|
if specificReturn {
|
||||||
|
return ret.result1, ret.result2
|
||||||
|
}
|
||||||
|
fakeReturns := fake.getX509CertificateReturns
|
||||||
|
return fakeReturns.result1, fakeReturns.result2
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) GetX509CertificateCallCount() int {
|
||||||
|
fake.getX509CertificateMutex.RLock()
|
||||||
|
defer fake.getX509CertificateMutex.RUnlock()
|
||||||
|
return len(fake.getX509CertificateArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) GetX509CertificateCalls(stub func() (*x509.Certificate, error)) {
|
||||||
|
fake.getX509CertificateMutex.Lock()
|
||||||
|
defer fake.getX509CertificateMutex.Unlock()
|
||||||
|
fake.GetX509CertificateStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) GetX509CertificateReturns(result1 *x509.Certificate, result2 error) {
|
||||||
|
fake.getX509CertificateMutex.Lock()
|
||||||
|
defer fake.getX509CertificateMutex.Unlock()
|
||||||
|
fake.GetX509CertificateStub = nil
|
||||||
|
fake.getX509CertificateReturns = struct {
|
||||||
|
result1 *x509.Certificate
|
||||||
|
result2 error
|
||||||
|
}{result1, result2}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) GetX509CertificateReturnsOnCall(i int, result1 *x509.Certificate, result2 error) {
|
||||||
|
fake.getX509CertificateMutex.Lock()
|
||||||
|
defer fake.getX509CertificateMutex.Unlock()
|
||||||
|
fake.GetX509CertificateStub = nil
|
||||||
|
if fake.getX509CertificateReturnsOnCall == nil {
|
||||||
|
fake.getX509CertificateReturnsOnCall = make(map[int]struct {
|
||||||
|
result1 *x509.Certificate
|
||||||
|
result2 error
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fake.getX509CertificateReturnsOnCall[i] = struct {
|
||||||
|
result1 *x509.Certificate
|
||||||
|
result2 error
|
||||||
|
}{result1, result2}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) Invocations() map[string][][]interface{} {
|
||||||
|
fake.invocationsMutex.RLock()
|
||||||
|
defer fake.invocationsMutex.RUnlock()
|
||||||
|
fake.assertAttributeValueMutex.RLock()
|
||||||
|
defer fake.assertAttributeValueMutex.RUnlock()
|
||||||
|
fake.getAttributeValueMutex.RLock()
|
||||||
|
defer fake.getAttributeValueMutex.RUnlock()
|
||||||
|
fake.getIDMutex.RLock()
|
||||||
|
defer fake.getIDMutex.RUnlock()
|
||||||
|
fake.getMSPIDMutex.RLock()
|
||||||
|
defer fake.getMSPIDMutex.RUnlock()
|
||||||
|
fake.getX509CertificateMutex.RLock()
|
||||||
|
defer fake.getX509CertificateMutex.RUnlock()
|
||||||
|
copiedInvocations := map[string][][]interface{}{}
|
||||||
|
for key, value := range fake.invocations {
|
||||||
|
copiedInvocations[key] = value
|
||||||
|
}
|
||||||
|
return copiedInvocations
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *ClientIdentity) recordInvocation(key string, args []interface{}) {
|
||||||
|
fake.invocationsMutex.Lock()
|
||||||
|
defer fake.invocationsMutex.Unlock()
|
||||||
|
if fake.invocations == nil {
|
||||||
|
fake.invocations = map[string][][]interface{}{}
|
||||||
|
}
|
||||||
|
if fake.invocations[key] == nil {
|
||||||
|
fake.invocations[key] = [][]interface{}{}
|
||||||
|
}
|
||||||
|
fake.invocations[key] = append(fake.invocations[key], args)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,232 @@
|
||||||
|
// Code generated by counterfeiter. DO NOT EDIT.
|
||||||
|
package mocks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/hyperledger/fabric-protos-go/ledger/queryresult"
|
||||||
|
)
|
||||||
|
|
||||||
|
type StateQueryIterator struct {
|
||||||
|
CloseStub func() error
|
||||||
|
closeMutex sync.RWMutex
|
||||||
|
closeArgsForCall []struct {
|
||||||
|
}
|
||||||
|
closeReturns struct {
|
||||||
|
result1 error
|
||||||
|
}
|
||||||
|
closeReturnsOnCall map[int]struct {
|
||||||
|
result1 error
|
||||||
|
}
|
||||||
|
HasNextStub func() bool
|
||||||
|
hasNextMutex sync.RWMutex
|
||||||
|
hasNextArgsForCall []struct {
|
||||||
|
}
|
||||||
|
hasNextReturns struct {
|
||||||
|
result1 bool
|
||||||
|
}
|
||||||
|
hasNextReturnsOnCall map[int]struct {
|
||||||
|
result1 bool
|
||||||
|
}
|
||||||
|
NextStub func() (*queryresult.KV, error)
|
||||||
|
nextMutex sync.RWMutex
|
||||||
|
nextArgsForCall []struct {
|
||||||
|
}
|
||||||
|
nextReturns struct {
|
||||||
|
result1 *queryresult.KV
|
||||||
|
result2 error
|
||||||
|
}
|
||||||
|
nextReturnsOnCall map[int]struct {
|
||||||
|
result1 *queryresult.KV
|
||||||
|
result2 error
|
||||||
|
}
|
||||||
|
invocations map[string][][]interface{}
|
||||||
|
invocationsMutex sync.RWMutex
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *StateQueryIterator) Close() error {
|
||||||
|
fake.closeMutex.Lock()
|
||||||
|
ret, specificReturn := fake.closeReturnsOnCall[len(fake.closeArgsForCall)]
|
||||||
|
fake.closeArgsForCall = append(fake.closeArgsForCall, struct {
|
||||||
|
}{})
|
||||||
|
fake.recordInvocation("Close", []interface{}{})
|
||||||
|
fake.closeMutex.Unlock()
|
||||||
|
if fake.CloseStub != nil {
|
||||||
|
return fake.CloseStub()
|
||||||
|
}
|
||||||
|
if specificReturn {
|
||||||
|
return ret.result1
|
||||||
|
}
|
||||||
|
fakeReturns := fake.closeReturns
|
||||||
|
return fakeReturns.result1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *StateQueryIterator) CloseCallCount() int {
|
||||||
|
fake.closeMutex.RLock()
|
||||||
|
defer fake.closeMutex.RUnlock()
|
||||||
|
return len(fake.closeArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *StateQueryIterator) CloseCalls(stub func() error) {
|
||||||
|
fake.closeMutex.Lock()
|
||||||
|
defer fake.closeMutex.Unlock()
|
||||||
|
fake.CloseStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *StateQueryIterator) CloseReturns(result1 error) {
|
||||||
|
fake.closeMutex.Lock()
|
||||||
|
defer fake.closeMutex.Unlock()
|
||||||
|
fake.CloseStub = nil
|
||||||
|
fake.closeReturns = struct {
|
||||||
|
result1 error
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *StateQueryIterator) CloseReturnsOnCall(i int, result1 error) {
|
||||||
|
fake.closeMutex.Lock()
|
||||||
|
defer fake.closeMutex.Unlock()
|
||||||
|
fake.CloseStub = nil
|
||||||
|
if fake.closeReturnsOnCall == nil {
|
||||||
|
fake.closeReturnsOnCall = make(map[int]struct {
|
||||||
|
result1 error
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fake.closeReturnsOnCall[i] = struct {
|
||||||
|
result1 error
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *StateQueryIterator) HasNext() bool {
|
||||||
|
fake.hasNextMutex.Lock()
|
||||||
|
ret, specificReturn := fake.hasNextReturnsOnCall[len(fake.hasNextArgsForCall)]
|
||||||
|
fake.hasNextArgsForCall = append(fake.hasNextArgsForCall, struct {
|
||||||
|
}{})
|
||||||
|
fake.recordInvocation("HasNext", []interface{}{})
|
||||||
|
fake.hasNextMutex.Unlock()
|
||||||
|
if fake.HasNextStub != nil {
|
||||||
|
return fake.HasNextStub()
|
||||||
|
}
|
||||||
|
if specificReturn {
|
||||||
|
return ret.result1
|
||||||
|
}
|
||||||
|
fakeReturns := fake.hasNextReturns
|
||||||
|
return fakeReturns.result1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *StateQueryIterator) HasNextCallCount() int {
|
||||||
|
fake.hasNextMutex.RLock()
|
||||||
|
defer fake.hasNextMutex.RUnlock()
|
||||||
|
return len(fake.hasNextArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *StateQueryIterator) HasNextCalls(stub func() bool) {
|
||||||
|
fake.hasNextMutex.Lock()
|
||||||
|
defer fake.hasNextMutex.Unlock()
|
||||||
|
fake.HasNextStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *StateQueryIterator) HasNextReturns(result1 bool) {
|
||||||
|
fake.hasNextMutex.Lock()
|
||||||
|
defer fake.hasNextMutex.Unlock()
|
||||||
|
fake.HasNextStub = nil
|
||||||
|
fake.hasNextReturns = struct {
|
||||||
|
result1 bool
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *StateQueryIterator) HasNextReturnsOnCall(i int, result1 bool) {
|
||||||
|
fake.hasNextMutex.Lock()
|
||||||
|
defer fake.hasNextMutex.Unlock()
|
||||||
|
fake.HasNextStub = nil
|
||||||
|
if fake.hasNextReturnsOnCall == nil {
|
||||||
|
fake.hasNextReturnsOnCall = make(map[int]struct {
|
||||||
|
result1 bool
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fake.hasNextReturnsOnCall[i] = struct {
|
||||||
|
result1 bool
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *StateQueryIterator) Next() (*queryresult.KV, error) {
|
||||||
|
fake.nextMutex.Lock()
|
||||||
|
ret, specificReturn := fake.nextReturnsOnCall[len(fake.nextArgsForCall)]
|
||||||
|
fake.nextArgsForCall = append(fake.nextArgsForCall, struct {
|
||||||
|
}{})
|
||||||
|
fake.recordInvocation("Next", []interface{}{})
|
||||||
|
fake.nextMutex.Unlock()
|
||||||
|
if fake.NextStub != nil {
|
||||||
|
return fake.NextStub()
|
||||||
|
}
|
||||||
|
if specificReturn {
|
||||||
|
return ret.result1, ret.result2
|
||||||
|
}
|
||||||
|
fakeReturns := fake.nextReturns
|
||||||
|
return fakeReturns.result1, fakeReturns.result2
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *StateQueryIterator) NextCallCount() int {
|
||||||
|
fake.nextMutex.RLock()
|
||||||
|
defer fake.nextMutex.RUnlock()
|
||||||
|
return len(fake.nextArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *StateQueryIterator) NextCalls(stub func() (*queryresult.KV, error)) {
|
||||||
|
fake.nextMutex.Lock()
|
||||||
|
defer fake.nextMutex.Unlock()
|
||||||
|
fake.NextStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *StateQueryIterator) NextReturns(result1 *queryresult.KV, result2 error) {
|
||||||
|
fake.nextMutex.Lock()
|
||||||
|
defer fake.nextMutex.Unlock()
|
||||||
|
fake.NextStub = nil
|
||||||
|
fake.nextReturns = struct {
|
||||||
|
result1 *queryresult.KV
|
||||||
|
result2 error
|
||||||
|
}{result1, result2}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *StateQueryIterator) NextReturnsOnCall(i int, result1 *queryresult.KV, result2 error) {
|
||||||
|
fake.nextMutex.Lock()
|
||||||
|
defer fake.nextMutex.Unlock()
|
||||||
|
fake.NextStub = nil
|
||||||
|
if fake.nextReturnsOnCall == nil {
|
||||||
|
fake.nextReturnsOnCall = make(map[int]struct {
|
||||||
|
result1 *queryresult.KV
|
||||||
|
result2 error
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fake.nextReturnsOnCall[i] = struct {
|
||||||
|
result1 *queryresult.KV
|
||||||
|
result2 error
|
||||||
|
}{result1, result2}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *StateQueryIterator) Invocations() map[string][][]interface{} {
|
||||||
|
fake.invocationsMutex.RLock()
|
||||||
|
defer fake.invocationsMutex.RUnlock()
|
||||||
|
fake.closeMutex.RLock()
|
||||||
|
defer fake.closeMutex.RUnlock()
|
||||||
|
fake.hasNextMutex.RLock()
|
||||||
|
defer fake.hasNextMutex.RUnlock()
|
||||||
|
fake.nextMutex.RLock()
|
||||||
|
defer fake.nextMutex.RUnlock()
|
||||||
|
copiedInvocations := map[string][][]interface{}{}
|
||||||
|
for key, value := range fake.invocations {
|
||||||
|
copiedInvocations[key] = value
|
||||||
|
}
|
||||||
|
return copiedInvocations
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *StateQueryIterator) recordInvocation(key string, args []interface{}) {
|
||||||
|
fake.invocationsMutex.Lock()
|
||||||
|
defer fake.invocationsMutex.Unlock()
|
||||||
|
if fake.invocations == nil {
|
||||||
|
fake.invocations = map[string][][]interface{}{}
|
||||||
|
}
|
||||||
|
if fake.invocations[key] == nil {
|
||||||
|
fake.invocations[key] = [][]interface{}{}
|
||||||
|
}
|
||||||
|
fake.invocations[key] = append(fake.invocations[key], args)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,164 @@
|
||||||
|
// Code generated by counterfeiter. DO NOT EDIT.
|
||||||
|
package mocks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/hyperledger/fabric-chaincode-go/pkg/cid"
|
||||||
|
"github.com/hyperledger/fabric-chaincode-go/shim"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TransactionContext struct {
|
||||||
|
GetClientIdentityStub func() cid.ClientIdentity
|
||||||
|
getClientIdentityMutex sync.RWMutex
|
||||||
|
getClientIdentityArgsForCall []struct {
|
||||||
|
}
|
||||||
|
getClientIdentityReturns struct {
|
||||||
|
result1 cid.ClientIdentity
|
||||||
|
}
|
||||||
|
getClientIdentityReturnsOnCall map[int]struct {
|
||||||
|
result1 cid.ClientIdentity
|
||||||
|
}
|
||||||
|
GetStubStub func() shim.ChaincodeStubInterface
|
||||||
|
getStubMutex sync.RWMutex
|
||||||
|
getStubArgsForCall []struct {
|
||||||
|
}
|
||||||
|
getStubReturns struct {
|
||||||
|
result1 shim.ChaincodeStubInterface
|
||||||
|
}
|
||||||
|
getStubReturnsOnCall map[int]struct {
|
||||||
|
result1 shim.ChaincodeStubInterface
|
||||||
|
}
|
||||||
|
invocations map[string][][]interface{}
|
||||||
|
invocationsMutex sync.RWMutex
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *TransactionContext) GetClientIdentity() cid.ClientIdentity {
|
||||||
|
fake.getClientIdentityMutex.Lock()
|
||||||
|
ret, specificReturn := fake.getClientIdentityReturnsOnCall[len(fake.getClientIdentityArgsForCall)]
|
||||||
|
fake.getClientIdentityArgsForCall = append(fake.getClientIdentityArgsForCall, struct {
|
||||||
|
}{})
|
||||||
|
fake.recordInvocation("GetClientIdentity", []interface{}{})
|
||||||
|
fake.getClientIdentityMutex.Unlock()
|
||||||
|
if fake.GetClientIdentityStub != nil {
|
||||||
|
return fake.GetClientIdentityStub()
|
||||||
|
}
|
||||||
|
if specificReturn {
|
||||||
|
return ret.result1
|
||||||
|
}
|
||||||
|
fakeReturns := fake.getClientIdentityReturns
|
||||||
|
return fakeReturns.result1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *TransactionContext) GetClientIdentityCallCount() int {
|
||||||
|
fake.getClientIdentityMutex.RLock()
|
||||||
|
defer fake.getClientIdentityMutex.RUnlock()
|
||||||
|
return len(fake.getClientIdentityArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *TransactionContext) GetClientIdentityCalls(stub func() cid.ClientIdentity) {
|
||||||
|
fake.getClientIdentityMutex.Lock()
|
||||||
|
defer fake.getClientIdentityMutex.Unlock()
|
||||||
|
fake.GetClientIdentityStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *TransactionContext) GetClientIdentityReturns(result1 cid.ClientIdentity) {
|
||||||
|
fake.getClientIdentityMutex.Lock()
|
||||||
|
defer fake.getClientIdentityMutex.Unlock()
|
||||||
|
fake.GetClientIdentityStub = nil
|
||||||
|
fake.getClientIdentityReturns = struct {
|
||||||
|
result1 cid.ClientIdentity
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *TransactionContext) GetClientIdentityReturnsOnCall(i int, result1 cid.ClientIdentity) {
|
||||||
|
fake.getClientIdentityMutex.Lock()
|
||||||
|
defer fake.getClientIdentityMutex.Unlock()
|
||||||
|
fake.GetClientIdentityStub = nil
|
||||||
|
if fake.getClientIdentityReturnsOnCall == nil {
|
||||||
|
fake.getClientIdentityReturnsOnCall = make(map[int]struct {
|
||||||
|
result1 cid.ClientIdentity
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fake.getClientIdentityReturnsOnCall[i] = struct {
|
||||||
|
result1 cid.ClientIdentity
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *TransactionContext) GetStub() shim.ChaincodeStubInterface {
|
||||||
|
fake.getStubMutex.Lock()
|
||||||
|
ret, specificReturn := fake.getStubReturnsOnCall[len(fake.getStubArgsForCall)]
|
||||||
|
fake.getStubArgsForCall = append(fake.getStubArgsForCall, struct {
|
||||||
|
}{})
|
||||||
|
fake.recordInvocation("GetStub", []interface{}{})
|
||||||
|
fake.getStubMutex.Unlock()
|
||||||
|
if fake.GetStubStub != nil {
|
||||||
|
return fake.GetStubStub()
|
||||||
|
}
|
||||||
|
if specificReturn {
|
||||||
|
return ret.result1
|
||||||
|
}
|
||||||
|
fakeReturns := fake.getStubReturns
|
||||||
|
return fakeReturns.result1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *TransactionContext) GetStubCallCount() int {
|
||||||
|
fake.getStubMutex.RLock()
|
||||||
|
defer fake.getStubMutex.RUnlock()
|
||||||
|
return len(fake.getStubArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *TransactionContext) GetStubCalls(stub func() shim.ChaincodeStubInterface) {
|
||||||
|
fake.getStubMutex.Lock()
|
||||||
|
defer fake.getStubMutex.Unlock()
|
||||||
|
fake.GetStubStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *TransactionContext) GetStubReturns(result1 shim.ChaincodeStubInterface) {
|
||||||
|
fake.getStubMutex.Lock()
|
||||||
|
defer fake.getStubMutex.Unlock()
|
||||||
|
fake.GetStubStub = nil
|
||||||
|
fake.getStubReturns = struct {
|
||||||
|
result1 shim.ChaincodeStubInterface
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *TransactionContext) GetStubReturnsOnCall(i int, result1 shim.ChaincodeStubInterface) {
|
||||||
|
fake.getStubMutex.Lock()
|
||||||
|
defer fake.getStubMutex.Unlock()
|
||||||
|
fake.GetStubStub = nil
|
||||||
|
if fake.getStubReturnsOnCall == nil {
|
||||||
|
fake.getStubReturnsOnCall = make(map[int]struct {
|
||||||
|
result1 shim.ChaincodeStubInterface
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fake.getStubReturnsOnCall[i] = struct {
|
||||||
|
result1 shim.ChaincodeStubInterface
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *TransactionContext) Invocations() map[string][][]interface{} {
|
||||||
|
fake.invocationsMutex.RLock()
|
||||||
|
defer fake.invocationsMutex.RUnlock()
|
||||||
|
fake.getClientIdentityMutex.RLock()
|
||||||
|
defer fake.getClientIdentityMutex.RUnlock()
|
||||||
|
fake.getStubMutex.RLock()
|
||||||
|
defer fake.getStubMutex.RUnlock()
|
||||||
|
copiedInvocations := map[string][][]interface{}{}
|
||||||
|
for key, value := range fake.invocations {
|
||||||
|
copiedInvocations[key] = value
|
||||||
|
}
|
||||||
|
return copiedInvocations
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *TransactionContext) recordInvocation(key string, args []interface{}) {
|
||||||
|
fake.invocationsMutex.Lock()
|
||||||
|
defer fake.invocationsMutex.Unlock()
|
||||||
|
if fake.invocations == nil {
|
||||||
|
fake.invocations = map[string][][]interface{}{}
|
||||||
|
}
|
||||||
|
if fake.invocations[key] == nil {
|
||||||
|
fake.invocations[key] = [][]interface{}{}
|
||||||
|
}
|
||||||
|
fake.invocations[key] = append(fake.invocations[key], args)
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
module github.com/hyperledger/fabric-samples/asset-transfer-private-data/chaincode-go/go
|
module github.com/hyperledger/fabric-samples/asset-transfer-private-data/chaincode-go
|
||||||
|
|
||||||
go 1.14
|
go 1.14
|
||||||
|
|
||||||
|
|
@ -11,14 +11,15 @@ require (
|
||||||
github.com/golang/protobuf v1.4.2 // indirect
|
github.com/golang/protobuf v1.4.2 // indirect
|
||||||
github.com/hyperledger/fabric-chaincode-go v0.0.0-20200511190512-bcfeb58dd83a
|
github.com/hyperledger/fabric-chaincode-go v0.0.0-20200511190512-bcfeb58dd83a
|
||||||
github.com/hyperledger/fabric-contract-api-go v1.1.0
|
github.com/hyperledger/fabric-contract-api-go v1.1.0
|
||||||
github.com/hyperledger/fabric-protos-go v0.0.0-20200707132912-fee30f3ccd23 // indirect
|
github.com/hyperledger/fabric-protos-go v0.0.0-20200707132912-fee30f3ccd23
|
||||||
github.com/mailru/easyjson v0.7.1 // indirect
|
github.com/mailru/easyjson v0.7.1 // indirect
|
||||||
github.com/rogpeppe/go-internal v1.6.0 // indirect
|
github.com/rogpeppe/go-internal v1.6.0 // indirect
|
||||||
|
github.com/stretchr/testify v1.5.1
|
||||||
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
|
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
|
||||||
golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect
|
golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect
|
||||||
golang.org/x/sys v0.0.0-20200720211630-cb9d2d5c5666 // indirect
|
golang.org/x/sys v0.0.0-20200720211630-cb9d2d5c5666 // indirect
|
||||||
google.golang.org/genproto v0.0.0-20200721032028-5044d0edf986 // indirect
|
google.golang.org/genproto v0.0.0-20200721032028-5044d0edf986 // indirect
|
||||||
google.golang.org/grpc v1.30.0 // indirect
|
google.golang.org/grpc v1.30.0 // indirect
|
||||||
google.golang.org/protobuf v1.25.0 // indirect
|
google.golang.org/protobuf v1.25.0
|
||||||
gopkg.in/yaml.v2 v2.3.0 // indirect
|
gopkg.in/yaml.v2 v2.3.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
|
||||||
23
asset-transfer-private-data/chaincode-go/main.go
Normal file
23
asset-transfer-private-data/chaincode-go/main.go
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/hyperledger/fabric-contract-api-go/contractapi"
|
||||||
|
"github.com/hyperledger/fabric-samples/asset-transfer-private-data/chaincode-go/chaincode"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
assetChaincode, err := contractapi.NewChaincode(&chaincode.SmartContract{})
|
||||||
|
if err != nil {
|
||||||
|
log.Panicf("Error creating asset-transfer-private-data chaincode: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := assetChaincode.Start(); err != nil {
|
||||||
|
log.Panicf("Error starting asset-transfer-private-data chaincode: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue