Documentation
¶
Index ¶
- Variables
- func CreateKey(index int32) (*btcec.PrivateKey, *btcec.PublicKey)
- func DumpGoroutines()
- func EncodePayReq(payReq *zpay32.Invoice) (string, error)
- func GetDestAddr(t *testing.T, nr byte) btcutil.Address
- func GetInvoice(hash lntypes.Hash, amt btcutil.Amount, memo string) (string, error)
- func Guard(t *testing.T, opts ...GuardOption) func()
- type ConfRegistration
- type Context
- func (ctx *Context) AssertEpochListeners(numListeners int32)
- func (ctx *Context) AssertFailed(expectedHash lntypes.Hash)
- func (ctx *Context) AssertPaid(expectedMemo string) func(error)
- func (ctx *Context) AssertRegisterConf(expectTxHash bool, confs int32) *ConfRegistration
- func (ctx *Context) AssertRegisterSpendNtfn(script []byte)
- func (ctx *Context) AssertSettled(expectedHash lntypes.Hash) lntypes.Preimage
- func (ctx *Context) AssertTrackPayment() TrackPaymentMessage
- func (ctx *Context) DecodeInvoice(request string) *zpay32.Invoice
- func (ctx *Context) GetOutputIndex(tx *wire.MsgTx, script []byte) int
- func (ctx *Context) NotifyConf(tx *wire.MsgTx)
- func (ctx *Context) NotifyServerHeight(height int32)
- func (ctx *Context) NotifySpend(tx *wire.MsgTx, inputIndex uint32)
- func (ctx *Context) ReceiveTx() *wire.MsgTx
- type GuardConfig
- type GuardOption
- type LndMockServices
- func (s *LndMockServices) AddTx(tx *wire.MsgTx)
- func (s *LndMockServices) DecodeInvoice(request string) (*zpay32.Invoice, error)
- func (s *LndMockServices) EpochSubscribers() int32
- func (s *LndMockServices) IsDone() error
- func (s *LndMockServices) NotifyHeight(height int32) error
- func (s *LndMockServices) SetFeeEstimate(confTarget int32, feeEstimate chainfee.SatPerKWeight)
- func (s *LndMockServices) SetListUnspent(utxos []*lnwallet.Utxo)
- func (s *LndMockServices) SetMinRelayFee(feeEstimate chainfee.SatPerKWeight)
- type PaymentChannelMessage
- type PublishHandler
- type RouterPaymentChannelMessage
- type SignOutputRawRequest
- type SingleInvoiceSubscription
- type SpendRegistration
- type TrackPaymentMessage
Constants ¶
This section is empty.
Variables ¶
var ( // Timeout is the default timeout when tests wait for something to // happen. Timeout = time.Second * 5 // ErrTimeout is returned on timeout. ErrTimeout = errors.New("test timeout") )
var DefaultMockFee = chainfee.SatPerKWeight(10000)
DefaultMockFee is the default value we use for fee estimates when no values are set for specific conf targets.
Functions ¶
func CreateKey ¶
func CreateKey(index int32) (*btcec.PrivateKey, *btcec.PublicKey)
CreateKey returns a deterministically generated key pair.
func EncodePayReq ¶
EncodePayReq encodes a zpay32 invoice with a fixed key.
func GetDestAddr ¶
GetDestAddr deterministically generates a sweep address for testing.
func GetInvoice ¶
GetInvoice creates a testnet payment request with the given parameters.
func Guard ¶
func Guard(t *testing.T, opts ...GuardOption) func()
Guard implements a test level timeout.
Types ¶
type ConfRegistration ¶
type ConfRegistration struct {
TxID *chainhash.Hash
PkScript []byte
HeightHint int32
NumConfs int32
ConfChan chan *chainntnfs.TxConfirmation
ErrChan chan<- error
}
ConfRegistration contains registration details.
type Context ¶
type Context struct {
T *testing.T
Lnd *LndMockServices
FailedInvoices map[lntypes.Hash]struct{}
PaidInvoices map[string]func(error)
}
Context contains shared test context functions.
func NewContext ¶
func NewContext(t *testing.T, lnd *LndMockServices) Context
NewContext instanties a new common test context.
func (*Context) AssertEpochListeners ¶
func (*Context) AssertFailed ¶
AssertFailed asserts that an invoice with the given hash is failed.
func (*Context) AssertPaid ¶
AssertPaid asserts that the expected payment request has been paid. This function returns a complete function to signal the final payment result.
func (*Context) AssertRegisterConf ¶
func (ctx *Context) AssertRegisterConf(expectTxHash bool, confs int32) *ConfRegistration
AssertRegisterConf asserts that a register for conf has been received.
func (*Context) AssertRegisterSpendNtfn ¶
AssertRegisterSpendNtfn asserts that a register for spend has been received.
func (*Context) AssertSettled ¶
AssertSettled asserts that an invoice with the given hash is settled.
func (*Context) AssertTrackPayment ¶
func (ctx *Context) AssertTrackPayment() TrackPaymentMessage
AssertTrackPayment asserts that a call was made to track payment, and returns the track payment message so that it can be used to send updates to the test.
func (*Context) DecodeInvoice ¶
DecodeInvoice decodes a payment request string.
func (*Context) GetOutputIndex ¶
GetOutputIndex returns the index in the tx outs of the given script hash.
func (*Context) NotifyConf ¶
NotifyConf simulates a conf.
func (*Context) NotifyServerHeight ¶
NotifyServerHeight notifies the server of the arrival of a new block and waits for the notification to be processed by selecting on a dedicated test channel.
func (*Context) NotifySpend ¶
NotifySpend simulates a spend.
type GuardConfig ¶
type GuardConfig struct {
// contains filtered or unexported fields
}
GuardConfig stores options for Guard function.
type GuardOption ¶
type GuardOption func(*GuardConfig)
GuardOption is an option for Guard function.
func WithGuardTimeout ¶
func WithGuardTimeout(timeout time.Duration) GuardOption
WithGuardTimeout sets timeout for the guard. Default is 5s.
type LndMockServices ¶
type LndMockServices struct {
lndclient.LndServices
SendPaymentChannel chan PaymentChannelMessage
SpendChannel chan *chainntnfs.SpendDetail
TxPublishChannel chan *wire.MsgTx
SendOutputsChannel chan wire.MsgTx
SettleInvoiceChannel chan lntypes.Preimage
FailInvoiceChannel chan lntypes.Hash
ConfChannel chan *chainntnfs.TxConfirmation
RegisterConfChannel chan *ConfRegistration
RegisterSpendChannel chan *SpendRegistration
SingleInvoiceSubcribeChannel chan *SingleInvoiceSubscription
RouterSendPaymentChannel chan RouterPaymentChannelMessage
TrackPaymentChannel chan TrackPaymentMessage
SignOutputRawChannel chan SignOutputRawRequest
Height int32
NodePubkey string
Signature []byte
SignatureMsg string
Transactions []lndclient.Transaction
Sweeps []string
SweepsVerbose []lnwallet.TransactionDetail
// Invoices is a set of invoices that have been created by the mock,
// keyed by hash string.
Invoices map[lntypes.Hash]*lndclient.Invoice
Channels []lndclient.ChannelInfo
ChannelEdges map[uint64]*lndclient.ChannelEdge
ClosedChannels []lndclient.ClosedChannel
ForwardingEvents []lndclient.ForwardingEvent
Payments []lndclient.Payment
MissionControlState []lndclient.MissionControlEntry
WaitForFinished func()
PublishHandler PublishHandler
// contains filtered or unexported fields
}
LndMockServices provides a full set of mocked lnd services.
func NewMockLnd ¶
func NewMockLnd() *LndMockServices
NewMockLnd returns a new instance of LndMockServices that can be used in unit tests.
func (*LndMockServices) AddTx ¶
func (s *LndMockServices) AddTx(tx *wire.MsgTx)
AddTx marks the given transaction as relevant.
func (*LndMockServices) DecodeInvoice ¶
func (s *LndMockServices) DecodeInvoice(request string) (*zpay32.Invoice, error)
DecodeInvoice decodes a payment request string.
func (*LndMockServices) EpochSubscribers ¶
func (s *LndMockServices) EpochSubscribers() int32
EpochSubscribers returns the number of subscribers to block epoch notifications.
func (*LndMockServices) IsDone ¶
func (s *LndMockServices) IsDone() error
IsDone checks whether all channels have been fully emptied. If not this may indicate unexpected behaviour of the code under test.
func (*LndMockServices) NotifyHeight ¶
func (s *LndMockServices) NotifyHeight(height int32) error
NotifyHeight notifies a new block height.
func (*LndMockServices) SetFeeEstimate ¶
func (s *LndMockServices) SetFeeEstimate(confTarget int32, feeEstimate chainfee.SatPerKWeight)
func (*LndMockServices) SetListUnspent ¶
func (s *LndMockServices) SetListUnspent(utxos []*lnwallet.Utxo)
SetListUnspent sets the list of UTXOs returned by the mock's WalletKit ListUnspent call.
func (*LndMockServices) SetMinRelayFee ¶
func (s *LndMockServices) SetMinRelayFee(feeEstimate chainfee.SatPerKWeight)
type PaymentChannelMessage ¶
type PaymentChannelMessage struct {
PaymentRequest string
Done chan lndclient.PaymentResult
}
PaymentChannelMessage is the data that passed through SendPaymentChannel.
type PublishHandler ¶
PublishHandler is optional transaction handler function called upon calling the method PublishTransaction.
type RouterPaymentChannelMessage ¶
type RouterPaymentChannelMessage struct {
lndclient.SendPaymentRequest
TrackPaymentMessage
}
RouterPaymentChannelMessage is the data that passed through RouterSendPaymentChannel.
type SignOutputRawRequest ¶
type SignOutputRawRequest struct {
Tx *wire.MsgTx
SignDescriptors []*lndclient.SignDescriptor
}
SignOutputRawRequest contains input data for a tx signing request.
type SingleInvoiceSubscription ¶
type SingleInvoiceSubscription struct {
Hash lntypes.Hash
Update chan lndclient.InvoiceUpdate
Err chan error
}
SingleInvoiceSubscription contains the single invoice subscribers.
type SpendRegistration ¶
type SpendRegistration struct {
Outpoint *wire.OutPoint
PkScript []byte
HeightHint int32
SpendChannel chan<- *chainntnfs.SpendDetail
ErrChan chan<- error
}
SpendRegistration contains registration details.
type TrackPaymentMessage ¶
type TrackPaymentMessage struct {
Hash lntypes.Hash
Updates chan lndclient.PaymentStatus
Errors chan error
}
TrackPaymentMessage is the data that passed through TrackPaymentChannel.