From 09d28b50dd32ed8a087847bd465489c13fe21ef4 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Fri, 21 Feb 2025 20:47:18 -0300 Subject: [PATCH] test: allow intercepting PublishTransaction --- test/lnd_services_mock.go | 7 +++++++ test/walletkit_mock.go | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/test/lnd_services_mock.go b/test/lnd_services_mock.go index 07e25170..aaf5c110 100644 --- a/test/lnd_services_mock.go +++ b/test/lnd_services_mock.go @@ -129,6 +129,11 @@ type SignOutputRawRequest struct { SignDescriptors []*lndclient.SignDescriptor } +// PublishHandler is optional transaction handler function called upon calling +// the method PublishTransaction. +type PublishHandler func(ctx context.Context, tx *wire.MsgTx, + label string) error + // LndMockServices provides a full set of mocked lnd services. type LndMockServices struct { lndclient.LndServices @@ -174,6 +179,8 @@ type LndMockServices struct { WaitForFinished func() + PublishHandler PublishHandler + lock sync.Mutex } diff --git a/test/walletkit_mock.go b/test/walletkit_mock.go index 4229e964..70a9f2f4 100644 --- a/test/walletkit_mock.go +++ b/test/walletkit_mock.go @@ -113,7 +113,13 @@ func (m *mockWalletKit) NextAddr(context.Context, string, walletrpc.AddressType, } func (m *mockWalletKit) PublishTransaction(ctx context.Context, tx *wire.MsgTx, - _ string) error { + label string) error { + + if m.lnd.PublishHandler != nil { + if err := m.lnd.PublishHandler(ctx, tx, label); err != nil { + return err + } + } m.lnd.AddTx(tx) m.lnd.TxPublishChannel <- tx