bitcoindevkit / bdk

A modern, lightweight, descriptor-based wallet library written in Rust!
Other
860 stars 307 forks source link

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

Open evanlinjin opened 8 months ago

evanlinjin commented 8 months ago

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

yanganto commented 8 months ago

Let me try this.

LLFourn commented 8 months ago

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!?!?!?

yanganto commented 8 months ago

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.

evanlinjin commented 8 months ago

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 commented 8 months ago

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

yanganto commented 8 months ago

yeh, I misread it.