@@ -39,7 +39,7 @@ import (
39
39
aclmocks "github.com/hyperledger/fabric/core/aclmgmt/mocks"
40
40
"github.com/hyperledger/fabric/core/chaincode/accesscontrol"
41
41
cm "github.com/hyperledger/fabric/core/chaincode/mock"
42
- "github.com/hyperledger/fabric/core/chaincode/persistence/intf"
42
+ persistence "github.com/hyperledger/fabric/core/chaincode/persistence/intf"
43
43
"github.com/hyperledger/fabric/core/chaincode/platforms"
44
44
"github.com/hyperledger/fabric/core/chaincode/platforms/golang"
45
45
"github.com/hyperledger/fabric/core/chaincode/shim"
@@ -49,11 +49,9 @@ import (
49
49
"github.com/hyperledger/fabric/core/container/dockercontroller"
50
50
"github.com/hyperledger/fabric/core/container/inproccontroller"
51
51
"github.com/hyperledger/fabric/core/ledger"
52
- "github.com/hyperledger/fabric/core/ledger/ledgerconfig"
53
52
"github.com/hyperledger/fabric/core/ledger/ledgermgmt"
54
53
ledgermock "github.com/hyperledger/fabric/core/ledger/mock"
55
54
cut "github.com/hyperledger/fabric/core/ledger/util"
56
- "github.com/hyperledger/fabric/core/ledger/util/couchdb"
57
55
cmp "github.com/hyperledger/fabric/core/mocks/peer"
58
56
"github.com/hyperledger/fabric/core/peer"
59
57
"github.com/hyperledger/fabric/core/policy"
@@ -214,26 +212,6 @@ func finitPeer(lis net.Listener, chainIDs ...string) {
214
212
ledgerPath := config .GetPath ("peer.fileSystemPath" )
215
213
os .RemoveAll (ledgerPath )
216
214
os .RemoveAll (filepath .Join (os .TempDir (), "hyperledger" ))
217
-
218
- //if couchdb is enabled, then cleanup the test couchdb
219
- if ledgerconfig .IsCouchDBEnabled () == true {
220
-
221
- chainID := util .GetTestChainID ()
222
-
223
- connectURL := viper .GetString ("ledger.state.couchDBConfig.couchDBAddress" )
224
- username := viper .GetString ("ledger.state.couchDBConfig.username" )
225
- password := viper .GetString ("ledger.state.couchDBConfig.password" )
226
- maxRetries := viper .GetInt ("ledger.state.couchDBConfig.maxRetries" )
227
- maxRetriesOnStartup := viper .GetInt ("ledger.state.couchDBConfig.maxRetriesOnStartup" )
228
- requestTimeout := viper .GetDuration ("ledger.state.couchDBConfig.requestTimeout" )
229
- createGlobalChangesDB := viper .GetBool ("ledger.state.couchDBConfig.createGlobalChangesDB" )
230
-
231
- couchInstance , _ := couchdb .CreateCouchInstance (connectURL , username , password , maxRetries , maxRetriesOnStartup , requestTimeout , createGlobalChangesDB , & disabled.Provider {})
232
- db := couchdb.CouchDatabase {CouchInstance : couchInstance , DBName : chainID }
233
- //drop the test database
234
- db .DropDatabase ()
235
-
236
- }
237
215
}
238
216
239
217
func startTxSimulation (chainID string , txid string ) (ledger.TxSimulator , ledger.HistoryQueryExecutor , error ) {
@@ -1267,164 +1245,6 @@ func TestQueries(t *testing.T) {
1267
1245
return
1268
1246
}
1269
1247
1270
- // ExecuteQuery supported only for CouchDB and
1271
- // query limits apply for CouchDB range and rich queries only
1272
- if ledgerconfig .IsCouchDBEnabled () == true {
1273
-
1274
- // corner cases for shim batching. currnt shim batch size is 100
1275
- // this query should return exactly 100 results (no call to Next())
1276
- f = "query"
1277
- args = util .ToChaincodeArgs (f , "{\" selector\" :{\" color\" :\" blue\" }}" )
1278
-
1279
- spec = & pb.ChaincodeSpec {Type : 1 , ChaincodeId : cID , Input : & pb.ChaincodeInput {Args : args }}
1280
- _ , _ , _ , err = invoke (chainID , spec , nextBlockNumber , nil , chaincodeSupport )
1281
- nextBlockNumber ++
1282
-
1283
- if err != nil {
1284
- t .Fail ()
1285
- t .Logf ("Error invoking <%s>: %s" , ccID , err )
1286
- return
1287
- }
1288
-
1289
- //unmarshal the results
1290
- err = json .Unmarshal (retval , & keys )
1291
-
1292
- //check to see if there are 100 values
1293
- if len (keys ) != 100 {
1294
- t .Fail ()
1295
- t .Logf ("Error detected with the rich query, should have returned 100 but returned %v %s" , len (keys ), keys )
1296
- return
1297
- }
1298
- //Reset the query limit to 5
1299
- viper .Set ("ledger.state.queryLimit" , 5 )
1300
-
1301
- //The following range query for "marble01" to "marble11" should return 5 marbles due to the queryLimit
1302
- f = "keys"
1303
- args = util .ToChaincodeArgs (f , "marble001" , "marble011" )
1304
-
1305
- spec = & pb.ChaincodeSpec {Type : 1 , ChaincodeId : cID , Input : & pb.ChaincodeInput {Args : args }}
1306
- _ , _ , retval , err := invoke (chainID , spec , nextBlockNumber , nil , chaincodeSupport )
1307
- nextBlockNumber ++
1308
- if err != nil {
1309
- t .Fail ()
1310
- t .Logf ("Error invoking <%s>: %s" , ccID , err )
1311
- return
1312
- }
1313
-
1314
- //unmarshal the results
1315
- err = json .Unmarshal (retval , & keys )
1316
- //check to see if there are 5 values
1317
- if len (keys ) != 5 {
1318
- t .Fail ()
1319
- t .Logf ("Error detected with the range query, should have returned 5 but returned %v" , len (keys ))
1320
- return
1321
- }
1322
-
1323
- //Reset the query limit to 10000
1324
- viper .Set ("ledger.state.queryLimit" , 10000 )
1325
-
1326
- //The following rich query for should return 50 marbles
1327
- f = "query"
1328
- args = util .ToChaincodeArgs (f , "{\" selector\" :{\" owner\" :\" jerry\" }}" )
1329
-
1330
- spec = & pb.ChaincodeSpec {Type : 1 , ChaincodeId : cID , Input : & pb.ChaincodeInput {Args : args }}
1331
- _ , _ , retval , err = invoke (chainID , spec , nextBlockNumber , nil , chaincodeSupport )
1332
- nextBlockNumber ++
1333
-
1334
- if err != nil {
1335
- t .Fail ()
1336
- t .Logf ("Error invoking <%s>: %s" , ccID , err )
1337
- return
1338
- }
1339
-
1340
- //unmarshal the results
1341
- err = json .Unmarshal (retval , & keys )
1342
-
1343
- //check to see if there are 50 values
1344
- //default query limit of 10000 is used, this query is effectively unlimited
1345
- if len (keys ) != 50 {
1346
- t .Fail ()
1347
- t .Logf ("Error detected with the rich query, should have returned 50 but returned %v" , len (keys ))
1348
- return
1349
- }
1350
-
1351
- //Reset the query limit to 5
1352
- viper .Set ("ledger.state.queryLimit" , 5 )
1353
-
1354
- //The following rich query should return 5 marbles due to the queryLimit
1355
- f = "query"
1356
- args = util .ToChaincodeArgs (f , "{\" selector\" :{\" owner\" :\" jerry\" }}" )
1357
-
1358
- spec = & pb.ChaincodeSpec {Type : 1 , ChaincodeId : cID , Input : & pb.ChaincodeInput {Args : args }}
1359
- _ , _ , retval , err = invoke (chainID , spec , nextBlockNumber , nil , chaincodeSupport )
1360
- nextBlockNumber ++
1361
- if err != nil {
1362
- t .Fail ()
1363
- t .Logf ("Error invoking <%s>: %s" , ccID , err )
1364
- return
1365
- }
1366
-
1367
- //unmarshal the results
1368
- err = json .Unmarshal (retval , & keys )
1369
-
1370
- //check to see if there are 5 values
1371
- if len (keys ) != 5 {
1372
- t .Fail ()
1373
- t .Logf ("Error detected with the rich query, should have returned 5 but returned %v" , len (keys ))
1374
- return
1375
- }
1376
-
1377
- //The following rich query should return 2 marbles due to the pagesize
1378
- f = "queryByPage"
1379
- args = util .ToChaincodeArgs (f , "{\" selector\" :{\" owner\" :\" jerry\" }}" , "2" , "" )
1380
-
1381
- spec = & pb.ChaincodeSpec {Type : 1 , ChaincodeId : cID , Input : & pb.ChaincodeInput {Args : args }}
1382
- _ , _ , retval , err = invoke (chainID , spec , nextBlockNumber , nil , chaincodeSupport )
1383
- nextBlockNumber ++
1384
- if err != nil {
1385
- t .Fail ()
1386
- t .Logf ("Error invoking <%s>: %s" , ccID , err )
1387
- return
1388
- }
1389
-
1390
- queryPage := & PageResponse {}
1391
-
1392
- json .Unmarshal (retval , & queryPage )
1393
-
1394
- expectedResult := []string {"marble001" , "marble003" }
1395
-
1396
- if ! reflect .DeepEqual (expectedResult , queryPage .Keys ) {
1397
- t .Fail ()
1398
- t .Logf ("Error detected with the paginated range query. Returned: %v should have returned: %v" , queryPage .Keys , expectedResult )
1399
- return
1400
- }
1401
-
1402
- // set args for the next page
1403
- args = util .ToChaincodeArgs (f , "{\" selector\" :{\" owner\" :\" jerry\" }}" , "2" , queryPage .Bookmark )
1404
-
1405
- spec = & pb.ChaincodeSpec {Type : 1 , ChaincodeId : cID , Input : & pb.ChaincodeInput {Args : args }}
1406
- _ , _ , retval , err = invoke (chainID , spec , nextBlockNumber , nil , chaincodeSupport )
1407
- nextBlockNumber ++
1408
- if err != nil {
1409
- t .Fail ()
1410
- t .Logf ("Error invoking <%s>: %s" , ccID , err )
1411
- return
1412
- }
1413
-
1414
- queryPage = & PageResponse {}
1415
-
1416
- json .Unmarshal (retval , & queryPage )
1417
-
1418
- expectedResult = []string {"marble005" , "marble007" }
1419
-
1420
- if ! reflect .DeepEqual (expectedResult , queryPage .Keys ) {
1421
- t .Fail ()
1422
- t .Logf ("Error detected with the paginated range query. Returned: %v should have returned: %v" , queryPage .Keys , expectedResult )
1423
- return
1424
- }
1425
-
1426
- }
1427
-
1428
1248
// modifications for history query
1429
1249
f = "put"
1430
1250
args = util .ToChaincodeArgs (f , "marble012" , "{\" docType\" :\" marble\" ,\" name\" :\" marble012\" ,\" color\" :\" red\" ,\" size\" :30,\" owner\" :\" jerry\" }" )
0 commit comments