@@ -29,10 +29,10 @@ func TestBuildExpirySchedule(t *testing.T) {
29
29
btlPolicy := pvtdatapolicy .ConstructBTLPolicy (cs )
30
30
updates := privacyenabledstate .NewUpdateBatch ()
31
31
updates .PubUpdates .Put ("ns1" , "pubkey1" , []byte ("pubvalue1" ), version .NewHeight (1 , 1 ))
32
- putPvtUpdates (t , updates , "ns1" , "coll1" , "pvtkey1" , []byte ("pvtvalue1" ), version .NewHeight (1 , 1 ))
33
- putPvtUpdates (t , updates , "ns1" , "coll2" , "pvtkey2" , []byte ("pvtvalue2" ), version .NewHeight (2 , 1 ))
34
- putPvtUpdates (t , updates , "ns2" , "coll3" , "pvtkey3" , []byte ("pvtvalue3" ), version .NewHeight (3 , 1 ))
35
- putPvtUpdates (t , updates , "ns3" , "coll4" , "pvtkey4" , []byte ("pvtvalue4" ), version .NewHeight (4 , 1 ))
32
+ putPvtAndHashUpdates (t , updates , "ns1" , "coll1" , "pvtkey1" , []byte ("pvtvalue1" ), version .NewHeight (1 , 1 ))
33
+ putPvtAndHashUpdates (t , updates , "ns1" , "coll2" , "pvtkey2" , []byte ("pvtvalue2" ), version .NewHeight (2 , 1 ))
34
+ putPvtAndHashUpdates (t , updates , "ns2" , "coll3" , "pvtkey3" , []byte ("pvtvalue3" ), version .NewHeight (3 , 1 ))
35
+ putPvtAndHashUpdates (t , updates , "ns3" , "coll4" , "pvtkey4" , []byte ("pvtvalue4" ), version .NewHeight (4 , 1 ))
36
36
37
37
listExpinfo , err := buildExpirySchedule (btlPolicy , updates .PvtUpdates , updates .HashUpdates )
38
38
testutil .AssertNoError (t , err , "" )
@@ -57,12 +57,67 @@ func TestBuildExpirySchedule(t *testing.T) {
57
57
testutil .AssertContainsAll (t , listExpinfo , expectedListExpInfo )
58
58
}
59
59
60
- func putPvtUpdates (t * testing.T , updates * privacyenabledstate.UpdateBatch , ns , coll , key string , value []byte , ver * version.Height ) {
60
+ func TestBuildExpiryScheduleWithMissingPvtdata (t * testing.T ) {
61
+ cs := btltestutil .NewMockCollectionStore ()
62
+ cs .SetBTL ("ns1" , "coll1" , 1 )
63
+ cs .SetBTL ("ns1" , "coll2" , 2 )
64
+ cs .SetBTL ("ns2" , "coll3" , 3 )
65
+ cs .SetBTL ("ns3" , "coll4" , 0 )
66
+ cs .SetBTL ("ns3" , "coll5" , 20 )
67
+ btlPolicy := pvtdatapolicy .ConstructBTLPolicy (cs )
68
+ updates := privacyenabledstate .NewUpdateBatch ()
69
+
70
+ // This update should appear in the expiry schedule with both the key and the hash
71
+ putPvtAndHashUpdates (t , updates , "ns1" , "coll1" , "pvtkey1" , []byte ("pvtvalue1" ), version .NewHeight (50 , 1 ))
72
+
73
+ // This update should appear in the expiry schedule with only the key-hash
74
+ putHashUpdates (updates , "ns1" , "coll2" , "pvtkey2" , []byte ("pvtvalue2" ), version .NewHeight (50 , 2 ))
75
+
76
+ // This update should appear in the expiry schedule with only the key-hash
77
+ putHashUpdates (updates , "ns2" , "coll3" , "pvtkey3" , []byte ("pvtvalue3" ), version .NewHeight (50 , 3 ))
78
+
79
+ // this update is not expectd to appear in the expiry schdule as this collection is configured to expire - 'never'
80
+ putPvtAndHashUpdates (t , updates , "ns3" , "coll4" , "pvtkey4" , []byte ("pvtvalue4" ), version .NewHeight (50 , 4 ))
81
+
82
+ // the following two updates are not expected to appear in the expiry schdule as they are deletes
83
+ deletePvtAndHashUpdates (t , updates , "ns3" , "coll5" , "pvtkey5" , version .NewHeight (50 , 5 ))
84
+ deleteHashUpdates (updates , "ns3" , "coll5" , "pvtkey6" , version .NewHeight (50 , 6 ))
85
+
86
+ listExpinfo , err := buildExpirySchedule (btlPolicy , updates .PvtUpdates , updates .HashUpdates )
87
+ testutil .AssertNoError (t , err , "" )
88
+ t .Logf ("listExpinfo=%s" , spew .Sdump (listExpinfo ))
89
+
90
+ pvtdataKeys1 := newPvtdataKeys ()
91
+ pvtdataKeys1 .add ("ns1" , "coll1" , "pvtkey1" , util .ComputeStringHash ("pvtkey1" ))
92
+ pvtdataKeys2 := newPvtdataKeys ()
93
+ pvtdataKeys2 .add ("ns1" , "coll2" , "" , util .ComputeStringHash ("pvtkey2" ))
94
+ pvtdataKeys3 := newPvtdataKeys ()
95
+ pvtdataKeys3 .add ("ns2" , "coll3" , "" , util .ComputeStringHash ("pvtkey3" ))
96
+
97
+ expectedListExpInfo := []* expiryInfo {
98
+ {expiryInfoKey : & expiryInfoKey {expiryBlk : 52 , committingBlk : 50 }, pvtdataKeys : pvtdataKeys1 },
99
+ {expiryInfoKey : & expiryInfoKey {expiryBlk : 53 , committingBlk : 50 }, pvtdataKeys : pvtdataKeys2 },
100
+ {expiryInfoKey : & expiryInfoKey {expiryBlk : 54 , committingBlk : 50 }, pvtdataKeys : pvtdataKeys3 },
101
+ }
102
+
103
+ testutil .AssertEquals (t , len (listExpinfo ), 3 )
104
+ testutil .AssertContainsAll (t , listExpinfo , expectedListExpInfo )
105
+ }
106
+
107
+ func putPvtAndHashUpdates (t * testing.T , updates * privacyenabledstate.UpdateBatch , ns , coll , key string , value []byte , ver * version.Height ) {
61
108
updates .PvtUpdates .Put (ns , coll , key , value , ver )
62
- updates . HashUpdates . Put ( ns , coll , util . ComputeStringHash ( key ), util . ComputeHash ( value ) , ver )
109
+ putHashUpdates ( updates , ns , coll , key , value , ver )
63
110
}
64
111
65
- func deletePvtUpdates (t * testing.T , updates * privacyenabledstate.UpdateBatch , ns , coll , key string , ver * version.Height ) {
112
+ func deletePvtAndHashUpdates (t * testing.T , updates * privacyenabledstate.UpdateBatch , ns , coll , key string , ver * version.Height ) {
66
113
updates .PvtUpdates .Delete (ns , coll , key , ver )
114
+ deleteHashUpdates (updates , ns , coll , key , ver )
115
+ }
116
+
117
+ func putHashUpdates (updates * privacyenabledstate.UpdateBatch , ns , coll , key string , value []byte , ver * version.Height ) {
118
+ updates .HashUpdates .Put (ns , coll , util .ComputeStringHash (key ), util .ComputeHash (value ), ver )
119
+ }
120
+
121
+ func deleteHashUpdates (updates * privacyenabledstate.UpdateBatch , ns , coll , key string , ver * version.Height ) {
67
122
updates .HashUpdates .Delete (ns , coll , util .ComputeStringHash (key ), ver )
68
123
}
0 commit comments