Skip to content

Commit b71fcd5

Browse files
committed
Drop proptests in lightning-liquidity
`proptest`'s transitive dependency tree has always been somewhat large, but one of them (`rusty-fork`'s `tempfile` dependency) just went ahead with a bump of their `rand` dependency, breaking our MSRV yet again. Because we don't actually use `proptest` for anything interesting, the simplest solution is to simply drop it, which we do here. Note that we'll likely transition the LSPS5 URL type to simply use the `bitreq` URL type over the next few days anyway, so there's not much reason to care about its continued test coverage.
1 parent 927edf1 commit b71fcd5

4 files changed

Lines changed: 20 additions & 156 deletions

File tree

ci/ci-tests.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ PIN_RELEASE_DEPS # pin the release dependencies in our main workspace
1616
# The backtrace v0.3.75 crate relies on rustc 1.82
1717
[ "$RUSTC_MINOR_VERSION" -lt 82 ] && cargo update -p backtrace --precise "0.3.74" --quiet
1818

19-
# proptest 1.9.0 requires rustc 1.82.0
20-
[ "$RUSTC_MINOR_VERSION" -lt 82 ] && cargo update -p proptest --precise "1.8.0" --quiet
21-
2219
# Starting with version 1.2.0, the `idna_adapter` crate has an MSRV of rustc 1.81.0.
2320
[ "$RUSTC_MINOR_VERSION" -lt 81 ] && cargo update -p idna_adapter --precise "1.1.0" --quiet
2421

