testframework

package
v0.2.97 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2022 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Addresses to generate to
	LBTC_BURN = "ert1qfkht0df45q00kzyayagw6vqhfhe8ve7z7wecm0xsrkgmyulewlzqumq3ep"
	BTC_BURN  = "2N61yGL5ZBy3yaiEM8312CuG78CBNQMWE4Y"
)

Variables

View Source
var TIMEOUT = setTimeout()

Functions

func AssertWaitForBalanceChange

func AssertWaitForBalanceChange(t *testing.T, node LightningNode, scid string, before uint64, timeout time.Duration) bool

AssertWaitForBalanceChange waits for a change form the before value until timeout. Returns false if timeout was triggered and fails the test.

func AssertWaitForChannelBalance

func AssertWaitForChannelBalance(t *testing.T, node LightningNode, scid string, expected, delta float64, timeout time.Duration) bool

func BalanceChannel5050

func BalanceChannel5050(node, peer *CLightningNode, scid string) error

func FreePort

func FreePort(port int)

func GenerateRandomString

func GenerateRandomString(n int) (string, error)

func GenerateToLiquidWallet

func GenerateToLiquidWallet(node *LiquidNode, walletName string, bitcoin float64) error

func GetFreePort

func GetFreePort() (port int, err error)

func GetFreePorts

func GetFreePorts(n int) ([]int, error)

func ReadConfig

func ReadConfig(filename string) (map[string]string, error)

func RequireWaitForBalanceChange

func RequireWaitForBalanceChange(t *testing.T, node LightningNode, scid string, before uint64, timeout time.Duration)

RequireWaitForBalanceChange waits for a change from the before value until timeout. Fatals the test.

func RequireWaitForChannelBalance

func RequireWaitForChannelBalance(t *testing.T, node LightningNode, scid string, expected, delta float64, timeout time.Duration)

func ScidFromLndChanId

func ScidFromLndChanId(id uint64) string

func SplitLnAddr

func SplitLnAddr(addr string) (string, string, int, error)

func SwitchWallet

func SwitchWallet(node *LiquidNode, walletName string) error

func WaitFor

func WaitFor(f WaitFunc, timeout time.Duration) error

WaitFor takes a WaitFunc and checks for true every 100ms.

func WaitForWithErr

func WaitForWithErr(f WaitFuncWithErr, timeout time.Duration) error

WaitForWithErr takes a WaitFuncWithErr and checks for true every 100ms.

func WriteConfig

func WriteConfig(filename string, config map[string]string, regtestConfig map[string]string, sectionName string)

Types

type BitcoinNode

type BitcoinNode struct {
	*DaemonProcess
	*RpcProxy

	DataDir     string
	ConfigFile  string
	RpcPort     int
	RpcUser     string
	RpcPassword string
	WalletName  string

	ZmqPubRawTx    string
	ZmqPubRawBlock string
}

func NewBitcoinNode

func NewBitcoinNode(testDir string, id int) (*BitcoinNode, error)

func (*BitcoinNode) GenerateBlocks

func (n *BitcoinNode) GenerateBlocks(b int) error

func (*BitcoinNode) ReturnAsset

func (n *BitcoinNode) ReturnAsset() string

func (*BitcoinNode) Run

func (n *BitcoinNode) Run(generateInitialBlocks bool) error

type CLightningNode

type CLightningNode struct {
	*DaemonProcess
	*CLightningProxy

	DataDir    string
	ConfigFile string
	Port       int
	Info       *glightning.NodeInfo
	// contains filtered or unexported fields
}

func NewCLightningNode

func NewCLightningNode(testDir string, bitcoin *BitcoinNode, id int) (*CLightningNode, error)

func (*CLightningNode) AddInvoice

func (n *CLightningNode) AddInvoice(amtSat uint64, desc, label string) (payreq string, err error)

func (*CLightningNode) Address

func (n *CLightningNode) Address() string

func (*CLightningNode) Connect

func (n *CLightningNode) Connect(peer LightningNode, waitForConnection bool) error

func (*CLightningNode) FundWallet

func (n *CLightningNode) FundWallet(sats uint64, mineBlock bool) (string, error)

func (*CLightningNode) GetBtcBalanceSat

func (n *CLightningNode) GetBtcBalanceSat() (sats uint64, err error)

func (*CLightningNode) GetChannelBalanceSat

func (n *CLightningNode) GetChannelBalanceSat(scid string) (sats uint64, err error)

func (*CLightningNode) GetDataDir

func (n *CLightningNode) GetDataDir() string

func (*CLightningNode) GetLatestInvoice

func (n *CLightningNode) GetLatestInvoice() (string, error)

