lntest

package
v0.0.0-...-fd58d5e Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: MIT Imports: 38 Imported by: 0

README

lntest

A testing framework for lightning nodes on regtest.

Features

  • Isolated testing environment
  • Create node in testing environment (choice which node/version you want)
  • Connect nodes (peering)
  • Deposit onchain funds
  • Open channel
  • Wait for channel to confirm
  • Check channel is in node's channel graph
  • Check node is in node's channel graph
  • Create invoice
  • Send payment
  • Create lsp (custom node) in testing environment

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckError

func CheckError(t *testing.T, err error)

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

func GenerateRandomString

func GenerateRandomString() (string, error)

func GetBitcoinCliBinary

func GetBitcoinCliBinary() (string, error)

func GetBitcoindBinary

func GetBitcoindBinary() (string, error)

func GetLightningdBinary

func GetLightningdBinary() (string, error)

func GetLndBinary

func GetLndBinary() (string, error)

func GetPort

func GetPort() (uint32, error)

func GetPreserveLogs

func GetPreserveLogs() bool

func GetPreserveState

func GetPreserveState() bool

func GetTestRootDir

func GetTestRootDir() (*string, error)

func PerformCleanup

func PerformCleanup(cleanups []*Cleanup)

Runs the cleanup functions in reverse order.

Types

type ChannelDetails

type ChannelDetails struct {
	PeerId              []byte
	ShortChannelID      ShortChannelID
	CapacityMsat        uint64
	LocalReserveMsat    uint64
	RemoteReserveMsat   uint64
	LocalSpendableMsat  uint64
	RemoteSpendableMsat uint64
	LocalAlias          *ShortChannelID
	RemoteAlias         *ShortChannelID
}

type ChannelInfo

type ChannelInfo struct {
	From            LightningNode
	To              LightningNode
	FundingTxId     []byte
	FundingTxOutnum uint32
}

func (*ChannelInfo) GetPeer

func (c *ChannelInfo) GetPeer(this LightningNode) LightningNode

func (*ChannelInfo) WaitForChannelReady

func (c *ChannelInfo) WaitForChannelReady() ShortChannelID

type Cleanable

type Cleanable interface {
	Cleanup() error
}

type Cleanup

type Cleanup struct {
	Name string
	Fn   CleanupFunc
}

type CleanupFunc

type CleanupFunc func() error

type ClnNode

type ClnNode struct {
	// contains filtered or unexported fields
}

func NewClnNode

func NewClnNode(h *TestHarness, m *Miner, name string, extraArgs ...string) *ClnNode

func NewClnNodeFromBinary

func NewClnNodeFromBinary(h *TestHarness, m *Miner, name string, binary string, extraArgs ...string) *ClnNode

func (*ClnNode) CaCertPath

func (n *ClnNode) CaCertPath() string

func (*ClnNode) ClientCertPath

func (n *ClnNode) ClientCertPath() string

func (*ClnNode) ClientKeyPath

func (n *ClnNode) ClientKeyPath() string

func (*ClnNode) ConnectPeer

func (n *ClnNode) ConnectPeer(peer LightningNode)

func (*ClnNode) CreateBolt11Invoice

func (n *ClnNode) CreateBolt11Invoice(options *CreateInvoiceOptions) *CreateInvoiceResult

func (*ClnNode) Fund

func (n *ClnNode) Fund(amountSat uint64)

func (*ClnNode) GetChannels

func (n *ClnNode) GetChannels() []*ChannelDetails

func (*ClnNode) GetInvoice

func (n *ClnNode) GetInvoice(paymentHash []byte) *GetInvoiceResponse

func (*ClnNode) GetNewAddress

func (n *ClnNode) GetNewAddress() string

func (*ClnNode) GetPeerFeatures

func (n *ClnNode) GetPeerFeatures(peerId []byte) map[uint32]string

func (*ClnNode) GetRemoteNodeFeatures

func (n *ClnNode) GetRemoteNodeFeatures(nodeId []byte) map[uint32]string

