mock: make ListUnspentWitness return new outpoints each call

This commit is contained in:
Johan T. Halseth 2018-07-26 19:18:59 +02:00
parent 5b77ebddb2
commit 3afa16b7a6
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

13
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