func (*CLightningNode) GetMemoFromPayreq

func (n *CLightningNode) GetMemoFromPayreq(bolt11 string) (string, error)

func (*CLightningNode) GetScid

func (n *CLightningNode) GetScid(remote LightningNode) (string, error)

func (*CLightningNode) Id

func (n *CLightningNode) Id() string

func (*CLightningNode) IsBlockHeightSynced

func (n *CLightningNode) IsBlockHeightSynced() (bool, error)

func (*CLightningNode) IsChannelActive

func (n *CLightningNode) IsChannelActive(scid string) (bool, error)

func (*CLightningNode) IsConnected

func (n *CLightningNode) IsConnected(remote LightningNode) (bool, error)

func (*CLightningNode) OpenChannel

func (n *CLightningNode) OpenChannel(remote LightningNode, capacity uint64, connect, confirm, waitForActiveChannel bool) (string, error)

func (*CLightningNode) PayInvoice

func (n *CLightningNode) PayInvoice(payreq string) error

func (*CLightningNode) Run

func (n *CLightningNode) Run(waitForReady, waitForBitcoinSynced bool) error

func (*CLightningNode) SendPay

func (n *CLightningNode) SendPay(bolt11, scid string) error

func (*CLightningNode) Shutdown

func (n *CLightningNode) Shutdown() error

func (*CLightningNode) Stop

func (n *CLightningNode) Stop() error

type CLightningProxy

type CLightningProxy struct {
	Rpc *glightning.Lightning
	// contains filtered or unexported fields
}

func NewCLightningProxy

func NewCLightningProxy(socketFileName, dataDir string) (*CLightningProxy, error)

func (*CLightningProxy) StartProxy

func (p *CLightningProxy) StartProxy() error

type DaemonProcess

type DaemonProcess struct {
	CmdLine []string
	Cmd     *exec.Cmd
	StdOut  *lockedWriter
	StdErr  *lockedWriter
	// contains filtered or unexported fields
}

func NewDaemonProcess

func NewDaemonProcess(cmdline []string, prefix string) *DaemonProcess

func (*DaemonProcess) AppendCmdLine

func (d *DaemonProcess) AppendCmdLine(options []string)

func (*DaemonProcess) HasLog

func (d *DaemonProcess) HasLog(regex string) (bool, error)

func (*DaemonProcess) Kill

func (d *DaemonProcess) Kill()

func (*DaemonProcess) Prefix

func (d *DaemonProcess) Prefix() string

func (*DaemonProcess) Run

func (d *DaemonProcess) Run()

func (*DaemonProcess) WaitForLog

func (d *DaemonProcess) WaitForLog(regex string, timeout time.Duration) error

func (*DaemonProcess) WithCmd

func (d *DaemonProcess) WithCmd(cmd string)

type IdGetter

type IdGetter interface {
	NextId() int
}

type IntIdGetter

type IntIdGetter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*IntIdGetter) NextId

func (i *IntIdGetter) NextId() int

type LightningNode

type LightningNode interface {
	Address() (addr string)
	Id() (id string)

	// GetBtcBalanceSat returns the total amount of sats on the nodes
	// wallet.
	GetBtcBalanceSat() (sats uint64, err error)
	// GetChannelBalanceSat returns the confirmed balance of a channel.
	// scid is given clightning style i.e `100x0x1`.
	GetChannelBalanceSat(scid string) (sats uint64, err error)
	// GetScid returns the short channel id with a peer in clightning style
	// i.e. `100x0x1`.
	GetScid(peer LightningNode) (scid string, err error)

	Connect(peer LightningNode, waitForConnection bool) error
	FundWallet(sats uint64, mineBlock bool) (addr string, err error)
	OpenChannel(peer LightningNode, capacity uint64, connect, confirm, waitForChannelActive bool) (scid string, err error)

	IsBlockHeightSynced() (bool, error)
	IsChannelActive(scid string) (bool, error)
	IsConnected(peer LightningNode) (bool, error)

	AddInvoice(amtSat uint64, desc, label string) (payreq string, err error)
	PayInvoice(payreq string) error
	SendPay(bolt11, scid string) error

	// GetLatestInvoice returns the latest invoice from the stack of created
	// invoices.
	GetLatestInvoice() (payreq string, err error)
	GetMemoFromPayreq(payreq string) (memo string, err error)

	Run(waitForReady, swaitForBitcoinSynced bool) error
	Stop() error
}

type LiquidNode

type LiquidNode struct {
	*DaemonProcess
	*RpcProxy

	DataDir     string
	ConfigFile  string
	Port        int
	RpcPort     int
	RpcUser     string
	RpcPassword string
	WalletName  string
	Network     string
	// contains filtered or unexported fields
}

