@@ -1130,7 +1130,8 @@ func testValidationAndCommitOfOldPvtData(t *testing.T, env testEnv) {
1130
1130
v1 := []byte ("value1" )
1131
1131
// ns1-coll1-key1 should be rejected as it is updated in the future by Blk2Tx1
1132
1132
pvtDataBlk1Tx1 := producePvtdata (t , 1 , []string {"ns1:coll1" }, []string {"key1" }, [][]byte {v1 })
1133
- // ns1-coll2-key3 should be accepted but ns1-coll1-key2 as it is updated in the future by Blk2Tx2
1133
+ // ns1-coll2-key3 should be accepted but ns1-coll1-key2
1134
+ // should be rejected as it is updated in the future by Blk2Tx2
1134
1135
v2 := []byte ("value2" )
1135
1136
v3 := []byte ("value3" )
1136
1137
pvtDataBlk1Tx2 := producePvtdata (t , 2 , []string {"ns1:coll1" , "ns1:coll2" }, []string {"key2" , "key3" }, [][]byte {v2 , v3 })
@@ -1209,34 +1210,22 @@ func TestTxSimulatorMissingPvtdata(t *testing.T) {
1209
1210
updateBatch .PvtUpdates .Put ("ns1" , "coll1" , "key1" , []byte ("value1" ), version .NewHeight (1 , 1 ))
1210
1211
db .ApplyPrivacyAwareUpdates (updateBatch , version .NewHeight (1 , 1 ))
1211
1212
1212
- simulator , _ := txMgr .NewTxSimulator ("testTxid1" )
1213
- val , _ := simulator .GetPrivateData ("ns1" , "coll1" , "key1" )
1214
- assert .Equal (t , []byte ("value1" ), val )
1215
- simulator .Done ()
1213
+ assert .True (t , testPvtValueEqual (t , txMgr , "ns1" , "coll1" , "key1" , []byte ("value1" )))
1216
1214
1217
1215
updateBatch = privacyenabledstate .NewUpdateBatch ()
1218
1216
updateBatch .HashUpdates .Put ("ns1" , "coll1" , util .ComputeStringHash ("key1" ), util .ComputeStringHash ("value1" ), version .NewHeight (2 , 1 ))
1219
1217
updateBatch .HashUpdates .Put ("ns1" , "coll2" , util .ComputeStringHash ("key2" ), util .ComputeStringHash ("value2" ), version .NewHeight (2 , 1 ))
1220
1218
updateBatch .HashUpdates .Put ("ns1" , "coll3" , util .ComputeStringHash ("key3" ), util .ComputeStringHash ("value3" ), version .NewHeight (2 , 1 ))
1221
1219
updateBatch .PvtUpdates .Put ("ns1" , "coll3" , "key3" , []byte ("value3" ), version .NewHeight (2 , 1 ))
1222
1220
db .ApplyPrivacyAwareUpdates (updateBatch , version .NewHeight (2 , 1 ))
1223
- simulator , _ = txMgr .NewTxSimulator ("testTxid2" )
1224
- defer simulator .Done ()
1225
1221
1226
- val , err := simulator .GetPrivateData ("ns1" , "coll1" , "key1" )
1227
- _ , ok := err .(* txmgr.ErrPvtdataNotAvailable )
1228
- assert .True (t , ok )
1222
+ assert .False (t , testPvtKeyExist (t , txMgr , "ns1" , "coll1" , "key1" ))
1229
1223
1230
- val , err = simulator .GetPrivateData ("ns1" , "coll2" , "key2" )
1231
- _ , ok = err .(* txmgr.ErrPvtdataNotAvailable )
1232
- assert .True (t , ok )
1224
+ assert .False (t , testPvtKeyExist (t , txMgr , "ns1" , "coll2" , "key2" ))
1233
1225
1234
- val , err = simulator .GetPrivateData ("ns1" , "coll3" , "key3" )
1235
- assert .Equal (t , []byte ("value3" ), val )
1226
+ assert .True (t , testPvtValueEqual (t , txMgr , "ns1" , "coll3" , "key3" , []byte ("value3" )))
1236
1227
1237
- val , err = simulator .GetPrivateData ("ns1" , "coll4" , "key4" )
1238
- assert .NoError (t , err )
1239
- assert .Nil (t , val )
1228
+ assert .True (t , testPvtValueEqual (t , txMgr , "ns1" , "coll4" , "key4" , nil ))
1240
1229
}
1241
1230
1242
1231
func TestRemoveStaleAndCommitPvtDataOfOldBlocksWithExpiry (t * testing.T ) {
@@ -1258,7 +1247,6 @@ func TestRemoveStaleAndCommitPvtDataOfOldBlocksWithExpiry(t *testing.T) {
1258
1247
version .NewHeight (1 , 1 ),
1259
1248
)
1260
1249
1261
- viper .Set (fmt .Sprintf ("ledger.pvtdata.btlpolicy.%s.ns.coll" , ledgerid ), 1 )
1262
1250
bg , _ := testutil .NewBlockGenerator (t , ledgerid , false )
1263
1251
1264
1252
// storing hashed data but the pvt key is missing
@@ -1270,12 +1258,7 @@ func TestRemoveStaleAndCommitPvtDataOfOldBlocksWithExpiry(t *testing.T) {
1270
1258
assert .NoError (t , txMgr .Commit ())
1271
1259
1272
1260
// pvt data should not exist
1273
- simulator , _ := txMgr .NewTxSimulator ("tx-tmp" )
1274
- pvtval , err := simulator .GetPrivateData ("ns" , "coll" , "pvtkey1" )
1275
- _ , ok := err .(* txmgr.ErrPvtdataNotAvailable )
1276
- assert .Equal (t , ok , true )
1277
- assert .Nil (t , pvtval )
1278
- simulator .Done ()
1261
+ assert .False (t , testPvtKeyExist (t , txMgr , "ns" , "coll" , "pvtkey1" ))
1279
1262
1280
1263
// committing pvt data of block 1
1281
1264
v1 := []byte ("pvt-value1" )
@@ -1285,15 +1268,11 @@ func TestRemoveStaleAndCommitPvtDataOfOldBlocksWithExpiry(t *testing.T) {
1285
1268
pvtDataBlk1Tx1 ,
1286
1269
},
1287
1270
}
1288
- err = txMgr .RemoveStaleAndCommitPvtDataOfOldBlocks (blocksPvtData )
1271
+ err : = txMgr .RemoveStaleAndCommitPvtDataOfOldBlocks (blocksPvtData )
1289
1272
assert .NoError (t , err )
1290
1273
1291
1274
// pvt data should exist
1292
- simulator , _ = txMgr .NewTxSimulator ("tx-tmp" )
1293
- pvtval , err = simulator .GetPrivateData ("ns" , "coll" , "pvtkey1" )
1294
- assert .Nil (t , err )
1295
- assert .Equal (t , pvtval , v1 )
1296
- simulator .Done ()
1275
+ assert .True (t , testPvtValueEqual (t , txMgr , "ns" , "coll" , "pvtkey1" , v1 ))
1297
1276
1298
1277
// storing hashed data but the pvt key is missing
1299
1278
// stored pvt key would get expired and purged while committing block 4
@@ -1304,12 +1283,7 @@ func TestRemoveStaleAndCommitPvtDataOfOldBlocksWithExpiry(t *testing.T) {
1304
1283
assert .NoError (t , txMgr .Commit ())
1305
1284
1306
1285
// pvt data should not exist
1307
- simulator , _ = txMgr .NewTxSimulator ("tx-tmp" )
1308
- pvtval , err = simulator .GetPrivateData ("ns" , "coll" , "pvtkey2" )
1309
- _ , ok = err .(* txmgr.ErrPvtdataNotAvailable )
1310
- assert .Equal (t , ok , true )
1311
- assert .Nil (t , pvtval )
1312
- simulator .Done ()
1286
+ assert .False (t , testPvtKeyExist (t , txMgr , "ns" , "coll" , "pvtkey2" ))
1313
1287
1314
1288
blkAndPvtdata = prepareNextBlockForTest (t , txMgr , bg , "txid-3" ,
1315
1289
map [string ]string {"pubkey3" : "pub-value3" }, nil , false )
@@ -1333,23 +1307,34 @@ func TestRemoveStaleAndCommitPvtDataOfOldBlocksWithExpiry(t *testing.T) {
1333
1307
assert .NoError (t , err )
1334
1308
1335
1309
// pvt data should exist
1336
- simulator , _ = txMgr .NewTxSimulator ("tx-tmp" )
1337
- pvtval , err = simulator .GetPrivateData ("ns" , "coll" , "pvtkey2" )
1338
- assert .Nil (t , err )
1339
- assert .Equal (t , pvtval , v2 )
1340
- simulator .Done ()
1310
+ assert .True (t , testPvtValueEqual (t , txMgr , "ns" , "coll" , "pvtkey2" , v2 ))
1341
1311
1342
1312
blkAndPvtdata = prepareNextBlockForTest (t , txMgr , bg , "txid-4" ,
1343
1313
map [string ]string {"pubkey4" : "pub-value4" }, nil , false )
1344
1314
assert .NoError (t , txMgr .ValidateAndPrepare (blkAndPvtdata , true ))
1345
1315
// committing block 4 and should purge pvtkey2
1346
1316
assert .NoError (t , txMgr .Commit ())
1347
1317
1348
- simulator , _ = txMgr .NewTxSimulator ("tx-tmp" )
1349
- pvtval , err = simulator .GetPrivateData ("ns" , "coll" , "pvtkey2" )
1318
+ assert .True (t , testPvtValueEqual (t , txMgr , "ns" , "coll" , "pvtkey2" , nil ))
1319
+ }
1320
+
1321
+ func testPvtKeyExist (t * testing.T , txMgr txmgr.TxMgr , ns , coll , key string ) bool {
1322
+ simulator , _ := txMgr .NewTxSimulator ("tx-tmp" )
1323
+ defer simulator .Done ()
1324
+ _ , err := simulator .GetPrivateData (ns , coll , key )
1325
+ _ , ok := err .(* txmgr.ErrPvtdataNotAvailable )
1326
+ return ! ok
1327
+ }
1328
+
1329
+ func testPvtValueEqual (t * testing.T , txMgr txmgr.TxMgr , ns , coll , key string , value []byte ) bool {
1330
+ simulator , _ := txMgr .NewTxSimulator ("tx-tmp" )
1331
+ defer simulator .Done ()
1332
+ pvtValue , err := simulator .GetPrivateData (ns , coll , key )
1350
1333
assert .NoError (t , err )
1351
- assert .Nil (t , pvtval )
1352
- simulator .Done ()
1334
+ if bytes .Compare (pvtValue , value ) == 0 {
1335
+ return true
1336
+ }
1337
+ return false
1353
1338
}
1354
1339
1355
1340
func TestDeleteOnCursor (t * testing.T ) {
@@ -1422,31 +1407,21 @@ func TestTxSimulatorMissingPvtdataExpiry(t *testing.T) {
1422
1407
assert .NoError (t , txMgr .ValidateAndPrepare (blkAndPvtdata , true ))
1423
1408
assert .NoError (t , txMgr .Commit ())
1424
1409
1425
- simulator , _ := txMgr .NewTxSimulator ("tx-tmp" )
1426
- pvtval , err := simulator .GetPrivateData ("ns" , "coll" , "pvtkey1" )
1427
- assert .NoError (t , err )
1428
- assert .Equal (t , []byte ("pvt-value1" ), pvtval )
1429
- simulator .Done ()
1410
+ assert .True (t , testPvtValueEqual (t , txMgr , "ns" , "coll" , "pvtkey1" , []byte ("pvt-value1" )))
1430
1411
1431
1412
blkAndPvtdata = prepareNextBlockForTest (t , txMgr , bg , "txid-2" ,
1432
1413
map [string ]string {"pubkey1" : "pub-value2" }, map [string ]string {"pvtkey2" : "pvt-value2" }, false )
1433
1414
assert .NoError (t , txMgr .ValidateAndPrepare (blkAndPvtdata , true ))
1434
1415
assert .NoError (t , txMgr .Commit ())
1435
1416
1436
- simulator , _ = txMgr .NewTxSimulator ("tx-tmp" )
1437
- pvtval , _ = simulator .GetPrivateData ("ns" , "coll" , "pvtkey1" )
1438
- assert .Equal (t , []byte ("pvt-value1" ), pvtval )
1439
- simulator .Done ()
1417
+ assert .True (t , testPvtValueEqual (t , txMgr , "ns" , "coll" , "pvtkey1" , []byte ("pvt-value1" )))
1440
1418
1441
1419
blkAndPvtdata = prepareNextBlockForTest (t , txMgr , bg , "txid-2" ,
1442
1420
map [string ]string {"pubkey1" : "pub-value3" }, map [string ]string {"pvtkey3" : "pvt-value3" }, false )
1443
1421
assert .NoError (t , txMgr .ValidateAndPrepare (blkAndPvtdata , true ))
1444
1422
assert .NoError (t , txMgr .Commit ())
1445
1423
1446
- simulator , _ = txMgr .NewTxSimulator ("tx-tmp" )
1447
- pvtval , _ = simulator .GetPrivateData ("ns" , "coll" , "pvtkey1" )
1448
- assert .Nil (t , pvtval )
1449
- simulator .Done ()
1424
+ assert .True (t , testPvtValueEqual (t , txMgr , "ns" , "coll" , "pvtkey1" , nil ))
1450
1425
}
1451
1426
1452
1427
func TestTxWithPubMetadata (t * testing.T ) {
0 commit comments