@@ -1386,6 +1386,71 @@ func TestChaincodeQueryChaincodeUsingInvoke(t *testing.T) {
1386
1386
theChaincodeSupport .Stop (ctxt , cccid2 , & pb.ChaincodeDeploymentSpec {ChaincodeSpec : spec2 })
1387
1387
}
1388
1388
1389
+ // Test the execution of a chaincode that invokes system chaincode
1390
+ // uses the "pthru" chaincode to query "lccc" for the "pthru" chaincode
1391
+ func TestChaincodeInvokesSystemChaincode (t * testing.T ) {
1392
+ chainID := util .GetTestChainID ()
1393
+
1394
+ lis , err := initPeer (chainID )
1395
+ if err != nil {
1396
+ t .Fail ()
1397
+ t .Logf ("Error creating peer: %s" , err )
1398
+ }
1399
+
1400
+ defer finitPeer (lis , chainID )
1401
+
1402
+ var ctxt = context .Background ()
1403
+
1404
+ var nextBlockNumber uint64
1405
+
1406
+ // Deploy second chaincode
1407
+ url := "github.com/hyperledger/fabric/examples/chaincode/go/passthru"
1408
+
1409
+ cID := & pb.ChaincodeID {Name : "pthru" , Path : url , Version : "0" }
1410
+ f := "init"
1411
+ args := util .ToChaincodeArgs (f )
1412
+
1413
+ spec := & pb.ChaincodeSpec {Type : 1 , ChaincodeId : cID , Input : & pb.ChaincodeInput {Args : args }}
1414
+
1415
+ cccid := ccprovider .NewCCContext (chainID , "pthru" , "0" , "" , false , nil , nil )
1416
+
1417
+ _ , err = deploy (ctxt , cccid , spec , nextBlockNumber )
1418
+ nextBlockNumber ++
1419
+ ccID := spec .ChaincodeId .Name
1420
+ if err != nil {
1421
+ t .Fail ()
1422
+ t .Logf ("Error initializing chaincode %s(%s)" , ccID , err )
1423
+ theChaincodeSupport .Stop (ctxt , cccid , & pb.ChaincodeDeploymentSpec {ChaincodeSpec : spec })
1424
+ return
1425
+ }
1426
+
1427
+ time .Sleep (time .Second )
1428
+
1429
+ //send an invoke to pass thru to query "lccc" system chaincode on chainID to get
1430
+ //information about "pthru"
1431
+ args = util .ToChaincodeArgs ("lccc/" + chainID , "getid" , chainID , "pthru" )
1432
+
1433
+ spec = & pb.ChaincodeSpec {Type : 1 , ChaincodeId : cID , Input : & pb.ChaincodeInput {Args : args }}
1434
+ // Invoke chaincode
1435
+ _ , _ , retval , err := invoke (ctxt , chainID , spec , nextBlockNumber )
1436
+
1437
+ if err != nil {
1438
+ t .Fail ()
1439
+ t .Logf ("Error invoking <%s>: %s" , ccID , err )
1440
+ theChaincodeSupport .Stop (ctxt , cccid , & pb.ChaincodeDeploymentSpec {ChaincodeSpec : spec })
1441
+ return
1442
+ }
1443
+
1444
+ if string (retval ) != "pthru" {
1445
+ t .Fail ()
1446
+ t .Logf ("Expected to get back \" pthru\" from lccc but got back %s" , string (retval ))
1447
+ theChaincodeSupport .Stop (ctxt , cccid , & pb.ChaincodeDeploymentSpec {ChaincodeSpec : spec })
1448
+ return
1449
+ }
1450
+
1451
+ theChaincodeSupport .Stop (ctxt , cccid , & pb.ChaincodeDeploymentSpec {ChaincodeSpec : spec })
1452
+ }
1453
+
1389
1454
var signer msp.SigningIdentity
1390
1455
1391
1456
func TestMain (m * testing.M ) {
0 commit comments