lightning-liquidity/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ lightning = { version = "0.3.0", path = "../lightning", default-features = false
3939
lightning-invoice = { version = "0.35.0", path = "../lightning-invoice", default-features = false, features = ["serde", "std"] }
4040
lightning-persister = { version = "0.3.0", path = "../lightning-persister", default-features = false }
4141

42-
proptest = "1.0.0"
4342
tokio = { version = "1.35", default-features = false, features = [ "rt-multi-thread", "time", "sync", "macros" ] }
4443
parking_lot = { version = "0.12", default-features = false }
4544

lightning-liquidity/src/lsps2/utils.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,27 @@ pub fn compute_opening_fee(
6868
#[cfg(test)]
6969
mod tests {
7070
use super::*;
71-
use proptest::prelude::*;
7271

73-
const MAX_VALUE_MSAT: u64 = 21_000_000_0000_0000_000;
74-
75-
fn arb_opening_fee_params() -> impl Strategy<Value = (u64, u64, u64)> {
76-
(0u64..MAX_VALUE_MSAT, 0u64..MAX_VALUE_MSAT, 0u64..MAX_VALUE_MSAT)
77-
}
78-
79-
proptest! {
80-
#[test]
81-
fn test_compute_opening_fee((payment_size_msat, opening_fee_min_fee_msat, opening_fee_proportional) in arb_opening_fee_params()) {
82-
if let Some(res) = compute_opening_fee(payment_size_msat, opening_fee_min_fee_msat, opening_fee_proportional) {
83-
assert!(res >= opening_fee_min_fee_msat);
84-
assert_eq!(res as f32, (payment_size_msat as f32 * opening_fee_proportional as f32));
85-
} else {
86-
// Check we actually overflowed.
87-
let max_value = u64::MAX as u128;
88-
assert!((payment_size_msat as u128 * opening_fee_proportional as u128) > max_value);
72+
#[test]
73+
fn test_compute_opening_fee() {
74+
const ONE_BITCOIN: u64 = 1_0000_000_000
75+
const MAX_VALUE_MSAT: u64 = 21_000_000_0000_0000_000;
76+
let amt_list = [0, 1, 100_000, ONE_BITCOIN, 1_000_000 * ONE_BITCOIN, MAX_VALUE_MSAT];
77+
let amt_list_iter = amt_list.iter()
78+
for payment_size in amt_list {
79+
for min_fee in amt_list {
80+
for opening_fee_proportional in amt_list {
81+
let res = compute_opening_fee(payment_size, min_fee, opening_fee_proportional);
82+
if let Some(res) = res {
83+
assert!(res >= min_fee);
84+
let float_res = (payment_size as f32 * opening_fee_proportional as f32);
85+
assert_eq!(res as f32, float_res);
86+
} else {
87+
// Check we actually overflowed.
88+
let u128_res = payment_size_msat as u128 * opening_fee_proportional as u128;
89+
assert!(u128_res > u64::MAX as u128);
90+
}
91+
}
8992
}
9093
}
9194
}

lightning-liquidity/src/lsps5/url_utils.rs

Lines changed: 0 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -102,138 +102,3 @@ impl Readable for LSPSUrl {
102102
Ok(Self(Readable::read(reader)?))
103103
}
104104
}
105-
106-
#[cfg(test)]
107-
mod tests {
108-
use super::*;
109-
use crate::alloc::string::ToString;
110-
use alloc::vec::Vec;
111-
use proptest::prelude::*;
112-
113-
#[test]
114-
fn test_extremely_long_url() {
115-
let url_str = format!("https://{}/path", "a".repeat(1000)).to_string();
116-
let url_chars = url_str.chars().count();
117-
let result = LSPSUrl::parse(url_str);
118-
119-
assert!(result.is_ok());
120-
let url = result.unwrap();
121-
assert_eq!(url.0 .0.chars().count(), url_chars);
122-
}
123-
124-
#[test]
125-
fn test_parse_http_url() {
126-
let url_str = "http://example.com/path".to_string();
127-
let url = LSPSUrl::parse(url_str).unwrap_err();
128-
assert_eq!(url, LSPS5ProtocolError::UnsupportedProtocol);
129-
}
130-
131-
#[test]
132-
fn valid_lsps_url() {
133-
let test_vec: Vec<&'static str> = vec![
134-
"https://www.example.org/push?l=1234567890abcopqrstuv&c=best",
135-
"https://www.example.com/path",
136-
"https://example.org",
137-
"https://example.com:8080/path",
138-
"https://api.example.com/v1/resources",
139-
"https://example.com/page#section1",
140-
"https://example.com/search?q=test#results",
141-
"https://user:pass@example.com/",
142-
"https://192.168.1.1/admin",
143-
"https://example.com://path",
144-
"https://example.com/path%20with%20spaces",
145-
"https://example_example.com/path?query=with&spaces=true",
146-
];
147-
for url_str in test_vec {
148-
let url = LSPSUrl::parse(url_str.to_string());
149-
assert!(url.is_ok(), "Failed to parse URL: {}", url_str);
150-
}
151-
}
152-
153-
#[test]
154-
fn invalid_lsps_url() {
155-
let test_vec = vec![
156-
"ftp://ftp.example.org/pub/files/document.pdf",
157-
"sftp://user:password@sftp.example.com:22/uploads/",
158-
"ssh://username@host.com:2222",
159-
"lightning://03a.example.com/invoice?amount=10000",
160-
"ftp://user@ftp.example.com/files/",
161-
"https://例子.测试/path",
162-
"a123+-.://example.com",
163-
"a123+-.://example.com",
164-
"https:\\\\example.com\\path",
165-
"https:///whatever",
166-
"https://example.com/path with spaces",
167-
];
168-
for url_str in test_vec {
169-
let url = LSPSUrl::parse(url_str.to_string());
170-
assert!(url.is_err(), "Expected error for URL: {}", url_str);
171-
}
172-
}
173-
174-
#[test]
175-
fn parsing_errors() {
176-
let test_vec = vec![
177-
"example.com/path",
178-
"https://bad domain.com/",
179-
"https://example.com\0/path",
180-
"https://",
181-
"ht@ps://example.com",
182-
"http!://example.com",
183-
"1https://example.com",
184-
"https://://example.com",
185-
"https://example.com:port/path",
186-
"https://:8080/path",
187-
"https:",
188-
"://",
189-
"https://example.com\0/path",
190-
];
191-
for url_str in test_vec {
192-
let url = LSPSUrl::parse(url_str.to_string());
193-
assert!(url.is_err(), "Expected error for URL: {}", url_str);
194-
}
195-
}
196-
197-
fn host_strategy() -> impl Strategy<Value = String> {
198-
prop_oneof![
199-
proptest::string::string_regex(
200-
"[a-z0-9]+(?:-[a-z0-9]+)*(?:\\.[a-z0-9]+(?:-[a-z0-9]+)*)*"
201-
)
202-
.unwrap(),
203-
(0u8..=255u8, 0u8..=255u8, 0u8..=255u8, 0u8..=255u8)
204-
.prop_map(|(a, b, c, d)| format!("{}.{}.{}.{}", a, b, c, d))
205-
]
206-
}
207-
208-
proptest! {
209-
#[test]
210-
fn proptest_parse_round_trip(
211-
host in host_strategy(),
212-
port in proptest::option::of(0u16..=65535u16),
213-
path in proptest::option::of(proptest::string::string_regex("[a-zA-Z0-9._%&=:@/-]{0,20}").unwrap()),
214-
query in proptest::option::of(proptest::string::string_regex("[a-zA-Z0-9._%&=:@/-]{0,20}").unwrap()),
215-
fragment in proptest::option::of(proptest::string::string_regex("[a-zA-Z0-9._%&=:@/-]{0,20}").unwrap())
216-
) {
217-
let mut url = format!("https://{}", host);
218-
if let Some(p) = port {
219-
url.push_str(&format!(":{}", p));
220-
}
221-
if let Some(pth) = &path {
222-
url.push('/');
223-
url.push_str(pth);
224-
}
225-
if let Some(q) = &query {
226-
url.push('?');
227-
url.push_str(q);
228-
}
229-
if let Some(f) = &fragment {
230-
url.push('#');
231-
url.push_str(f);
232-
}
233-
234-
let parsed = LSPSUrl::parse(url.clone()).expect("should parse");
235-
prop_assert_eq!(parsed.url(), url.as_str());
236-
prop_assert_eq!(parsed.url_length(), url.chars().count());
237-
}
238-
}
239-
}

0 commit comments

Comments
 (0)