func (*ClnNode) GetRoute

func (n *ClnNode) GetRoute(destination []byte, amountMsat uint64) *Route

func (*ClnNode) GrpcPort

func (n *ClnNode) GrpcPort() uint32

func (*ClnNode) Host

func (n *ClnNode) Host() string

func (*ClnNode) IsStarted

func (n *ClnNode) IsStarted() bool

func (*ClnNode) NodeId

func (n *ClnNode) NodeId() []byte

func (*ClnNode) OpenChannel

func (n *ClnNode) OpenChannel(peer LightningNode, options *OpenChannelOptions) *ChannelInfo

func (*ClnNode) Pay

func (n *ClnNode) Pay(bolt11 string) *PayResult

func (*ClnNode) PayViaRoute

func (n *ClnNode) PayViaRoute(
	amountMsat uint64,
	paymentHash []byte,
	paymentSecret []byte,
	route *Route,
) (*PayResult, error)

func (*ClnNode) Port

func (n *ClnNode) Port() uint32

func (*ClnNode) PrivateKey

func (n *ClnNode) PrivateKey() *secp256k1.PrivateKey

func (*ClnNode) SendCustomMessage

func (n *ClnNode) SendCustomMessage(req *CustomMsgRequest)

func (*ClnNode) SendToAddress

func (n *ClnNode) SendToAddress(addr string, amountSat uint64)

func (*ClnNode) SignMessage

func (n *ClnNode) SignMessage(message []byte) []byte

func (*ClnNode) SocketDir

func (n *ClnNode) SocketDir() string

func (*ClnNode) SocketFile

func (n *ClnNode) SocketFile() string

func (*ClnNode) Start

func (n *ClnNode) Start()

func (*ClnNode) Stop

func (n *ClnNode) Stop() error

func (*ClnNode) WaitForChannelReady

func (n *ClnNode) WaitForChannelReady(channel *ChannelInfo) ShortChannelID

func (*ClnNode) WaitForSync

func (n *ClnNode) WaitForSync()

type CreateInvoiceOptions

type CreateInvoiceOptions struct {
	AmountMsat      uint64
	Description     *string
	Preimage        *[]byte
	Cltv            *uint32
	IncludeHopHints bool
}

type CreateInvoiceResult

type CreateInvoiceResult struct {
	Bolt11        string
	PaymentHash   []byte
	PaymentSecret []byte
}

type CustomMsgRequest

type CustomMsgRequest struct {
	PeerId string
	Type   uint32
	Data   []byte
}

type GetInvoiceResponse

type GetInvoiceResponse struct {
	Exists             bool
	AmountMsat         uint64
	AmountReceivedMsat uint64
	Bolt11             *string
	Description        *string
	ExpiresAt          uint64
	PaidAt             *uint64
	PayerNote          *string
	PaymentHash        []byte
	PaymentPreimage    []byte
	IsPaid             bool
	IsExpired          bool
}

type HarnessOption

type HarnessOption int
const (
	DumpLogs      HarnessOption = 0
	PreserveLogs  HarnessOption = 1
	PreserveState HarnessOption = 2
)

type Hop

type Hop struct {
	Id         []byte
	Channel    ShortChannelID
	AmountMsat uint64
	Delay      uint16
}

type InvoiceStatus

type InvoiceStatus int32
const (
	Invoice_UNPAID  InvoiceStatus = 0
	Invoice_PAID    InvoiceStatus = 1
	Invoice_EXPIRED InvoiceStatus = 2
)

type LightningNode

