From 3afa16b7a640e7be6b9549a22cb29cf572d024de Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Thu, 26 Jul 2018 19:18:59 +0200 Subject: [PATCH] mock: make ListUnspentWitness return new outpoints each call --- mock.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mock.go b/mock.go index e7b41828..b3ccd610 100644 --- a/mock.go +++ b/mock.go @@ -4,16 +4,17 @@ import ( "crypto/sha256" "fmt" "sync" + "sync/atomic" - "github.com/lightningnetwork/lnd/chainntnfs" - "github.com/lightningnetwork/lnd/keychain" - "github.com/lightningnetwork/lnd/lnwallet" "github.com/btcsuite/btcd/btcec" "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" + "github.com/lightningnetwork/lnd/chainntnfs" + "github.com/lightningnetwork/lnd/keychain" + "github.com/lightningnetwork/lnd/lnwallet" ) // The block height returned by the mock BlockChainIO's GetBestBlock. @@ -191,6 +192,7 @@ type mockWalletController struct { rootKey *btcec.PrivateKey prevAddres btcutil.Address publishedTransactions chan *wire.MsgTx + index uint32 } // BackEnd returns "mock" to signify a mock wallet controller. @@ -231,16 +233,17 @@ func (*mockWalletController) SendOutputs(outputs []*wire.TxOut, // ListUnspentWitness is called by the wallet when doing coin selection. We just // need one unspent for the funding transaction. -func (*mockWalletController) ListUnspentWitness(confirms int32) ([]*lnwallet.Utxo, error) { +func (m *mockWalletController) ListUnspentWitness(confirms int32) ([]*lnwallet.Utxo, error) { utxo := &lnwallet.Utxo{ AddressType: lnwallet.WitnessPubKey, Value: btcutil.Amount(10 * btcutil.SatoshiPerBitcoin), PkScript: make([]byte, 22), OutPoint: wire.OutPoint{ Hash: chainhash.Hash{}, - Index: 0, + Index: m.index, }, } + atomic.AddUint32(&m.index, 1) var ret []*lnwallet.Utxo ret = append(ret, utxo) return ret, nil