routing/router test: assert SendToRoute init values

This commit adds an assertion to the SendToRoute test that the payment
value stored to the DB during SendToRoute execution is the correct one.

This assertion would fail before the previous commit that fixed a
missing value initialization.
This commit is contained in:
Johan T. Halseth 2019-06-04 10:34:59 +02:00
parent 1161d87eec
commit 6d52128da0
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -3175,27 +3175,31 @@ func TestSendToRouteStructuredError(t *testing.T) {
} }
defer cleanUp() defer cleanUp()
// Set up an init channel for the control tower, such that we can make
// sure the payment is initiated correctly.
init := make(chan initArgs, 1)
ctx.router.cfg.Control.(*mockControlTower).init = init
// Setup a route from source a to destination c. The route will be used // Setup a route from source a to destination c. The route will be used
// in a call to SendToRoute. SendToRoute also applies channel updates, // in a call to SendToRoute. SendToRoute also applies channel updates,
// but it saves us from including RequestRoute in the test scope too. // but it saves us from including RequestRoute in the test scope too.
const payAmt = lnwire.MilliSatoshi(10000)
hop1 := ctx.aliases["b"] hop1 := ctx.aliases["b"]
hop2 := ctx.aliases["c"] hop2 := ctx.aliases["c"]
hops := []*route.Hop{ hops := []*route.Hop{
{ {
ChannelID: 1, ChannelID: 1,
PubKeyBytes: hop1, PubKeyBytes: hop1,
AmtToForward: payAmt,
}, },
{ {
ChannelID: 2, ChannelID: 2,
PubKeyBytes: hop2, PubKeyBytes: hop2,
AmtToForward: payAmt,
}, },
} }
rt, err := route.NewRouteFromHops( rt, err := route.NewRouteFromHops(payAmt, 100, ctx.aliases["a"], hops)
lnwire.MilliSatoshi(10000), 100,
ctx.aliases["a"], hops,
)
if err != nil { if err != nil {
t.Fatalf("unable to create route: %v", err) t.Fatalf("unable to create route: %v", err)
} }
@ -3239,4 +3243,14 @@ func TestSendToRouteStructuredError(t *testing.T) {
if _, ok := fErr.FailureMessage.(*lnwire.FailFeeInsufficient); !ok { if _, ok := fErr.FailureMessage.(*lnwire.FailFeeInsufficient); !ok {
t.Fatalf("expected fee insufficient error") t.Fatalf("expected fee insufficient error")
} }
// Check that the correct values were used when initiating the payment.
select {
case initVal := <-init:
if initVal.c.Value != payAmt {
t.Fatalf("expected %v, got %v", payAmt, initVal.c.Value)
}
case <-time.After(100 * time.Millisecond):
t.Fatalf("initPayment not called")
}
} }