htlcswicth.test: add 'future' payment response

Add js-like future object which might be used to wait for the response
to be received or return the error otherwise.
This commit is contained in:
Andrey Samokhvalov
2017-07-09 02:04:49 +03:00
committed by Olaoluwa Osuntokun
parent e170b43615
commit 25efbb61a4
2 changed files with 66 additions and 30 deletions

View File

@@ -14,6 +14,7 @@ import (
"math"
"github.com/davecgh/go-spew/spew"
"github.com/go-errors/errors"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire"
@@ -189,7 +190,8 @@ func TestChannelLinkSingleHopPayment(t *testing.T) {
// * alice<->bob commitment state to be updated.
// * user notification to be sent.
invoice, err := n.makePayment(n.aliceServer, n.bobServer,
n.bobServer.PubKey(), hops, amount, htlcAmt, totalTimelock)
n.bobServer.PubKey(), hops, amount, htlcAmt,
totalTimelock).Wait(10 * time.Second)
if err != nil {
t.Fatalf("unable to make the payment: %v", err)
}
@@ -275,7 +277,7 @@ func TestChannelLinkBidirectionalOneHopPayments(t *testing.T) {
_, r.err = n.makePayment(n.aliceServer, n.bobServer,
n.bobServer.PubKey(), hopsForwards, amt, htlcAmt,
totalTimelock)
totalTimelock).Wait(30 * time.Second)
resultChan <- r
}(i)
}
@@ -290,7 +292,7 @@ func TestChannelLinkBidirectionalOneHopPayments(t *testing.T) {
_, r.err = n.makePayment(n.bobServer, n.aliceServer,
n.aliceServer.PubKey(), hopsBackwards, amt, htlcAmt,
totalTimelock)
totalTimelock).Wait(30 * time.Second)
resultChan <- r
}(i)
}
@@ -398,7 +400,7 @@ func TestChannelLinkMultiHopPayment(t *testing.T) {
// * user notification to be sent.
invoice, err := n.makePayment(n.aliceServer, n.carolServer,
n.bobServer.PubKey(), hops, amount, htlcAmt,
totalTimelock)
totalTimelock).Wait(10 * time.Second)
if err != nil {
t.Fatalf("unable to send payment: %v", err)
}
@@ -467,7 +469,8 @@ func TestExitNodeTimelockPayloadMismatch(t *testing.T) {
hops[0].OutgoingCTLV = 500
_, err := n.makePayment(n.aliceServer, n.bobServer,
n.bobServer.PubKey(), hops, amount, htlcAmt, htlcExpiry)
n.bobServer.PubKey(), hops, amount, htlcAmt,
htlcExpiry).Wait(10 * time.Second)
if err == nil {
t.Fatalf("payment should have failed but didn't")
}
@@ -515,7 +518,8 @@ func TestExitNodeAmountPayloadMismatch(t *testing.T) {
hops[0].AmountToForward = 1
_, err := n.makePayment(n.aliceServer, n.bobServer,
n.bobServer.PubKey(), hops, amount, htlcAmt, htlcExpiry)
n.bobServer.PubKey(), hops, amount, htlcAmt,
htlcExpiry).Wait(10 * time.Second)
if err == nil {
t.Fatalf("payment should have failed but didn't")
} else if err.Error() != lnwire.CodeIncorrectPaymentAmount.String() {
@@ -557,8 +561,8 @@ func TestLinkForwardTimelockPolicyMismatch(t *testing.T) {
// Next, we'll make the payment which'll send an HTLC with our
// specified parameters to the first hop in the route.
_, err := n.makePayment(n.aliceServer, n.carolServer,
n.bobServer.PubKey(), hops, amount, htlcAmt, htlcExpiry)
n.bobServer.PubKey(), hops, amount, htlcAmt,
htlcExpiry).Wait(10 * time.Second)
// We should get an error, and that error should indicate that the HTLC
// should be rejected due to a policy violation.
if err == nil {
@@ -610,7 +614,7 @@ func TestLinkForwardFeePolicyMismatch(t *testing.T) {
// specified parameters to the first hop in the route.
_, err := n.makePayment(n.aliceServer, n.bobServer,
n.bobServer.PubKey(), hops, amountNoFee, amountNoFee,
htlcExpiry)
htlcExpiry).Wait(10 * time.Second)
// We should get an error, and that error should indicate that the HTLC
// should be rejected due to a policy violation.
@@ -663,7 +667,7 @@ func TestLinkForwardMinHTLCPolicyMismatch(t *testing.T) {
// specified parameters to the first hop in the route.
_, err := n.makePayment(n.aliceServer, n.bobServer,
n.bobServer.PubKey(), hops, amountNoFee, htlcAmt,
htlcExpiry)
htlcExpiry).Wait(10 * time.Second)
// We should get an error, and that error should indicate that the HTLC
// should be rejected due to a policy violation (below min HTLC).
@@ -717,7 +721,7 @@ func TestUpdateForwardingPolicy(t *testing.T) {
// should succeed, and all balances should be updated accordingly.
invoice, err := n.makePayment(n.aliceServer, n.carolServer,
n.bobServer.PubKey(), hops, amountNoFee, htlcAmt,
htlcExpiry)
htlcExpiry).Wait(10 * time.Second)
if err != nil {
t.Fatalf("unable to send payment: %v", err)
}
@@ -813,8 +817,9 @@ func TestChannelLinkMultiHopInsufficientPayment(t *testing.T) {
// * Bob trying to add HTLC add request in Bob<->Carol channel.
// * Cancel HTLC request to be sent back from Bob to Alice.
// * user notification to be sent.
invoice, err := n.makePayment(n.aliceServer, n.bobServer,
n.bobServer.PubKey(), hops, amount, htlcAmt, totalTimelock)
invoice, err := n.makePayment(n.aliceServer, n.carolServer,
n.bobServer.PubKey(), hops, amount, htlcAmt,
totalTimelock).Wait(10 * time.Second)
if err == nil {
t.Fatal("error haven't been received")
} else if !strings.Contains(err.Error(), "insufficient capacity") {
@@ -966,8 +971,9 @@ func TestChannelLinkMultiHopUnknownNextHop(t *testing.T) {
n.firstBobChannelLink, n.carolChannelLink)
davePub := newMockServer("save", serverErr).PubKey()
invoice, err := n.makePayment(n.aliceServer, n.bobServer, davePub, hops,
amount, htlcAmt, totalTimelock)
amount, htlcAmt, totalTimelock).Wait(10 * time.Second)
if err == nil {
t.Fatal("error haven't been received")
} else if err.Error() != lnwire.CodeUnknownNextPeer.String() {
@@ -1039,7 +1045,8 @@ func TestChannelLinkMultiHopDecodeError(t *testing.T) {
n.firstBobChannelLink, n.carolChannelLink)
invoice, err := n.makePayment(n.aliceServer, n.carolServer,
n.bobServer.PubKey(), hops, amount, htlcAmt, totalTimelock)
n.bobServer.PubKey(), hops, amount, htlcAmt,
totalTimelock).Wait(10 * time.Second)
if err == nil {
t.Fatal("error haven't been received")
}
@@ -1245,12 +1252,14 @@ func TestChannelLinkSingleHopMessageOrdering(t *testing.T) {
n.firstBobChannelLink)
// Wait for:
// * htlc add htlc request to be sent to alice
// * alice<->bob commitment state to be updated
// * settle request to be sent back from alice to bob
// * alice<->bob commitment state to be updated
_, err := n.makePayment(n.aliceServer, n.bobServer,
n.bobServer.PubKey(), hops, amount, htlcAmt, totalTimelock)
// * HTLC add request to be sent to bob.
// * alice<->bob commitment state to be updated.
// * settle request to be sent back from bob to alice.
// * alice<->bob commitment state to be updated.
// * user notification to be sent.
_, err = n.makePayment(n.aliceServer, n.bobServer,
n.bobServer.PubKey(), hops, amount, htlcAmt,
totalTimelock).Wait(10 * time.Second)
if err != nil {
t.Fatalf("unable to make the payment: %v", err)
}