bdk icon indicating copy to clipboard operation
bdk copied to clipboard

More tests for `bdk_electrum` fee calculation

Open evanlinjin opened this issue 1 year ago • 1 comments

PR #1443 identified a large oversight when we added the new feature of including prev txouts for fee calculation.

I propose a separate test specific to testing fee calculation that takes into account what @ValuedMammal mentioned in https://github.com/bitcoindevkit/bdk/pull/1443#issuecomment-2111400860:

In the integration test for electrum the outpoint we're looking for will always have a vout of 0 (they are coinbase txs), so calculating the fee of the received tx happens to work by sheer luck. A more robust test would involve controlling the utxo spent by Core and in which order it appears in the tx which is posing more of a challenge.

Originally posted by @evanlinjin in https://github.com/bitcoindevkit/bdk/issues/1443#issuecomment-2112131325

evanlinjin avatar May 15 '24 10:05 evanlinjin

calculating the fee of the received tx happens to work by sheer luck

Correction: not by luck, but because the outpoint is determined to have a vout of 0 and before the fix we're always inserting the first txout.

After sleeping on it I think one way to do this is to send a "preliminary" tx to an address in Core's wallet such that the output created becomes the input of the next tx. This preliminary tx is the prev_tx that needs to be fetched in order to calculate the fee of the tx sent to the receiver. This way is better because the required outpoint is less determined. Then we assert we have the right (outpoint, txout) in the update TxGraph. Example ValuedMammal/bdk@953dbb3d9c78496b16c8c312387f0087f1756f5d

ValuedMammal avatar May 15 '24 14:05 ValuedMammal

hi @ValuedMammal @notmandatory could I work on this issue?

f3r10 avatar Nov 12 '24 18:11 f3r10