Skip to content

Commit

Permalink
[FAB-8923] Fix example compilation issues
Browse files Browse the repository at this point in the history
As part of correcting some compilation issues, the chaincode
implementations were separated from the main package(s). The main
package for the impacted samples now live under a cmd folder in the
example.

Since some of the examples were actually used as test fixtures, some of
the users needed updates to reflect the new location of the main.

Given the need to update callers anyway, we removed chaincode_ prefix
from the directory names and the _exampleXX suffix chaincode source
files as they were redundant. (The examples were already located in
examples/chaincode/.../exampleXX folders.)

Change-Id: I58e040fc5eba7186c1fec2b00d58b0faf3cb1a09
Signed-off-by: William Lahti <wtlahti@us.ibm.com>
Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
  • Loading branch information
sykesm committed Mar 20, 2018
1 parent ab5c060 commit 621725f
Show file tree
Hide file tree
Showing 38 changed files with 200 additions and 233 deletions.
6 changes: 3 additions & 3 deletions bddtests/features/endorser.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Feature: Endorser
And I register with CA supplying username "binhn" and secret "7avZQLwcUe9q" on peers:
| vp0 |

When user "binhn" creates a chaincode spec "cc_spec" of type "GOLANG" for chaincode "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" with args
When user "binhn" creates a chaincode spec "cc_spec" of type "GOLANG" for chaincode "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd" with args
| funcName | arg1 | arg2 | arg3 | arg4 |
| init | a | 100 | b | 200 |
And user "binhn" creates a deployment spec "cc_deploy_spec" using chaincode spec "cc_spec" and devops on peer "vp0"
Expand All @@ -49,7 +49,7 @@ Feature: Endorser
And I register with CA supplying username "binhn" and secret "7avZQLwcUe9q" on peers:
| vp0 |

When user "binhn" creates a chaincode spec of type "GOLANG" for chaincode "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" aliased as "cc_spec" with args
When user "binhn" creates a chaincode spec of type "GOLANG" for chaincode "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd" aliased as "cc_spec" with args
| funcName | arg1 | arg2 | arg3 | arg4 |
| init | a | 100 | b | 200 |
And user "binhn" sets ESCC to "my_escc" for chaincode spec "cc_spec"
Expand All @@ -72,7 +72,7 @@ Feature: Endorser
And I register with CA supplying username "binhn" and secret "7avZQLwcUe9q" on peers:
| vp0 |

When user "binhn" creates a chaincode spec of type "GOLANG" for chaincode "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" aliased as "cc_spec" with args
When user "binhn" creates a chaincode spec of type "GOLANG" for chaincode "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd" aliased as "cc_spec" with args
| funcName | arg1 | arg2 | arg3 | arg4 |
| init | a | 100 | b | 200 |
And user "binhn" sets VSCC to "my_vscc" for chaincode spec "cc_spec"
Expand Down
4 changes: 2 additions & 2 deletions bddtests/steps/endorser_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ def getEndorserStubs(context, composeServices, directory, nodeAdminTuple):
return stubs

def getExample02ChaincodeSpec():
return getChaincodeSpec("GOLANG", "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02", "example02", ["init","a","100","b","200"])
return getChaincodeSpec("GOLANG", "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd", "example02", ["init","a","100","b","200"])



