Skip to content

Commit 4cf6f6f

Browse files
committed
test: allow intercepting PublishTransaction
1 parent 8645668 commit 4cf6f6f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

test/lnd_services_mock.go

+7
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ type SignOutputRawRequest struct {
129129
SignDescriptors []*lndclient.SignDescriptor
130130
}
131131

132+
// PublishHandler is optional transaction handler function called upon calling
133+
// the method PublishTransaction.
134+
type PublishHandler func(ctx context.Context, tx *wire.MsgTx,
135+
label string) error
136+
132137
// LndMockServices provides a full set of mocked lnd services.
133138
type LndMockServices struct {
134139
lndclient.LndServices
@@ -174,6 +179,8 @@ type LndMockServices struct {
174179

175180
WaitForFinished func()
176181

182+
PublishHandler PublishHandler
183+
177184
lock sync.Mutex
178185
}
179186

test/walletkit_mock.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,13 @@ func (m *mockWalletKit) NextAddr(context.Context, string, walletrpc.AddressType,
113113
}
114114

115115
func (m *mockWalletKit) PublishTransaction(ctx context.Context, tx *wire.MsgTx,
116-
_ string) error {
116+
label string) error {
117+
118+
if m.lnd.PublishHandler != nil {
119+
if err := m.lnd.PublishHandler(ctx, tx, label); err != nil {
120+
return err
121+
}
122+
}
117123

118124
m.lnd.AddTx(tx)
119125
m.lnd.TxPublishChannel <- tx

0 commit comments

Comments
 (0)