Skip to content

Commit

Permalink
[FAB-8705] Remove samplesyscc package
Browse files Browse the repository at this point in the history
The sample system chaincode was used as part of a system chaincode test
so moving it closer to where it's used.

That said, the test that uses it has been skipped for a long time and it
no longer passes when enabled.

Change-Id: Ib94344dfb4029a7a53aaf4c90f54d8e37463eac0
Signed-off-by: Matthew Sykes <[email protected]>
  • Loading branch information
sykesm committed Mar 8, 2018
1 parent 7af4f2e commit f922b70
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 356 deletions.
64 changes: 62 additions & 2 deletions core/chaincode/systemchaincode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (

"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/chaincode/accesscontrol"
"github.com/hyperledger/fabric/core/chaincode/shim"
"github.com/hyperledger/fabric/core/common/ccprovider"
"github.com/hyperledger/fabric/core/peer"
"github.com/hyperledger/fabric/core/scc"
"github.com/hyperledger/fabric/core/scc/samplesyscc"
pb "github.com/hyperledger/fabric/protos/peer"
"github.com/spf13/viper"
"golang.org/x/net/context"
Expand All @@ -44,6 +44,66 @@ func (osyscc *oldSysCCInfo) reset() {
viper.Set("chaincode.system", osyscc.origSysCCWhitelist)
}

type SampleSysCC struct{}

func (t *SampleSysCC) Init(stub shim.ChaincodeStubInterface) pb.Response {
return shim.Success(nil)
}

func (t *SampleSysCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
f, args := stub.GetFunctionAndParameters()

switch f {
case "putval":
if len(args) != 2 {
return shim.Error("need 2 args (key and a value)")
}

// Initialize the chaincode
key := args[0]
val := args[1]

_, err := stub.GetState(key)
if err != nil {
jsonResp := "{\"Error\":\"Failed to get val for " + key + "\"}"
return shim.Error(jsonResp)
}

// Write the state to the ledger
err = stub.PutState(key, []byte(val))
if err != nil {
return shim.Error(err.Error())
}

return shim.Success(nil)
case "getval":
var err error

if len(args) != 1 {
return shim.Error("Incorrect number of arguments. Expecting key to query")
}

key := args[0]

// Get the state from the ledger
valbytes, err := stub.GetState(key)
if err != nil {
jsonResp := "{\"Error\":\"Failed to get state for " + key + "\"}"
return shim.Error(jsonResp)
}

if valbytes == nil {
jsonResp := "{\"Error\":\"Nil val for " + key + "\"}"
return shim.Error(jsonResp)
}

return shim.Success(valbytes)
default:
jsonResp := "{\"Error\":\"Unknown function " + f + "\"}"
return shim.Error(jsonResp)
}
}

func initSysCCTests() (*oldSysCCInfo, net.Listener, error) {
var opts []grpc.ServerOption
grpcServer := grpc.NewServer(opts...)
Expand Down Expand Up @@ -81,7 +141,7 @@ func initSysCCTests() (*oldSysCCInfo, net.Listener, error) {
Name: "sample_syscc",
Path: "github.com/hyperledger/fabric/core/scc/samplesyscc",
InitArgs: [][]byte{},
Chaincode: &samplesyscc.SampleSysCC{},
Chaincode: &SampleSysCC{},
},
}

Expand Down
91 changes: 0 additions & 91 deletions core/scc/samplesyscc/samplesyscc.go

This file was deleted.

Loading

0 comments on commit f922b70

Please sign in to comment.