@@ -1917,6 +1917,66 @@ mod tests {
1917
1917
p
1918
1918
}
1919
1919
1920
+ #[ test]
1921
+ fn test_add_penalty_record ( ) {
1922
+ let mut pdb = get_db ( ) ;
1923
+ let random_peer = PeerId :: random ( ) ;
1924
+
1925
+ pdb. connect_ingoing ( & random_peer, "/ip4/0.0.0.0" . parse ( ) . unwrap ( ) , None ) ;
1926
+
1927
+ // Check to see if get_penalty_records is able to get the associated peer info
1928
+ assert ! ( pdb. get_penalty_records( & random_peer) . is_some( ) ) ;
1929
+
1930
+ // Check to see if there are no initial penalty records
1931
+ assert_eq ! ( pdb. get_penalty_records( & random_peer) . unwrap( ) . into_iter( ) . count( ) , 0 ) ;
1932
+
1933
+ let _ = pdb. report_peer (
1934
+ & random_peer,
1935
+ PeerAction :: HighToleranceError ,
1936
+ ReportSource :: PeerManager ,
1937
+ "Minor report action" ,
1938
+ ) ;
1939
+
1940
+ // Check to see if there was a penalty record added
1941
+ assert_eq ! ( pdb. get_penalty_records( & random_peer) . unwrap( ) . into_iter( ) . count( ) , 1 ) ;
1942
+
1943
+ let first_record = pdb. get_penalty_records ( & random_peer) . unwrap ( ) . into_iter ( ) . next ( ) . unwrap ( ) ;
1944
+
1945
+ // Check to see the correct report action for the penalty record
1946
+ assert ! ( matches!( first_record. action( ) , PeerAction :: HighToleranceError ) ) ;
1947
+
1948
+ // Check to see the correct report source for the penalty record
1949
+ assert ! ( matches!( first_record. source( ) , ReportSource :: PeerManager ) ) ;
1950
+
1951
+ // Check to see the correct message for the penalty record
1952
+ assert_eq ! ( * first_record. msg( ) , "Minor report action" . to_string( ) ) ;
1953
+
1954
+ // Check to see the correct result for the penalty record
1955
+ assert ! ( matches!( first_record. result( ) , ScoreUpdateResult :: NoAction ) ) ;
1956
+
1957
+ let _ = pdb. report_peer (
1958
+ & random_peer,
1959
+ PeerAction :: HighToleranceError ,
1960
+ ReportSource :: PeerManager ,
1961
+ "Minor report action" ,
1962
+ ) ;
1963
+
1964
+ // Check to see if there was a penalty record added
1965
+ assert_eq ! ( pdb. get_penalty_records( & random_peer) . unwrap( ) . into_iter( ) . count( ) , 2 ) ;
1966
+
1967
+ for _ in 1 ..( MAX_STORED_PENALTY_RECORDS +1 ) {
1968
+ let _ = pdb. report_peer (
1969
+ & random_peer,
1970
+ PeerAction :: HighToleranceError ,
1971
+ ReportSource :: PeerManager ,
1972
+ "Minor report action" ,
1973
+ ) ;
1974
+ }
1975
+
1976
+ // Check to make sure that the number of penalty records don't exceed the maximum
1977
+ assert_eq ! ( pdb. get_penalty_records( & random_peer) . unwrap( ) . into_iter( ) . count( ) , MAX_STORED_PENALTY_RECORDS ) ;
1978
+ }
1979
+
1920
1980
#[ test]
1921
1981
fn test_ban_address ( ) {
1922
1982
let mut pdb = get_db ( ) ;
0 commit comments