@@ -20,7 +20,6 @@ import (
20
20
"archive/tar"
21
21
"bytes"
22
22
"compress/gzip"
23
- "errors"
24
23
"io/ioutil"
25
24
"path/filepath"
26
25
"testing"
@@ -70,27 +69,7 @@ func buildPackage(name string, path string, version string, initArgs [][]byte) (
70
69
}
71
70
72
71
type mockCCInfoFSStorageMgrImpl struct {
73
- CCMap map [string ]CCPackage
74
- putchaincodeErr bool
75
- }
76
-
77
- func (m * mockCCInfoFSStorageMgrImpl ) PutChaincode (depSpec * peer.ChaincodeDeploymentSpec ) (CCPackage , error ) {
78
- if m .putchaincodeErr {
79
- return nil , errors .New ("Error putting the chaincode" )
80
- }
81
-
82
- buf , err := proto .Marshal (depSpec )
83
- if err != nil {
84
- return nil , err
85
- }
86
- cccdspack := & CDSPackage {}
87
- if _ , err := cccdspack .InitFromBuffer (buf ); err != nil {
88
- return nil , err
89
- }
90
-
91
- m .CCMap [depSpec .ChaincodeSpec .ChaincodeId .Name + depSpec .ChaincodeSpec .ChaincodeId .Version ] = cccdspack
92
-
93
- return cccdspack , nil
72
+ CCMap map [string ]CCPackage
94
73
}
95
74
96
75
func (m * mockCCInfoFSStorageMgrImpl ) GetChaincode (ccname string , ccversion string ) (CCPackage , error ) {
@@ -109,7 +88,7 @@ func TestCCInfoCache(t *testing.T) {
109
88
// test the get side
110
89
111
90
// the cc data is not yet in the cache
112
- _ , err := cccache .GetChaincode (ccname , ccver )
91
+ _ , err := cccache .GetChaincodeData (ccname , ccver )
113
92
assert .Error (t , err )
114
93
115
94
// put it in the file system
@@ -118,11 +97,11 @@ func TestCCInfoCache(t *testing.T) {
118
97
ccinfoFs .CCMap [ccname + ccver ] = pack
119
98
120
99
// expect it to be in the cache now
121
- cd1 , err := cccache .GetChaincode (ccname , ccver )
100
+ cd1 , err := cccache .GetChaincodeData (ccname , ccver )
122
101
assert .NoError (t , err )
123
102
124
103
// it should still be in the cache
125
- cd2 , err := cccache .GetChaincode (ccname , ccver )
104
+ cd2 , err := cccache .GetChaincodeData (ccname , ccver )
126
105
assert .NoError (t , err )
127
106
128
107
// they are not null
@@ -131,21 +110,21 @@ func TestCCInfoCache(t *testing.T) {
131
110
132
111
// test the put side now..
133
112
ccver = "2.0"
134
-
135
- // create a dep spec to put
136
- ds , err := getDepSpec (ccname , ccpath , ccver , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )})
113
+ // put it in the file system
114
+ pack , err = buildPackage (ccname , ccpath , ccver , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )})
137
115
assert .NoError (t , err )
116
+ ccinfoFs .CCMap [ccname + ccver ] = pack
138
117
139
- // put it
140
- _ , err = cccache . PutChaincode ( ds )
118
+ // create a dep spec to put
119
+ _ , err = getDepSpec ( ccname , ccpath , ccver , [][] byte {[] byte ( "init" ), [] byte ( "a" ), [] byte ( "100" ), [] byte ( "b" ), [] byte ( "200" )} )
141
120
assert .NoError (t , err )
142
121
143
- // expect it to be in the cache
144
- cd1 , err = cccache .GetChaincode (ccname , ccver )
122
+ // expect it to be cached
123
+ cd1 , err = cccache .GetChaincodeData (ccname , ccver )
145
124
assert .NoError (t , err )
146
125
147
126
// it should still be in the cache
148
- cd2 , err = cccache .GetChaincode (ccname , ccver )
127
+ cd2 , err = cccache .GetChaincodeData (ccname , ccver )
149
128
assert .NoError (t , err )
150
129
151
130
// they are not null
@@ -159,36 +138,27 @@ func TestPutChaincode(t *testing.T) {
159
138
ccpath := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
160
139
161
140
ccinfoFs := & mockCCInfoFSStorageMgrImpl {CCMap : map [string ]CCPackage {}}
162
- cccache := NewCCInfoCache (ccinfoFs )
141
+ NewCCInfoCache (ccinfoFs )
163
142
164
143
// Error case 1: ccname is empty
165
144
// create a dep spec to put
166
- ds , err := getDepSpec (ccname , ccpath , ccver , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )})
145
+ _ , err := getDepSpec (ccname , ccpath , ccver , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )})
167
146
assert .NoError (t , err )
168
- _ , err = cccache .PutChaincode (ds )
169
- assert .Error (t , err )
170
- assert .Equal (t , "the chaincode name cannot be an empty string" , err .Error (), "Unexpected error received" )
171
147
172
148
// Error case 2: ccver is empty
173
149
ccname = "foo"
174
150
ccver = ""
175
- ds , err = getDepSpec (ccname , ccpath , ccver , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )})
151
+ _ , err = getDepSpec (ccname , ccpath , ccver , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )})
176
152
assert .NoError (t , err )
177
- _ , err = cccache .PutChaincode (ds )
178
- assert .Error (t , err )
179
- assert .Equal (t , "the chaincode version cannot be an empty string" , err .Error (), "Unexpected error received" )
180
153
181
154
// Error case 3: ccfs.PutChainCode returns an error
182
- ccinfoFs = & mockCCInfoFSStorageMgrImpl {CCMap : map [string ]CCPackage {}, putchaincodeErr : true }
183
- cccache = NewCCInfoCache (ccinfoFs )
155
+ ccinfoFs = & mockCCInfoFSStorageMgrImpl {CCMap : map [string ]CCPackage {}}
156
+ NewCCInfoCache (ccinfoFs )
184
157
185
158
ccname = "foo"
186
159
ccver = "1.0"
187
- ds , err = getDepSpec (ccname , ccpath , ccver , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )})
160
+ _ , err = getDepSpec (ccname , ccpath , ccver , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )})
188
161
assert .NoError (t , err )
189
- _ , err = cccache .PutChaincode (ds )
190
- assert .Error (t , err )
191
- assert .Contains (t , err .Error (), "PutChaincodeIntoFS failed" , "Unexpected error received" )
192
162
}
193
163
194
164
// here we test the peer's built-in cache after enabling it
@@ -208,44 +178,16 @@ func TestCCInfoFSPeerInstance(t *testing.T) {
208
178
// put it
209
179
err = PutChaincodeIntoFS (ds )
210
180
assert .NoError (t , err )
211
- }
212
-
213
- // here we test the peer's built-in cache after enabling it
214
- func TestCCInfoCachePeerInstance (t * testing.T ) {
215
- // enable the cache first: it's disabled by default
216
- EnableCCInfoCache ()
217
-
218
- ccname := "foo"
219
- ccver := "1.0"
220
- ccpath := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
221
-
222
- // the cc data is not yet in the cache
223
- _ , err := GetChaincodeFromFS (ccname , ccver )
224
- assert .Error (t , err )
225
-
226
- // create a dep spec to put
227
- ds , err := getDepSpec (ccname , ccpath , ccver , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )})
228
- assert .NoError (t , err )
229
-
230
- // put it
231
- err = PutChaincodeIntoFS (ds )
232
- assert .NoError (t , err )
233
-
234
- // Check if chain code package exists
235
- exists , err := ChaincodePackageExists (ccname , ccver )
236
- assert .NoError (t , err )
237
- assert .True (t , exists , "ChaincodePackageExists should have returned true for an existing package" )
238
181
239
182
// Get all installed chaincodes, it should not return 0 chain codes
240
183
resp , err := GetInstalledChaincodes ()
241
184
assert .NoError (t , err )
242
185
assert .NotNil (t , resp )
243
186
assert .NotZero (t , len (resp .Chaincodes ), "GetInstalledChaincodes should not have returned 0 chain codes" )
244
187
245
- // expect it to be in the cache
246
- cd , err := GetChaincodeFromFS (ccname , ccver )
188
+ //get chaincode data
189
+ _ , err = GetChaincodeData (ccname , ccver )
247
190
assert .NoError (t , err )
248
- assert .NotNil (t , cd )
249
191
}
250
192
251
193
func TestGetInstalledChaincodesErrorPaths (t * testing.T ) {
0 commit comments