test: allow intercepting PublishTransaction

This commit is contained in:
Boris Nagaev 2025-02-21 20:47:18 -03:00
parent cd599b0cea
commit 09d28b50dd
No known key found for this signature in database
2 changed files with 14 additions and 1 deletions

View file

@ -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
}

View file

@ -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