2019-02-13 13:53:32 +03:00
|
|
|
package routing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/lightningnetwork/lnd/channeldb"
|
|
|
|
"github.com/lightningnetwork/lnd/lnwire"
|
2019-04-05 18:36:11 +03:00
|
|
|
"github.com/lightningnetwork/lnd/routing/route"
|
2019-02-13 13:53:32 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRequestRoute(t *testing.T) {
|
|
|
|
const (
|
|
|
|
height = 10
|
|
|
|
)
|
|
|
|
|
|
|
|
findPath := func(g *graphParams, r *RestrictParams,
|
2019-04-05 18:36:11 +03:00
|
|
|
source, target route.Vertex, amt lnwire.MilliSatoshi) (
|
2019-02-13 13:53:32 +03:00
|
|
|
[]*channeldb.ChannelEdgePolicy, error) {
|
|
|
|
|
|
|
|
// We expect find path to receive a cltv limit excluding the
|
|
|
|
// final cltv delta.
|
|
|
|
if *r.CltvLimit != 22 {
|
|
|
|
t.Fatal("wrong cltv limit")
|
|
|
|
}
|
|
|
|
|
|
|
|
path := []*channeldb.ChannelEdgePolicy{
|
|
|
|
{
|
|
|
|
Node: &channeldb.LightningNode{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return path, nil
|
|
|
|
}
|
|
|
|
|
2019-06-18 19:30:56 +03:00
|
|
|
sessionSource := &SessionSource{
|
|
|
|
SelfNode: &channeldb.LightningNode{},
|
|
|
|
MissionControl: &MissionControl{
|
|
|
|
cfg: &MissionControlConfig{},
|
2019-02-13 13:53:32 +03:00
|
|
|
},
|
2019-06-18 19:30:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
session := &paymentSession{
|
|
|
|
sessionSource: sessionSource,
|
|
|
|
pathFinder: findPath,
|
2019-02-13 13:53:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cltvLimit := uint32(30)
|
|
|
|
finalCltvDelta := uint16(8)
|
|
|
|
|
|
|
|
payment := &LightningPayment{
|
|
|
|
CltvLimit: &cltvLimit,
|
2019-04-18 10:45:21 +03:00
|
|
|
FinalCLTVDelta: finalCltvDelta,
|
2019-02-13 13:53:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
route, err := session.RequestRoute(payment, height, finalCltvDelta)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// We expect an absolute route lock value of height + finalCltvDelta
|
|
|
|
if route.TotalTimeLock != 18 {
|
|
|
|
t.Fatalf("unexpected total time lock of %v",
|
|
|
|
route.TotalTimeLock)
|
|
|
|
}
|
|
|
|
}
|