@@ -20,7 +20,10 @@ import (
20
20
"github.com/hyperledger/fabric/core/ledger/pvtdatapolicy"
21
21
btltestutil "github.com/hyperledger/fabric/core/ledger/pvtdatapolicy/testutil"
22
22
"github.com/hyperledger/fabric/core/ledger/pvtdatastorage"
23
+ lutil "github.com/hyperledger/fabric/core/ledger/util"
24
+ "github.com/hyperledger/fabric/protos/common"
23
25
"github.com/hyperledger/fabric/protos/ledger/rwset"
26
+ pb "github.com/hyperledger/fabric/protos/peer"
24
27
"github.com/spf13/viper"
25
28
"github.com/stretchr/testify/assert"
26
29
)
@@ -56,7 +59,9 @@ func TestStore(t *testing.T) {
56
59
assert .NoError (t , err )
57
60
assert .Nil (t , pvtdata )
58
61
59
- // block 2 has pvt data for tx 3 and 5 only
62
+ // block 2 has pvt data for tx 3, 5 and 6. However, tx 6
63
+ // is marked as invalid in the block and hence should not
64
+ // have been stored
60
65
pvtdata , err = store .GetPvtDataByNum (2 , nil )
61
66
assert .NoError (t , err )
62
67
assert .Equal (t , 2 , len (pvtdata ))
@@ -72,20 +77,10 @@ func TestStore(t *testing.T) {
72
77
73
78
blockAndPvtdata , err := store .GetPvtDataAndBlockByNum (2 , nil )
74
79
assert .NoError (t , err )
75
- assert .Equal (t , len (sampleData [2 ].MissingPvtData ), len (blockAndPvtdata .MissingPvtData ))
76
- for txNum := range blockAndPvtdata .MissingPvtData {
77
- assert .ElementsMatch (t , sampleData [2 ].MissingPvtData [txNum ],
78
- blockAndPvtdata .MissingPvtData )
79
- }
80
80
assert .True (t , proto .Equal (sampleData [2 ].Block , blockAndPvtdata .Block ))
81
81
82
82
blockAndPvtdata , err = store .GetPvtDataAndBlockByNum (3 , nil )
83
83
assert .NoError (t , err )
84
- assert .Equal (t , len (sampleData [2 ].MissingPvtData ), len (blockAndPvtdata .MissingPvtData ))
85
- for txNum := range blockAndPvtdata .MissingPvtData {
86
- assert .ElementsMatch (t , sampleData [2 ].MissingPvtData [txNum ],
87
- blockAndPvtdata .MissingPvtData )
88
- }
89
84
assert .True (t , proto .Equal (sampleData [3 ].Block , blockAndPvtdata .Block ))
90
85
91
86
// pvt data retrieval for block 3 with filter should return filtered pvtdata
@@ -101,6 +96,15 @@ func TestStore(t *testing.T) {
101
96
assert .Equal (t , 1 , len (blockAndPvtdata .PvtData [6 ].WriteSet .NsPvtRwset ))
102
97
// any other transaction entry should be nil
103
98
assert .Nil (t , blockAndPvtdata .PvtData [2 ])
99
+
100
+ // test missing data retrieval in the presence of invalid tx. Block 5 had
101
+ // missing data (for tx4 and tx5). However, tx5 was marked as invalid tx.
102
+ // Hence, only tx4's missing data should be returned
103
+ expectedMissingDataInfo := make (ledger.MissingPvtDataInfo )
104
+ expectedMissingDataInfo .Add (5 , 4 , "ns-4" , "coll-4" )
105
+ missingDataInfo , err := store .GetMissingPvtDataInfoForMostRecentBlocks (1 )
106
+ assert .NoError (t , err )
107
+ assert .Equal (t , expectedMissingDataInfo , missingDataInfo )
104
108
}
105
109
106
110
func TestStoreWithExistingBlockchain (t * testing.T ) {
@@ -326,10 +330,25 @@ func sampleDataWithPvtdataForSelectiveTx(t *testing.T) []*ledger.BlockAndPvtData
326
330
for i := 0 ; i < 10 ; i ++ {
327
331
blockAndpvtdata = append (blockAndpvtdata , & ledger.BlockAndPvtData {Block : blocks [i ]})
328
332
}
329
- // txNum 3, 5 in block 2 has pvtdata
330
- blockAndpvtdata [2 ].PvtData = samplePvtData (t , []uint64 {3 , 5 })
333
+
334
+ // txNum 3, 5, 6 in block 2 has pvtdata but txNum 6 is invalid
335
+ blockAndpvtdata [2 ].PvtData = samplePvtData (t , []uint64 {3 , 5 , 6 })
336
+ txFilter := lutil .TxValidationFlags (blockAndpvtdata [2 ].Block .Metadata .Metadata [common .BlockMetadataIndex_TRANSACTIONS_FILTER ])
337
+ txFilter .SetFlag (6 , pb .TxValidationCode_INVALID_WRITESET )
338
+ blockAndpvtdata [2 ].Block .Metadata .Metadata [common .BlockMetadataIndex_TRANSACTIONS_FILTER ] = txFilter
339
+
331
340
// txNum 4, 6 in block 3 has pvtdata
332
341
blockAndpvtdata [3 ].PvtData = samplePvtData (t , []uint64 {4 , 6 })
342
+
343
+ // txNum 4, 5 in block 5 has missing pvt data but txNum 5 is invalid
344
+ missingData := make (ledger.TxMissingPvtDataMap )
345
+ missingData .Add (4 , "ns-4" , "coll-4" , true )
346
+ missingData .Add (5 , "ns-5" , "coll-5" , true )
347
+ blockAndpvtdata [5 ].MissingPvtData = missingData
348
+ txFilter = lutil .TxValidationFlags (blockAndpvtdata [5 ].Block .Metadata .Metadata [common .BlockMetadataIndex_TRANSACTIONS_FILTER ])
349
+ txFilter .SetFlag (5 , pb .TxValidationCode_INVALID_WRITESET )
350
+ blockAndpvtdata [5 ].Block .Metadata .Metadata [common .BlockMetadataIndex_TRANSACTIONS_FILTER ] = txFilter
351
+
333
352
return blockAndpvtdata
334
353
}
335
354
0 commit comments