test

package
v0.7.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2025 License: MIT Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ListenAddrTemplate is the template for the address the mock server
	// listens on.
	ListenAddrTemplate = "127.0.0.1:%d"

	// StartupWaitTime is the time we wait for the server to start up.
	StartupWaitTime = 50 * time.Millisecond
)
View Source
var (
	HexCompressedPubKeyLen = hex.EncodedLen(btcec.PubKeyBytesLenCompressed)
	HexTaprootPkScript     = hex.EncodedLen(input.P2TRSize)

	DefaultHashLockWitness = []byte("foobar")
)
View Source
var (
	// TestVectorAllowedUnknownType is a custom odd TLV type that can be
	// used in test vectors to verify that unknown odd types are allowed.
	TestVectorAllowedUnknownType tlv.Type = 31337
)

Functions

func AssertCopyEqual added in v0.6.0

func AssertCopyEqual[T fn.Copyable[T]](t *testing.T, debug, strict bool,
	original T)

AssertCopyEqual checks that the Copy method returns a value that: 1) is deeply equal 2) does not alias mutable fields (pointers, slices, maps)

func BuildTapscriptTree added in v0.4.0

func BuildTapscriptTree(t *testing.T, useHashLock, valid bool,
	internalKey *btcec.PublicKey) (*txscript.TapLeaf, *waddrmgr.Tapscript,
	*psbt.TaprootTapLeafScript, []byte, []byte)

BuildTapscriptTree builds a Tapscript tree with two leaves, a hash lock script and a signature verification script. It also returns the data needed to satisfy one of the two leaves.

func BuildTapscriptTreeNoReveal added in v0.4.0

func BuildTapscriptTreeNoReveal(t *testing.T,
	internalKey *btcec.PublicKey) txscript.TapBranch

BuildTapscriptTreeNoReveal builds a Tapscript tree with two leaves, a hash lock script and a signature verification script.

func ComputeTaprootScript

func ComputeTaprootScript(t testing.TB, taprootKey *btcec.PublicKey) []byte

func ComputeTaprootScriptErr added in v0.3.0

func ComputeTaprootScriptErr(witnessProgram []byte) ([]byte, error)

func FillFakeData added in v0.6.0

func FillFakeData[T any](t *testing.T, debug bool, maxDepth int, v T)

FillFakeData recursively fills a struct with dummy values.

func HexPubKey added in v0.3.0

func HexPubKey(pk *btcec.PublicKey) string

func HexSchnorrPubKey added in v0.3.0

func HexSchnorrPubKey(pk *btcec.PublicKey) string

func HexSignature added in v0.3.0

func HexSignature(sig *schnorr.Signature) string

func HexTx added in v0.3.0

func HexTx(t testing.TB, tx *wire.MsgTx) string

func Parse32Byte added in v0.3.0

func Parse32Byte(t testing.TB, b string) [32]byte

func Parse33Byte added in v0.3.0

func Parse33Byte(t testing.TB, b string) [33]byte

func ParseChainHash added in v0.3.0

func ParseChainHash(t testing.TB, hash string) chainhash.Hash

func ParseHex added in v0.3.0

func ParseHex(t testing.TB, b string) []byte

func ParseOutPoint added in v0.3.0

func ParseOutPoint(t testing.TB, op string) wire.OutPoint

func ParsePubKey added in v0.3.0

func ParsePubKey(t testing.TB, key string) *btcec.PublicKey

func ParseRPCKeyDescriptor

func ParseRPCKeyDescriptor(t testing.TB,
	rpcDesc *signrpc.KeyDescriptor) keychain.KeyDescriptor

func ParseSchnorrPubKey added in v0.3.0

func ParseSchnorrPubKey(t testing.TB, key string) *btcec.PublicKey

func ParseSchnorrSig added in v0.3.0

func ParseSchnorrSig(t testing.TB, sigHex string) *schnorr.Signature

func ParseTestVectors added in v0.3.0

func ParseTestVectors(t testing.TB, fileName string, target any)

func ParseTx added in v0.3.0

func ParseTx(t testing.TB, tx string) *wire.MsgTx

func PubToKeyDesc

func PubToKeyDesc(p *btcec.PublicKey) keychain.KeyDescriptor

func RandBool

func RandBool() bool

