@@ -113,7 +113,8 @@ type dataRetrieverMock struct {
113
113
}
114
114
115
115
func (dr * dataRetrieverMock ) CollectionRWSet (dig * proto.PvtDataDigest ) (* util.PrivateRWSetWithConfig , error ) {
116
- return dr .Called (dig ).Get (0 ).(* util.PrivateRWSetWithConfig ), dr .Called (dig ).Error (1 )
116
+ args := dr .Called (dig )
117
+ return args .Get (0 ).(* util.PrivateRWSetWithConfig ), args .Error (1 )
117
118
}
118
119
119
120
type receivedMsg struct {
@@ -720,19 +721,18 @@ func TestPullerAvoidPullingPurgedData(t *testing.T) {
720
721
factoryMock := & collectionAccessFactoryMock {}
721
722
accessPolicyMock2 := & collectionAccessPolicyMock {}
722
723
accessPolicyMock2 .Setup (1 , 2 , func (data fcommon.SignedData ) bool {
723
- return bytes .Equal (data .Identity , []byte ("p2" )) || bytes . Equal ( data . Identity , [] byte ( " p1" ))
724
+ return bytes .Equal (data .Identity , []byte ("p1" ))
724
725
}, []string {"org1" , "org2" })
725
726
factoryMock .On ("AccessPolicy" , mock .Anything , mock .Anything ).Return (accessPolicyMock2 , nil )
726
727
727
- policyStore := newCollectionStore ().
728
- withPolicy ("col1" , uint64 (100 )).
729
- thatMapsTo ("p1" , "p2" , "p3" )
728
+ policyStore := newCollectionStore ().withPolicy ("col1" , uint64 (100 )).thatMapsTo ("p1" , "p2" , "p3" ).
729
+ withPolicy ("col2" , uint64 (1000 )).thatMapsTo ("p1" , "p2" , "p3" )
730
730
731
731
// p2 is at ledger height 1, while p2 is at 111 which is beyond BTL defined for col1 (100)
732
732
p1 := gn .newPuller ("p1" , policyStore , factoryMock , membership (peerData {"p2" , uint64 (1 )},
733
733
peerData {"p3" , uint64 (111 )})... )
734
734
735
- transientStore := & util.PrivateRWSetWithConfig {
735
+ privateData1 := & util.PrivateRWSetWithConfig {
736
736
RWSet : newPRWSet (),
737
737
CollectionConfig : & fcommon.CollectionConfig {
738
738
Payload : & fcommon.CollectionConfig_StaticCollectionConfig {
@@ -742,6 +742,16 @@ func TestPullerAvoidPullingPurgedData(t *testing.T) {
742
742
},
743
743
},
744
744
}
745
+ privateData2 := & util.PrivateRWSetWithConfig {
746
+ RWSet : newPRWSet (),
747
+ CollectionConfig : & fcommon.CollectionConfig {
748
+ Payload : & fcommon.CollectionConfig_StaticCollectionConfig {
749
+ StaticCollectionConfig : & fcommon.StaticCollectionConfig {
750
+ Name : "col2" ,
751
+ },
752
+ },
753
+ },
754
+ }
745
755
746
756
p2 := gn .newPuller ("p2" , policyStore , factoryMock )
747
757
p3 := gn .newPuller ("p3" , policyStore , factoryMock )
@@ -752,20 +762,37 @@ func TestPullerAvoidPullingPurgedData(t *testing.T) {
752
762
Namespace : "ns1" ,
753
763
}
754
764
755
- p2 .PrivateDataRetriever .(* dataRetrieverMock ).On ("CollectionRWSet" , dig1 ).Return (transientStore , nil )
765
+ dig2 := & proto.PvtDataDigest {
766
+ TxId : "txID1" ,
767
+ Collection : "col2" ,
768
+ Namespace : "ns1" ,
769
+ }
756
770
757
- p3 .PrivateDataRetriever .(* dataRetrieverMock ).On ("CollectionRWSet" , dig1 ).Return (transientStore , nil ).
771
+ p2 .PrivateDataRetriever .(* dataRetrieverMock ).On ("CollectionRWSet" , dig1 ).Return (privateData1 , nil )
772
+ p3 .PrivateDataRetriever .(* dataRetrieverMock ).On ("CollectionRWSet" , dig1 ).Return (privateData1 , nil ).
758
773
Run (
759
- func (mock.Arguments ) {
774
+ func (arg mock.Arguments ) {
760
775
assert .Fail (t , "we should not fetch private data from peers where it was purged" )
761
776
},
762
777
)
763
778
779
+ p3 .PrivateDataRetriever .(* dataRetrieverMock ).On ("CollectionRWSet" , dig2 ).Return (privateData2 , nil )
780
+ p2 .PrivateDataRetriever .(* dataRetrieverMock ).On ("CollectionRWSet" , dig2 ).Return (privateData2 , nil ).
781
+ Run (
782
+ func (mock.Arguments ) {
783
+ assert .Fail (t , "we should not fetch private data of collection2 from peer 2" )
784
+
785
+ },
786
+ )
787
+
764
788
dasf := & digestsAndSourceFactory {}
765
- d2s := dasf .mapDigest (dig1 ).toSources ("p3" , "p2" ).create ()
789
+ d2s := dasf .mapDigest (dig1 ).toSources ("p3" , "p2" ).mapDigest ( dig2 ). toSources ( "p3" ). create ()
766
790
// trying to fetch missing pvt data for block seq 1
767
791
fetchedMessages , err := p1 .fetch (d2s , uint64 (1 ))
792
+
768
793
assert .NoError (t , err )
769
794
assert .Equal (t , 1 , len (fetchedMessages .PurgedElements ))
770
795
assert .Equal (t , dig1 , fetchedMessages .PurgedElements [0 ])
796
+ p3 .PrivateDataRetriever .(* dataRetrieverMock ).AssertNumberOfCalls (t , "CollectionRWSet" , 1 )
797
+
771
798
}
0 commit comments