func NewLiquidNode

func NewLiquidNode(testDir string, bitcoin *BitcoinNode, id int) (*LiquidNode, error)

func (*LiquidNode) GenerateBlocks

func (n *LiquidNode) GenerateBlocks(b int) error

func (*LiquidNode) ReturnAsset

func (n *LiquidNode) ReturnAsset() string

func (*LiquidNode) Run

func (n *LiquidNode) Run(generateInitialBlocks bool) error

func (*LiquidNode) SwitchWallet

func (n *LiquidNode) SwitchWallet(wallet string) error

type LndNode

type LndNode struct {
	*DaemonProcess
	*LndRpcClient

	DataDir      string
	ConfigFile   string
	RpcPort      int
	ListenPort   int
	TlsPath      string
	MacaroonPath string
	Info         *lnrpc.GetInfoResponse
	// contains filtered or unexported fields
}

func NewLndNode

func NewLndNode(testDir string, bitcoin *BitcoinNode, id int, extraConfig map[string]string) (*LndNode, error)

func (*LndNode) AddInvoice

func (n *LndNode) AddInvoice(amt uint64, desc, _ string) (payreq string, err error)

func (*LndNode) Address

func (n *LndNode) Address() string

func (*LndNode) ChanIdFromScid

func (n *LndNode) ChanIdFromScid(scid string) (uint64, error)

func (*LndNode) Connect

func (n *LndNode) Connect(peer LightningNode, waitForConnection bool) error

func (*LndNode) FundWallet

func (n *LndNode) FundWallet(sats uint64, mineBlock bool) (string, error)

func (*LndNode) GetBtcBalanceSat

func (n *LndNode) GetBtcBalanceSat() (uint64, error)

func (*LndNode) GetChannelBalanceSat

func (n *LndNode) GetChannelBalanceSat(scid string) (sats uint64, err error)

func (*LndNode) GetLatestInvoice

func (n *LndNode) GetLatestInvoice() (payreq string, err error)

func (*LndNode) GetMemoFromPayreq

func (n *LndNode) GetMemoFromPayreq(bolt11 string) (string, error)

func (*LndNode) GetScid

func (n *LndNode) GetScid(peer LightningNode) (scid string, err error)

func (*LndNode) HasPendingHtlcOnChannel

func (n *LndNode) HasPendingHtlcOnChannel(scid string) (bool, error)

func (*LndNode) Id

func (n *LndNode) Id() (id string)

func (*LndNode) IsBlockHeightSynced

func (n *LndNode) IsBlockHeightSynced() (bool, error)

func (*LndNode) IsChannelActive

func (n *LndNode) IsChannelActive(scid string) (bool, error)

func (*LndNode) IsConnected

func (n *LndNode) IsConnected(remote LightningNode) (bool, error)

func (*LndNode) OpenChannel

func (n *LndNode) OpenChannel(peer LightningNode, capacity uint64, connect, confirm, waitForChannelActive bool) (string, error)

func (*LndNode) PayInvoice

func (n *LndNode) PayInvoice(payreq string) error

func (*LndNode) Run

func (n *LndNode) Run(waitForReady, waitForBitcoinSynced bool) error

func (*LndNode) SendPay

func (n *LndNode) SendPay(bolt11, _ string) error

func (*LndNode) Stop

func (n *LndNode) Stop() error

type LndRpcClient

type LndRpcClient struct {
	Rpc   lnrpc.LightningClient
	RpcV2 routerrpc.RouterClient
	// contains filtered or unexported fields
}

func NewLndRpcClient

func NewLndRpcClient(host, certPath, macaroonPath string, options ...grpc.DialOption) (*LndRpcClient, error)

type PortMap

type PortMap struct {
	sync.Mutex
	// contains filtered or unexported fields
}

type RpcProxy

type RpcProxy struct {
	Rpc jsonrpc.RPCClient
	// contains filtered or unexported fields
}

func NewRpcProxy

func NewRpcProxy(configFile string) (*RpcProxy, error)

func (*RpcProxy) Call

func (p *RpcProxy) Call(method string, parameters ...interface{}) (*jsonrpc.RPCResponse, error)

func (*RpcProxy) UpdateServiceUrl

func (p *RpcProxy) UpdateServiceUrl(url string)

type WaitFunc

type WaitFunc func() bool

WaitFunc returns just a bool value to check if the desired conditions are met.

type WaitFuncWithErr

type WaitFuncWithErr func() (bool, error)

WaitFunc returns a bool value to check if the desired conditions are met. Also returns an error.

Jump to

Keyboard shortcuts

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