Add psbt BIP174 test vectors tests#935
Conversation
I stole that error type, and a bunch of the code for signing PSBTs from the bdk project. By 'clean up' I meant remove all the variants that were not being used. Also, in general, all the error handling code is incomplete i.e., usage of
That's a PR you can do if you would like to. Conceptually simple but likely to get some argument/discussion if you like that sort of thing :) Otherwise I'll do it. Cheers, will review. EDIT: By the way, this should probably be a draft PR, its not ready for merge yet. EDIT EDIT: So cool to wake up on Monday morning and find all your problems from last week solved! Thanks man. |
examples/psbt.rs
Outdated
There was a problem hiding this comment.
I did some digging, this is because in rust-bitcoin we map OP_1 - OP_16 to all::OP_PUSHNUM_0 - all::OP_PUSHNUM_16. Bitcoin Core does not define opcodes for the byte values 0x01 - 0x4b (at least not in enum opcodetype) but in rust-bitcoin we define all::OP_PUSHBYTES_1 - all::OP_PUSHBYTES_75, when these are serialized they are simply the byte values 0x01 - 0x4b. So, OP_0 could have been defined as OP_PUSHNUM_0 I guess but OP_PUSHBYTES_0 was chosen.
@apoelstra do you remember why this was done or why we did not explicitly have an OP_0 defined or aliased as we do for OP_FALSE?
This seem so obvious I feel like I'm missing something?
/// OP_0, the zero byte, the empty stack.
pub static OP_ZERO: All = all::OP_PUSHBYTES_0;
There was a problem hiding this comment.
I think it just didn't occur to me. I have never needed to push a zero to the stack, only FALSE 🤷
I'd be happy to accept a new alias.
|
Nice work man! We have the seed passing issue to resolve still. Also, I'm starting to think that this should not be an example but rather should be an integration test. Then, the remaining TODOs are changes to |
|
Locally this builds fine but CI is including recent changes to the sighash types, no idea what is going on with that. Its your branch @DanGould so I won't mess with it but my blunt guess would be update your local |
concept ack to that and your psbt watch-only example as an example. I'll turn these TODOs into PRs. |
|
For your CI fixes you can check out #940 or
|
dea0872 to
4bde605
Compare
|
Why the heck aren't I seeing these errors when running |
|
Don't beat yourself up about it, it took me months on this project to work out how to see the Rust 1.29 errors. I don't use And the shell function |
|
@tcharding would it make sense to add this script to contributing.md? I wonder why this doesn't show up with act on its own. I get that this will change when we upgrade rust. this would have saved me 3 pushes at this point |
|
Yeah go for it. |
|
All green! I rekon this is pretty close to ready-for-review. I still rekon we should be asserting against PSBTs not against hex, do you have an opinion on that? |
31da281 to
eff0d9a
Compare
|
We're asserting against PSBTs now 👍 Sincere thanks for all the guidance. I'm thrilled to be able to contribute :D edit: if this is going to be an integration test it looks like we'll need a home for them. |
There were a few missed, I pushed a wip patch, you can squash if you like it. I also pushed a commit that moves the example to |
I'm glad you are enjoying it, this is a mad project with good people working on it. I'm learning heaps hacking on this repo. |
|
Oh and incase you want to know why its in |
|
Now this uses the same signer as #940, is rebased on master, and satisfies the clippy gods. I pair programmed the latest with @0xBEEFCAF3 and added him as a co-author. |
tcharding
left a comment
There was a problem hiding this comment.
This looks good, a few trivial whitespace issues to fix.
With the whitespace fixes: ACK 210f5ecb
tests/psbt.rs
Outdated
There was a problem hiding this comment.
Perhaps we should comment here that finalizing can better be done with miniscript?
There was a problem hiding this comment.
If we do we should add the same comment in examples/ecdsa-psbt.rs.
tests/psbt.rs
Outdated
There was a problem hiding this comment.
I applied the patches from this PR to the sign PSBT (#957) PR and was able to implement GetKey for &[PriavateKey] based on this code. If/when both this PR and #957 merges this function can become
/// Signs `psbt` with `keys` if required.
fn sign(mut psbt: Psbt, keys: &[PrivateKey]) -> Psbt {
let secp = SECP256K1;
psbt.sign(&keys, &secp);
psbt
}which smells like success :)
There was a problem hiding this comment.
This took a little massaging since &keys needs to be GetKeys. I think it works now
|
Thanks for sticking at this one @DanGould! |
|
Hey @DanGould, now that the |
|
I re-named the PR to remove the word "example" because this adds tests not example. |
62259a2 to
421fe92
Compare
bitcoin/tests/psbt.rs
Outdated
There was a problem hiding this comment.
| sequence: bitcoin::Sequence(0xFFFFFFFF), // Disable nSequence. | |
| sequence: Sequence::MAX, // Disable nSequence. |
bitcoin/tests/psbt.rs
Outdated
There was a problem hiding this comment.
nit: With the addition of use bitcoin::locktime::absolute;
| lock_time: bitcoin::absolute::PackedLockTime::ZERO, | |
| lock_time: absolute::PackedLockTime::ZERO, |
bitcoin/tests/psbt.rs
Outdated
There was a problem hiding this comment.
nit: We are in the process of flattening util, would be better if the import path did not use util (both psbt and bip32 are in scope at the crate root).
|
Will need to be rebased once #1345 goes in. |
421fe92 to
5459c4f
Compare
|
added nits & |
tcharding
left a comment
There was a problem hiding this comment.
formatted, awesome. Thanks man.
ACK 5459c4f8bd51ebf7059bab6b54324c92bfd11bf0
(Rebase after we merge fix to master still to come.)
3ad55bf to
12714f8
Compare
In preparation for adding integration tests in the standard Rust `tests/` directroy; move the contents of `test_data` to `tests/data`.
Implement Test Vectors from BIP 174 Co-authored-by: Tobin Harding <me@tobin.cc> Co-authored-by: Armin Sabouri <armins88@gmail.com>
12714f8 to
b8bd31d
Compare
|
cherry-picked #1347 so we have a clean history and pass CI before @tcharding wakes up |
|
ACK b8bd31d Thanks man! |
resolves #892