@@ -53,16 +53,18 @@ func register(stub *shim.MockStub, ccname string) error {
53
53
return nil
54
54
}
55
55
56
- func constructDeploymentSpec (name string , path string , version string , initArgs [][]byte ) (* pb.ChaincodeDeploymentSpec , error ) {
56
+ func constructDeploymentSpec (name string , path string , version string , initArgs [][]byte , createFS bool ) (* pb.ChaincodeDeploymentSpec , error ) {
57
57
spec := & pb.ChaincodeSpec {Type : 1 , ChaincodeId : & pb.ChaincodeID {Name : name , Path : path , Version : version }, Input : & pb.ChaincodeInput {Args : initArgs }}
58
58
59
59
codePackageBytes := []byte (name + path + version )
60
60
61
61
chaincodeDeploymentSpec := & pb.ChaincodeDeploymentSpec {ChaincodeSpec : spec , CodePackage : codePackageBytes }
62
62
63
- err := ccprovider .PutChaincodeIntoFS (chaincodeDeploymentSpec )
64
- if err != nil {
65
- return nil , err
63
+ if createFS {
64
+ err := ccprovider .PutChaincodeIntoFS (chaincodeDeploymentSpec )
65
+ if err != nil {
66
+ return nil , err
67
+ }
66
68
}
67
69
68
70
return chaincodeDeploymentSpec , nil
@@ -78,8 +80,8 @@ func TestDeploy(t *testing.T) {
78
80
t .FailNow ()
79
81
}
80
82
81
- cds , err := constructDeploymentSpec ("example02" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "0" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )})
82
- defer os .Remove (lccctestpath + "/chaincodes/ example02.0" )
83
+ cds , err := constructDeploymentSpec ("example02" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "0" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )}, true )
84
+ defer os .Remove (lccctestpath + "/example02.0" )
83
85
var b []byte
84
86
if b , err = proto .Marshal (cds ); err != nil || b == nil {
85
87
t .FailNow ()
@@ -91,6 +93,55 @@ func TestDeploy(t *testing.T) {
91
93
}
92
94
}
93
95
96
+ //TestInstall tests the install function
97
+ func TestInstall (t * testing.T ) {
98
+ scc := new (LifeCycleSysCC )
99
+ stub := shim .NewMockStub ("lccc" , scc )
100
+
101
+ if res := stub .MockInit ("1" , nil ); res .Status != shim .OK {
102
+ fmt .Println ("Init failed" , string (res .Message ))
103
+ t .FailNow ()
104
+ }
105
+
106
+ cds , err := constructDeploymentSpec ("example02" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "0" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )}, false )
107
+ var b []byte
108
+ if b , err = proto .Marshal (cds ); err != nil || b == nil {
109
+ t .FailNow ()
110
+ }
111
+
112
+ //constructDeploymentSpec puts the depspec on the FS. This should fail
113
+ args := [][]byte {[]byte (INSTALL ), b }
114
+ defer os .Remove (lccctestpath + "/example02.0" )
115
+ if res := stub .MockInvoke ("1" , args ); res .Status != shim .OK {
116
+ t .FailNow ()
117
+ }
118
+ }
119
+
120
+ //TestReinstall tests the install function
121
+ func TestReinstall (t * testing.T ) {
122
+ scc := new (LifeCycleSysCC )
123
+ stub := shim .NewMockStub ("lccc" , scc )
124
+
125
+ if res := stub .MockInit ("1" , nil ); res .Status != shim .OK {
126
+ fmt .Println ("Init failed" , string (res .Message ))
127
+ t .FailNow ()
128
+ }
129
+
130
+ //note that this puts the code on the filesyste....
131
+ cds , err := constructDeploymentSpec ("example02" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "0" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )}, true )
132
+ defer os .Remove (lccctestpath + "/example02.0" )
133
+ var b []byte
134
+ if b , err = proto .Marshal (cds ); err != nil || b == nil {
135
+ t .FailNow ()
136
+ }
137
+
138
+ //constructDeploymentSpec puts the depspec on the FS. This should fail
139
+ args := [][]byte {[]byte (INSTALL ), b }
140
+ if res := stub .MockInvoke ("1" , args ); res .Status == shim .OK {
141
+ t .FailNow ()
142
+ }
143
+ }
144
+
94
145
//TestInvalidCodeDeploy tests the deploy function with invalid code package
95
146
func TestInvalidCodeDeploy (t * testing.T ) {
96
147
scc := new (LifeCycleSysCC )
@@ -121,8 +172,11 @@ func TestInvalidChaincodeName(t *testing.T) {
121
172
t .FailNow ()
122
173
}
123
174
124
- cds , err := constructDeploymentSpec ("example02" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "0" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )})
125
- defer os .Remove (lccctestpath + "/chaincodes/example02.0" )
175
+ cds , err := constructDeploymentSpec ("example02" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "0" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )}, true )
176
+ defer os .Remove (lccctestpath + "/example02.0" )
177
+ if err != nil {
178
+ t .FailNow ()
179
+ }
126
180
127
181
//change name to empty
128
182
cds .ChaincodeSpec .ChaincodeId .Name = ""
@@ -150,8 +204,11 @@ func TestEmptyChaincodeVersion(t *testing.T) {
150
204
t .FailNow ()
151
205
}
152
206
153
- cds , err := constructDeploymentSpec ("example02" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "0" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )})
154
- defer os .Remove (lccctestpath + "/chaincodes/example02.0" )
207
+ cds , err := constructDeploymentSpec ("example02" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "0" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )}, true )
208
+ defer os .Remove (lccctestpath + "/example02.0" )
209
+ if err != nil {
210
+ t .FailNow ()
211
+ }
155
212
156
213
//change version to empty
157
214
cds .ChaincodeSpec .ChaincodeId .Version = ""
@@ -179,8 +236,8 @@ func TestRedeploy(t *testing.T) {
179
236
t .FailNow ()
180
237
}
181
238
182
- cds , err := constructDeploymentSpec ("example02" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "0" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )})
183
- defer os .Remove (lccctestpath + "/chaincodes/ example02.0" )
239
+ cds , err := constructDeploymentSpec ("example02" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "0" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )}, true )
240
+ defer os .Remove (lccctestpath + "/example02.0" )
184
241
var b []byte
185
242
if b , err = proto .Marshal (cds ); err != nil || b == nil {
186
243
t .FailNow ()
@@ -209,8 +266,8 @@ func TestCheckCC(t *testing.T) {
209
266
t .FailNow ()
210
267
}
211
268
212
- cds , err := constructDeploymentSpec ("example02" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "0" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )})
213
- defer os .Remove (lccctestpath + "/chaincodes/ example02.0" )
269
+ cds , err := constructDeploymentSpec ("example02" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "0" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )}, true )
270
+ defer os .Remove (lccctestpath + "/example02.0" )
214
271
215
272
var b []byte
216
273
if b , err = proto .Marshal (cds ); err != nil || b == nil {
@@ -228,7 +285,7 @@ func TestCheckCC(t *testing.T) {
228
285
}
229
286
}
230
287
231
- //TestMultipleDeploy tests deploying multiple chaincodes
288
+ //TestMultipleDeploy tests deploying multiple chaincodeschaincodes
232
289
func TestMultipleDeploy (t * testing.T ) {
233
290
scc := new (LifeCycleSysCC )
234
291
stub := shim .NewMockStub ("lccc" , scc )
@@ -239,8 +296,8 @@ func TestMultipleDeploy(t *testing.T) {
239
296
}
240
297
241
298
//deploy 02
242
- cds , err := constructDeploymentSpec ("example02" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "0" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )})
243
- defer os .Remove (lccctestpath + "/chaincodes/ example02.0" )
299
+ cds , err := constructDeploymentSpec ("example02" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "0" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )}, true )
300
+ defer os .Remove (lccctestpath + "/example02.0" )
244
301
var b []byte
245
302
if b , err = proto .Marshal (cds ); err != nil || b == nil {
246
303
t .FailNow ()
@@ -257,8 +314,8 @@ func TestMultipleDeploy(t *testing.T) {
257
314
}
258
315
259
316
//deploy 01
260
- cds , err = constructDeploymentSpec ("example01" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example01" , "0" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )})
261
- defer os .Remove (lccctestpath + "/chaincodes/ example01.0" )
317
+ cds , err = constructDeploymentSpec ("example01" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example01" , "0" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )}, true )
318
+ defer os .Remove (lccctestpath + "/example01.0" )
262
319
if b , err = proto .Marshal (cds ); err != nil || b == nil {
263
320
t .FailNow ()
264
321
}
@@ -285,8 +342,8 @@ func TestRetryFailedDeploy(t *testing.T) {
285
342
}
286
343
287
344
//deploy 02
288
- cds , err := constructDeploymentSpec ("example02" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "0" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )})
289
- defer os .Remove (lccctestpath + "/chaincodes/ example02.0" )
345
+ cds , err := constructDeploymentSpec ("example02" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "0" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )}, true )
346
+ defer os .Remove (lccctestpath + "/example02.0" )
290
347
var b []byte
291
348
if b , err = proto .Marshal (cds ); err != nil || b == nil {
292
349
t .FailNow ()
@@ -328,8 +385,8 @@ func TestUpgrade(t *testing.T) {
328
385
t .FailNow ()
329
386
}
330
387
331
- cds , err := constructDeploymentSpec ("example02" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "0" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )})
332
- defer os .Remove (lccctestpath + "/chaincodes/ example02.0" )
388
+ cds , err := constructDeploymentSpec ("example02" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "0" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )}, true )
389
+ defer os .Remove (lccctestpath + "/example02.0" )
333
390
var b []byte
334
391
if b , err = proto .Marshal (cds ); err != nil || b == nil {
335
392
t .Fatalf ("Marshal DeploymentSpec failed" )
@@ -340,8 +397,8 @@ func TestUpgrade(t *testing.T) {
340
397
t .Fatalf ("Deploy chaincode error: %v" , err )
341
398
}
342
399
343
- newCds , err := constructDeploymentSpec ("example02" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "1" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )})
344
- defer os .Remove (lccctestpath + "/chaincodes/ example02.1" )
400
+ newCds , err := constructDeploymentSpec ("example02" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "1" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )}, true )
401
+ defer os .Remove (lccctestpath + "/example02.1" )
345
402
var newb []byte
346
403
if newb , err = proto .Marshal (newCds ); err != nil || newb == nil {
347
404
t .Fatalf ("Marshal DeploymentSpec failed" )
@@ -370,8 +427,8 @@ func TestUpgradeNonExistChaincode(t *testing.T) {
370
427
t .FailNow ()
371
428
}
372
429
373
- cds , err := constructDeploymentSpec ("example02" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "0" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )})
374
- defer os .Remove (lccctestpath + "/chaincodes/ example02.0" )
430
+ cds , err := constructDeploymentSpec ("example02" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "0" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )}, true )
431
+ defer os .Remove (lccctestpath + "/example02.0" )
375
432
var b []byte
376
433
if b , err = proto .Marshal (cds ); err != nil || b == nil {
377
434
t .Fatalf ("Marshal DeploymentSpec failed" )
@@ -382,8 +439,8 @@ func TestUpgradeNonExistChaincode(t *testing.T) {
382
439
t .Fatalf ("Deploy chaincode error: %s" , res .Message )
383
440
}
384
441
385
- newCds , err := constructDeploymentSpec ("example03" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "1" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )})
386
- defer os .Remove (lccctestpath + "/chaincodes/ example03.1" )
442
+ newCds , err := constructDeploymentSpec ("example03" , "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" , "1" , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )}, true )
443
+ defer os .Remove (lccctestpath + "/example03.1" )
387
444
var newb []byte
388
445
if newb , err = proto .Marshal (newCds ); err != nil || newb == nil {
389
446
t .Fatalf ("Marshal DeploymentSpec failed" )
0 commit comments