This repository was archived by the owner on Jan 6, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -55,3 +55,29 @@ pub fn compute_opening_fee(
55
55
. and_then ( |f| f. checked_div ( 1000000 ) )
56
56
. map ( |f| core:: cmp:: max ( f, opening_fee_min_fee_msat) )
57
57
}
58
+
59
+ #[ cfg( test) ]
60
+ mod tests {
61
+ use super :: * ;
62
+ use proptest:: prelude:: * ;
63
+
64
+ const MAX_VALUE_MSAT : u64 = 21_000_000_0000_0000_000 ;
65
+
66
+ fn arb_opening_fee_params ( ) -> impl Strategy < Value = ( u64 , u64 , u64 ) > {
67
+ ( 0u64 ..MAX_VALUE_MSAT , 0u64 ..MAX_VALUE_MSAT , 0u64 ..MAX_VALUE_MSAT )
68
+ }
69
+
70
+ proptest ! {
71
+ #[ test]
72
+ fn test_compute_opening_fee( ( payment_size_msat, opening_fee_min_fee_msat, opening_fee_proportional) in arb_opening_fee_params( ) ) {
73
+ if let Some ( res) = compute_opening_fee( payment_size_msat, opening_fee_min_fee_msat, opening_fee_proportional) {
74
+ assert!( res >= opening_fee_min_fee_msat) ;
75
+ assert_eq!( res as f32 , ( payment_size_msat as f32 * opening_fee_proportional as f32 ) ) ;
76
+ } else {
77
+ // Check we actually overflowed.
78
+ let max_value = u64 :: MAX as u128 ;
79
+ assert!( ( payment_size_msat as u128 * opening_fee_proportional as u128 ) > max_value) ;
80
+ }
81
+ }
82
+ }
83
+ }
You can’t perform that action at this time.
0 commit comments