@@ -163,18 +163,25 @@ impl fmt::Debug for Url {
163
163
mod test {
164
164
use super :: * ;
165
165
166
- static TESTS_IPFS_V1 : [ & str ; 4 ] = [
166
+ // CID V0
167
+ static TESTS_IPFS_V0 : [ & str ; 4 ] = [
167
168
"QmcUVX7fvoLMM93uN2bD3wGTH8MXSxeL8hojYfL2Lhp7mR" ,
168
169
"Qmasg8FrbuSQpjFu3kRnZF9beg8rEBFrqgi1uXDRwCbX5f" ,
169
170
"QmQnu8zrHsuVvnTJsEgDHYA8c1MmRL7YLiMD8uzDUJKcNq" ,
170
171
"QmYYBULc9QDEaDr8HAXvVWHDmFfL2GvyumYRr1g4ERBC96" ,
171
172
] ;
172
173
174
+ // CID V1
175
+ static TESTS_IPFS_V1 : [ & str ; 1 ] = [
176
+ // V1 of the V0 ipfs: `QmcUVX7fvoLMM93uN2bD3wGTH8MXSxeL8hojYfL2Lhp7mR`
177
+ "bafybeif2h3mynaf3ylgdbs6arf6mczqycargt5cqm3rmel3wpjarlswway" ,
178
+ ] ;
179
+
173
180
#[ test]
174
181
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 | {
176
183
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 ) ;
178
185
assert_eq ! ( ipfs. 0 . to_string( ) , ipfs_str) ;
179
186
180
187
let expected_json = format ! ( "\" {}\" " , ipfs) ;
@@ -185,6 +192,15 @@ mod test {
185
192
ipfs,
186
193
serde_json:: from_str( & actual_json) . expect( "Should Deserialize" )
187
194
)
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 )
188
204
}
189
205
}
190
206
@@ -216,15 +232,20 @@ mod test {
216
232
}
217
233
218
234
// Invalid cases
219
- // CID V1 - Invalid scheme - valid IPFS
235
+ // CID V0 - Invalid scheme - valid IPFS
220
236
assert_eq ! (
221
237
Err ( UrlError :: NoPrefix ) ,
222
238
"https://QmcUVX7fvoLMM93uN2bD3wGTH8MXSxeL8hojYfL2Lhp7mR" . parse:: <Url >( )
223
239
) ;
224
- // CID V1 - Invalid scheme - valid IPFS
240
+ // CID V0 - Invalid scheme - valid IPFS
225
241
assert_eq ! (
226
242
Err ( UrlError :: IPFS ( cid:: Error :: ParsingError ) ) ,
227
243
"ipfs://NotValid" . parse:: <Url >( )
228
244
) ;
245
+ // CID V1 - Invalid scheme - valid IPFS
246
+ assert_eq ! (
247
+ Err ( UrlError :: NoPrefix ) ,
248
+ "https://bafybeif2h3mynaf3ylgdbs6arf6mczqycargt5cqm3rmel3wpjarlswway" . parse:: <Url >( )
249
+ ) ;
229
250
}
230
251
}
0 commit comments