From c56457c869042daf04b0746c8c8fc61ca4b0f61a Mon Sep 17 00:00:00 2001 From: Bjarne Magnussen Date: Wed, 19 Aug 2020 12:09:35 +0200 Subject: [PATCH] chanfunding: add test for a non-zero change --- lnwallet/chanfunding/coin_select_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lnwallet/chanfunding/coin_select_test.go b/lnwallet/chanfunding/coin_select_test.go index 36cc64fd..3b02c34b 100644 --- a/lnwallet/chanfunding/coin_select_test.go +++ b/lnwallet/chanfunding/coin_select_test.go @@ -244,6 +244,27 @@ func TestCoinSelectSubtractFees(t *testing.T) { expectedFundingAmt: 1*btcutil.SatoshiPerBitcoin - fundingFee(feeRate, 1, false), expectedChange: 0, }, + { + // We have 1.0 BTC available and spend half of it. This + // should lead to a funding TX with a change output. + name: "spend with change", + coins: []Coin{ + { + TxOut: wire.TxOut{ + PkScript: p2wkhScript, + Value: 1 * btcutil.SatoshiPerBitcoin, + }, + }, + }, + spendValue: 0.5 * btcutil.SatoshiPerBitcoin, + + // The one and only input will be selected. + expectedInput: []btcutil.Amount{ + 1 * btcutil.SatoshiPerBitcoin, + }, + expectedFundingAmt: 0.5*btcutil.SatoshiPerBitcoin - fundingFee(feeRate, 1, true), + expectedChange: 0.5 * btcutil.SatoshiPerBitcoin, + }, { // The total funds available is below the dust limit // after paying fees.