Skip to content

Commit eb42d21

Browse files
Jason Yellickwlahti
authored andcommitted
FAB-10725 Add lifecycle SCC InstallChaincode func
This CR exposes the underlying peer function of persisting a chaincode to disk through the new lifecycle SCC. Makes #Done FAB-10725 Change-Id: Idab96e10a8f1377265b108087c7ed62c3ab641be Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent 46546b3 commit eb42d21

File tree

10 files changed

+710
-11
lines changed

10 files changed

+710
-11
lines changed

core/chaincode/lifecycle/lifecycle_suite_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ type packageParser interface {
3131
lifecycle.PackageParser
3232
}
3333

34+
//go:generate counterfeiter -o mock/scc_functions.go --fake-name SCCFunctions . sccFunctions
35+
type sccFunctions interface {
36+
lifecycle.SCCFunctions
37+
}
38+
3439
func TestLifecycle(t *testing.T) {
3540
RegisterFailHandler(Fail)
3641
RunSpecs(t, "Lifecycle Suite")

core/chaincode/lifecycle/mock/protobuf.go

Lines changed: 169 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/chaincode/lifecycle/mock/scc_functions.go

Lines changed: 108 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/chaincode/lifecycle/protobuf.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package lifecycle
8+
9+
import (
10+
"github.com/golang/protobuf/proto"
11+
12+
"github.com/pkg/errors"
13+
)
14+
15+
// Protobuf defines the subset of protobuf lifecycle needs and allows
16+
// for injection of mocked marshaling errors.
17+
type Protobuf interface {
18+
Marshal(msg proto.Message) (marshaled []byte, err error)
19+
Unmarshal(marshaled []byte, msg proto.Message) error
20+
}
21+
22+
// ProtobufImpl is the standard implementation to use for Protobuf
23+
type ProtobufImpl struct{}
24+
25+
// Marshal passes through to proto.Marshal
26+
func (p ProtobufImpl) Marshal(msg proto.Message) ([]byte, error) {
27+
res, err := proto.Marshal(msg)
28+
return res, errors.WithStack(err)
29+
}
30+
31+
// Unmarshal passes through to proto.Unmarshal
32+
func (p ProtobufImpl) Unmarshal(marshaled []byte, msg proto.Message) error {
33+
return errors.WithStack(proto.Unmarshal(marshaled, msg))
34+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package lifecycle_test
8+
9+
import (
10+
. "github.com/onsi/ginkgo"
11+
. "github.com/onsi/gomega"
12+
13+
"github.com/hyperledger/fabric/core/chaincode/lifecycle"
14+
lc "github.com/hyperledger/fabric/protos/peer/lifecycle"
15+
16+
"github.com/golang/protobuf/proto"
17+
)
18+
19+
var _ = Describe("ProtobufImpl", func() {
20+
var (
21+
pi *lifecycle.ProtobufImpl
22+
sampleMsg *lc.InstallChaincodeArgs
23+
)
24+
25+
BeforeEach(func() {
26+
pi = &lifecycle.ProtobufImpl{}
27+
sampleMsg = &lc.InstallChaincodeArgs{
28+
Name: "name",
29+
Version: "version",
30+
ChaincodeInstallPackage: []byte("install-package"),
31+
}
32+
})
33+
34+
Describe("Marshal", func() {
35+
It("passes through to the proto implementation", func() {
36+
res, err := pi.Marshal(sampleMsg)
37+
Expect(err).NotTo(HaveOccurred())
38+
39+
msg := &lc.InstallChaincodeArgs{}
40+
err = proto.Unmarshal(res, msg)
41+
Expect(err).NotTo(HaveOccurred())
42+
Expect(proto.Equal(msg, sampleMsg)).To(BeTrue())
43+
})
44+
})
45+
46+
Describe("Unmarshal", func() {
47+
It("passes through to the proto implementation", func() {
48+
res, err := proto.Marshal(sampleMsg)
49+
Expect(err).NotTo(HaveOccurred())
50+
51+
msg := &lc.InstallChaincodeArgs{}
52+
err = pi.Unmarshal(res, msg)
53+
Expect(err).NotTo(HaveOccurred())
54+
Expect(proto.Equal(msg, sampleMsg)).To(BeTrue())
55+
})
56+
})
57+
})

0 commit comments

Comments
 (0)