invoices: rename event to resolution in tests
This commit is contained in:
parent
2c44afa3a7
commit
6464f0dda0
@ -66,7 +66,7 @@ func TestSettleInvoice(t *testing.T) {
|
||||
hodlChan := make(chan interface{}, 1)
|
||||
|
||||
// Try to settle invoice with an htlc that expires too soon.
|
||||
event, err := ctx.registry.NotifyExitHopHtlc(
|
||||
resolution, err := ctx.registry.NotifyExitHopHtlc(
|
||||
testInvoicePaymentHash, testInvoice.Terms.Value,
|
||||
uint32(testCurrentHeight)+testInvoiceCltvDelta-1,
|
||||
testCurrentHeight, getCircuitKey(10), hodlChan, testPayload,
|
||||
@ -74,12 +74,12 @@ func TestSettleInvoice(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if event.Preimage != nil {
|
||||
t.Fatal("expected cancel event")
|
||||
if resolution.Preimage != nil {
|
||||
t.Fatal("expected cancel resolution")
|
||||
}
|
||||
if event.AcceptHeight != testCurrentHeight {
|
||||
if resolution.AcceptHeight != testCurrentHeight {
|
||||
t.Fatalf("expected acceptHeight %v, but got %v",
|
||||
testCurrentHeight, event.AcceptHeight)
|
||||
testCurrentHeight, resolution.AcceptHeight)
|
||||
}
|
||||
|
||||
// Settle invoice with a slightly higher amount.
|
||||
@ -120,42 +120,42 @@ func TestSettleInvoice(t *testing.T) {
|
||||
|
||||
// Try to settle again with the same htlc id. We need this idempotent
|
||||
// behaviour after a restart.
|
||||
event, err = ctx.registry.NotifyExitHopHtlc(
|
||||
resolution, err = ctx.registry.NotifyExitHopHtlc(
|
||||
testInvoicePaymentHash, amtPaid, testHtlcExpiry, testCurrentHeight,
|
||||
getCircuitKey(0), hodlChan, testPayload,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected NotifyExitHopHtlc error: %v", err)
|
||||
}
|
||||
if event.Preimage == nil {
|
||||
t.Fatal("expected settle event")
|
||||
if resolution.Preimage == nil {
|
||||
t.Fatal("expected settle resolution")
|
||||
}
|
||||
|
||||
// Try to settle again with a new higher-valued htlc. This payment
|
||||
// should also be accepted, to prevent any change in behaviour for a
|
||||
// paid invoice that may open up a probe vector.
|
||||
event, err = ctx.registry.NotifyExitHopHtlc(
|
||||
resolution, err = ctx.registry.NotifyExitHopHtlc(
|
||||
testInvoicePaymentHash, amtPaid+600, testHtlcExpiry, testCurrentHeight,
|
||||
getCircuitKey(1), hodlChan, testPayload,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected NotifyExitHopHtlc error: %v", err)
|
||||
}
|
||||
if event.Preimage == nil {
|
||||
t.Fatal("expected settle event")
|
||||
if resolution.Preimage == nil {
|
||||
t.Fatal("expected settle resolution")
|
||||
}
|
||||
|
||||
// Try to settle again with a lower amount. This should fail just as it
|
||||
// would have failed if it were the first payment.
|
||||
event, err = ctx.registry.NotifyExitHopHtlc(
|
||||
resolution, err = ctx.registry.NotifyExitHopHtlc(
|
||||
testInvoicePaymentHash, amtPaid-600, testHtlcExpiry, testCurrentHeight,
|
||||
getCircuitKey(2), hodlChan, testPayload,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected NotifyExitHopHtlc error: %v", err)
|
||||
}
|
||||
if event.Preimage != nil {
|
||||
t.Fatal("expected cancel event")
|
||||
if resolution.Preimage != nil {
|
||||
t.Fatal("expected cancel resolution")
|
||||
}
|
||||
|
||||
// Check that settled amount is equal to the sum of values of the htlcs
|
||||
@ -177,7 +177,7 @@ func TestSettleInvoice(t *testing.T) {
|
||||
// As this is a direct sette, we expect nothing on the hodl chan.
|
||||
select {
|
||||
case <-hodlChan:
|
||||
t.Fatal("unexpected event")
|
||||
t.Fatal("unexpected resolution")
|
||||
default:
|
||||
}
|
||||
}
|
||||
@ -270,9 +270,9 @@ func TestCancelInvoice(t *testing.T) {
|
||||
}
|
||||
|
||||
// Notify arrival of a new htlc paying to this invoice. This should
|
||||
// result in a cancel event.
|
||||
// result in a cancel resolution.
|
||||
hodlChan := make(chan interface{})
|
||||
event, err := ctx.registry.NotifyExitHopHtlc(
|
||||
resolution, err := ctx.registry.NotifyExitHopHtlc(
|
||||
testInvoicePaymentHash, amt, testHtlcExpiry, testCurrentHeight,
|
||||
getCircuitKey(0), hodlChan, testPayload,
|
||||
)
|
||||
@ -280,12 +280,12 @@ func TestCancelInvoice(t *testing.T) {
|
||||
t.Fatal("expected settlement of a canceled invoice to succeed")
|
||||
}
|
||||
|
||||
if event.Preimage != nil {
|
||||
if resolution.Preimage != nil {
|
||||
t.Fatal("expected cancel htlc resolution")
|
||||
}
|
||||
if event.AcceptHeight != testCurrentHeight {
|
||||
if resolution.AcceptHeight != testCurrentHeight {
|
||||
t.Fatalf("expected acceptHeight %v, but got %v",
|
||||
testCurrentHeight, event.AcceptHeight)
|
||||
testCurrentHeight, resolution.AcceptHeight)
|
||||
}
|
||||
}
|
||||
|
||||
@ -354,52 +354,52 @@ func TestSettleHoldInvoice(t *testing.T) {
|
||||
|
||||
// NotifyExitHopHtlc without a preimage present in the invoice registry
|
||||
// should be possible.
|
||||
event, err := registry.NotifyExitHopHtlc(
|
||||
resolution, err := registry.NotifyExitHopHtlc(
|
||||
testInvoicePaymentHash, amtPaid, testHtlcExpiry, testCurrentHeight,
|
||||
getCircuitKey(0), hodlChan, testPayload,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("expected settle to succeed but got %v", err)
|
||||
}
|
||||
if event != nil {
|
||||
if resolution != nil {
|
||||
t.Fatalf("expected htlc to be held")
|
||||
}
|
||||
|
||||
// Test idempotency.
|
||||
event, err = registry.NotifyExitHopHtlc(
|
||||
resolution, err = registry.NotifyExitHopHtlc(
|
||||
testInvoicePaymentHash, amtPaid, testHtlcExpiry, testCurrentHeight,
|
||||
getCircuitKey(0), hodlChan, testPayload,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("expected settle to succeed but got %v", err)
|
||||
}
|
||||
if event != nil {
|
||||
if resolution != nil {
|
||||
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(
|
||||
resolution, err = registry.NotifyExitHopHtlc(
|
||||
testInvoicePaymentHash, amtPaid, testHtlcExpiry, testCurrentHeight+10,
|
||||
getCircuitKey(0), hodlChan, testPayload,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("expected settle to succeed but got %v", err)
|
||||
}
|
||||
if event != nil {
|
||||
if resolution != 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.
|
||||
event, err = registry.NotifyExitHopHtlc(
|
||||
resolution, err = registry.NotifyExitHopHtlc(
|
||||
testInvoicePaymentHash, amtPaid, 1, testCurrentHeight,
|
||||
getCircuitKey(1), hodlChan, testPayload,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("expected settle to succeed but got %v", err)
|
||||
}
|
||||
if event == nil || event.Preimage != nil {
|
||||
if resolution == nil || resolution.Preimage != nil {
|
||||
t.Fatalf("expected htlc to be canceled")
|
||||
}
|
||||
|
||||
@ -427,7 +427,7 @@ func TestSettleHoldInvoice(t *testing.T) {
|
||||
}
|
||||
if htlcResolution.AcceptHeight != testCurrentHeight {
|
||||
t.Fatalf("expected acceptHeight %v, but got %v",
|
||||
testCurrentHeight, event.AcceptHeight)
|
||||
testCurrentHeight, resolution.AcceptHeight)
|
||||
}
|
||||
|
||||
// We expect a settled notification to be sent out for both all and
|
||||
@ -496,14 +496,14 @@ func TestCancelHoldInvoice(t *testing.T) {
|
||||
|
||||
// NotifyExitHopHtlc without a preimage present in the invoice registry
|
||||
// should be possible.
|
||||
event, err := registry.NotifyExitHopHtlc(
|
||||
resolution, err := registry.NotifyExitHopHtlc(
|
||||
testInvoicePaymentHash, amtPaid, testHtlcExpiry, testCurrentHeight,
|
||||
getCircuitKey(0), hodlChan, testPayload,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("expected settle to succeed but got %v", err)
|
||||
}
|
||||
if event != nil {
|
||||
if resolution != nil {
|
||||
t.Fatalf("expected htlc to be held")
|
||||
}
|
||||
|
||||
@ -521,19 +521,19 @@ func TestCancelHoldInvoice(t *testing.T) {
|
||||
// Offering the same htlc again at a higher height should still result
|
||||
// in a rejection. The accept height is expected to be the original
|
||||
// accept height.
|
||||
event, err = registry.NotifyExitHopHtlc(
|
||||
resolution, err = registry.NotifyExitHopHtlc(
|
||||
testInvoicePaymentHash, amtPaid, testHtlcExpiry, testCurrentHeight+1,
|
||||
getCircuitKey(0), hodlChan, testPayload,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("expected settle to succeed but got %v", err)
|
||||
}
|
||||
if event.Preimage != nil {
|
||||
if resolution.Preimage != nil {
|
||||
t.Fatalf("expected htlc to be canceled")
|
||||
}
|
||||
if event.AcceptHeight != testCurrentHeight {
|
||||
if resolution.AcceptHeight != testCurrentHeight {
|
||||
t.Fatalf("expected acceptHeight %v, but got %v",
|
||||
testCurrentHeight, event.AcceptHeight)
|
||||
testCurrentHeight, resolution.AcceptHeight)
|
||||
}
|
||||
}
|
||||
|
||||
@ -578,7 +578,7 @@ func TestSettleMpp(t *testing.T) {
|
||||
|
||||
// Send htlc 1.
|
||||
hodlChan1 := make(chan interface{}, 1)
|
||||
event, err := ctx.registry.NotifyExitHopHtlc(
|
||||
resolution, err := ctx.registry.NotifyExitHopHtlc(
|
||||
testInvoicePaymentHash, testInvoice.Terms.Value/2,
|
||||
testHtlcExpiry,
|
||||
testCurrentHeight, getCircuitKey(10), hodlChan1, mppPayload,
|
||||
@ -586,7 +586,7 @@ func TestSettleMpp(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if event != nil {
|
||||
if resolution != nil {
|
||||
t.Fatal("expected no direct resolution")
|
||||
}
|
||||
|
||||
@ -595,12 +595,12 @@ func TestSettleMpp(t *testing.T) {
|
||||
|
||||
htlcResolution := (<-hodlChan1).(HtlcResolution)
|
||||
if htlcResolution.Preimage != nil {
|
||||
t.Fatal("expected cancel event")
|
||||
t.Fatal("expected cancel resolution")
|
||||
}
|
||||
|
||||
// Send htlc 2.
|
||||
hodlChan2 := make(chan interface{}, 1)
|
||||
event, err = ctx.registry.NotifyExitHopHtlc(
|
||||
resolution, err = ctx.registry.NotifyExitHopHtlc(
|
||||
testInvoicePaymentHash, testInvoice.Terms.Value/2,
|
||||
testHtlcExpiry,
|
||||
testCurrentHeight, getCircuitKey(11), hodlChan2, mppPayload,
|
||||
@ -608,13 +608,13 @@ func TestSettleMpp(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if event != nil {
|
||||
if resolution != nil {
|
||||
t.Fatal("expected no direct resolution")
|
||||
}
|
||||
|
||||
// Send htlc 3.
|
||||
hodlChan3 := make(chan interface{}, 1)
|
||||
event, err = ctx.registry.NotifyExitHopHtlc(
|
||||
resolution, err = ctx.registry.NotifyExitHopHtlc(
|
||||
testInvoicePaymentHash, testInvoice.Terms.Value/2,
|
||||
testHtlcExpiry,
|
||||
testCurrentHeight, getCircuitKey(12), hodlChan3, mppPayload,
|
||||
@ -622,8 +622,8 @@ func TestSettleMpp(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if event == nil {
|
||||
t.Fatal("expected a settle event")
|
||||
if resolution == nil {
|
||||
t.Fatal("expected a settle resolution")
|
||||
}
|
||||
|
||||
// Check that settled amount is equal to the sum of values of the htlcs
|
||||
|
Loading…
Reference in New Issue
Block a user