Files
lnd.xprv/routing/payment_session_test.go
T

89 lines
1.8 KiB
Go
Raw Normal View History

2019-02-13 11:53:32 +01:00
package routing
import (
"testing"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lnwire"
2019-04-05 17:36:11 +02:00
"github.com/lightningnetwork/lnd/routing/route"
2019-02-13 11:53:32 +01:00
)
func TestRequestRoute(t *testing.T) {
const (
height = 10
)
2020-04-16 15:20:23 +02:00
cltvLimit := uint32(30)
finalCltvDelta := uint16(8)
payment := &LightningPayment{
CltvLimit: cltvLimit,
FinalCLTVDelta: finalCltvDelta,
Amount: 1000,
FeeLimit: 1000,
}
session, err := newPaymentSession(
payment,
func() (map[uint64]lnwire.MilliSatoshi,
error) {
return nil, nil
},
func() (routingGraph, func(), error) {
return &sessionGraph{}, func() {}, nil
},
2021-01-19 10:57:10 +02:00
&MissionControl{},
2020-04-16 15:20:23 +02:00
PathFindingConfig{},
)
if err != nil {
t.Fatal(err)
}
// Override pathfinder with a mock.
session.pathFinder = func(
g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
source, target route.Vertex, amt lnwire.MilliSatoshi,
finalHtlcExpiry int32) ([]*channeldb.ChannelEdgePolicy, error) {
2019-02-13 11:53:32 +01:00
// We expect find path to receive a cltv limit excluding the
// final cltv delta (including the block padding).
if r.CltvLimit != 22-uint32(BlockPadding) {
2019-02-13 11:53:32 +01:00
t.Fatal("wrong cltv limit")
}
path := []*channeldb.ChannelEdgePolicy{
{
Node: &channeldb.LightningNode{
Features: lnwire.NewFeatureVector(
nil, nil,
),
},
2019-02-13 11:53:32 +01:00
},
}
return path, nil
}
route, err := session.RequestRoute(
payment.Amount, payment.FeeLimit, 0, height,
)
2019-02-13 11:53:32 +01:00
if err != nil {
t.Fatal(err)
}
// We expect an absolute route lock value of height + finalCltvDelta
// + BlockPadding.
if route.TotalTimeLock != 18+uint32(BlockPadding) {
2019-02-13 11:53:32 +01:00
t.Fatalf("unexpected total time lock of %v",
route.TotalTimeLock)
}
}
type sessionGraph struct {
routingGraph
}
func (g *sessionGraph) sourceNode() route.Vertex {
return route.Vertex{}
}