From 7f9df26efd34d5c723b6519bd7f8983efb52ea2a Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Mon, 9 Nov 2020 18:49:44 +0100 Subject: [PATCH] sweeper_test: return unique wallet utxos We also increase the value of the wallet UTXO, as it is needed when we want to afford fees for larger transactions. --- sweep/backend_mock_test.go | 11 +++++++++++ sweep/sweeper_test.go | 13 +++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/sweep/backend_mock_test.go b/sweep/backend_mock_test.go index dea018e3..a466b272 100644 --- a/sweep/backend_mock_test.go +++ b/sweep/backend_mock_test.go @@ -27,6 +27,7 @@ type mockBackend struct { publishChan chan wire.MsgTx walletUtxos []*lnwallet.Utxo + utxoCnt int } func newMockBackend(t *testing.T, notifier *MockNotifier) *mockBackend { @@ -88,6 +89,16 @@ func (b *mockBackend) PublishTransaction(tx *wire.MsgTx, _ string) error { func (b *mockBackend) ListUnspentWitness(minconfirms, maxconfirms int32) ( []*lnwallet.Utxo, error) { + b.lock.Lock() + defer b.lock.Unlock() + + // Each time we list output, we increment the utxo counter, to + // ensure we don't return the same outpoint every time. + b.utxoCnt++ + + for i := range b.walletUtxos { + b.walletUtxos[i].OutPoint.Hash[0] = byte(b.utxoCnt) + } return b.walletUtxos, nil } diff --git a/sweep/sweeper_test.go b/sweep/sweeper_test.go index 77e9d2b5..af27ecb6 100644 --- a/sweep/sweeper_test.go +++ b/sweep/sweeper_test.go @@ -64,7 +64,7 @@ var ( func createTestInput(value int64, witnessType input.WitnessType) input.BaseInput { hash := chainhash.Hash{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - byte(testInputCount)} + byte(testInputCount + 1)} input := input.MakeBaseInput( &wire.OutPoint{ @@ -106,7 +106,7 @@ func createSweeperTestContext(t *testing.T) *sweeperTestContext { backend := newMockBackend(t, notifier) backend.walletUtxos = []*lnwallet.Utxo{ { - Value: btcutil.Amount(10000), + Value: btcutil.Amount(1_000_000), AddressType: lnwallet.WitnessPubKey, }, } @@ -493,8 +493,9 @@ func TestWalletUtxo(t *testing.T) { "inputs instead", len(sweepTx.TxIn)) } - // Calculate expected output value based on wallet utxo of 10000 sats. - expectedOutputValue := int64(294 + 10000 - 180) + // Calculate expected output value based on wallet utxo of 1_000_000 + // sats. + expectedOutputValue := int64(294 + 1_000_000 - 180) if sweepTx.TxOut[0].Value != expectedOutputValue { t.Fatalf("Expected output value of %v, but got %v", expectedOutputValue, sweepTx.TxOut[0].Value) @@ -1369,8 +1370,8 @@ func TestCpfp(t *testing.T) { // package, making a total of 1059. At 5000 sat/kw, the required fee for // the package is 5295 sats. The parent already paid 900 sats, so there // is 4395 sat remaining to be paid. The expected output value is - // therefore: 10000 + 330 - 4395 = 5935. - require.Equal(t, int64(5935), tx.TxOut[0].Value) + // therefore: 1_000_000 + 330 - 4395 = 995 935. + require.Equal(t, int64(995_935), tx.TxOut[0].Value) // Mine the tx and assert that the result is passed back. ctx.backend.mine()