Add support for writing integration tests that fail#417
Add support for writing integration tests that fail#417sanket1729 merged 2 commits intorust-bitcoin:masterfrom
Conversation
kanishk779
commented
May 22, 2022
- Earlier we did not have the ability to write integration tests that fail.
- The default behaviour was to panic and stop the execution of the program.
- But in addition to verifying that the code works in the correct cases, we must also ensure that it should generate an appropriate error in incorrect cases.
- Some functions are modified to return Result<T, E> to support this feature.
- Four failing tests have also been added (tests 10-13) to demonstrate this.
09ed81b to
210376a
Compare
| } else { | ||
| return Err(Error::Unexpected(String::from( | ||
| "Computing spend data on a valid Tree should always succeed", | ||
| ))); |
There was a problem hiding this comment.
How do you actually hit this case? How do you obtain a Tr with an invalid tree? Can you add a unit test?
Relatedly, can you separate out the changes to src/ into a separate commit from the changes to the integration test?
Thanks for your contribution!!
There was a problem hiding this comment.
- This case is hit when the height of the tree is more than 128. In the Impl for
TaprootBuilderin file taproot.rs of the rust-bitcoin project, there is a functioninsert, which returns aTaprootBuilderError. - For which function do you want me to add the unit tests?
- Ok I will split it into two commits.
There was a problem hiding this comment.
Can you add a unit test for Taproot::spend_info which causes this new error path to be taken?
I think that would answer my "how do you hit this case" question, which I'm still confused about, sorry.
And thanks for splitting up the commits!
There was a problem hiding this comment.
Yep, I am also curious when this gets hit. This seems like a big bug if we need to change this.
|
|
||
| RPC_URL=http://localhost:12348 \ | ||
| RPC_COOKIE=${TESTDIR}/1/regtest/.cookie \ | ||
| RUST_BACKTRACE=1 \ |
There was a problem hiding this comment.
It is odd to supply this in RPC_URL.
You can supply this via your own shell environment.
| // Currently this is not being used, since miniscript::Error is being propagated | ||
| // But if the types of errors grow in future, we can extend this enum and use it. | ||
| #[derive(Debug, PartialEq)] | ||
| pub enum MalleableDescError { |
There was a problem hiding this comment.
This Error should be used as the return type
There was a problem hiding this comment.
Here is a suggestion for how to use this enum.
- Rename this type to DescTestError
- Change the return type from Error to DescTestError for the test function.
pub enum DesctestError {
DescParseError(Error),
PsbtFinalizeError(Error),
AddressComputationError(Error),
...
}In the test function then, you would change the lines to make sure that correct variant is retuned.
| } else { | ||
| return Err(Error::Unexpected(String::from( | ||
| "Computing spend data on a valid Tree should always succeed", | ||
| ))); |
There was a problem hiding this comment.
Yep, I am also curious when this gets hit. This seems like a big bug if we need to change this.
210376a to
58ccb93
Compare
987545b to
be10ec1
Compare
| use std::fmt; | ||
| use miniscript::Error; | ||
| mod setup; | ||
| // use crate::test_util::{self, TestData}; |
| assert_eq!(blocks.len(), 1); | ||
|
|
||
| let desc = test_util::parse_test_desc(&desc, &testdata.pubdata); | ||
| let mut desc; |
| let derived_desc = desc.derived_descriptor(&secp, 0).unwrap(); | ||
| // Next send some btc to each address corresponding to the miniscript | ||
| let mut rest; | ||
| match derived_desc.address(bitcoin::Network::Regtest) { |
|
|
||
| // Test 5: When everything is available, we should select the key spend path | ||
| let wit = test_desc_satisfy(cl, testdata, "tr(X,{pk(X1),and_v(v:pk(X2),pk(X3!))})"); | ||
| let wit = test_desc_satisfy(cl, testdata, "tr(X,{pk(X1),and_v(v:pk(X2),pk(X3!))})").unwrap(); |
There was a problem hiding this comment.
Fix other warnings requiring the same unwrap
| Descriptor::Wsh(ref wsh) => Ok(wsh.address(network)), | ||
| Descriptor::Sh(ref sh) => Ok(sh.address(network)), | ||
| Descriptor::Tr(ref tr) => Ok(tr.address(network)), | ||
| Descriptor::Tr(ref tr) => Ok(tr.address(network)?), |
be10ec1 to
9ef6607
Compare
|
@kanishk779 , the history is still unclean. The first commit still adds a bunch of files. |
9ef6607 to
ce0220d
Compare
ce0220d to
ab79593
Compare
|
@sanket1729 I have made the required changes. |
…ration tests that fail
ab7959382a2ae9e0dd8aaf3500fd3951455ff464 Use DescError instead of miniscript::Error (kanishk779)
b446ced71ff8a01de49f0400fa43754f64d4022c Add support for writing integration tests that fail (kanishk779)
Pull request description:
- Earlier we did not have the ability to write integration tests that fail.
- The default behaviour was to panic and stop the execution of the program.
- But in addition to verifying that the code works in the correct cases, we must also ensure that it should generate an appropriate error in incorrect cases.
- Some functions are modified to return Result<T, E> to support this feature.
- Four failing tests have also been added (tests 10-13) to demonstrate this.
ACKs for top commit:
sanket1729:
ACK ab7959382a2ae9e0dd8aaf3500fd3951455ff464
Tree-SHA512: 2f0800194c06325cd32fc81988f88989d412c4d0164d8d3f2105068a16db22a3e25fcdefe9f1c7736739faf765fb1e8adc850f9c524e7dec7c89af4dcca22e47