@@ -624,9 +624,11 @@ func invokeExample02Transaction(ctxt context.Context, cccid *ccprovider.CCContex
624
624
}
625
625
626
626
const (
627
- chaincodeExample02GolangPath = "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
628
- chaincodeExample02JavaPath = "../../examples/chaincode/java/chaincode_example02"
629
- chaincodeExample06JavaPath = "../../examples/chaincode/java/chaincode_example06"
627
+ chaincodeExample02GolangPath = "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
628
+ chaincodeEventSenderGolangPath = "github.com/hyperledger/fabric/examples/chaincode/go/eventsender"
629
+ chaincodeExample02JavaPath = "../../examples/chaincode/java/chaincode_example02"
630
+ chaincodeExample06JavaPath = "../../examples/chaincode/java/chaincode_example06"
631
+ chaincodeEventSenderJavaPath = "../../examples/chaincode/java/eventsender"
630
632
)
631
633
632
634
func runChaincodeInvokeChaincode (t * testing.T , chainID1 string , chainID2 string , _ string ) (err error ) {
@@ -1307,66 +1309,86 @@ func TestQueries(t *testing.T) {
1307
1309
}
1308
1310
1309
1311
func TestGetEvent (t * testing.T ) {
1312
+
1313
+ testCases := []struct {
1314
+ chaincodeType pb.ChaincodeSpec_Type
1315
+ chaincodePath string
1316
+ }{
1317
+ {pb .ChaincodeSpec_GOLANG , chaincodeEventSenderGolangPath },
1318
+ {pb .ChaincodeSpec_JAVA , chaincodeEventSenderJavaPath },
1319
+ }
1320
+
1310
1321
chainID := util .GetTestChainID ()
1322
+ var nextBlockNumber uint64
1311
1323
1312
1324
lis , err := initPeer (chainID )
1313
1325
if err != nil {
1314
1326
t .Fail ()
1315
1327
t .Logf ("Error creating peer: %s" , err )
1316
1328
}
1317
1329
1330
+ nextBlockNumber ++
1331
+
1318
1332
defer finitPeer (lis , chainID )
1319
1333
1320
- var ctxt = context .Background ()
1334
+ for _ , tc := range testCases {
1335
+ t .Run (tc .chaincodeType .String (), func (t * testing.T ) {
1321
1336
1322
- url := "github.com/hyperledger/fabric/examples/chaincode/go/eventsender"
1337
+ if tc .chaincodeType == pb .ChaincodeSpec_JAVA && runtime .GOARCH != "amd64" {
1338
+ t .Skip ("No Java chaincode support yet on non-x86_64." )
1339
+ }
1323
1340
1324
- cID := & pb.ChaincodeID {Name : "esender" , Path : url , Version : "0" }
1325
- f := "init"
1326
- spec := & pb.ChaincodeSpec {Type : 1 , ChaincodeId : cID , Input : & pb.ChaincodeInput {Args : util .ToChaincodeArgs (f )}}
1341
+ var ctxt = context .Background ()
1327
1342
1328
- cccid := ccprovider .NewCCContext (chainID , "esender" , "0" , "" , false , nil , nil )
1329
- var nextBlockNumber uint64 = 1
1330
- _ , err = deploy (ctxt , cccid , spec , nextBlockNumber )
1331
- nextBlockNumber ++
1332
- ccID := spec .ChaincodeId .Name
1333
- if err != nil {
1334
- t .Fail ()
1335
- t .Logf ("Error initializing chaincode %s(%s)" , ccID , err )
1336
- theChaincodeSupport .Stop (ctxt , cccid , & pb.ChaincodeDeploymentSpec {ChaincodeSpec : spec })
1337
- return
1338
- }
1343
+ cID := & pb.ChaincodeID {Name : generateChaincodeName (tc .chaincodeType ), Path : tc .chaincodePath , Version : "0" }
1344
+ f := "init"
1345
+ spec := & pb.ChaincodeSpec {Type : tc .chaincodeType , ChaincodeId : cID , Input : & pb.ChaincodeInput {Args : util .ToChaincodeArgs (f )}}
1339
1346
1340
- time .Sleep (time .Second )
1347
+ cccid := ccprovider .NewCCContext (chainID , cID .Name , cID .Version , "" , false , nil , nil )
1348
+ _ , err = deploy (ctxt , cccid , spec , nextBlockNumber )
1349
+ nextBlockNumber ++
1350
+ ccID := spec .ChaincodeId .Name
1351
+ if err != nil {
1352
+ t .Fail ()
1353
+ t .Logf ("Error initializing chaincode %s(%s)" , ccID , err )
1354
+ theChaincodeSupport .Stop (ctxt , cccid , & pb.ChaincodeDeploymentSpec {ChaincodeSpec : spec })
1355
+ return
1356
+ }
1341
1357
1342
- args := util . ToChaincodeArgs ( "invoke" , "i" , "am" , "satoshi" )
1358
+ time . Sleep ( time . Second )
1343
1359
1344
- spec = & pb. ChaincodeSpec { Type : 1 , ChaincodeId : cID , Input : & pb. ChaincodeInput { Args : args }}
1360
+ args := util . ToChaincodeArgs ( "invoke" , "i" , "am" , "satoshi" )
1345
1361
1346
- var ccevt * pb.ChaincodeEvent
1347
- ccevt , _ , _ , err = invoke (ctxt , chainID , spec , nextBlockNumber , nil )
1362
+ spec = & pb.ChaincodeSpec {Type : 1 , ChaincodeId : cID , Input : & pb.ChaincodeInput {Args : args }}
1348
1363
1349
- if err != nil {
1350
- t .Logf ("Error invoking chaincode %s(%s)" , ccID , err )
1351
- t .Fail ()
1352
- }
1364
+ var ccevt * pb.ChaincodeEvent
1365
+ ccevt , _ , _ , err = invoke (ctxt , chainID , spec , nextBlockNumber , nil )
1366
+ nextBlockNumber ++
1353
1367
1354
- if ccevt = = nil {
1355
- t .Logf ("Error ccevt is nil %s(%s)" , ccID , err )
1356
- t .Fail ()
1357
- }
1368
+ if err ! = nil {
1369
+ t .Logf ("Error invoking chaincode %s(%s)" , ccID , err )
1370
+ t .Fail ()
1371
+ }
1358
1372
1359
- if ccevt . ChaincodeId != ccID {
1360
- t .Logf ("Error ccevt id(%s) != cid (%s)" , ccevt . ChaincodeId , ccID )
1361
- t .Fail ()
1362
- }
1373
+ if ccevt == nil {
1374
+ t .Logf ("Error ccevt is nil %s (%s)" , ccID , err )
1375
+ t .Fail ()
1376
+ }
1363
1377
1364
- if strings .Index (string (ccevt .Payload ), "i,am,satoshi" ) < 0 {
1365
- t .Logf ("Error expected event not found (%s)" , string (ccevt .Payload ))
1366
- t .Fail ()
1378
+ if ccevt .ChaincodeId != ccID {
1379
+ t .Logf ("Error ccevt id(%s) != cid(%s)" , ccevt .ChaincodeId , ccID )
1380
+ t .Fail ()
1381
+ }
1382
+
1383
+ if strings .Index (string (ccevt .Payload ), "i,am,satoshi" ) < 0 {
1384
+ t .Logf ("Error expected event not found (%s)" , string (ccevt .Payload ))
1385
+ t .Fail ()
1386
+ }
1387
+
1388
+ theChaincodeSupport .Stop (ctxt , cccid , & pb.ChaincodeDeploymentSpec {ChaincodeSpec : spec })
1389
+ })
1367
1390
}
1368
1391
1369
- theChaincodeSupport .Stop (ctxt , cccid , & pb.ChaincodeDeploymentSpec {ChaincodeSpec : spec })
1370
1392
}
1371
1393
1372
1394
// Test the execution of a chaincode that queries another chaincode
0 commit comments