Skip to content

Conversation

@cryptoquick
Copy link
Member

(supersedes #119)
WIP, getting an error when running cargo test --test payjoin -- --nocapture --exact:

 DEBUG bitmask_core::operations::bitcoin::balance > Getting blockchain
 DEBUG bitmask_core::operations::bitcoin::balance > Synced
 DEBUG bitmask_core::operations::bitcoin::send_sats > Request PayJoin transaction: TransactionDetails {
    transaction: None,
    txid: 38a97c8a0315fcee84516feebefb0f922ef7bb17c05314db4b217adaeef12b86,
    received: 2558877,
    sent: 2560049,
    fee: Some(
        172,
    ),
    confirmation_time: None,
}
 DEBUG bitmask_core::operations::bitcoin::send_sats > Unsigned Origianl PSBT: cHNidP8BAIkBAAAAAXawG2frrnZlpUgQqC0bmFEYtb19m/Y5F6Rv5XTzDUvwAQAAAAD9////Ap0LJwAAAAAAIlEgNNs+NbksZmZSj2z9i6bvkCaiPKA7pfUGGxxHKDhCj9DoAwAAAAAAACJRINhq31ocWYm3HCObie2xp0VAoX1gqBvl1uc0zzxwR3/zJswkAAABASsxECcAAAAAACJRIO4tBgsUjDLP9jxtWzLt5JRKjHuPwlP/ozpAdjWw1AA9IRbitxMv819QE7RxwhvwezlWwQF7iP0L98dc4HSrwok0IBkAd9HUEVYAAIABAACAAAAAgAEAAABGAAAAARcg4rcTL/NfUBO0ccIb8Hs5VsEBe4j9C/fHXOB0q8KJNCAAAQUgK4EzqTdTSbWTMlwmWFGfdwg8K0i1UeosxiTvAfCn3UEhByuBM6k3U0m1kzJcJlhRn3cIPCtItVHqLMYk7wHwp91BGQB30dQRVgAAgAEAAIAAAACAAQAAAEcAAAAAAA==
 DEBUG bitmask_core::operations::bitcoin::sign_psbt > Funding PSBT...
 INFO  bitmask_core::operations::bitcoin::send_sats > Original PSBT successfully signed
Error: couldn't decode PSBT

Caused by:
    I/O error: Invalid byte 123, offset 0.
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `1`,
 right: `0`: the test returned a termination value with a non-zero status code (1) which indicates a failure', /rustc/897e37553bba8b42751c67658967889d11ecd120/library/test/src/lib.rs:184:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
FAILED

failures:

failures:
    payjoin

@DanGould please feel free to PR into this branch, so we can collaborate.

@cryptoquick
Copy link
Member Author

@DanGould Made some changes to get things running in our new regtest environment, and to get us updated to using rust-bitcoin 0.29. I Found your new version of payjoin, that was helpful, thank you.

To test locally, I had to set up a regtest environment using the instructions in this link:
https://bisq.network/blog/how-to-set-up-bitcoin-regtest/

And then some commands...

bitcoind -regtest -server -txindex=0
electrs --network regtest -vvvv --http-addr="127.0.0.1:3000" --electrum-rpc-addr="127.0.0.1:60601"
bitcoin-cli -regtest generatetoaddress 111 bcrt1pdut30dgz700zqedv76surg5rnsj8ydc30faefs6h9kmxs67etmesn84alg
TEST_WALLET_SEED="cycle neglect unfair area that weather ketchup audit frequent volcano whisper come" MAIN_VAULT_ADDRESS="bcrt1pdut30dgz700zqedv76surg5rnsj8ydc30faefs6h9kmxs67etmesn84alg" BITCOIN_ELECTRUM_API_REGTEST=127.0.0.1:60601 BITCOIN_EXPLORER_API_REGTEST=http://127.0.0.1:3000 cargo test --test payjoin -- --nocapture --exact --test-threads=1

This is the test output, I expanded the BDK Wallet struct for debugging...

TEST_WALLET_SEED="cycle neglect unfair area that weather ketchup audit frequent volcano whisper come" MAIN_VAULT_ADDRESS="bcrt1pdut30dgz700zqedv76surg5rnsj8ydc30faefs6h9kmxs67etmesn84alg" BITCOIN_ELECTRUM_API_REGTEST=127.0.0.1:60601 BITCOIN_EXPLORER_API_REGTEST=http://127.0.0.1:3000 cargo test --test payjoin -- --nocapture --exact --test-threads=1
   Compiling bitmask-core v0.4.4 (/home/hunter/Projects/diba/bitmask-core-3)
    Finished test [unoptimized + debuginfo] target(s) in 2.21s
     Running tests/payjoin.rs (target/debug/deps/payjoin-25bee1afc81156f0)

running 1 test
test payjoin ...  INFO  payjoin > Asset test on regtest
 INFO  payjoin > Import wallets
 INFO  bitmask_core > get_wallet_data
 INFO  bitmask_core > descriptor: tr([77d1d411/86'/1'/0']tprv8fPjzuFHhGWrCCUbPf73GjpFHHgGQxmgD4X9vJjyk2wyQ9DmHXHhvwNGS5NACX9Y1wMpAxunDaNzqks1scjeMMEywvRGGmAK7K2CbrUH1NU/0/*)
 INFO  bitmask_core > change_descriptor: Some("tr([77d1d411/86'/1'/0']tprv8fPjzuFHhGWrCCUbPf73GjpFHHgGQxmgD4X9vJjyk2wyQ9DmHXHhvwNGS5NACX9Y1wMpAxunDaNzqks1scjeMMEywvRGGmAK7K2CbrUH1NU/1/*)")
 DEBUG bitmask_core::operations::bitcoin::balance > Using database: Memory(MemoryDatabase { map: {}, deleted_keys: [] })
 DEBUG bitmask_core::operations::bitcoin::balance > Using wallet: Wallet {
    descriptor: tr(XPub(DescriptorXKey { origin: Some((77d1d411, m/86'/1'/0')), xkey: ExtendedPubKey { network: Testnet, depth: 3, parent_fingerprint: 07ee0f0a, child_number: Hardened { index: 0 }, public_key: PublicKey(82886995067bdbd743c761cfa4567f46aa57797a93df48ffc4691a987deeec4148bae49d101f611e403b62295d6f4b1c5df9168945ca505614b7ab417e8f57b5), chain_code: c6c203d474c16eb03c95e33e8a590a159a2c343e92470d7e9e00dd4ee51a500e }, derivation_path: m/0, wildcard: Unhardened })),
    change_descriptor: Some(
        tr(XPub(DescriptorXKey { origin: Some((77d1d411, m/86'/1'/0')), xkey: ExtendedPubKey { network: Testnet, depth: 3, parent_fingerprint: 07ee0f0a, child_number: Hardened { index: 0 }, public_key: PublicKey(82886995067bdbd743c761cfa4567f46aa57797a93df48ffc4691a987deeec4148bae49d101f611e403b62295d6f4b1c5df9168945ca505614b7ab417e8f57b5), chain_code: c6c203d474c16eb03c95e33e8a590a159a2c343e92470d7e9e00dd4ee51a500e }, derivation_path: m/1, wildcard: Unhardened })),
    ),
    signers: SignersContainer(
        {
            SignersContainerKey {
                id: Fingerprint(
                    77d1d411,
                ),
                ordering: SignerOrdering(
                    100,
                ),
            }: SignerWrapper {
                signer: DescriptorXKey {
                    origin: Some(
                        (
                            77d1d411,
                            m/86h/1h/0h,
                        ),
                    ),
                    xkey: ExtendedPrivKey {
                        network: Testnet,
                        depth: 3,
                        parent_fingerprint: 07ee0f0a,
                        child_number: Hardened {
                            index: 0,
                        },
                        private_key: SecretKey(
                            #dda8e51e80a5e771,
                        ),
                        chain_code: c6c203d474c16eb03c95e33e8a590a159a2c343e92470d7e9e00dd4ee51a500e,
                    },
                    derivation_path: m/0,
                    wildcard: Unhardened,
                },
                ctx: Tap {
                    is_internal_key: true,
                },
            },
        },
    ),
    change_signers: SignersContainer(
        {
            SignersContainerKey {
                id: Fingerprint(
                    77d1d411,
                ),
                ordering: SignerOrdering(
                    100,
                ),
            }: SignerWrapper {
                signer: DescriptorXKey {
                    origin: Some(
                        (
                            77d1d411,
                            m/86h/1h/0h,
                        ),
                    ),
                    xkey: ExtendedPrivKey {
                        network: Testnet,
                        depth: 3,
                        parent_fingerprint: 07ee0f0a,
                        child_number: Hardened {
                            index: 0,
                        },
                        private_key: SecretKey(
                            #dda8e51e80a5e771,
                        ),
                        chain_code: c6c203d474c16eb03c95e33e8a590a159a2c343e92470d7e9e00dd4ee51a500e,
                    },
                    derivation_path: m/1,
                    wildcard: Unhardened,
                },
                ctx: Tap {
                    is_internal_key: true,
                },
            },
        },
    ),
    network: Regtest,
    database: RefCell {
        value: Memory(
            MemoryDatabase {
                map: {
                    [
                        100,
                        101,
                    ]: Any { .. },
                    [
                        100,
                        105,
                    ]: Any { .. },
                },
                deleted_keys: [],
            },
        ),
    },
    secp: <secp256k1 context 0x563bbfac8e40, all capabilities>,
}
 DEBUG bitmask_core::operations::bitcoin::balance > Getting blockchain
 DEBUG bitmask_core::operations::bitcoin::balance > Synced
 INFO  bitmask_core                               > address: bcrt1pyg2rcectuwjg4wcwaxt5z7sne4da7fdjnl376drxxmp2ru0jelhsu5tksl
 INFO  bitmask_core                               > balance: Balance { immature: 1250000000, trusted_pending: 0, untrusted_pending: 0, confirmed: 100000000 }
 INFO  payjoin                                    > Address: bcrt1pyg2rcectuwjg4wcwaxt5z7sne4da7fdjnl376drxxmp2ru0jelhsu5tksl
 INFO  payjoin                                    > Initiating PayJoin using BIP-21
 DEBUG bitmask_core::operations::bitcoin::balance > Using database: Memory(MemoryDatabase { map: {}, deleted_keys: [] })
 DEBUG bitmask_core::operations::bitcoin::balance > Using wallet: Wallet {
    descriptor: tr(XPub(DescriptorXKey { origin: Some((77d1d411, m/86'/1'/0')), xkey: ExtendedPubKey { network: Testnet, depth: 3, parent_fingerprint: 07ee0f0a, child_number: Hardened { index: 0 }, public_key: PublicKey(82886995067bdbd743c761cfa4567f46aa57797a93df48ffc4691a987deeec4148bae49d101f611e403b62295d6f4b1c5df9168945ca505614b7ab417e8f57b5), chain_code: c6c203d474c16eb03c95e33e8a590a159a2c343e92470d7e9e00dd4ee51a500e }, derivation_path: m/0, wildcard: Unhardened })),
    change_descriptor: Some(
        tr(XPub(DescriptorXKey { origin: Some((77d1d411, m/86'/1'/0')), xkey: ExtendedPubKey { network: Testnet, depth: 3, parent_fingerprint: 07ee0f0a, child_number: Hardened { index: 0 }, public_key: PublicKey(82886995067bdbd743c761cfa4567f46aa57797a93df48ffc4691a987deeec4148bae49d101f611e403b62295d6f4b1c5df9168945ca505614b7ab417e8f57b5), chain_code: c6c203d474c16eb03c95e33e8a590a159a2c343e92470d7e9e00dd4ee51a500e }, derivation_path: m/1, wildcard: Unhardened })),
    ),
    signers: SignersContainer(
        {
            SignersContainerKey {
                id: Fingerprint(
                    77d1d411,
                ),
                ordering: SignerOrdering(
                    100,
                ),
            }: SignerWrapper {
                signer: DescriptorXKey {
                    origin: Some(
                        (
                            77d1d411,
                            m/86h/1h/0h,
                        ),
                    ),
                    xkey: ExtendedPrivKey {
                        network: Testnet,
                        depth: 3,
                        parent_fingerprint: 07ee0f0a,
                        child_number: Hardened {
                            index: 0,
                        },
                        private_key: SecretKey(
                            #dda8e51e80a5e771,
                        ),
                        chain_code: c6c203d474c16eb03c95e33e8a590a159a2c343e92470d7e9e00dd4ee51a500e,
                    },
                    derivation_path: m/0,
                    wildcard: Unhardened,
                },
                ctx: Tap {
                    is_internal_key: true,
                },
            },
        },
    ),
    change_signers: SignersContainer(
        {
            SignersContainerKey {
                id: Fingerprint(
                    77d1d411,
                ),
                ordering: SignerOrdering(
                    100,
                ),
            }: SignerWrapper {
                signer: DescriptorXKey {
                    origin: Some(
                        (
                            77d1d411,
                            m/86h/1h/0h,
                        ),
                    ),
                    xkey: ExtendedPrivKey {
                        network: Testnet,
                        depth: 3,
                        parent_fingerprint: 07ee0f0a,
                        child_number: Hardened {
                            index: 0,
                        },
                        private_key: SecretKey(
                            #dda8e51e80a5e771,
                        ),
                        chain_code: c6c203d474c16eb03c95e33e8a590a159a2c343e92470d7e9e00dd4ee51a500e,
                    },
                    derivation_path: m/1,
                    wildcard: Unhardened,
                },
                ctx: Tap {
                    is_internal_key: true,
                },
            },
        },
    ),
    network: Regtest,
    database: RefCell {
        value: Memory(
            MemoryDatabase {
                map: {
                    [
                        100,
                        101,
                    ]: Any { .. },
                    [
                        100,
                        105,
                    ]: Any { .. },
                },
                deleted_keys: [],
            },
        ),
    },
    secp: <secp256k1 context 0x563bbfc334e0, all capabilities>,
}
 DEBUG bitmask_core::operations::bitcoin::balance > Getting blockchain
 DEBUG bitmask_core::operations::bitcoin::balance > Synced
 DEBUG bitmask_core::operations::bitcoin::send_sats > Request PayJoin transaction: TransactionDetails {
    transaction: None,
    txid: ad60e972d29fcb9fadb836feb8ea5fc1ec0b482d8ab4fbf409a0b3683c78bd41,
    received: 99999827,
    sent: 100000000,
    fee: Some(
        173,
    ),
    confirmation_time: None,
}
 DEBUG bitmask_core::operations::bitcoin::send_sats > Unsigned Original PSBT: cHNidP8BAIkBAAAAAdNRSae8tcAzUzdCdZLCPCKu1RBZ71iKrwz+20+a7MgDAQAAAAD9////AugDAAAAAAAAIlEgbxcXtQLz3iBlrPahwaKDnCRyNxF6e5TDVy22aGvZXvNr3PUFAAAAACJRIEIs0HJLi2u6LK9BpKXpyJJlbFPYjDl623HsCClurHgLVwEAAAABASsA4fUFAAAAACJRIG8XF7UC894gZaz2ocGig5wkcjcRenuUw1cttmhr2V7zIRb1sP0b0rWOmZ3zTNybJsPUXuUP3TR5ehKheIZkfHC3JxkAd9HUEVYAAIABAACAAAAAgAAAAAAAAAAAARcg9bD9G9K1jpmd80zcmybD1F7lD900eXoSoXiGZHxwtycAAQUg9bD9G9K1jpmd80zcmybD1F7lD900eXoSoXiGZHxwtychB/Ww/RvStY6ZnfNM3Jsmw9Re5Q/dNHl6EqF4hmR8cLcnGQB30dQRVgAAgAEAAIAAAACAAAAAAAAAAAAAAQUgfo4hQY43Ao5x3vLAgoGNItBfrJyYSOvhx8kU1v7rfeghB36OIUGONwKOcd7ywIKBjSLQX6ycmEjr4cfJFNb+633oGQB30dQRVgAAgAEAAIAAAACAAQAAAAAAAAAA
 DEBUG bitmask_core::operations::bitcoin::psbt      > Funding PSBT...
 INFO  bitmask_core::operations::bitcoin::send_sats > Original PSBT successfully signed
 INFO  bitmask_core::operations::bitcoin::send_sats > Built PayJoin request
 INFO  bitmask_core::operations::bitcoin::send_sats > Got PayJoin response
 INFO  bitmask_core::operations::bitcoin::send_sats > Response hex: {} 7b226572726f72436f6465223a226f726967696e616c2d707362742d72656a6563746564222c226d657373616765223a2254686520505342542073686f756c642062652066696e616c697a6564227d
Error: couldn't decode PSBT

Caused by:
    0: IO error
    1: Invalid byte 123, offset 0.
FAILED

failures:

failures:
    payjoin

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.93s

I'm not sure if the fact that BDK seems to have some internal confusion over regtest vs testnet is the issue.

@DanGould
Copy link
Collaborator

DanGould commented Jan 1, 2023

what is BITCOIN_EXPLORER_API_REGTEST=http://127.0.0.1:3000? Do I need local mempool.space, too?

Co-authored-by: Dan Gould <d@ngould.dev>
@cryptoquick
Copy link
Member Author

what is BITCOIN_EXPLORER_API_REGTEST=http://127.0.0.1:3000? Do I need local mempool.space, too?

No, it's to the Blockstream fork of electrs used for Esplora, which can be found here:
https://github.com/Blockstream/electrs

It must be run in conjunction with bitcoind, like in the example I provided here:
#121 (comment)

Perhaps we should document this, but it was always meant to be temporary, since we also want to build this:
romanz/electrs#820

@cryptoquick
Copy link
Member Author

@DanGould Just tested your latest change, got this as a response:
Response: {"errorCode":"original-psbt-rejected","message":"Provided transaction isn't mempool eligible missing-inputs"}

@DanGould
Copy link
Collaborator

DanGould commented Jan 2, 2023

Sounds like it's working to me! Of course btcpayserver won't find your regtest input, they're running testnet.

I'm not clear about the direction of the test environment. How do you switch between testnet / regtest? Will there be a docker container or nix flake to manage the env in the future?

@cryptoquick
Copy link
Member Author

Oh nice, that makes sense! We switch by calling a method to change it in an in-memory singleton, but I just realized, we don't have a way to do so through env vars yet. I can get that added, it's a handy feature to have, and then we can use different wallets in CI.

@cryptoquick
Copy link
Member Author

@DanGould It's kind of silly, but I've cheesed it on this for now. Once it makes it into the next version of BitMask, I'll have to invite you to test it out. Also, one thing that might be helpful is if your process_response method returned an error that had more error information than just "couldn't decode PSBT"; something including the error message might be more helpful to disambiguate between the different kinds of errors. Anyway, I'll ask my teammates to review this now.

@cryptoquick cryptoquick marked this pull request as ready for review January 3, 2023 07:16
@DanGould
Copy link
Collaborator

DanGould commented Jan 4, 2023

can't decode PSBT means the PSBT as serialized is not valid and it's a single error from consensus decoding. Maybe it should be more explicit that the de/encoding de/serialization is wrong

Edit: I need to know what "cheesed it on this" means. You smilin?

@cryptoquick
Copy link
Member Author

can't decode PSBT means the PSBT as serialized is not valid and it's a single error from consensus decoding. Maybe it should be more explicit that the de/encoding de/serialization is wrong

Edit: I need to know what "cheesed it on this" means. You smilin?

Yeah, the error message is wrong, it returns the same message when there's multiple things that could go wrong.

And yes, smilin, it's just a silly test case, but it could be improved if there were richer errors returned.

@cryptoquick
Copy link
Member Author

@josediegorobles Please review at your earliest convenience.

@cryptoquick
Copy link
Member Author

Thanks for the review, @josediegorobles!

@cryptoquick cryptoquick merged commit 836ea42 into development Jan 9, 2023
@cryptoquick cryptoquick deleted the HT/payjoin-test-wip branch January 18, 2023 19:31
DanGould added a commit to payjoin/rust-payjoin that referenced this pull request Apr 24, 2023
node-smithxby72w added a commit to node-smithxby72w/rust-payjoin that referenced this pull request Sep 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants