@@ -91,6 +91,7 @@ func initPeer(chainIDs ...string) (net.Listener, error) {
91
91
RegisterSysCCs ()
92
92
93
93
for _ , id := range chainIDs {
94
+ deDeploySysCCs (id )
94
95
if err = peer .MockCreateChain (id ); err != nil {
95
96
closeListenerAndSleep (lis )
96
97
return nil , err
@@ -106,7 +107,7 @@ func initPeer(chainIDs ...string) (net.Listener, error) {
106
107
func finitPeer (lis net.Listener , chainIDs ... string ) {
107
108
if lis != nil {
108
109
for _ , c := range chainIDs {
109
- deRegisterSysCCs (c )
110
+ deDeploySysCCs (c )
110
111
if lgr := peer .GetLedger (c ); lgr != nil {
111
112
lgr .Close ()
112
113
}
@@ -263,7 +264,8 @@ func deploy2(ctx context.Context, cccid *CCContext, chaincodeDeploymentSpec *pb.
263
264
}
264
265
}()
265
266
266
- lcccid := NewCCContext (cccid .ChainID , cis .ChaincodeSpec .ChaincodeID .Name , "" , uuid , true , nil )
267
+ sysCCVers := util .GetSysCCVersion ()
268
+ lcccid := NewCCContext (cccid .ChainID , cis .ChaincodeSpec .ChaincodeID .Name , sysCCVers , uuid , true , nil )
267
269
268
270
//write to lccc
269
271
if _ , _ , err = Execute (ctx , lcccid , cis ); err != nil {
@@ -279,6 +281,11 @@ func deploy2(ctx context.Context, cccid *CCContext, chaincodeDeploymentSpec *pb.
279
281
280
282
// Invoke a chaincode.
281
283
func invoke (ctx context.Context , chainID string , spec * pb.ChaincodeSpec ) (ccevt * pb.ChaincodeEvent , uuid string , retval []byte , err error ) {
284
+ return invokeWithVersion (ctx , chainID , "0" , spec )
285
+ }
286
+
287
+ // Invoke a chaincode with version (needed for upgrade)
288
+ func invokeWithVersion (ctx context.Context , chainID string , version string , spec * pb.ChaincodeSpec ) (ccevt * pb.ChaincodeEvent , uuid string , retval []byte , err error ) {
282
289
chaincodeInvocationSpec := & pb.ChaincodeInvocationSpec {ChaincodeSpec : spec }
283
290
284
291
// Now create the Transactions message and send to Peer.
@@ -301,7 +308,7 @@ func invoke(ctx context.Context, chainID string, spec *pb.ChaincodeSpec) (ccevt
301
308
}
302
309
}()
303
310
304
- cccid := NewCCContext (chainID , chaincodeInvocationSpec .ChaincodeSpec .ChaincodeID .Name , "" , uuid , false , nil )
311
+ cccid := NewCCContext (chainID , chaincodeInvocationSpec .ChaincodeSpec .ChaincodeID .Name , version , uuid , false , nil )
305
312
retval , ccevt , err = Execute (ctx , cccid , chaincodeInvocationSpec )
306
313
if err != nil {
307
314
return nil , uuid , nil , fmt .Errorf ("Error invoking chaincode: %s " , err )
@@ -332,7 +339,7 @@ func executeDeployTransaction(t *testing.T, chainID string, name string, url str
332
339
args := util .ToChaincodeArgs (f , "a" , "100" , "b" , "200" )
333
340
spec := & pb.ChaincodeSpec {Type : 1 , ChaincodeID : & pb.ChaincodeID {Name : name , Path : url }, CtorMsg : & pb.ChaincodeInput {Args : args }}
334
341
335
- cccid := NewCCContext (chainID , name , "" , "" , false , nil )
342
+ cccid := NewCCContext (chainID , name , "0 " , "" , false , nil )
336
343
337
344
_ , err = deploy (ctxt , cccid , spec )
338
345
@@ -359,7 +366,7 @@ func chaincodeQueryChaincode(chainID string, user string) error {
359
366
360
367
spec1 := & pb.ChaincodeSpec {Type : 1 , ChaincodeID : cID1 , CtorMsg : & pb.ChaincodeInput {Args : args }, SecureContext : user }
361
368
362
- cccid1 := NewCCContext (chainID , "example02" , "" , "" , false , nil )
369
+ cccid1 := NewCCContext (chainID , "example02" , "0 " , "" , false , nil )
363
370
364
371
_ , err := deploy (ctxt , cccid1 , spec1 )
365
372
@@ -380,7 +387,7 @@ func chaincodeQueryChaincode(chainID string, user string) error {
380
387
381
388
spec2 := & pb.ChaincodeSpec {Type : 1 , ChaincodeID : cID2 , CtorMsg : & pb.ChaincodeInput {Args : args }, SecureContext : user }
382
389
383
- cccid2 := NewCCContext (chainID , "example05" , "" , "" , false , nil )
390
+ cccid2 := NewCCContext (chainID , "example05" , "0 " , "" , false , nil )
384
391
385
392
_ , err = deploy (ctxt , cccid2 , spec2 )
386
393
chaincodeID2 := spec2 .ChaincodeID .Name
@@ -479,32 +486,33 @@ func checkFinalState(cccid *CCContext) error {
479
486
480
487
defer txsim .Done ()
481
488
482
- canName := cccid .GetCanonicalName ()
489
+ cName := cccid .GetCanonicalName ()
490
+
483
491
// Invoke ledger to get state
484
492
var Aval , Bval int
485
- resbytes , resErr := txsim .GetState (canName , "a" )
493
+ resbytes , resErr := txsim .GetState (cccid . Name , "a" )
486
494
if resErr != nil {
487
- return fmt .Errorf ("Error retrieving state from ledger for <%s>: %s" , canName , resErr )
495
+ return fmt .Errorf ("Error retrieving state from ledger for <%s>: %s" , cName , resErr )
488
496
}
489
497
fmt .Printf ("Got string: %s\n " , string (resbytes ))
490
498
Aval , resErr = strconv .Atoi (string (resbytes ))
491
499
if resErr != nil {
492
- return fmt .Errorf ("Error retrieving state from ledger for <%s>: %s" , canName , resErr )
500
+ return fmt .Errorf ("Error retrieving state from ledger for <%s>: %s" , cName , resErr )
493
501
}
494
502
if Aval != 90 {
495
- return fmt .Errorf ("Incorrect result. Aval is wrong for <%s>" , canName )
503
+ return fmt .Errorf ("Incorrect result. Aval is wrong for <%s>" , cName )
496
504
}
497
505
498
- resbytes , resErr = txsim .GetState (canName , "b" )
506
+ resbytes , resErr = txsim .GetState (cccid . Name , "b" )
499
507
if resErr != nil {
500
- return fmt .Errorf ("Error retrieving state from ledger for <%s>: %s" , canName , resErr )
508
+ return fmt .Errorf ("Error retrieving state from ledger for <%s>: %s" , cName , resErr )
501
509
}
502
510
Bval , resErr = strconv .Atoi (string (resbytes ))
503
511
if resErr != nil {
504
- return fmt .Errorf ("Error retrieving state from ledger for <%s>: %s" , canName , resErr )
512
+ return fmt .Errorf ("Error retrieving state from ledger for <%s>: %s" , cName , resErr )
505
513
}
506
514
if Bval != 210 {
507
- return fmt .Errorf ("Incorrect result. Bval is wrong for <%s>" , canName )
515
+ return fmt .Errorf ("Incorrect result. Bval is wrong for <%s>" , cName )
508
516
}
509
517
510
518
// Success
@@ -576,7 +584,7 @@ func TestExecuteInvokeTransaction(t *testing.T) {
576
584
577
585
var ctxt = context .Background ()
578
586
579
- cccid := NewCCContext (chainID , "example02" , "" , "" , false , nil )
587
+ cccid := NewCCContext (chainID , "example02" , "0 " , "" , false , nil )
580
588
url := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
581
589
chaincodeID := & pb.ChaincodeID {Name : "example02" , Path : url }
582
590
@@ -642,7 +650,7 @@ func TestExecuteInvokeInvalidTransaction(t *testing.T) {
642
650
url := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
643
651
chaincodeID := & pb.ChaincodeID {Name : "example02" , Path : url }
644
652
645
- cccid := NewCCContext (chainID , "example02" , "" , "" , false , nil )
653
+ cccid := NewCCContext (chainID , "example02" , "0 " , "" , false , nil )
646
654
647
655
//FAIL, FAIL!
648
656
args := []string {"x" , "-1" }
@@ -699,7 +707,7 @@ func chaincodeInvokeChaincode(t *testing.T, chainID string, user string) (err er
699
707
700
708
spec1 := & pb.ChaincodeSpec {Type : 1 , ChaincodeID : cID1 , CtorMsg : & pb.ChaincodeInput {Args : args }, SecureContext : user }
701
709
702
- cccid1 := NewCCContext (chainID , "example02" , "" , "" , false , nil )
710
+ cccid1 := NewCCContext (chainID , "example02" , "0 " , "" , false , nil )
703
711
704
712
_ , err = deploy (ctxt , cccid1 , spec1 )
705
713
chaincodeID1 := spec1 .ChaincodeID .Name
@@ -723,7 +731,7 @@ func chaincodeInvokeChaincode(t *testing.T, chainID string, user string) (err er
723
731
724
732
spec2 := & pb.ChaincodeSpec {Type : 1 , ChaincodeID : cID2 , CtorMsg : & pb.ChaincodeInput {Args : args }, SecureContext : user }
725
733
726
- cccid2 := NewCCContext (chainID , "example04" , "" , "" , false , nil )
734
+ cccid2 := NewCCContext (chainID , "example04" , "0 " , "" , false , nil )
727
735
728
736
_ , err = deploy (ctxt , cccid2 , spec2 )
729
737
chaincodeID2 := spec2 .ChaincodeID .Name
@@ -798,7 +806,7 @@ func TestChaincodeInvokeChaincodeErrorCase(t *testing.T) {
798
806
799
807
spec1 := & pb.ChaincodeSpec {Type : 1 , ChaincodeID : cID1 , CtorMsg : & pb.ChaincodeInput {Args : args }}
800
808
801
- cccid1 := NewCCContext (chainID , "example02" , "" , "" , false , nil )
809
+ cccid1 := NewCCContext (chainID , "example02" , "0 " , "" , false , nil )
802
810
803
811
_ , err = deploy (ctxt , cccid1 , spec1 )
804
812
chaincodeID1 := spec1 .ChaincodeID .Name
@@ -820,7 +828,7 @@ func TestChaincodeInvokeChaincodeErrorCase(t *testing.T) {
820
828
821
829
spec2 := & pb.ChaincodeSpec {Type : 1 , ChaincodeID : cID2 , CtorMsg : & pb.ChaincodeInput {Args : args }}
822
830
823
- cccid2 := NewCCContext (chainID , "pthru" , "" , "" , false , nil )
831
+ cccid2 := NewCCContext (chainID , "pthru" , "0 " , "" , false , nil )
824
832
825
833
_ , err = deploy (ctxt , cccid2 , spec2 )
826
834
chaincodeID2 := spec2 .ChaincodeID .Name
@@ -887,7 +895,7 @@ func TestRangeQuery(t *testing.T) {
887
895
888
896
spec := & pb.ChaincodeSpec {Type : 1 , ChaincodeID : cID , CtorMsg : & pb.ChaincodeInput {Args : args }}
889
897
890
- cccid := NewCCContext (chainID , "tmap" , "" , "" , false , nil )
898
+ cccid := NewCCContext (chainID , "tmap" , "0 " , "" , false , nil )
891
899
892
900
_ , err = deploy (ctxt , cccid , spec )
893
901
chaincodeID := spec .ChaincodeID .Name
@@ -933,7 +941,7 @@ func TestGetEvent(t *testing.T) {
933
941
f := "init"
934
942
spec := & pb.ChaincodeSpec {Type : 1 , ChaincodeID : cID , CtorMsg : & pb.ChaincodeInput {Args : util .ToChaincodeArgs (f )}}
935
943
936
- cccid := NewCCContext (chainID , "esender" , "" , "" , false , nil )
944
+ cccid := NewCCContext (chainID , "esender" , "0 " , "" , false , nil )
937
945
938
946
_ , err = deploy (ctxt , cccid , spec )
939
947
chaincodeID := spec .ChaincodeID .Name
@@ -1002,7 +1010,7 @@ func TestChaincodeQueryChaincodeUsingInvoke(t *testing.T) {
1002
1010
1003
1011
spec1 := & pb.ChaincodeSpec {Type : 1 , ChaincodeID : cID1 , CtorMsg : & pb.ChaincodeInput {Args : args }}
1004
1012
1005
- cccid1 := NewCCContext (chainID , "example02" , "" , "" , false , nil )
1013
+ cccid1 := NewCCContext (chainID , "example02" , "0 " , "" , false , nil )
1006
1014
1007
1015
_ , err = deploy (ctxt , cccid1 , spec1 )
1008
1016
chaincodeID1 := spec1 .ChaincodeID .Name
@@ -1024,7 +1032,7 @@ func TestChaincodeQueryChaincodeUsingInvoke(t *testing.T) {
1024
1032
1025
1033
spec2 := & pb.ChaincodeSpec {Type : 1 , ChaincodeID : cID2 , CtorMsg : & pb.ChaincodeInput {Args : args }}
1026
1034
1027
- cccid2 := NewCCContext (chainID , "example05" , "" , "" , false , nil )
1035
+ cccid2 := NewCCContext (chainID , "example05" , "0 " , "" , false , nil )
1028
1036
1029
1037
_ , err = deploy (ctxt , cccid2 , spec2 )
1030
1038
chaincodeID2 := spec2 .ChaincodeID .Name
0 commit comments