RandBool rolls a random boolean.

func RandBytes

func RandBytes(num int) []byte

func RandCommitmentKeyRing added in v0.5.0

func RandCommitmentKeyRing(t *testing.T) lnwallet.CommitmentKeyRing

func RandFlip added in v0.4.0

func RandFlip[T any](t, f T) T

RandFlip picks one of two values randomly.

func RandHash

func RandHash() chainhash.Hash

func RandInt

func RandInt[T constraints.Integer]() T

RandInt makes a random integer of the specified type.

func RandInt31n added in v0.3.0

func RandInt31n(n int32) int32

RandInt31n returns a random 32-bit integer in the range [0, n).

func RandIntn added in v0.3.0

func RandIntn(n int) int

RandIntn returns a random integer in the range [0, n).

func RandKeyDesc added in v0.4.0

func RandKeyDesc(t testing.TB) (keychain.KeyDescriptor, *btcec.PrivateKey)

func RandKeyLoc added in v0.5.0

func RandKeyLoc() keychain.KeyLocator

func RandOp

func RandOp(t testing.TB) wire.OutPoint

func RandPrivKey

func RandPrivKey() *btcec.PrivateKey

func RandPubKey

func RandPubKey(t testing.TB) *btcec.PublicKey

func RandRead added in v0.3.0

func RandRead(t testing.TB, b []byte)

RandRead fills the passed byte slice with random data.

func RandTapLeaf added in v0.4.0

func RandTapLeaf(customScriptLen *int) txscript.TapLeaf

func RandTxWitnesses

func RandTxWitnesses(t testing.TB) wire.TxWitness

func ReadTestDataFile added in v0.4.0

func ReadTestDataFile(t *testing.T, fileName string) string

ReadTestDataFile reads a file from the testdata directory and returns its content as a string.

func RunUnknownOddTypeTest added in v0.5.0

func RunUnknownOddTypeTest[T any](t *testing.T, knownItem T,
	unknownTypeErr error, encode func(*bytes.Buffer, T) error,
	decode func(*bytes.Buffer) (T, error), verify func(T, tlv.TypeMap))

RunUnknownOddTypeTest is a generic test that can be used to test the behavior of a TLV decoding function when an unknown odd type is encountered. The test will encode a known item, add an unknown even type to the encoded bytes, and verify that the decoding function returns an error. It will then encode the known item again, add an unknown odd type, and verify that the decoding function returns the expected item and unknown types.

func SchnorrKey

func SchnorrKey(t testing.TB, pubKey *btcec.PublicKey) *btcec.PublicKey

func SchnorrKeysEqual added in v0.4.0

func SchnorrKeysEqual(t testing.TB, a, b *btcec.PublicKey) bool

func SchnorrPubKey

func SchnorrPubKey(t testing.TB, privKey *btcec.PrivateKey) *btcec.PublicKey

func ScriptCltv added in v0.4.0

func ScriptCltv(t *testing.T, cltv int64) txscript.TapLeaf

ScriptCltv returns a simple bitcoin script that locks the funds with a CLTV lock until the given block height.

func ScriptCltv0 added in v0.4.0

func ScriptCltv0(t *testing.T) txscript.TapLeaf

ScriptCltv0 returns a simple bitcoin script that locks the funds with a CLTV lock until block height 0. The script is explicitly invalid as it should return a clean stack error on evaluation.

func ScriptCsv added in v0.4.0

func ScriptCsv(t *testing.T, csv int64) txscript.TapLeaf

ScriptCsv returns a simple bitcoin script that locks the funds with a CSV lock for the given number of blocks.

func ScriptCsv0 added in v0.4.0

func ScriptCsv0(t *testing.T) txscript.TapLeaf

ScriptCsv0 returns a simple bitcoin script that locks the funds with a CSV lock for the zero blocks. The script is explicitly invalid as it should return a clean stack error on evaluation.

func ScriptHashLock

func ScriptHashLock(t *testing.T, preimage []byte) txscript.TapLeaf

ScriptHashLock returns a simple bitcoin script that locks the funds to a hash lock of the given preimage.

func ScriptSchnorrSig

func ScriptSchnorrSig(t *testing.T, pubKey *btcec.PublicKey) txscript.TapLeaf

ScriptSchnorrSig returns a simple bitcoin script that locks the funds to a Schnorr signature of the given public key.

