From e464ed18c7bcb144cda901ffa00d85da514983e7 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Fri, 22 Feb 2019 18:37:33 +0100 Subject: [PATCH] htlcswitch/test: make unknown hash test independent of mock In the TestChannelLinkMultiHopUnknownPaymentHash test, a preimage was modified to trigger an unknown payment hash failure. The way the mock is implemented, it would take the hash of that modified preimage and store it. It basically stores a completely different invoice. For this test, it is just as good to store no invoice at all. --- htlcswitch/link_test.go | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go index 8b466948..602933df 100644 --- a/htlcswitch/link_test.go +++ b/htlcswitch/link_test.go @@ -1066,22 +1066,15 @@ func TestChannelLinkMultiHopUnknownPaymentHash(t *testing.T) { t.Fatal(err) } - // Generate payment: invoice and htlc. - invoice, htlc, err := generatePayment(amount, htlcAmt, totalTimelock, + // Generate payment invoice and htlc, but don't add this invoice to the + // receiver registry. This should trigger an unknown payment hash + // failure. + _, htlc, err := generatePayment(amount, htlcAmt, totalTimelock, blob) if err != nil { t.Fatal(err) } - // We need to have wrong rhash for that reason we should change the - // preimage. Inverse first byte by xoring with 0xff. - invoice.Terms.PaymentPreimage[0] ^= byte(255) - - // Check who is last in the route and add invoice to server registry. - if err := n.carolServer.registry.AddInvoice(*invoice); err != nil { - t.Fatalf("unable to add invoice in carol registry: %v", err) - } - // Send payment and expose err channel. _, err = n.aliceServer.htlcSwitch.SendHTLC( n.firstBobChannelLink.ShortChanID(), htlc, @@ -1095,12 +1088,6 @@ func TestChannelLinkMultiHopUnknownPaymentHash(t *testing.T) { // Wait for Alice to receive the revocation. time.Sleep(100 * time.Millisecond) - // Check that alice invoice wasn't settled and bandwidth of htlc - // links hasn't been changed. - if invoice.Terms.State == channeldb.ContractSettled { - t.Fatal("alice invoice was settled") - } - if n.aliceChannelLink.Bandwidth() != aliceBandwidthBefore { t.Fatal("the bandwidth of alice channel link which handles " + "alice->bob channel should be the same")