-
Notifications
You must be signed in to change notification settings - Fork 50
routerclient: add payment request route fee estimates #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hieblmi
merged 1 commit into
lightninglabs:master
from
hieblmi:upgrade-estimate-route-fee
Jun 15, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| package lndclient | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/btcsuite/btcd/btcutil" | ||
| "github.com/lightningnetwork/lnd/lnrpc" | ||
| "github.com/lightningnetwork/lnd/lnrpc/routerrpc" | ||
| "github.com/lightningnetwork/lnd/lnwire" | ||
| "github.com/lightningnetwork/lnd/routing/route" | ||
| "github.com/stretchr/testify/require" | ||
| "google.golang.org/grpc" | ||
| ) | ||
|
|
||
| type mockRouterRPCClient struct { | ||
| routerrpc.RouterClient | ||
|
|
||
| request *routerrpc.RouteFeeRequest | ||
| response *routerrpc.RouteFeeResponse | ||
| err error | ||
| } | ||
|
|
||
| func (m *mockRouterRPCClient) EstimateRouteFee(_ context.Context, | ||
| request *routerrpc.RouteFeeRequest, _ ...grpc.CallOption) ( | ||
| *routerrpc.RouteFeeResponse, error) { | ||
|
|
||
| m.request = request | ||
| return m.response, m.err | ||
| } | ||
|
|
||
| // TestEstimateRouteFeeWithProbe checks that invoice-based route fee estimates | ||
| // are mapped to lnd's RouteFeeRequest fields and response values. | ||
| func TestEstimateRouteFeeWithProbe(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| mock := &mockRouterRPCClient{ | ||
| response: &routerrpc.RouteFeeResponse{ | ||
| RoutingFeeMsat: 987, | ||
| TimeLockDelay: 654, | ||
| FailureReason: lnrpc.PaymentFailureReason_FAILURE_REASON_NONE, | ||
| }, | ||
| } | ||
| client := &routerClient{ | ||
| client: mock, | ||
| } | ||
|
|
||
| resp, err := client.EstimateRouteFeeWithProbe( | ||
| t.Context(), "lnbc1...", 1500*time.Millisecond, | ||
| ) | ||
| require.NoError(t, err) | ||
|
|
||
| require.Empty(t, mock.request.Dest) | ||
| require.Zero(t, mock.request.AmtSat) | ||
| require.Equal(t, "lnbc1...", mock.request.PaymentRequest) | ||
| require.Equal(t, uint32(2), mock.request.Timeout) | ||
| require.Equal(t, lnwire.MilliSatoshi(987), resp.RoutingFee) | ||
| require.Equal(t, int64(654), resp.TimeLockDelay) | ||
| require.Equal( | ||
| t, lnrpc.PaymentFailureReason_FAILURE_REASON_NONE, | ||
| resp.FailureReason, | ||
| ) | ||
| } | ||
|
|
||
| // TestEstimateRouteFee checks that destination and amount route fee estimates | ||
| // are mapped to lnd's RouteFeeRequest fields. | ||
| func TestEstimateRouteFee(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| dest := testVertex() | ||
| mock := &mockRouterRPCClient{ | ||
| response: &routerrpc.RouteFeeResponse{ | ||
| RoutingFeeMsat: 4321, | ||
| }, | ||
| } | ||
| client := &routerClient{ | ||
| client: mock, | ||
| } | ||
|
|
||
| fee, err := client.EstimateRouteFee( | ||
| t.Context(), dest, btcutil.Amount(1000), | ||
| ) | ||
| require.NoError(t, err) | ||
|
|
||
| require.Equal(t, dest[:], mock.request.Dest) | ||
| require.Equal(t, int64(1000), mock.request.AmtSat) | ||
| require.Equal(t, lnwire.MilliSatoshi(4321), fee) | ||
| } | ||
|
|
||
| // TestEstimateRouteFeeWithProbeRejectsInvalidTimeout checks that invalid probe | ||
| // timeout values are rejected before making the RPC. | ||
| func TestEstimateRouteFeeWithProbeRejectsInvalidTimeout(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| testCases := []struct { | ||
| name string | ||
| timeout time.Duration | ||
| err string | ||
| }{ | ||
| { | ||
| name: "negative", | ||
| timeout: -time.Second, | ||
| err: "timeout must not be negative", | ||
| }, | ||
| { | ||
| name: "too large", | ||
| timeout: time.Duration(^uint32(0))*time.Second + | ||
| time.Nanosecond, | ||
| err: "timeout exceeds maximum", | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| mock := &mockRouterRPCClient{} | ||
| client := &routerClient{ | ||
| client: mock, | ||
| } | ||
|
|
||
| _, err := client.EstimateRouteFeeWithProbe( | ||
| t.Context(), "lnbc1...", tc.timeout, | ||
| ) | ||
| require.ErrorContains(t, err, tc.err) | ||
| require.Nil(t, mock.request) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func testVertex() route.Vertex { | ||
| var vertex route.Vertex | ||
| for i := range vertex { | ||
| vertex[i] = byte(i + 1) | ||
| } | ||
|
|
||
| return vertex | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.