htlcswitch/test: test canceled invoice
This commit is contained in:
parent
f80fb286d8
commit
077852cd4e
@ -5201,3 +5201,60 @@ func TestHtlcSatisfyPolicy(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestChannelLinkCanceledInvoice in this test checks the interaction
|
||||
// between Alice and Bob for a canceled invoice.
|
||||
func TestChannelLinkCanceledInvoice(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup a alice-bob network.
|
||||
aliceChannel, bobChannel, cleanUp, err := createTwoClusterChannels(
|
||||
btcutil.SatoshiPerBitcoin*3,
|
||||
btcutil.SatoshiPerBitcoin*5)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create channel: %v", err)
|
||||
}
|
||||
defer cleanUp()
|
||||
|
||||
n := newTwoHopNetwork(t, aliceChannel, bobChannel, testStartingHeight)
|
||||
if err := n.start(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer n.stop()
|
||||
|
||||
// Prepare an alice -> bob payment.
|
||||
amount := lnwire.NewMSatFromSatoshis(btcutil.SatoshiPerBitcoin)
|
||||
htlcAmt, totalTimelock, hops := generateHops(amount, testStartingHeight,
|
||||
n.bobChannelLink)
|
||||
|
||||
firstHop := n.bobChannelLink.ShortChanID()
|
||||
|
||||
invoice, payFunc, err := preparePayment(
|
||||
n.aliceServer, n.bobServer, firstHop, hops, amount, htlcAmt,
|
||||
totalTimelock,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to prepare the payment: %v", err)
|
||||
}
|
||||
|
||||
// Cancel the invoice at bob's end.
|
||||
hash := invoice.Terms.PaymentPreimage.Hash()
|
||||
err = n.bobServer.registry.CancelInvoice(hash)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Have Alice fire the payment.
|
||||
err = waitForPayFuncResult(payFunc, 30*time.Second)
|
||||
|
||||
// Because the invoice is canceled, we expect an unknown payment hash
|
||||
// result.
|
||||
fErr, ok := err.(*ForwardingError)
|
||||
if !ok {
|
||||
t.Fatalf("expected ForwardingError, but got %v", err)
|
||||
}
|
||||
_, ok = fErr.FailureMessage.(*lnwire.FailUnknownPaymentHash)
|
||||
if !ok {
|
||||
t.Fatalf("expected unknown payment hash, but got %v", err)
|
||||
}
|
||||
}
|
||||
|
@ -670,6 +670,17 @@ func waitForPaymentResult(c chan error, d time.Duration) error {
|
||||
}
|
||||
}
|
||||
|
||||
// waitForPayFuncResult executes the given function and waits for a result with
|
||||
// a timeout.
|
||||
func waitForPayFuncResult(payFunc func() error, d time.Duration) error {
|
||||
errChan := make(chan error)
|
||||
go func() {
|
||||
errChan <- payFunc()
|
||||
}()
|
||||
|
||||
return waitForPaymentResult(errChan, d)
|
||||
}
|
||||
|
||||
// makePayment takes the destination node and amount as input, sends the
|
||||
// payment and returns the error channel to wait for error to be received and
|
||||
// invoice in order to check its status after the payment finished.
|
||||
|
Loading…
Reference in New Issue
Block a user