type LightningNode interface {
	Stoppable
	NodeId() []byte
	Host() string
	Port() uint32
	Start()
	IsStarted() bool
	PrivateKey() *secp256k1.PrivateKey

	WaitForSync()
	GetNewAddress() string
	Fund(amountSat uint64)
	ConnectPeer(peer LightningNode)
	OpenChannel(peer LightningNode, options *OpenChannelOptions) *ChannelInfo
	WaitForChannelReady(channel *ChannelInfo) ShortChannelID
	CreateBolt11Invoice(options *CreateInvoiceOptions) *CreateInvoiceResult
	SignMessage(message []byte) []byte
	Pay(bolt11 string) *PayResult
	GetRoute(destination []byte, amountMsat uint64) *Route
	PayViaRoute(
		amountMsat uint64,
		paymentHash []byte,
		paymentSecret []byte,
		route *Route) (*PayResult, error)
	GetInvoice(paymentHash []byte) *GetInvoiceResponse
	GetPeerFeatures(peerId []byte) map[uint32]string
	GetRemoteNodeFeatures(nodeId []byte) map[uint32]string
	GetChannels() []*ChannelDetails
	SendToAddress(addr string, amountSat uint64)
	SendCustomMessage(req *CustomMsgRequest)
}

type LndNode

type LndNode struct {
	// contains filtered or unexported fields
}

func NewLndNode

func NewLndNode(h *TestHarness, m *Miner, name string, extraArgs ...string) *LndNode

func NewLndNodeFromBinary

func NewLndNodeFromBinary(h *TestHarness, m *Miner, name string, binary string, extraArgs ...string) *LndNode

func (*LndNode) Conn

func (n *LndNode) Conn() grpc.ClientConnInterface

func (*LndNode) ConnectPeer

func (n *LndNode) ConnectPeer(peer LightningNode)

func (*LndNode) CreateBolt11Invoice

func (n *LndNode) CreateBolt11Invoice(options *CreateInvoiceOptions) *CreateInvoiceResult

func (*LndNode) Fund

func (n *LndNode) Fund(amountSat uint64)

func (*LndNode) GetChannels

func (n *LndNode) GetChannels() []*ChannelDetails

func (*LndNode) GetInvoice

func (n *LndNode) GetInvoice(paymentHash []byte) *GetInvoiceResponse

func (*LndNode) GetNewAddress

func (n *LndNode) GetNewAddress() string

func (*LndNode) GetPeerFeatures

func (n *LndNode) GetPeerFeatures(peerId []byte) map[uint32]string

func (*LndNode) GetRemoteNodeFeatures

func (n *LndNode) GetRemoteNodeFeatures(nodeId []byte) map[uint32]string

func (*LndNode) GetRoute

func (n *LndNode) GetRoute(destination []byte, amountMsat uint64) *Route

func (*LndNode) GrpcHost

func (n *LndNode) GrpcHost() string

func (*LndNode) Host

func (n *LndNode) Host() string

func (*LndNode) IsStarted

func (n *LndNode) IsStarted() bool

func (*LndNode) LightningClient

func (n *LndNode) LightningClient() lnd.LightningClient

func (*LndNode) Macaroon

func (n *LndNode) Macaroon() []byte

func (*LndNode) NodeId

func (n *LndNode) NodeId() []byte

func (*LndNode) OpenChannel

func (n *LndNode) OpenChannel(peer LightningNode, options *OpenChannelOptions) *ChannelInfo

func (*LndNode) Pay

func (n *LndNode) Pay(bolt11 string) *PayResult

func (*LndNode) PayViaRoute

func (n *LndNode) PayViaRoute(amountMsat uint64, paymentHash []byte, paymentSecret []byte, route *Route) (*PayResult, error)

func (*LndNode) Port

func (n *LndNode) Port() uint32

func (*LndNode) PrivateKey

func (n *LndNode) PrivateKey() *secp256k1.PrivateKey

func (*LndNode) SendCustomMessage

func (n *LndNode) SendCustomMessage(msg *CustomMsgRequest)

func (*LndNode) SendToAddress

func (n *LndNode) SendToAddress(addr string, amountSat uint64)

func (*LndNode) SignMessage

func (n *LndNode) SignMessage(message []byte) []byte

func (*LndNode) Start

func (n *LndNode) Start()

func (*LndNode) Stop

func (n *LndNode) Stop() error

func (*LndNode) TlsCert

