mock

package module
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: MIT Imports: 27 Imported by: 0

README

Coverage Status Renovate enabled Build status Build status Go Report Card

What is this?

This is a helper library by entropy that hopes to imitate some of the functionality of polar for continuous integration. Right now this supports creating btcd and lnd nodes and funding them. You can check out an example in lnd_test. This also supports mocking bolt11 invoices

Note:

This library was open sourced as a dependency for another project. While this is functional, documentation may be lacking for a bit.

Helpful tips:

This command will remove lndmock containers:

docker stop $(docker ps -a -q --filter label="created-by=docker-utils") || true && docker rm -v $(docker ps -a -q --filter label="created-by=docker-utils") || true && docker network rm lightning-network || true && docker volume rm $( docker volume ls -q --filter label="created-by=docker-utils") || true

Docker Images

Docker images are currently built in this repository. Eventually, we'd like to support bitcoind, eclair, c-lightning, etc and automate retroactive/proactive builds (e.g. a consistent lnd master image). Polar has some docs here and we're probably best off following their lead

Documentation

Overview

Package mock contains utilities for mocking lightning interactions within docker

Index

Constants

View Source
const MiningAddressName = "MINING_ADDRESS"

MiningAddressName is the name of the mining address argument passed to BtcdContainer

View Source
const NetworkName container.NetworkMode = "lightning-network"

NetworkName is the name of the network we use in docker

Variables

This section is empty.

Functions

func EnvArgs

func EnvArgs() []string

EnvArgs defines a list of arguments that must be used with the rpc server this is a function to make it immutable

func LnCLIPrefix added in v0.16.0

func LnCLIPrefix() []string

LnCLIPrefix defines a constant for the network all command use this is a function to make it immutable

func MockLndInvoiceMainnet added in v0.13.0

func MockLndInvoiceMainnet(t *testing.T) (encoded string, decoded *zpay32.Invoice)

MockLndInvoiceMainnet creates a mock lnd invoice on mainnet and returns the encoded and decoded *zpay32.Invoice object

func Volumes

func Volumes() []string

Volumes defines mounted volumes this is a function to make it immutable

Types

type BtcdContainer added in v0.11.0

type BtcdContainer struct {

	// PortMap contains a list of ports on the host to the internal container port
	PortMap PortMap
	// contains filtered or unexported fields
}

BtcdContainer object contains methods that allow us to interact with a created btcd container

func (*BtcdContainer) Mine added in v0.28.0

func (b *BtcdContainer) Mine(blocks int) (err error)

Mine a given number of blocks

func (*BtcdContainer) MineToAddress added in v0.11.0

func (b *BtcdContainer) MineToAddress(address string, blocks int) (err error)

MineToAddress mines a given number of block rewards to an address

type LightningMocker

type LightningMocker struct {
	docker.Client
	// contains filtered or unexported fields
}

LightningMocker defines the lnd mocker object

func NewLightningMocker

func NewLightningMocker() LightningMocker

NewLightningMocker creates a new lightning mock object with a given session id

func (LightningMocker) CreateBtcdContainer

func (c LightningMocker) CreateBtcdContainer() (ctn BtcdContainer, err error)

CreateBtcdContainer creates a BtcdContainer and starts it so it can respond to rpc requests. Mining must be done manually and a mining address should be set using BtcdContainer.MineToAddress.

func (LightningMocker) CreateLndContainer

func (c LightningMocker) CreateLndContainer(name string) (ctn LndContainer, err error)

CreateLndContainer create's an lnd container with a given name and no channels

func (*LightningMocker) CreateNetworks added in v0.15.0

func (c *LightningMocker) CreateNetworks() (err error)

CreateNetworks sets up the networks needed for

func (LightningMocker) CreateVolumes

func (c LightningMocker) CreateVolumes() error

CreateVolumes creates new volumes if they don't exist

func (*LightningMocker) Initialize added in v0.15.0

func (c *LightningMocker) Initialize() (err error)

Initialize creates common resources by calling CreateNetworks and CreateVolumes and returning an error if necessary

func (LightningMocker) Teardown

func (c LightningMocker) Teardown() error

Teardown removes all containers created in the session

type LndContainer added in v0.11.0

type LndContainer struct {

	// PortMap is the mapping of ports to the host binding
	PortMap PortMap
	// contains filtered or unexported fields
}

LndContainer object contains methods that allow us to interact with a created lnd container

func (*LndContainer) Address added in v0.11.0

func (l *LndContainer) Address() (address string, err error)

Address gets the address of the user

func (*LndContainer) Connect added in v0.15.0

func (l *LndContainer) Connect(pubKey, host string) (err error)

Connect connects to the lightning peer

func (*LndContainer) GetAdminMacaroon added in v0.16.0

func (l *LndContainer) GetAdminMacaroon() (mac *macaroon.Macaroon, err error)

GetAdminMacaroon fetches the admin macaroon from LndContainer

func (*LndContainer) GetPubKey added in v0.11.0

func (l *LndContainer) GetPubKey() (pubKey string, err error)

GetPubKey of instance

func (*LndContainer) GetTLSCert added in v0.16.0

func (l *LndContainer) GetTLSCert() (cert *tls.Config, rawCert string, err error)

GetTLSCert gets the tls cert for LndContainer

func (*LndContainer) GrpcConnection added in v0.16.0

func (l *LndContainer) GrpcConnection() (conn *grpc.ClientConn, err error)

GrpcConnection generates a grpc connection to a

func (*LndContainer) OpenChannel added in v0.11.0

func (l *LndContainer) OpenChannel(pubKey, host string, amount int) (err error)

OpenChannel connects to the peer and broadcasts a channel opening transaction to the mempool. Note: blocks must be mined for channel to be established

func (*LndContainer) RPCClient added in v0.16.0

func (l *LndContainer) RPCClient() (rpcClient lnrpc.LightningClient, err error)

RPCClient gets an authenticated

func (*LndContainer) WaitForCondition added in v0.28.0

func (l *LndContainer) WaitForCondition(checker func(res *lnrpc.GetInfoResponse) bool) (err error)

WaitForCondition waits for a custom condition from info. Useful for verifying chain states Use with caution. Loop will not terminate until checker is true

func (*LndContainer) WaitForSync added in v0.26.0

func (l *LndContainer) WaitForSync(chain, graph bool) (err error)

WaitForSync waits for a the chain to be synced

type PortMap added in v0.16.0

type PortMap nat.PortMap

PortMap wraps nat.PortMap for easier port querying

func (PortMap) GetHostPort added in v0.16.0

func (p PortMap) GetHostPort(containerPort int) (hostPort int)

GetHostPort will return a host port for any given container port

func (PortMap) NatMap added in v0.16.0

func (p PortMap) NatMap() nat.PortMap

NatMap returns a nat.Portap for use with docker

Jump to

Keyboard shortcuts

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