From 07549d50ff4209265f4f421530b44875fae5af90 Mon Sep 17 00:00:00 2001 From: Bjarne Magnussen Date: Wed, 19 Aug 2020 12:00:05 +0200 Subject: [PATCH] chanfunding: assure logic for high-fee Without this change the high-fee logic is never tested as it is instead caught by the dust-output logic. This change uses a higher fee rate to ensure an output value above the dust limit, while still spending 20% on fees. --- lnwallet/chanfunding/coin_select_test.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lnwallet/chanfunding/coin_select_test.go b/lnwallet/chanfunding/coin_select_test.go index 38a1a7e1d..36cc64fdb 100644 --- a/lnwallet/chanfunding/coin_select_test.go +++ b/lnwallet/chanfunding/coin_select_test.go @@ -205,11 +205,13 @@ func TestCoinSelectSubtractFees(t *testing.T) { t.Parallel() const feeRate = chainfee.SatPerKWeight(100) + const highFeeRate = chainfee.SatPerKWeight(1000) const dustLimit = btcutil.Amount(1000) const dust = btcutil.Amount(100) type testCase struct { name string + highFee bool spendValue btcutil.Amount coins []Coin @@ -320,16 +322,17 @@ func TestCoinSelectSubtractFees(t *testing.T) { }, { // If more than 20% of funds goes to fees, it should fail. - name: "high fee", + name: "high fee", + highFee: true, coins: []Coin{ { TxOut: wire.TxOut{ PkScript: p2wkhScript, - Value: int64(5 * fundingFee(feeRate, 1, false)), + Value: int64(5 * fundingFee(highFeeRate, 1, false)), }, }, }, - spendValue: 5 * fundingFee(feeRate, 1, false), + spendValue: 5 * fundingFee(highFeeRate, 1, false), expectErr: true, }, @@ -339,6 +342,11 @@ func TestCoinSelectSubtractFees(t *testing.T) { test := test t.Run(test.name, func(t *testing.T) { + feeRate := feeRate + if test.highFee { + feeRate = highFeeRate + } + selected, localFundingAmt, changeAmt, err := CoinSelectSubtractFees( feeRate, test.spendValue, dustLimit, test.coins, )