Skip to content

Commit

Permalink
Merge "Adding examples to make unit-test"
Browse files Browse the repository at this point in the history
  • Loading branch information
christo4ferris authored and Gerrit Code Review committed Sep 5, 2016
2 parents b27f6ce + b7a57a9 commit 0f959c0
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 35 deletions.
10 changes: 4 additions & 6 deletions examples/chaincode/go/asset_management/app/app_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func deployInternal(deployer crypto.Client, adminCert crypto.CertificateHandler)
Type: 1,
ChaincodeID: &pb.ChaincodeID{Path: "github.com/hyperledger/fabric/examples/chaincode/go/asset_management"},
//ChaincodeID: &pb.ChaincodeID{Name: chaincodeName},
CtorMsg: &pb.ChaincodeInput{Function: "init", Args: []string{}},
CtorMsg: &pb.ChaincodeInput{Args: util.ToChaincodeArgs("init")},
Metadata: adminCert.GetCertificate(),
ConfidentialityLevel: confidentialityLevel,
}
Expand Down Expand Up @@ -187,8 +187,7 @@ func assignOwnershipInternal(invoker crypto.Client, invokerCert crypto.Certifica
}

chaincodeInput := &pb.ChaincodeInput{
Function: "assign",
Args: []string{asset, base64.StdEncoding.EncodeToString(newOwnerCert.GetCertificate())},
Args: util.ToChaincodeArgs("assign", asset, base64.StdEncoding.EncodeToString(newOwnerCert.GetCertificate())),
}
chaincodeInputRaw, err := proto.Marshal(chaincodeInput)
if err != nil {
Expand Down Expand Up @@ -239,8 +238,7 @@ func transferOwnershipInternal(owner crypto.Client, ownerCert crypto.Certificate
}

chaincodeInput := &pb.ChaincodeInput{
Function: "transfer",
Args: []string{asset, base64.StdEncoding.EncodeToString(newOwnerCert.GetCertificate())},
Args: util.ToChaincodeArgs("transfer", asset, base64.StdEncoding.EncodeToString(newOwnerCert.GetCertificate())),
}
chaincodeInputRaw, err := proto.Marshal(chaincodeInput)
if err != nil {
Expand Down Expand Up @@ -275,7 +273,7 @@ func transferOwnershipInternal(owner crypto.Client, ownerCert crypto.Certificate
}

func whoIsTheOwner(invoker crypto.Client, asset string) (transaction *pb.Transaction, resp *pb.Response, err error) {
chaincodeInput := &pb.ChaincodeInput{Function: "query", Args: []string{asset}}
chaincodeInput := &pb.ChaincodeInput{Args: util.ToChaincodeArgs("query", asset)}

// Prepare spec and submit
spec := &pb.ChaincodeSpec{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"testing"
"time"

"io/ioutil"
"os"
"path/filepath"

Expand All @@ -34,6 +33,7 @@ import (
"github.com/hyperledger/fabric/core/container"
"github.com/hyperledger/fabric/core/crypto"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/membersrvc/ca"
pb "github.com/hyperledger/fabric/protos"
"github.com/op/go-logging"
Expand Down Expand Up @@ -330,7 +330,7 @@ func deploy(admCert crypto.CertificateHandler) error {
spec := &pb.ChaincodeSpec{
Type: 1,
ChaincodeID: &pb.ChaincodeID{Name: "mycc"},
CtorMsg: &pb.ChaincodeInput{Function: "init", Args: []string{}},
CtorMsg: &pb.ChaincodeInput{Args: util.ToChaincodeArgs("init")},
Metadata: []byte("issuer"),
ConfidentialityLevel: pb.ConfidentialityLevel_PUBLIC,
}
Expand Down Expand Up @@ -373,7 +373,7 @@ func assignOwnership(assigner crypto.Client, newOwnerCert crypto.CertificateHand
return err
}

chaincodeInput := &pb.ChaincodeInput{Function: "assignOwnership", Args: []string{base64.StdEncoding.EncodeToString(newOwnerCert.GetCertificate()), attributeName, amount}}
chaincodeInput := &pb.ChaincodeInput{Args: util.ToChaincodeArgs("assignOwnership", base64.StdEncoding.EncodeToString(newOwnerCert.GetCertificate()), attributeName, amount)}

// Prepare spec and submit
spec := &pb.ChaincodeSpec{
Expand Down Expand Up @@ -419,12 +419,13 @@ func transferOwnership(owner crypto.Client, ownerCert crypto.CertificateHandler,
return err
}

args := []string{base64.StdEncoding.EncodeToString(ownerCert.GetCertificate()),
chaincodeInput := &pb.ChaincodeInput{Args: util.ToChaincodeArgs(
"transferOwnership",
base64.StdEncoding.EncodeToString(ownerCert.GetCertificate()),
fromAttributes,
base64.StdEncoding.EncodeToString(newOwnerCert.GetCertificate()),
toAttributes,
amount}
chaincodeInput := &pb.ChaincodeInput{Function: "transferOwnership", Args: args}
amount)}

// Prepare spec and submit
spec := &pb.ChaincodeSpec{
Expand Down Expand Up @@ -466,7 +467,7 @@ func getBalance(accountID string) ([]byte, error) {
}

func Query(function, accountID string) ([]byte, error) {
chaincodeInput := &pb.ChaincodeInput{Function: function, Args: []string{accountID}}
chaincodeInput := &pb.ChaincodeInput{Args: util.ToChaincodeArgs(function, accountID)}

// Prepare spec and submit
spec := &pb.ChaincodeSpec{
Expand Down Expand Up @@ -526,7 +527,8 @@ func setup() {
}

func initMembershipSrvc() {
ca.LogInit(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr, os.Stdout)
// ca.LogInit seems to have been removed
//ca.LogInit(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr, os.Stdout)
ca.CacheConfiguration() // Cache configuration
aca = ca.NewACA()
eca = ca.NewECA()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"time"

"encoding/base64"
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -33,6 +32,7 @@ import (
"github.com/hyperledger/fabric/core/container"
"github.com/hyperledger/fabric/core/crypto"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/membersrvc/ca"
pb "github.com/hyperledger/fabric/protos"
"github.com/op/go-logging"
Expand Down Expand Up @@ -180,7 +180,7 @@ func deploy(admCert crypto.CertificateHandler) error {
spec := &pb.ChaincodeSpec{
Type: 1,
ChaincodeID: &pb.ChaincodeID{Name: "mycc"},
CtorMsg: &pb.ChaincodeInput{Function: "init", Args: []string{}},
CtorMsg: &pb.ChaincodeInput{Args: util.ToChaincodeArgs("init")},
Metadata: []byte("assigner"),
ConfidentialityLevel: pb.ConfidentialityLevel_PUBLIC,
}
Expand Down Expand Up @@ -224,7 +224,7 @@ func assignOwnership(assigner crypto.Client, asset string, newOwnerCert crypto.C
}

newOwner := base64.StdEncoding.EncodeToString(newOwnerCert.GetCertificate())
chaincodeInput := &pb.ChaincodeInput{Function: "assign", Args: []string{asset, newOwner}}
chaincodeInput := &pb.ChaincodeInput{Args: util.ToChaincodeArgs("assign", asset, newOwner)}

// Prepare spec and submit
spec := &pb.ChaincodeSpec{
Expand Down Expand Up @@ -270,7 +270,7 @@ func transferOwnership(owner crypto.Client, ownerCert crypto.CertificateHandler,
}

newOwner := base64.StdEncoding.EncodeToString(newOwnerCert.GetCertificate())
chaincodeInput := &pb.ChaincodeInput{Function: "transfer", Args: []string{asset, newOwner}}
chaincodeInput := &pb.ChaincodeInput{Args: util.ToChaincodeArgs("transfer", asset, newOwner)}

// Prepare spec and submit
spec := &pb.ChaincodeSpec{
Expand Down Expand Up @@ -304,7 +304,7 @@ func transferOwnership(owner crypto.Client, ownerCert crypto.CertificateHandler,
}

func whoIsTheOwner(asset string) ([]byte, error) {
chaincodeInput := &pb.ChaincodeInput{Function: "query", Args: []string{asset}}
chaincodeInput := &pb.ChaincodeInput{Args: util.ToChaincodeArgs("query", asset)}

// Prepare spec and submit
spec := &pb.ChaincodeSpec{
Expand Down Expand Up @@ -364,7 +364,6 @@ func setup() {
}

func initMembershipSrvc() {
ca.LogInit(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr, os.Stdout)
ca.CacheConfiguration() // Cache configuration
aca = ca.NewACA()
eca = ca.NewECA()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

"github.com/hyperledger/fabric/core/chaincode/shim"
ex02 "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
main "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example05"
)

// chaincode_example02's hash is used here and must be updated if the example is changed
Expand Down Expand Up @@ -78,7 +77,7 @@ func checkInvoke(t *testing.T, stub *shim.MockStub, args []string) {
}

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

// Init A=123 B=234
Expand All @@ -88,7 +87,7 @@ func TestExample04_Init(t *testing.T) {
}

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

ccEx2 := new(ex02.SimpleChaincode)
Expand All @@ -103,7 +102,7 @@ func TestExample04_Query(t *testing.T) {
}

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

ccEx2 := new(ex02.SimpleChaincode)
Expand Down
19 changes: 9 additions & 10 deletions examples/chaincode/go/rbac_tcerts_no_attrs/rbac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"testing"
"time"

"io/ioutil"
"os"
"path/filepath"

Expand All @@ -35,6 +34,7 @@ import (
"github.com/hyperledger/fabric/core/container"
"github.com/hyperledger/fabric/core/crypto"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/membersrvc/ca"
pb "github.com/hyperledger/fabric/protos"
"github.com/op/go-logging"
Expand Down Expand Up @@ -175,7 +175,7 @@ func deploy(admCert crypto.CertificateHandler) error {
spec := &pb.ChaincodeSpec{
Type: 1,
ChaincodeID: &pb.ChaincodeID{Name: "mycc"},
CtorMsg: &pb.ChaincodeInput{Function: "init", Args: []string{}},
CtorMsg: &pb.ChaincodeInput{Args: util.ToChaincodeArgs("init")},
Metadata: admCert.GetCertificate(),
ConfidentialityLevel: pb.ConfidentialityLevel_PUBLIC,
}
Expand All @@ -197,7 +197,7 @@ func deploy(admCert crypto.CertificateHandler) error {

ledger, err := ledger.GetLedger()
ledger.BeginTxBatch("1")
_, err = chaincode.Execute(ctx, chaincode.GetChain(chaincode.DefaultChain), transaction)
_, _, err = chaincode.Execute(ctx, chaincode.GetChain(chaincode.DefaultChain), transaction)
if err != nil {
return fmt.Errorf("Error deploying chaincode: %s", err)
}
Expand All @@ -222,7 +222,7 @@ func addRole(admCert crypto.CertificateHandler, idCert crypto.CertificateHandler
return err
}

chaincodeInput := &pb.ChaincodeInput{Function: "addRole", Args: []string{string(idCert.GetCertificate()), role}}
chaincodeInput := &pb.ChaincodeInput{Args: util.ToChaincodeArgs("addRole", string(idCert.GetCertificate()), role)}
chaincodeInputRaw, err := proto.Marshal(chaincodeInput)
if err != nil {
return err
Expand Down Expand Up @@ -263,7 +263,7 @@ func addRole(admCert crypto.CertificateHandler, idCert crypto.CertificateHandler

ledger, err := ledger.GetLedger()
ledger.BeginTxBatch("1")
_, err = chaincode.Execute(ctx, chaincode.GetChain(chaincode.DefaultChain), transaction)
_, _, err = chaincode.Execute(ctx, chaincode.GetChain(chaincode.DefaultChain), transaction)
if err != nil {
return fmt.Errorf("Error deploying chaincode: %s", err)
}
Expand All @@ -289,7 +289,7 @@ func write(invoker crypto.Client, invokerCert crypto.CertificateHandler, value [
return err
}

chaincodeInput := &pb.ChaincodeInput{Function: "write", Args: []string{string(value)}}
chaincodeInput := &pb.ChaincodeInput{Args: util.ToChaincodeArgs("write", string(value))}
chaincodeInputRaw, err := proto.Marshal(chaincodeInput)
if err != nil {
return err
Expand Down Expand Up @@ -330,7 +330,7 @@ func write(invoker crypto.Client, invokerCert crypto.CertificateHandler, value [

ledger, err := ledger.GetLedger()
ledger.BeginTxBatch("1")
_, err = chaincode.Execute(ctx, chaincode.GetChain(chaincode.DefaultChain), transaction)
_, _, err = chaincode.Execute(ctx, chaincode.GetChain(chaincode.DefaultChain), transaction)
if err != nil {
return fmt.Errorf("Error deploying chaincode: %s", err)
}
Expand All @@ -357,7 +357,7 @@ func read(invoker crypto.Client, invokerCert crypto.CertificateHandler) ([]byte,
return nil, err
}

chaincodeInput := &pb.ChaincodeInput{Function: "read", Args: []string{}}
chaincodeInput := &pb.ChaincodeInput{Args: util.ToChaincodeArgs("read")}
chaincodeInputRaw, err := proto.Marshal(chaincodeInput)
if err != nil {
return nil, err
Expand Down Expand Up @@ -398,7 +398,7 @@ func read(invoker crypto.Client, invokerCert crypto.CertificateHandler) ([]byte,

ledger, err := ledger.GetLedger()
ledger.BeginTxBatch("1")
result, err := chaincode.Execute(ctx, chaincode.GetChain(chaincode.DefaultChain), transaction)
result, _, err := chaincode.Execute(ctx, chaincode.GetChain(chaincode.DefaultChain), transaction)
if err != nil {
return nil, fmt.Errorf("Error deploying chaincode: %s", err)
}
Expand Down Expand Up @@ -440,7 +440,6 @@ func setup() {
}

func initMemershipServices() {
ca.LogInit(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr, os.Stdout)
ca.CacheConfiguration() // Cache configuration
eca = ca.NewECA()
tca = ca.NewTCA(eca)
Expand Down
7 changes: 6 additions & 1 deletion scripts/goUnitTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ echo "Cleaning membership services folder"
rm -rf membersrvc/ca/.ca/

echo -n "Obtaining list of tests to run.."
PKGS=`go list github.com/hyperledger/fabric/... | grep -v /vendor/ | grep -v /examples/`
# Some examples don't play nice with `go test`
PKGS=`go list github.com/hyperledger/fabric/... | grep -v /vendor/ | \
grep -v /examples/chaincode/chaintool/ | \
grep -v /examples/chaincode/go/asset_management | \
grep -v /examples/chaincode/go/utxo | \
grep -v /examples/chaincode/go/rbac_tcerts_no_attrs`
echo "DONE!"

echo -n "Starting peer.."
Expand Down

0 comments on commit 0f959c0

Please sign in to comment.