Skip to content

Commit 2d7fbed

Browse files
committed
primitives - ipfs - fix test
1 parent 545c157 commit 2d7fbed

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

primitives/src/ipfs.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,18 +163,25 @@ impl fmt::Debug for Url {
163163
mod test {
164164
use super::*;
165165

166-
static TESTS_IPFS_V1: [&str; 4] = [
166+
// CID V0
167+
static TESTS_IPFS_V0: [&str; 4] = [
167168
"QmcUVX7fvoLMM93uN2bD3wGTH8MXSxeL8hojYfL2Lhp7mR",
168169
"Qmasg8FrbuSQpjFu3kRnZF9beg8rEBFrqgi1uXDRwCbX5f",
169170
"QmQnu8zrHsuVvnTJsEgDHYA8c1MmRL7YLiMD8uzDUJKcNq",
170171
"QmYYBULc9QDEaDr8HAXvVWHDmFfL2GvyumYRr1g4ERBC96",
171172
];
172173

174+
// CID V1
175+
static TESTS_IPFS_V1: [&str; 1] = [
176+
// V1 of the V0 ipfs: `QmcUVX7fvoLMM93uN2bD3wGTH8MXSxeL8hojYfL2Lhp7mR`
177+
"bafybeif2h3mynaf3ylgdbs6arf6mczqycargt5cqm3rmel3wpjarlswway",
178+
];
179+
173180
#[test]
174181
fn ipfs_from_string_and_serialize_deserialize() {
175-
for &ipfs_str in TESTS_IPFS_V1.iter() {
182+
let check = |ipfs_str: &str, version: cid::Version| {
176183
let ipfs = IPFS::try_from(ipfs_str).expect("should be ok");
177-
assert_eq!(ipfs.0.version(), cid::Version::V0);
184+
assert_eq!(ipfs.0.version(), version);
178185
assert_eq!(ipfs.0.to_string(), ipfs_str);
179186

180187
let expected_json = format!("\"{}\"", ipfs);
@@ -185,6 +192,15 @@ mod test {
185192
ipfs,
186193
serde_json::from_str(&actual_json).expect("Should Deserialize")
187194
)
195+
};
196+
197+
198+
for &ipfs_str in TESTS_IPFS_V0.iter() {
199+
check(ipfs_str, cid::Version::V0)
200+
}
201+
202+
for &ipfs_str in TESTS_IPFS_V1.iter() {
203+
check(ipfs_str, cid::Version::V1)
188204
}
189205
}
190206

@@ -216,15 +232,20 @@ mod test {
216232
}
217233

218234
// Invalid cases
219-
// CID V1 - Invalid scheme - valid IPFS
235+
// CID V0 - Invalid scheme - valid IPFS
220236
assert_eq!(
221237
Err(UrlError::NoPrefix),
222238
"https://QmcUVX7fvoLMM93uN2bD3wGTH8MXSxeL8hojYfL2Lhp7mR".parse::<Url>()
223239
);
224-
// CID V1 - Invalid scheme - valid IPFS
240+
// CID V0 - Invalid scheme - valid IPFS
225241
assert_eq!(
226242
Err(UrlError::IPFS(cid::Error::ParsingError)),
227243
"ipfs://NotValid".parse::<Url>()
228244
);
245+
// CID V1 - Invalid scheme - valid IPFS
246+
assert_eq!(
247+
Err(UrlError::NoPrefix),
248+
"https://bafybeif2h3mynaf3ylgdbs6arf6mczqycargt5cqm3rmel3wpjarlswway".parse::<Url>()
249+
);
229250
}
230251
}

0 commit comments

Comments
 (0)