func StartMockGRPCServer added in v0.6.0

func StartMockGRPCServer(t *testing.T, grpcServer *grpc.Server,
	withTLS bool) (string, func(), error)

StartMockGRPCServer starts a mock gRPC server on a free port and returns the address it's listening on. The caller should clean up the server by calling the cleanup function.

func StartMockGRPCServerWithAddr

func StartMockGRPCServerWithAddr(t *testing.T, grpcServer *grpc.Server,
	withTLS bool, listenAddr string) (func(), error)

StartMockGRPCServerWithAddr starts a mock gRPC server on the given address and returns the address it's listening on. The caller should clean up the server by calling the cleanup function.

func WriteTestFileHex added in v0.3.0

func WriteTestFileHex(t testing.TB, fileName string, content []byte)

func WriteTestVectors added in v0.3.0

func WriteTestVectors(t testing.TB, fileName string, target any)

Types

type MockSigner

type MockSigner struct {
	lndclient.SignerClient

	SignOutputRawChannel chan SignOutputRawRequest

	Signature []byte

	// SignMessageErr holds the error returned by SignMessage, if any.
	SignMessageErr error

	SignatureMsg string
}

func NewMockSigner

func NewMockSigner() *MockSigner

func (*MockSigner) DeriveSharedKey

func (s *MockSigner) DeriveSharedKey(context.Context, *btcec.PublicKey,
	*keychain.KeyLocator) ([32]byte, error)

func (*MockSigner) MuSig2Cleanup

func (s *MockSigner) MuSig2Cleanup(context.Context, [32]byte) error

MuSig2Cleanup removes a session from memory to free up resources.

func (*MockSigner) MuSig2CombineSig

func (s *MockSigner) MuSig2CombineSig(context.Context, [32]byte,
	[][]byte) (bool, []byte, error)

MuSig2CombineSig combines the given partial signature(s) with the local one, if it already exists. Once a partial signature of all participants is registered, the final signature will be combined and returned.

func (*MockSigner) MuSig2CreateSession

MuSig2CreateSession creates a new MuSig2 signing session using the local key identified by the key locator. The complete list of all public keys of all signing parties must be provided, including the public key of the local signing key. If nonces of other parties are already known, they can be submitted as well to reduce the number of method calls necessary later on.

func (*MockSigner) MuSig2RegisterNonces

func (s *MockSigner) MuSig2RegisterNonces(context.Context, [32]byte,
	[][66]byte) (bool, error)

MuSig2RegisterNonces registers one or more public nonces of other signing participants for a session identified by its ID. This method returns true once we have all nonces for all other signing participants.

func (*MockSigner) MuSig2Sign

func (s *MockSigner) MuSig2Sign(context.Context, [32]byte, [32]byte,
	bool) ([]byte, error)

MuSig2Sign creates a partial signature using the local signing key that was specified when the session was created. This can only be called when all public nonces of all participants are known and have been registered with the session. If this node isn't responsible for combining all the partial signatures, then the cleanup parameter should be set, indicating that the session can be removed from memory once the signature was produced.

func (*MockSigner) RawClientWithMacAuth

func (s *MockSigner) RawClientWithMacAuth(
	ctx context.Context) (context.Context, time.Duration,
	signrpc.SignerClient)

func (*MockSigner) SignMessage

func (s *MockSigner) SignMessage(_ context.Context, _ []byte,
	_ keychain.KeyLocator, _ ...lndclient.SignMessageOption) ([]byte,
	error)

func (*MockSigner) SignOutputRaw

func (s *MockSigner) SignOutputRaw(_ context.Context, tx *wire.MsgTx,
	signDescriptors []*lndclient.SignDescriptor,
	_ []*wire.TxOut) ([][]byte, error)

func (*MockSigner) VerifyMessage

func (s *MockSigner) VerifyMessage(_ context.Context, msg, sig []byte,
	_ [33]byte, _ ...lndclient.VerifyMessageOption) (bool, error)

type SignOutputRawRequest

type SignOutputRawRequest struct {
	Tx              *wire.MsgTx
	SignDescriptors []*lndclient.SignDescriptor
}

SignOutputRawRequest contains input data for a tx signing request.

Jump to

Keyboard shortcuts

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