sweep: use p2tr output as change weight

This commit is contained in:
Eugene Siegel
2023-12-14 12:14:08 -05:00
committed by eugene
parent ac9ca024a4
commit b47c1da07d
2 changed files with 7 additions and 7 deletions

View File

@@ -79,7 +79,7 @@ func (t *txInputSetState) weightEstimate(change bool) *weightEstimator {
// Add a change output to the weight estimate if requested. // Add a change output to the weight estimate if requested.
if change { if change {
weightEstimate.addP2WKHOutput() weightEstimate.addP2TROutput()
} }
return weightEstimate return weightEstimate

View File

@@ -32,23 +32,23 @@ func TestTxInputSet(t *testing.T) {
} }
fee := set.weightEstimate(true).fee() fee := set.weightEstimate(true).fee()
require.Equal(t, btcutil.Amount(439), fee) require.Equal(t, btcutil.Amount(487), fee)
// The tx output should now be 700-439 = 261 sats. The dust limit isn't // The tx output should now be 700-487 = 213 sats. The dust limit isn't
// reached yet. // reached yet.
if set.totalOutput() != 261 { if set.totalOutput() != 213 {
t.Fatal("unexpected output value") t.Fatal("unexpected output value")
} }
if set.enoughInput() { if set.enoughInput() {
t.Fatal("expected dust limit not yet to be reached") t.Fatal("expected dust limit not yet to be reached")
} }
// Add a 1000 sat input. This increases the tx fee to 712 sats. The tx // Add a 1000 sat input. This increases the tx fee to 760 sats. The tx
// output should now be 1000+700 - 712 = 988 sats. // output should now be 1000+700 - 760 = 940 sats.
if !set.add(createP2WKHInput(1000), constraintsRegular) { if !set.add(createP2WKHInput(1000), constraintsRegular) {
t.Fatal("expected add of positively yielding input to succeed") t.Fatal("expected add of positively yielding input to succeed")
} }
if set.totalOutput() != 988 { if set.totalOutput() != 940 {
t.Fatal("unexpected output value") t.Fatal("unexpected output value")
} }
if !set.enoughInput() { if !set.enoughInput() {