Skip to content

Commit e754582

Browse files
committed
[FAB-15420] Release interop tests for cc2cc invocations
Change-Id: I9af8ed408619cc2792b361a2813cfa8001d4608f Signed-off-by: Alessandro Sorniotti <ale.linux@sopit.net>
1 parent 4f1a7db commit e754582

File tree

6 files changed

+615
-0
lines changed

6 files changed

+615
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package callee
8+
9+
import (
10+
"github.com/hyperledger/fabric/core/chaincode/shim"
11+
pb "github.com/hyperledger/fabric/protos/peer"
12+
)
13+
14+
// CC example simple Chaincode implementation
15+
type CC struct {
16+
}
17+
18+
func (t *CC) Init(stub shim.ChaincodeStubInterface) pb.Response {
19+
err := stub.PutState("foo", []byte("foo"))
20+
if err != nil {
21+
return shim.Error(err.Error())
22+
}
23+
24+
return shim.Success(nil)
25+
}
26+
27+
func (t *CC) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
28+
fn, _ := stub.GetFunctionAndParameters()
29+
switch fn {
30+
case "INVOKE":
31+
err := stub.PutState("foo", []byte("bar"))
32+
if err != nil {
33+
return shim.Error(err.Error())
34+
}
35+
36+
return shim.Success(nil)
37+
case "QUERY":
38+
val, err := stub.GetState("foo")
39+
if err != nil {
40+
return shim.Error(err.Error())
41+
}
42+
43+
return shim.Success(val)
44+
default:
45+
return shim.Error("unknown function")
46+
}
47+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package main
8+
9+
import (
10+
"fmt"
11+
"os"
12+
13+
"github.com/hyperledger/fabric/core/chaincode/shim"
14+
"github.com/hyperledger/fabric/integration/e2e/lifecycle/chaincode/callee"
15+
)
16+
17+
func main() {
18+
err := shim.Start(&callee.CC{})
19+
if err != nil {
20+
fmt.Fprintf(os.Stderr, "Exiting callee chaincode: %s", err)
21+
os.Exit(2)
22+
}
23+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package caller
8+
9+
import (
10+
"github.com/hyperledger/fabric/core/chaincode/shim"
11+
pb "github.com/hyperledger/fabric/protos/peer"
12+
)
13+
14+
// CC example simple Chaincode implementation
15+
type CC struct {
16+
}
17+
18+
func (t *CC) Init(stub shim.ChaincodeStubInterface) pb.Response {
19+
err := stub.PutState("foo", []byte("foo"))
20+
if err != nil {
21+
return shim.Error(err.Error())
22+
}
23+
24+
return shim.Success(nil)
25+
}
26+
27+
func (t *CC) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
28+
fn, args := stub.GetFunctionAndParameters()
29+
switch fn {
30+
case "INVOKE":
31+
err := stub.PutState("foo", []byte("bar"))
32+
if err != nil {
33+
return shim.Error(err.Error())
34+
}
35+
36+
return stub.InvokeChaincode(string(args[0]), [][]byte{[]byte("INVOKE")}, "")
37+
case "QUERY":
38+
val, err := stub.GetState("foo")
39+
if err != nil {
40+
return shim.Error(err.Error())
41+
}
42+
43+
return shim.Success(val)
44+
default:
45+
return shim.Error("unknown function")
46+
}
47+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package main
8+
9+
import (
10+
"fmt"
11+
"os"
12+
13+
"github.com/hyperledger/fabric/core/chaincode/shim"
14+
"github.com/hyperledger/fabric/integration/e2e/lifecycle/chaincode/caller"
15+
)
16+
17+
func main() {
18+
err := shim.Start(&caller.CC{})
19+
if err != nil {
20+
fmt.Fprintf(os.Stderr, "Exiting caller chaincode: %s", err)
21+
os.Exit(2)
22+
}
23+
}

0 commit comments

Comments
 (0)