test

package
v0.11.1-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2020 License: MIT Imports: 35 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)

Functions

func CreateKey

func CreateKey(index int32) (*btcec.PrivateKey, *btcec.PublicKey)

CreateKey returns a deterministically generated key pair.

func DumpGoroutines

func DumpGoroutines()

DumpGoroutines dumps all currently running goroutines.

func EncodePayReq

func EncodePayReq(payReq *zpay32.Invoice) (string, error)

EncodePayReq encodes a zpay32 invoice with a fixed key.

func GetDestAddr

func GetDestAddr(t *testing.T, nr byte) btcutil.Address

GetDestAddr deterministically generates a sweep address for testing.

func GetInvoice

func GetInvoice(hash lntypes.Hash, amt btcutil.Amount, memo string) (
	string, error)

GetInvoice creates a testnet payment request with the given parameters.

func Guard

func Guard(t *testing.T) 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
}

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) AssertFailed

func (ctx *Context) AssertFailed(expectedHash lntypes.Hash)

AssertFailed asserts that an invoice with the given hash is failed.

func (*Context) AssertPaid

func (ctx *Context) AssertPaid(
	expectedMemo string) func(error)

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

func (ctx *Context) AssertRegisterSpendNtfn(script []byte)

AssertRegisterSpendNtfn asserts that a register for spend has been received.

func (*Context) AssertSettled

func (ctx *Context) AssertSettled(
	expectedHash lntypes.Hash) lntypes.Preimage

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

func (ctx *Context) DecodeInvoice(request string) *zpay32.Invoice

DecodeInvoice decodes a payment request string.

func (*Context) GetOutputIndex

func (ctx *Context) GetOutputIndex(tx *wire.MsgTx,
	script []byte) int

GetOutputIndex returns the index in the tx outs of the given script hash.

func (*Context) NotifyConf

func (ctx *Context) NotifyConf(tx *wire.MsgTx)

NotifyConf simulates a conf.

func (*Context) NotifyServerHeight

func (ctx *Context) NotifyServerHeight(height int32)

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

func (ctx *Context) NotifySpend(tx *wire.MsgTx, inputIndex uint32)

NotifySpend simulates a spend.

func (*Context) ReceiveTx

func (ctx *Context) ReceiveTx() *wire.MsgTx

ReceiveTx receives and decodes a published tx.

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

	// 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
	ClosedChannels   []lndclient.ClosedChannel
	ForwardingEvents []lndclient.ForwardingEvent
	Payments         []lndclient.Payment

	WaitForFinished func()
	// 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)

AddRelevantTx 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) 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)

type PaymentChannelMessage

type PaymentChannelMessage struct {
	PaymentRequest string
	Done           chan lndclient.PaymentResult
}

PaymentChannelMessage is the data that passed through SendPaymentChannel.

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
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL