Skip to content

Commit

Permalink
FAB-15782 Sample Go CC should include deps
Browse files Browse the repository at this point in the history
The ccenv used to build Go chaincode is being
updated to no longer include the shim
dependency.  Go chaincode must now vendor
all of its dependencies prior to being
packaged and installed.

Go chaincodes have been updated to include
go.mod for versioned dependencies.

Change-Id: Ib971cd3f841d5c92a509450bd85f6e424cc60c6e
Signed-off-by: Gari Singh <gari.r.singh@gmail.com>
  • Loading branch information
mastersingh24 committed Jun 25, 2019
1 parent 6ba5a19 commit c57d67c
Show file tree
Hide file tree
Showing 53 changed files with 1,627 additions and 15,235 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
/config
.DS_Store
.project
# omit Go vendor directories
vendor/
19 changes: 10 additions & 9 deletions chaincode/abac/go/abac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
"testing"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/protos/msp"
"github.com/hyperledger/fabric/core/chaincode/shim"
"github.com/hyperledger/fabric/core/chaincode/shim/shimtest"
"github.com/hyperledger/fabric/protos/msp"
)

// Cert with attribute. "abac.init":"true"
Expand All @@ -36,15 +37,15 @@ w8Ou1Sh9IjeXj/SDAA==
-----END CERTIFICATE-----
`

func checkInit(t *testing.T, stub *shim.MockStub, args [][]byte) {
func checkInit(t *testing.T, stub *shimtest.MockStub, args [][]byte) {
res := stub.MockInit("1", args)
if res.Status != shim.OK {
fmt.Println("Init failed", string(res.Message))
t.FailNow()
}
}

func checkState(t *testing.T, stub *shim.MockStub, name string, value string) {
func checkState(t *testing.T, stub *shimtest.MockStub, name string, value string) {
bytes := stub.State[name]
if bytes == nil {
fmt.Println("State", name, "failed to get value")
Expand All @@ -56,7 +57,7 @@ func checkState(t *testing.T, stub *shim.MockStub, name string, value string) {
}
}

func checkQuery(t *testing.T, stub *shim.MockStub, name string, value string) {
func checkQuery(t *testing.T, stub *shimtest.MockStub, name string, value string) {
res := stub.MockInvoke("1", [][]byte{[]byte("query"), []byte(name)})
if res.Status != shim.OK {
fmt.Println("Query", name, "failed", string(res.Message))
Expand All @@ -72,15 +73,15 @@ func checkQuery(t *testing.T, stub *shim.MockStub, name string, value string) {
}
}

func checkInvoke(t *testing.T, stub *shim.MockStub, args [][]byte) {
func checkInvoke(t *testing.T, stub *shimtest.MockStub, args [][]byte) {
res := stub.MockInvoke("1", args)
if res.Status != shim.OK {
fmt.Println("Invoke", args, "failed", string(res.Message))
t.FailNow()
}
}

func setCreator(t *testing.T, stub *shim.MockStub, mspID string, idbytes []byte) {
func setCreator(t *testing.T, stub *shimtest.MockStub, mspID string, idbytes []byte) {
sid := &msp.SerializedIdentity{Mspid: mspID, IdBytes: idbytes}
b, err := proto.Marshal(sid)
if err != nil {
Expand All @@ -91,7 +92,7 @@ func setCreator(t *testing.T, stub *shim.MockStub, mspID string, idbytes []byte)

func TestAbac_Init(t *testing.T) {
scc := new(SimpleChaincode)
stub := shim.NewMockStub("abac", scc)
stub := shimtest.NewMockStub("abac", scc)

setCreator(t, stub, "org1MSP", []byte(certWithAttrs))

Expand All @@ -104,7 +105,7 @@ func TestAbac_Init(t *testing.T) {

func TestAbac_Query(t *testing.T) {
scc := new(SimpleChaincode)
stub := shim.NewMockStub("abac", scc)
stub := shimtest.NewMockStub("abac", scc)

setCreator(t, stub, "org1MSP", []byte(certWithAttrs))

Expand All @@ -120,7 +121,7 @@ func TestAbac_Query(t *testing.T) {

func TestAbac_Invoke(t *testing.T) {
scc := new(SimpleChaincode)
stub := shim.NewMockStub("abac", scc)
stub := shimtest.NewMockStub("abac", scc)

setCreator(t, stub, "org1MSP", []byte(certWithAttrs))

Expand Down
19 changes: 19 additions & 0 deletions chaincode/abac/go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module github.com/hyperledger/fabric-samples/chaincode/abac/go

go 1.12

require (
github.com/Knetic/govaluate v3.0.0+incompatible // indirect
github.com/Shopify/sarama v1.22.1 // indirect
github.com/golang/protobuf v1.3.1
github.com/hashicorp/go-version v1.2.0 // indirect
github.com/hyperledger/fabric v2.0.0-alpha.0.20190624224950-f2b8fef8859c+incompatible
github.com/hyperledger/fabric-amcl v0.0.0-20181230093703-5ccba6eab8d6 // indirect
github.com/miekg/pkcs11 v1.0.2 // indirect
github.com/onsi/ginkgo v1.8.0 // indirect
github.com/onsi/gomega v1.5.0 // indirect
github.com/spf13/viper v1.4.0 // indirect
github.com/sykesm/zap-logfmt v0.0.2 // indirect
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 // indirect
google.golang.org/grpc v1.21.1 // indirect
)
209 changes: 209 additions & 0 deletions chaincode/abac/go/go.sum

Large diffs are not rendered by default.

28 changes: 0 additions & 28 deletions chaincode/abac/go/vendor/github.com/golang/protobuf/LICENSE

This file was deleted.

253 changes: 0 additions & 253 deletions chaincode/abac/go/vendor/github.com/golang/protobuf/proto/clone.go

This file was deleted.

Loading

0 comments on commit c57d67c

Please sign in to comment.