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