invoices/test: extend hodl invoice test

Add logic to specifically exercise the replay behavior of invoice
registry for hodl invoices.
This commit is contained in:
Joost Jager 2019-08-20 15:51:34 +02:00
parent 43bad4af9f
commit 4fe846af6e
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

@ -388,7 +388,7 @@ func TestHoldInvoice(t *testing.T) {
t.Fatalf("expected settle to succeed but got %v", err)
}
if event != nil {
t.Fatalf("unexpect direct settle")
t.Fatalf("expected htlc to be held")
}
// Test idempotency.
@ -399,7 +399,34 @@ func TestHoldInvoice(t *testing.T) {
t.Fatalf("expected settle to succeed but got %v", err)
}
if event != nil {
t.Fatalf("unexpect direct settle")
t.Fatalf("expected htlc to be held")
}
// Test replay at a higher height. We expect the same result because it
// is a replay.
event, err = registry.NotifyExitHopHtlc(
hash, amtPaid, testHtlcExpiry, testCurrentHeight+10,
getCircuitKey(0), hodlChan,
)
if err != nil {
t.Fatalf("expected settle to succeed but got %v", err)
}
if event != nil {
t.Fatalf("expected htlc to be held")
}
// Test a new htlc coming in that doesn't meet the final cltv delta
// requirement. It should be rejected, but because invoice registry
// doesn't track individual htlcs it is accepted.
event, err = registry.NotifyExitHopHtlc(
hash, amtPaid, 1, testCurrentHeight,
getCircuitKey(1), hodlChan,
)
if err != nil {
t.Fatalf("expected settle to succeed but got %v", err)
}
if event != nil {
t.Fatalf("expected htlc to be held")
}
// We expect the accepted state to be sent to the single invoice
@ -432,6 +459,10 @@ func TestHoldInvoice(t *testing.T) {
t.Fatalf("expected state ContractSettled, but got %v",
settledInvoice.Terms.State)
}
if settledInvoice.AmtPaid != amtPaid {
t.Fatalf("expected amount to be %v, but got %v",
amtPaid, settledInvoice.AmtPaid)
}
update = <-subscription.Updates
if update.Terms.State != channeldb.ContractSettled {