func (n *LndNode) TlsCert() []byte

func (*LndNode) WaitForChannelReady

func (n *LndNode) WaitForChannelReady(channel *ChannelInfo) ShortChannelID

func (*LndNode) WaitForSync

func (n *LndNode) WaitForSync()

type MacaroonCredential

type MacaroonCredential struct {
	Macaroon []byte
}

func NewMacaroonCredential

func NewMacaroonCredential(m []byte) *MacaroonCredential

func NewMacaroonCredentialFromFile

func NewMacaroonCredentialFromFile(path string) (*MacaroonCredential, error)

func (*MacaroonCredential) GetRequestMetadata

func (m *MacaroonCredential) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error)

func (*MacaroonCredential) RequireTransportSecurity

func (m *MacaroonCredential) RequireTransportSecurity() bool

type Miner

type Miner struct {
	// contains filtered or unexported fields
}

func NewMiner

func NewMiner(h *TestHarness) *Miner

func NewMinerFromBinary

func NewMinerFromBinary(h *TestHarness, binary string) *Miner

func (*Miner) GetBlockHeight

func (m *Miner) GetBlockHeight() uint32

func (*Miner) MineBlocks

func (m *Miner) MineBlocks(n uint)

func (*Miner) SendToAddress

func (m *Miner) SendToAddress(addr string, amountSat uint64)

func (*Miner) SendToAddressAndMine

func (m *Miner) SendToAddressAndMine(addr string, amountSat uint64, blocks uint)

func (*Miner) Start

func (m *Miner) Start()

func (*Miner) Stop

func (m *Miner) Stop() error

func (*Miner) ZmqBlockAddress

func (m *Miner) ZmqBlockAddress() string

func (*Miner) ZmqTxAddress

func (m *Miner) ZmqTxAddress() string

type OpenChannelOptions

type OpenChannelOptions struct {
	IsPublic  bool
	AmountSat uint64
}

type PayResult

type PayResult struct {
	PaymentHash     []byte
	AmountMsat      uint64
	Destination     []byte
	AmountSentMsat  uint64
	PaymentPreimage []byte
}

type PayViaRouteResponse

type PayViaRouteResponse struct {
	PartId uint32
}

type Route

type Route struct {
	Hops []*Hop
}

type ShortChannelID

type ShortChannelID struct {
	BlockHeight uint32
	TxIndex     uint32
	OutputIndex uint16
}

func NewShortChanIDFromInt

func NewShortChanIDFromInt(chanID uint64) ShortChannelID

func NewShortChanIDFromString

func NewShortChanIDFromString(chanID string) ShortChannelID

func (ShortChannelID) String

func (c ShortChannelID) String() string

func (ShortChannelID) ToUint64

func (c ShortChannelID) ToUint64() uint64

type Stoppable

type Stoppable interface {
	Stop() error
}

type TestHarness

type TestHarness struct {
	*testing.T
	Ctx context.Context

	Dir string
	// contains filtered or unexported fields
}

func NewTestHarness

func NewTestHarness(t *testing.T, deadline time.Time, options ...HarnessOption) *TestHarness

func (*TestHarness) AddCleanable

func (h *TestHarness) AddCleanable(cleanable Cleanable)

func (*TestHarness) AddStoppable

func (h *TestHarness) AddStoppable(stoppable Stoppable)

func (*TestHarness) Deadline

func (h *TestHarness) Deadline() time.Time

func (*TestHarness) GetDirectory

func (h *TestHarness) GetDirectory(pattern string) string

func (*TestHarness) RegisterLogfile

func (h *TestHarness) RegisterLogfile(path string, name string)

func (*TestHarness) TearDown

func (h *TestHarness) TearDown()

type WaitPaymentCompleteResponse

type WaitPaymentCompleteResponse struct {
	PaymentHash     []byte
	AmountMsat      uint64
	Destination     []byte
	CreatedAt       uint64
	AmountSentMsat  uint64
	PaymentPreimage []byte
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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