test/test: add lookup invoice to mock lightning client

Track the invoices we create with AddInvoice so that we can
realistically lookup and settle with the mock.
pull/190/head
carla 4 years ago
parent c6695c485b
commit b4719862e2
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91

@ -7,6 +7,8 @@ import (
"sync"
"time"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
@ -125,9 +127,39 @@ func (h *mockLightningClient) AddInvoice(ctx context.Context,
return lntypes.Hash{}, "", err
}
// Add the invoice we have created to our mock's set of invoices.
h.lnd.Invoices[hash.String()] = &lndclient.Invoice{
Preiamge: nil,
Hash: hash,
PaymentRequest: payReqString,
Amount: in.Value,
CreationDate: time.Now(),
State: channeldb.ContractOpen,
IsKeysend: false,
}
return hash, payReqString, nil
}
// LookupInvoice looks up an invoice in the mock's set of stored invoices.
// If it is not found, this call will fail. Note that these invoices should
// be settled using settleInvoice to have a preimage, settled state and settled
// date set.
func (h *mockLightningClient) LookupInvoice(_ context.Context,
// nolint: interfacer
hash lntypes.Hash) (*lndclient.Invoice, error) {
h.lnd.lock.Lock()
defer h.lnd.lock.Unlock()
inv, ok := h.lnd.Invoices[hash.String()]
if !ok {
return nil, fmt.Errorf("invoice: %x not found", hash)
}
return inv, nil
}
// ListTransactions returns all known transactions of the backing lnd node.
func (h *mockLightningClient) ListTransactions(
ctx context.Context) ([]*wire.MsgTx, error) {

@ -69,6 +69,7 @@ func NewMockLnd() *LndMockServices {
NodePubkey: testNodePubkey,
Signature: testSignature,
SignatureMsg: testSignatureMsg,
Invoices: make(map[string]*lndclient.Invoice),
}
lightningClient.lnd = &lnd
@ -158,6 +159,10 @@ type LndMockServices struct {
Transactions []*wire.MsgTx
// Invoices is a set of invoices that have been created by the mock,
// keyed by hash string.
Invoices map[string]*lndclient.Invoice
WaitForFinished func()
lock sync.Mutex

Loading…
Cancel
Save