routing/router: define PaymentAttemptDispatcher interface

The switch satisfies this interface, and makes it easy to mock the send
method from the router.
This commit is contained in:
Johan T. Halseth committed 2019-05-16 23:53:08 +02:00
1 parent 27ae22fa6c
commit f1cb54f943
4 files changed
+214 -191

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
package routing
import (
"crypto/sha256"
"github.com/lightningnetwork/lnd/htlcswitch"
"github.com/lightningnetwork/lnd/lnwire"
)
type mockPaymentAttemptDispatcher struct {
onPayment func(firstHop lnwire.ShortChannelID) ([32]byte, error)
}
var _ PaymentAttemptDispatcher = (*mockPaymentAttemptDispatcher)(nil)
func (m *mockPaymentAttemptDispatcher) SendHTLC(firstHop lnwire.ShortChannelID,
_ *lnwire.UpdateAddHTLC,
_ htlcswitch.ErrorDecrypter) ([sha256.Size]byte, error) {
if m.onPayment != nil {
return m.onPayment(firstHop)
}
return [sha256.Size]byte{}, nil
}
func (m *mockPaymentAttemptDispatcher) setPaymentResult(
f func(firstHop lnwire.ShortChannelID) ([32]byte, error)) {
m.onPayment = f
}