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
|
|
|
|
)
|
|
|
|
|
|
|
|
findPath := func(g *graphParams, r *RestrictParams,
|
2019-06-20 12:03:45 +02:00
|
|
|
cfg *PathFindingConfig, source, target route.Vertex,
|
|
|
|
amt lnwire.MilliSatoshi) ([]*channeldb.ChannelEdgePolicy,
|
|
|
|
error) {
|
2019-02-13 11:53:32 +01:00
|
|
|
|
|
|
|
// We expect find path to receive a cltv limit excluding the
|
2019-07-24 03:00:30 +02:00
|
|
|
// final cltv delta (including the block padding).
|
2019-10-11 21:46:10 +02:00
|
|
|
if r.CltvLimit != 22-uint32(BlockPadding) {
|
2019-02-13 11:53:32 +01:00
|
|
|
t.Fatal("wrong cltv limit")
|
|
|
|
}
|
|
|
|
|
|
|
|
path := []*channeldb.ChannelEdgePolicy{
|
|
|
|
{
|
2019-07-31 06:41:58 +02:00
|
|
|
Node: &channeldb.LightningNode{
|
|
|
|
Features: lnwire.NewFeatureVector(
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
},
|
2019-02-13 11:53:32 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return path, nil
|
|
|
|
}
|
|
|
|
|
2019-06-18 18:30:56 +02:00
|
|
|
sessionSource := &SessionSource{
|
|
|
|
SelfNode: &channeldb.LightningNode{},
|
|
|
|
MissionControl: &MissionControl{
|
|
|
|
cfg: &MissionControlConfig{},
|
2019-02-13 11:53:32 +01:00
|
|
|
},
|
2019-06-18 18:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
session := &paymentSession{
|
2019-08-17 09:58:36 +02:00
|
|
|
getBandwidthHints: func() (map[uint64]lnwire.MilliSatoshi,
|
|
|
|
error) {
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
},
|
2019-06-18 18:30:56 +02:00
|
|
|
sessionSource: sessionSource,
|
|
|
|
pathFinder: findPath,
|
2019-02-13 11:53:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cltvLimit := uint32(30)
|
|
|
|
finalCltvDelta := uint16(8)
|
|
|
|
|
|
|
|
payment := &LightningPayment{
|
2019-10-11 21:46:10 +02:00
|
|
|
CltvLimit: cltvLimit,
|
2019-04-18 09:45:21 +02:00
|
|
|
FinalCLTVDelta: finalCltvDelta,
|
2019-02-13 11:53:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
route, err := session.RequestRoute(payment, height, finalCltvDelta)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// We expect an absolute route lock value of height + finalCltvDelta
|
2019-07-24 03:00:30 +02:00
|
|
|
// + 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)
|
|
|
|
}
|
|
|
|
}
|