@@ -7,31 +7,32 @@ SPDX-License-Identifier: Apache-2.0
77package lifecycle_test
88
99import (
10- "github.com/golang/protobuf/proto"
11- "github.com/hyperledger/fabric/common/util"
1210 lc "github.com/hyperledger/fabric/core/chaincode/lifecycle"
1311 "github.com/hyperledger/fabric/core/chaincode/lifecycle/mock"
14- "github.com/hyperledger/fabric/core/chaincode/shim"
1512 "github.com/hyperledger/fabric/core/common/ccprovider"
1613 pb "github.com/hyperledger/fabric/protos/peer"
1714 . "github.com/onsi/ginkgo"
1815 . "github.com/onsi/gomega"
1916 "github.com/pkg/errors"
20- "golang.org/x/net/context"
2117)
2218
2319var _ = Describe ("Lifecycle" , func () {
2420 var (
25- lifecycle * lc.Lifecycle
21+ lifecycle * lc.Lifecycle
22+ fakeInstantiatedCCStore * mock.InstantiatedChaincodeStore
2623 )
2724
2825 BeforeEach (func () {
26+ fakeInstantiatedCCStore = & mock.InstantiatedChaincodeStore {}
27+
28+ lifecycle = & lc.Lifecycle {
29+ InstantiatedChaincodeStore : fakeInstantiatedCCStore ,
30+ }
2931 })
3032
3133 Describe ("ChaincodeContainerInfo" , func () {
3234 var (
33- fakeInstantiatedCCStore * mock.InstantiatedChaincodeStore
34- deploymentSpec * pb.ChaincodeDeploymentSpec
35+ deploymentSpec * pb.ChaincodeDeploymentSpec
3536 )
3637
3738 BeforeEach (func () {
@@ -47,12 +48,7 @@ var _ = Describe("Lifecycle", func() {
4748 ExecEnv : pb .ChaincodeDeploymentSpec_SYSTEM ,
4849 }
4950
50- fakeInstantiatedCCStore = & mock.InstantiatedChaincodeStore {}
5151 fakeInstantiatedCCStore .ChaincodeDeploymentSpecReturns (deploymentSpec , nil )
52-
53- lifecycle = & lc.Lifecycle {
54- InstantiatedChaincodeStore : fakeInstantiatedCCStore ,
55- }
5652 })
5753
5854 It ("invokes lscc getdepspec with the correct args" , func () {
@@ -85,94 +81,24 @@ var _ = Describe("Lifecycle", func() {
8581 Describe ("GetChaincodeDefinition" , func () {
8682 var (
8783 chaincodeData * ccprovider.ChaincodeData
88-
89- fakeExecutor * mock.Executor
90- signedProp * pb.SignedProposal
91- proposal * pb.Proposal
9284 )
9385
9486 BeforeEach (func () {
95- fakeExecutor = & mock.Executor {}
96- signedProp = & pb.SignedProposal {ProposalBytes : []byte ("some-proposal-bytes" )}
97- proposal = & pb.Proposal {Payload : []byte ("some-payload-bytes" )}
98-
99- lifecycle = & lc.Lifecycle {
100- Executor : fakeExecutor ,
101- }
102-
10387 chaincodeData = & ccprovider.ChaincodeData {
104- Name : "george" ,
105- Version : "old" ,
106- }
107- payload , err := proto .Marshal (chaincodeData )
108- Expect (err ).NotTo (HaveOccurred ())
109-
110- response := & pb.Response {
111- Status : shim .OK ,
112- Payload : payload ,
88+ Name : "chaincode-data-name" ,
11389 }
114- fakeExecutor .ExecuteReturns (response , nil , nil )
115- })
11690
117- It ("invokes lscc getccdata with the correct args" , func () {
118- cd , err := lifecycle .GetChaincodeDefinition (context .Background (), "tx-id" , signedProp , proposal , "chain-id" , "chaincode-id" )
119- Expect (err ).NotTo (HaveOccurred ())
120- Expect (cd ).To (Equal (chaincodeData ))
121-
122- Expect (fakeExecutor .ExecuteCallCount ()).To (Equal (1 ))
123- ctx , cccid , cis := fakeExecutor .ExecuteArgsForCall (0 )
124- Expect (ctx ).To (Equal (context .Background ()))
125- Expect (cccid ).To (Equal (ccprovider .NewCCContext ("chain-id" , "lscc" , "latest" , "tx-id" , true , signedProp , proposal )))
126- Expect (cis ).To (Equal (& pb.ChaincodeInvocationSpec {
127- ChaincodeSpec : & pb.ChaincodeSpec {
128- Type : pb .ChaincodeSpec_GOLANG ,
129- ChaincodeId : & pb.ChaincodeID {Name : "lscc" },
130- Input : & pb.ChaincodeInput {
131- Args : util .ToChaincodeArgs ("getccdata" , "chain-id" , "chaincode-id" ),
132- },
133- },
134- }))
91+ fakeInstantiatedCCStore .ChaincodeDefinitionReturns (chaincodeData , errors .New ("fake-error" ))
13592 })
13693
137- Context ("when the executor fails" , func () {
138- BeforeEach (func () {
139- fakeExecutor .ExecuteReturns (nil , nil , errors .New ("mango-tango" ))
140- })
141-
142- It ("returns a wrapped error" , func () {
143- _ , err := lifecycle .GetChaincodeDefinition (context .Background (), "tx-id" , signedProp , proposal , "chain-id" , "chaincode-id" )
144- Expect (err ).To (MatchError ("getccdata chain-id/chaincode-id failed: mango-tango" ))
145- })
146- })
147-
148- Context ("when the executor returns an error response" , func () {
149- BeforeEach (func () {
150- response := & pb.Response {
151- Status : shim .ERROR ,
152- Message : "danger-danger" ,
153- }
154- fakeExecutor .ExecuteReturns (response , nil , nil )
155- })
156-
157- It ("returns a wrapped error" , func () {
158- _ , err := lifecycle .GetChaincodeDefinition (context .Background (), "tx-id" , signedProp , proposal , "chain-id" , "chaincode-id" )
159- Expect (err ).To (MatchError ("getccdata chain-id/chaincode-id responded with error: danger-danger" ))
160- })
161- })
162-
163- Context ("when unmarshaling the response fails" , func () {
164- BeforeEach (func () {
165- response := & pb.Response {
166- Status : shim .OK ,
167- Payload : []byte ("totally-bogus-payload" ),
168- }
169- fakeExecutor .ExecuteReturns (response , nil , nil )
170- })
171-
172- It ("returns a wrapped error" , func () {
173- _ , err := lifecycle .GetChaincodeDefinition (context .Background (), "tx-id" , signedProp , proposal , "chain-id" , "chaincode-id" )
174- Expect (err ).To (MatchError (HavePrefix ("failed to unmarshal chaincode definition: proto: " )))
175- })
94+ It ("passes through to the underlying implementation" , func () {
95+ chaincodeDefinition , err := lifecycle .GetChaincodeDefinition ("foo" , nil )
96+ Expect (chaincodeDefinition .(* ccprovider.ChaincodeData )).To (Equal (chaincodeData ))
97+ Expect (err ).To (MatchError ("fake-error" ))
98+ Expect (fakeInstantiatedCCStore .ChaincodeDefinitionCallCount ()).To (Equal (1 ))
99+ ccNameArg , txSimArg := fakeInstantiatedCCStore .ChaincodeDefinitionArgsForCall (0 )
100+ Expect (ccNameArg ).To (Equal ("foo" ))
101+ Expect (txSimArg ).To (BeNil ())
176102 })
177103 })
178104})
0 commit comments