@@ -22,113 +22,74 @@ import (
22
22
23
23
var _ = Describe ("Lifecycle" , func () {
24
24
var (
25
- fakeExecutor * mock.Executor
26
- signedProp * pb.SignedProposal
27
- proposal * pb.Proposal
28
-
29
25
lifecycle * lc.Lifecycle
30
26
)
31
27
32
28
BeforeEach (func () {
33
- fakeExecutor = & mock.Executor {}
34
- signedProp = & pb.SignedProposal {ProposalBytes : []byte ("some-proposal-bytes" )}
35
- proposal = & pb.Proposal {Payload : []byte ("some-payload-bytes" )}
36
- lifecycle = & lc.Lifecycle {
37
- Executor : fakeExecutor ,
38
- }
39
29
})
40
30
41
31
Describe ("GetChaincodeDeploymentSpec" , func () {
42
- var deploymentSpec * pb.ChaincodeDeploymentSpec
32
+ var (
33
+ fakeInstantiatedCCStore * mock.InstantiatedChaincodeStore
34
+ deploymentSpec * pb.ChaincodeDeploymentSpec
35
+ )
43
36
44
37
BeforeEach (func () {
45
38
chaincodeID := & pb.ChaincodeID {Name : "chaincode-name" , Version : "chaincode-version" }
46
39
deploymentSpec = & pb.ChaincodeDeploymentSpec {
47
40
CodePackage : []byte ("code-package" ),
48
41
ChaincodeSpec : & pb.ChaincodeSpec {ChaincodeId : chaincodeID },
49
42
}
50
- deploymentSpecPayload , err := proto .Marshal (deploymentSpec )
51
- Expect (err ).NotTo (HaveOccurred ())
52
43
53
- response := & pb.Response {Status : shim .OK , Payload : deploymentSpecPayload }
54
- fakeExecutor .ExecuteReturns (response , nil , nil )
44
+ fakeInstantiatedCCStore = & mock.InstantiatedChaincodeStore {}
45
+ fakeInstantiatedCCStore .ChaincodeDeploymentSpecReturns (deploymentSpec , nil )
46
+
47
+ lifecycle = & lc.Lifecycle {
48
+ InstantiatedChaincodeStore : fakeInstantiatedCCStore ,
49
+ }
55
50
})
56
51
57
52
It ("invokes lscc getdepspec with the correct args" , func () {
58
- cds , err := lifecycle .GetChaincodeDeploymentSpec (context . Background (), "tx-id" , signedProp , proposal , " chain-id" , "chaincode-id " )
53
+ cds , err := lifecycle .GetChaincodeDeploymentSpec (" chain-id" , "chaincode-name " )
59
54
Expect (err ).NotTo (HaveOccurred ())
60
55
Expect (proto .Equal (cds , deploymentSpec )).To (BeTrue ())
61
56
62
- Expect (fakeExecutor .ExecuteCallCount ()).To (Equal (1 ))
63
- ctx , cccid , cis := fakeExecutor .ExecuteArgsForCall (0 )
64
- Expect (ctx ).To (Equal (context .Background ()))
65
- Expect (cccid ).To (Equal (ccprovider .NewCCContext ("chain-id" , "lscc" , "latest" , "tx-id" , true , signedProp , proposal )))
66
- Expect (cis ).To (Equal (& pb.ChaincodeInvocationSpec {
67
- ChaincodeSpec : & pb.ChaincodeSpec {
68
- Type : pb .ChaincodeSpec_GOLANG ,
69
- ChaincodeId : & pb.ChaincodeID {Name : "lscc" },
70
- Input : & pb.ChaincodeInput {
71
- Args : util .ToChaincodeArgs ("getdepspec" , "chain-id" , "chaincode-id" ),
72
- },
73
- },
74
- }))
75
- })
76
-
77
- Context ("when the executor fails" , func () {
78
- BeforeEach (func () {
79
- fakeExecutor .ExecuteReturns (nil , nil , errors .New ("mango-tango" ))
80
- })
81
-
82
- It ("returns a wrapped error" , func () {
83
- _ , err := lifecycle .GetChaincodeDeploymentSpec (context .Background (), "tx-id" , signedProp , proposal , "chain-id" , "chaincode-id" )
84
- Expect (err ).To (MatchError ("getdepspec chain-id/chaincode-id failed: mango-tango" ))
85
- })
86
- })
87
-
88
- Context ("when the executor returns an error response" , func () {
89
- BeforeEach (func () {
90
- response := & pb.Response {
91
- Status : shim .ERROR ,
92
- Message : "danger-danger" ,
93
- }
94
- fakeExecutor .ExecuteReturns (response , nil , nil )
95
- })
96
-
97
- It ("returns a wrapped error" , func () {
98
- _ , err := lifecycle .GetChaincodeDeploymentSpec (context .Background (), "tx-id" , signedProp , proposal , "chain-id" , "chaincode-id" )
99
- Expect (err ).To (MatchError ("getdepspec chain-id/chaincode-id responded with error: danger-danger" ))
100
- })
101
- })
102
-
103
- Context ("when the response contains a nil payload" , func () {
104
- BeforeEach (func () {
105
- response := & pb.Response {Status : shim .OK , Payload : nil }
106
- fakeExecutor .ExecuteReturns (response , nil , nil )
107
- })
108
-
109
- It ("returns a wrapped error" , func () {
110
- _ , err := lifecycle .GetChaincodeDeploymentSpec (context .Background (), "tx-id" , signedProp , proposal , "chain-id" , "chaincode-id" )
111
- Expect (err ).To (MatchError ("getdepspec chain-id/chaincode-id failed: payload is nil" ))
112
- })
57
+ Expect (fakeInstantiatedCCStore .ChaincodeDeploymentSpecCallCount ()).To (Equal (1 ))
58
+ channelID , chaincodeName := fakeInstantiatedCCStore .ChaincodeDeploymentSpecArgsForCall (0 )
59
+ Expect (channelID ).To (Equal ("chain-id" ))
60
+ Expect (chaincodeName ).To (Equal ("chaincode-name" ))
113
61
})
114
62
115
- Context ("when unmarshaling the payload fails" , func () {
63
+ Context ("when the instantiated chaincode store fails" , func () {
116
64
BeforeEach (func () {
117
- response := & pb.Response {Status : shim .OK , Payload : []byte ("bogus-payload" )}
118
- fakeExecutor .ExecuteReturns (response , nil , nil )
65
+ fakeInstantiatedCCStore .ChaincodeDeploymentSpecReturns (nil , errors .New ("mango-tango" ))
119
66
})
120
67
121
68
It ("returns a wrapped error" , func () {
122
- _ , err := lifecycle .GetChaincodeDeploymentSpec (context . Background (), "tx-id" , signedProp , proposal , "chain-id" , "chaincode-id" )
123
- Expect (err ).To (MatchError (HavePrefix ( "failed to unmarshal deployment spec payload for chain-id/chaincode-id" ) ))
69
+ _ , err := lifecycle .GetChaincodeDeploymentSpec ("chain-id" , "chaincode-id" )
70
+ Expect (err ).To (MatchError ("could not retrieve deployment spec for chain-id/chaincode-id: mango-tango" ))
124
71
})
125
72
})
126
73
})
127
74
128
75
Describe ("GetChaincodeDefinition" , func () {
129
- var chaincodeData * ccprovider.ChaincodeData
76
+ var (
77
+ chaincodeData * ccprovider.ChaincodeData
78
+
79
+ fakeExecutor * mock.Executor
80
+ signedProp * pb.SignedProposal
81
+ proposal * pb.Proposal
82
+ )
130
83
131
84
BeforeEach (func () {
85
+ fakeExecutor = & mock.Executor {}
86
+ signedProp = & pb.SignedProposal {ProposalBytes : []byte ("some-proposal-bytes" )}
87
+ proposal = & pb.Proposal {Payload : []byte ("some-payload-bytes" )}
88
+
89
+ lifecycle = & lc.Lifecycle {
90
+ Executor : fakeExecutor ,
91
+ }
92
+
132
93
chaincodeData = & ccprovider.ChaincodeData {
133
94
Name : "george" ,
134
95
Version : "old" ,
0 commit comments