bdk icon indicating copy to clipboard operation
bdk copied to clipboard

The `insert_txouts` test in `test_tx_graph.rs` needs redoing.

Open evanlinjin opened this issue 1 year ago • 6 comments

Describe the bug

https://github.com/bitcoindevkit/bdk/blob/7aca88474ac241bc0938ff989026463bdaf8f3ab/crates/chain/tests/test_tx_graph.rs#L16-L17

This test misunderstands Anchors. There is no such thing as an "unconfirmed anchor", and ChainPosition does not implement Anchor. We should rewrite this test to be comprehensive.

Proposed test scenarios

  • [ ] Insert tx with txid A, then insert partial txout(s) of the same txid. Expect: No changes to TxGraph (full tx should still exist in graph). Returned changeset is empty.
  • [ ] Insert partial txout with txid B. Then insert full tx with txid B. Expect: the full tx should replace the partial tx. Check graph and returned changeset to confirm this.
  • [ ] Do the above two tests with different counts of partial txids.

evanlinjin avatar Feb 08 '24 07:02 evanlinjin

Let me try this.

yanganto avatar Feb 08 '24 07:02 yanganto

How does this line even compile:

https://github.com/bitcoindevkit/bdk/blob/7aca88474ac241bc0938ff989026463bdaf8f3ab/crates/chain/tests/test_tx_graph.rs#L97

If unconf_anchor isn't even an Anchor how can you pass it to insert_anchor!?!?!?

LLFourn avatar Feb 08 '24 23:02 LLFourn

If unconf_anchor isn't even an Anchor how can you pass it to insert_anchor!?!?!?

We will remove Anchor implementation for ChainPosition<A> to avoid the caller using UnconfirmChainPosition(u64) as an anchor to avoid malusage.

yanganto avatar Feb 10 '24 08:02 yanganto

How does this line even compile:

https://github.com/bitcoindevkit/bdk/blob/7aca88474ac241bc0938ff989026463bdaf8f3ab/crates/chain/tests/test_tx_graph.rs#L97

If unconf_anchor isn't even an Anchor how can you pass it to insert_anchor!?!?!?

We aren't enforcing the A: Anchor bound on that method. Now the question is, should we? What should be the policy of how we do generic bounds? I tend to avoid them wherever possible because bounds stack and it becomes annoying to deal with at higher levels.

evanlinjin avatar Feb 11 '24 08:02 evanlinjin

If unconf_anchor isn't even an Anchor how can you pass it to insert_anchor!?!?!?

We will remove Anchor implementation for ChainPosition<A> to avoid the caller using UnconfirmChainPosition(u64) as an anchor to avoid malusage.

There is no Anchor implementation for ChainPosition. https://github.com/bitcoindevkit/bdk/pull/1338#discussion_r1485538692

evanlinjin avatar Feb 11 '24 08:02 evanlinjin

yeh, I misread it.

yanganto avatar Feb 11 '24 23:02 yanganto