def _createDeploymentSpecAsFile(ccSpec, outputPath):
'''peer chaincode package -n myCC -c '{"Args":["init","a","100","b","200"]}' -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 --logging-level=DEBUG test.file'''
'''peer chaincode package -n myCC -c '{"Args":["init","a","100","b","200"]}' -p github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd --logging-level=DEBUG test.file'''
myEnv = os.environ.copy()
myEnv['CORE_PEER_MSPCONFIGPATH'] = "./../sampleconfig/msp"
nameArgs = ["-n", ccSpec.chaincode_id.name]
Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/multichains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestExecuteInvokeOnManyChains(t *testing.T) {

var ctxt = context.Background()

url := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
url := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"
chaincodeID := &pb.ChaincodeID{Name: "example02", Path: url, Version: "0"}

args := []string{"a", "b", "10"}
Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/platforms/golang/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func Test_DeploymentPayload(t *testing.T) {
platform := &Platform{}
spec := &pb.ChaincodeSpec{
ChaincodeId: &pb.ChaincodeID{
Path: "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02",
Path: "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd",
},
}

Expand Down
4 changes: 2 additions & 2 deletions core/chaincode/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func TestUpgradeCC(t *testing.T) {

//now upgrade to example02 which takes the same args as example01 but inits state vars
//and also allows query.
url = "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
url = "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"

//Note ccName hasn't changed...
chaincodeID = &pb.ChaincodeID{Name: ccName, Path: url, Version: "1"}
Expand Down Expand Up @@ -232,7 +232,7 @@ func TestInvalUpgradeCC(t *testing.T) {
var ctxt = context.Background()

ccName := "mycc"
url := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
url := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"

f := "init"
args := util.ToChaincodeArgs(f, "a", "100", "b", "200")
Expand Down
6 changes: 3 additions & 3 deletions core/common/ccprovider/ccinfocache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (m *mockCCInfoFSStorageMgrImpl) GetChaincode(ccname string, ccversion strin
func TestCCInfoCache(t *testing.T) {
ccname := "foo"
ccver := "1.0"
ccpath := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
ccpath := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"

ccinfoFs := &mockCCInfoFSStorageMgrImpl{CCMap: map[string]CCPackage{}}
cccache := NewCCInfoCache(ccinfoFs)
Expand Down Expand Up @@ -134,7 +134,7 @@ func TestCCInfoCache(t *testing.T) {
func TestPutChaincode(t *testing.T) {
ccname := ""
ccver := "1.0"
ccpath := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
ccpath := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"

ccinfoFs := &mockCCInfoFSStorageMgrImpl{CCMap: map[string]CCPackage{}}
NewCCInfoCache(ccinfoFs)
Expand Down Expand Up @@ -164,7 +164,7 @@ func TestPutChaincode(t *testing.T) {
func TestCCInfoFSPeerInstance(t *testing.T) {
ccname := "bar"
ccver := "1.0"
ccpath := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
ccpath := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"

// the cc data is not yet in the cache
_, err := GetChaincodeFromFS(ccname, ccver)
Expand Down
2 changes: 1 addition & 1 deletion core/container/dockercontroller/dockercontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func Test_Start(t *testing.T) {
err = dvm.Start(ctx, ccid, args, env, files, nil, nil)
testerr(t, err, false)

chaincodePath := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example01"
chaincodePath := "github.com/hyperledger/fabric/examples/chaincode/go/example01/cmd"
spec := &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_GOLANG,
ChaincodeId: &pb.ChaincodeID{Name: "ex01", Path: chaincodePath},
Input: &pb.ChaincodeInput{Args: util.ToChaincodeArgs("f")}}
Expand Down
2 changes: 1 addition & 1 deletion core/container/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestVM_BuildImage_ChaincodeLocal(t *testing.T) {
return
}
// Build the spec
chaincodePath := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example01"
chaincodePath := "github.com/hyperledger/fabric/examples/chaincode/go/example01/cmd"
spec := &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_GOLANG,
ChaincodeId: &pb.ChaincodeID{Name: "ex01", Path: chaincodePath},
Input: &pb.ChaincodeInput{Args: util.ToChaincodeArgs("f")}}
Expand Down
6 changes: 3 additions & 3 deletions core/scc/lscc/lscc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestInstall(t *testing.T) {
res = stub.MockInvokeWithSignedProposal("1", [][]byte{[]byte(INSTALL)}, nil)
assert.NotEqual(t, res.Status, int32(shim.OK), res.Message)

path := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"

testInstall(t, "example02", "0", path, false, "", "Alice", scc, stub)
testInstall(t, "example02-2", "1.0", path, false, "", "Alice", scc, stub)
Expand Down Expand Up @@ -163,7 +163,7 @@ func testInstall(t *testing.T, ccname string, version string, path string, creat
}

func TestDeploy(t *testing.T) {
path := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"

testDeploy(t, "example02", "0", path, false, false, true, "", nil, nil)
testDeploy(t, "example02", "1.0", path, false, false, true, "", nil, nil)
Expand Down Expand Up @@ -303,7 +303,7 @@ func testDeploy(t *testing.T, ccname string, version string, path string, forceB

// TestUpgrade tests the upgrade function with various inputs for basic use cases
func TestUpgrade(t *testing.T) {
path := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"

testUpgrade(t, "example02", "0", "example02", "1", path, "", nil, nil)
testUpgrade(t, "example02", "0", "example02", "", path, EmptyVersionErr("example02").Error(), nil, nil)
Expand Down
12 changes: 6 additions & 6 deletions core/scc/vscc/validator_onevalidsignature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ func TestAlreadyDeployed(t *testing.T) {

ccname := "mycc"
ccver := "1"
path := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"

ppath := lccctestpath + "/" + ccname + "." + ccver

Expand Down Expand Up @@ -1160,7 +1160,7 @@ func TestValidateUpgradeOK(t *testing.T) {

ccname := "mycc"
ccver := "1"
path := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"

ppath := lccctestpath + "/" + ccname + "." + ccver

Expand Down Expand Up @@ -1241,7 +1241,7 @@ func TestInvalidateUpgradeBadVersion(t *testing.T) {

ccname := "mycc"
ccver := "1"
path := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"

ppath := lccctestpath + "/" + ccname + "." + ccver

Expand Down Expand Up @@ -1320,7 +1320,7 @@ func TestValidateUpgradeWithPoliciesOK(t *testing.T) {

ccname := "mycc"
ccver := "1"
path := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"

ppath := lccctestpath + "/" + ccname + "." + ccver

Expand Down Expand Up @@ -1421,7 +1421,7 @@ func validateUpgradeWithNewFailAllIP(t *testing.T, v11capability, expecterr bool

ccname := "mycc"
ccver := "1"
path := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"
ppath := lccctestpath + "/" + ccname + "." + ccver

os.Remove(ppath)
Expand Down Expand Up @@ -1515,7 +1515,7 @@ func TestValidateUpgradeWithPoliciesFail(t *testing.T) {

ccname := "mycc"
ccver := "1"
path := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"

ppath := lccctestpath + "/" + ccname + "." + ccver

Expand Down
2 changes: 1 addition & 1 deletion docs/source/chaincode4noah.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ To create a signed chaincode package, use the following command:

.. code:: bash
peer chaincode package -n mycc -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -v 0 -s -S -i "AND('OrgA.admin')" ccpack.out
peer chaincode package -n mycc -p github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd -v 0 -s -S -i "AND('OrgA.admin')" ccpack.out
The ``-s`` option creates a package that can be signed by multiple owners as
opposed to simply creating a raw CDS. When ``-s`` is specified, the ``-S``
Expand Down
8 changes: 4 additions & 4 deletions docs/source/commands/peerchaincode.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Here are some examples of the `peer chaincode install` command:
* To install chaincode named `mycc` at version `1.0`:

```
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd
.
.
Expand Down Expand Up @@ -411,7 +411,7 @@ Here are some examples of the `peer chaincode list ` command:
peer chaincode list --installed
Get installed chaincodes on peer:
Name: mycc, Version: 1.0, Path: github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02, Id: 8cc2730fdafd0b28ef734eac12b29df5fc98ad98bdb1b7e0ef96265c3d893d61
Name: mycc, Version: 1.0, Path: github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd, Id: 8cc2730fdafd0b28ef734eac12b29df5fc98ad98bdb1b7e0ef96265c3d893d61
2018-02-22 17:07:13.476 UTC [main] main -> INFO 001 Exiting.....
```
Expand All @@ -426,7 +426,7 @@ Here are some examples of the `peer chaincode list ` command:
peer chaincode list --instantiated -C mychannel
Get instantiated chaincodes on channel mychannel:
Name: mycc, Version: 1.0, Path: github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02, Escc: escc, Vscc: vscc
Name: mycc, Version: 1.0, Path: github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd, Escc: escc, Vscc: vscc
2018-02-22 17:07:42.969 UTC [main] main -> INFO 001 Exiting.....
```
Expand Down Expand Up @@ -510,7 +510,7 @@ deployment spec, signs the package using the local MSP, and outputs it as
`ccpack.out`:

* ```
peer chaincode package ccpack.out -n mycc -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -v 1.1 -s -S
peer chaincode package ccpack.out -n mycc -p github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd -v 1.1 -s -S
.
.
Expand Down
6 changes: 3 additions & 3 deletions docs/source/install_instantiate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ of ``v0`` onto ``peer0``.

.. code:: bash
CORE_PEER_ADDRESS=peer0:7051 peer chaincode install -n mycc -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -v v0
CORE_PEER_ADDRESS=peer0:7051 peer chaincode install -n mycc -p github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd -v v0
Instantiate the chaincode on the channel from the remote CLI
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -86,7 +86,7 @@ instantiation will initialize the chaincode with key value pairs of

.. code:: bash
CORE_PEER_ADDRESS=peer0:7051 peer chaincode instantiate -o orderer:5005 -C myc -n mycc -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -v v0 -c '{"Args":["init","a","100","b","200"]}'
CORE_PEER_ADDRESS=peer0:7051 peer chaincode instantiate -o orderer:5005 -C myc -n mycc -v v0 -c '{"Args":["init","a","100","b","200"]}'
**Continue operating within your second terminal for the remainder of
the commands**
Expand Down Expand Up @@ -132,7 +132,7 @@ read/write operations.

.. code:: bash
CORE_PEER_ADDRESS=peer1:7051 peer chaincode install -n mycc -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -v v0
CORE_PEER_ADDRESS=peer1:7051 peer chaincode install -n mycc -p github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd -v v0
| **Note**: The initial instantiation applies to all peers in the
channel, and is affected upon any peer that has the chaincode
Expand Down
8 changes: 4 additions & 4 deletions docs/source/peer-chaincode-devmode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ Start the chaincode

::

cd examples/chaincode/go/chaincode_example02
go build
CORE_CHAINCODE_LOGLEVEL=debug CORE_PEER_ADDRESS=127.0.0.1:7052 CORE_CHAINCODE_ID_NAME=mycc:0 ./chaincode_example02
cd examples/chaincode/go/chaincode_example02/cmd
go build -o example02
CORE_CHAINCODE_LOGLEVEL=debug CORE_PEER_ADDRESS=127.0.0.1:7052 CORE_CHAINCODE_ID_NAME=mycc:0 ./example02

The chaincode is started with peer and chaincode logs indicating successful registration with the peer.
Note that at this stage the chaincode is not associated with any channel. This is done in subsequent steps
Expand All @@ -84,7 +84,7 @@ mode.

::

peer chaincode install -n mycc -v 0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
peer chaincode install -n mycc -v 0 -p github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd

Once installed, the chaincode is ready to be instantiated.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Copyright IBM Corp. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache-2.0
*/

package main
package example01

import (
"fmt"
Expand All @@ -25,8 +15,7 @@ import (
)

// SimpleChaincode example simple Chaincode implementation
type SimpleChaincode struct {
}
type SimpleChaincode struct{}

var A, B string
var Aval, Bval, X int
Expand All @@ -53,19 +42,6 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
}
fmt.Printf("Aval = %d, Bval = %d\n", Aval, Bval)

/************
// Write the state to the ledger
err = stub.PutState(A, []byte(strconv.Itoa(Aval))
if err != nil {
return nil, err
}
stub.PutState(B, []byte(strconv.Itoa(Bval))
err = stub.PutState(B, []byte(strconv.Itoa(Bval))
if err != nil {
return nil, err
}
************/
return shim.Success(nil)
}

Expand Down Expand Up @@ -95,10 +71,3 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {

return shim.Error("Invalid invoke function name. Expecting \"invoke\"")
}

func main() {
err := shim.Start(new(SimpleChaincode))
if err != nil {
fmt.Printf("Error starting Simple chaincode: %s", err)
}
}
21 changes: 21 additions & 0 deletions examples/chaincode/go/example01/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package main

import (
"fmt"

"github.com/hyperledger/fabric/core/chaincode/shim"
"github.com/hyperledger/fabric/examples/chaincode/go/example01"
)

func main() {
err := shim.Start(new(example01.SimpleChaincode))
if err != nil {
fmt.Printf("Error starting Simple chaincode: %s", err)
}
}
Loading

0 comments on commit 621725f

Please sign in to comment.