Repository navigation
Add Uri unit tests - #13
Conversation
Kixunil
left a comment
There was a problem hiding this comment.
Thanks! I'm not confident about changes as they are. Some tests test properties that this actually shouldn't have. I think it'd be cleaner to introduce them together with fixes as separate commits/PRs.
Also, can we avoid promising PartialEq for publicly-facing types?
|
|
||
| assert_eq!( | ||
| Uri::from_str("bitcoin:TB1Q6D3A2W975YNY0ASUVD9A67NER4NKS58FF0Q8G4?pj=https://testnet.demo.btcpayserver.org/BTC/pj"), | ||
| Err::<Uri<'_>, ParseUriError>(InternalPjParseError::MissingAmount.into()) |
There was a problem hiding this comment.
FYI we have this wrong (see e-mail from Nicolas).
There was a problem hiding this comment.
moved wrong tests in specific ignored test
| //TODO we may want endpoint to be a valid URL | ||
| assert!(Uri::from_str("bitcoin:TB1Q6D3A2W975YNY0ASUVD9A67NER4NKS58FF0Q8G4?amount=1&pj=http://a").is_ok()); | ||
|
|
||
| let uri = Uri::from_str("bitcoin:TB1Q6D3A2W975YNY0ASUVD9A67NER4NKS58FF0Q8G4?amount=1&pj=http://example.com?ciao").unwrap(); |
There was a problem hiding this comment.
The latter ? should be url-encoded, I believe. Or at least & have to be to distinguish them from BIP21 ampersands.
There was a problem hiding this comment.
moved wrong tests in specific ignored test
|
|
||
| #[derive(Debug)] | ||
| #[derive(Debug, Eq, PartialEq)] | ||
| pub struct PjParseError(InternalPjParseError); |
There was a problem hiding this comment.
I'm not confident in publicly promising equality now. I know it should be no-brainer but sadly io::Error exists and it's too popular and it doesn't impl PartialEq. Same goes for std::error::Error. Promising PartialEq means promising the inside will never contain io::Error. :(
I want to avoid io::Error like a plague but one never knows...
Note that those derives on internal types are OK, it's just public types I'm worried about.
Also feel free to hack together some macro for matching them if it helps in tests.
There was a problem hiding this comment.
What do you think to add https://docs.rs/assert_matches/1.5.0/assert_matches/ as a dev dep?
There was a problem hiding this comment.
Sounds great! Trivial to review and being dev-only is a great combination.
There was a problem hiding this comment.
removed Eq, PartialEq, added assert_matches
Note I could have matched to the Err variant, but it was a little too verbose because you have to specify the types, so I match against unwrap_err.
Kixunil
left a comment
There was a problem hiding this comment.
Good idea writing the tests to test the desired but unimplemented properties and adding #[ignore].
Also, unwrap_err is completely fine.
| rand = { version = "0.8.4", optional = true } | ||
|
|
||
| [dev-dependencies] | ||
| assert_matches = "1.5.0" No newline at end of file |
There was a problem hiding this comment.
Do you feel like adding the newline?
| } | ||
|
|
||
| let parse_err = ParseUriError::from(InternalBip21Error::Address( | ||
| util::address::Error::Base58(util::base58::Error::BadChecksum(291609738, 694262922)), |
There was a problem hiding this comment.
Going into specifics like this seems too much - basically we're testing what the dependency should have tested already. Just knowing it's InternalBip21Error::Address should be sufficient.
I don't feel strongly against it, so feel free to keep it but I suggest you don't bother with testing dependency details next time.
There was a problem hiding this comment.
Yeah, I agree, done. It was so specific because copied from old equality tests but now we have pattern matching
thanks! Note I added a commit to fix the CI |
Some unit tests to cover errors and valid Uris
They are written so they require equality comparison to errors