channeldb/invoice_test: only set htlc-level preimage on accept
This commit is contained in:
parent
88b72ab398
commit
24d283e615
@ -1374,7 +1374,7 @@ func TestSetIDIndex(t *testing.T) {
|
|||||||
invoice.AmtPaid = amt
|
invoice.AmtPaid = amt
|
||||||
invoice.SettleDate = dbInvoice.SettleDate
|
invoice.SettleDate = dbInvoice.SettleDate
|
||||||
invoice.Htlcs = map[CircuitKey]*InvoiceHTLC{
|
invoice.Htlcs = map[CircuitKey]*InvoiceHTLC{
|
||||||
{HtlcID: 0}: makeAMPInvoiceHTLC(amt, *setID, preimage),
|
{HtlcID: 0}: makeAMPInvoiceHTLC(amt, *setID, payHash, &preimage),
|
||||||
}
|
}
|
||||||
|
|
||||||
// We should get back the exact same invoice that we just inserted.
|
// We should get back the exact same invoice that we just inserted.
|
||||||
@ -1414,9 +1414,9 @@ func TestSetIDIndex(t *testing.T) {
|
|||||||
invoice.AmtPaid += 2 * amt
|
invoice.AmtPaid += 2 * amt
|
||||||
invoice.SettleDate = dbInvoice.SettleDate
|
invoice.SettleDate = dbInvoice.SettleDate
|
||||||
invoice.Htlcs = map[CircuitKey]*InvoiceHTLC{
|
invoice.Htlcs = map[CircuitKey]*InvoiceHTLC{
|
||||||
{HtlcID: 0}: makeAMPInvoiceHTLC(amt, *setID, preimage),
|
{HtlcID: 0}: makeAMPInvoiceHTLC(amt, *setID, payHash, &preimage),
|
||||||
{HtlcID: 1}: makeAMPInvoiceHTLC(amt, *setID2, preimage),
|
{HtlcID: 1}: makeAMPInvoiceHTLC(amt, *setID2, payHash, nil),
|
||||||
{HtlcID: 2}: makeAMPInvoiceHTLC(amt, *setID2, preimage),
|
{HtlcID: 2}: makeAMPInvoiceHTLC(amt, *setID2, payHash, nil),
|
||||||
}
|
}
|
||||||
|
|
||||||
// We should get back the exact same invoice that we just inserted.
|
// We should get back the exact same invoice that we just inserted.
|
||||||
@ -1460,7 +1460,7 @@ func TestSetIDIndex(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func makeAMPInvoiceHTLC(amt lnwire.MilliSatoshi, setID [32]byte,
|
func makeAMPInvoiceHTLC(amt lnwire.MilliSatoshi, setID [32]byte,
|
||||||
preimage lntypes.Preimage) *InvoiceHTLC {
|
hash lntypes.Hash, preimage *lntypes.Preimage) *InvoiceHTLC {
|
||||||
|
|
||||||
return &InvoiceHTLC{
|
return &InvoiceHTLC{
|
||||||
Amt: amt,
|
Amt: amt,
|
||||||
@ -1470,8 +1470,8 @@ func makeAMPInvoiceHTLC(amt lnwire.MilliSatoshi, setID [32]byte,
|
|||||||
CustomRecords: make(record.CustomSet),
|
CustomRecords: make(record.CustomSet),
|
||||||
AMP: &InvoiceHtlcAMPData{
|
AMP: &InvoiceHtlcAMPData{
|
||||||
Record: *record.NewAMP([32]byte{}, setID, 0),
|
Record: *record.NewAMP([32]byte{}, setID, 0),
|
||||||
Hash: preimage.Hash(),
|
Hash: hash,
|
||||||
Preimage: &preimage,
|
Preimage: preimage,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1488,18 +1488,23 @@ func updateAcceptAMPHtlc(id uint64, amt lnwire.MilliSatoshi,
|
|||||||
|
|
||||||
noRecords := make(record.CustomSet)
|
noRecords := make(record.CustomSet)
|
||||||
|
|
||||||
var state *InvoiceStateUpdateDesc
|
var (
|
||||||
|
state *InvoiceStateUpdateDesc
|
||||||
|
preimage *lntypes.Preimage
|
||||||
|
)
|
||||||
if accept {
|
if accept {
|
||||||
state = &InvoiceStateUpdateDesc{
|
state = &InvoiceStateUpdateDesc{
|
||||||
NewState: ContractAccepted,
|
NewState: ContractAccepted,
|
||||||
SetID: setID,
|
SetID: setID,
|
||||||
}
|
}
|
||||||
|
pre := *invoice.Terms.PaymentPreimage
|
||||||
|
preimage = &pre
|
||||||
}
|
}
|
||||||
|
|
||||||
ampData := &InvoiceHtlcAMPData{
|
ampData := &InvoiceHtlcAMPData{
|
||||||
Record: *record.NewAMP([32]byte{}, *setID, 0),
|
Record: *record.NewAMP([32]byte{}, *setID, 0),
|
||||||
Hash: invoice.Terms.PaymentPreimage.Hash(),
|
Hash: invoice.Terms.PaymentPreimage.Hash(),
|
||||||
Preimage: invoice.Terms.PaymentPreimage,
|
Preimage: preimage,
|
||||||
}
|
}
|
||||||
update := &InvoiceUpdateDesc{
|
update := &InvoiceUpdateDesc{
|
||||||
State: state,
|
State: state,
|
||||||
|
Loading…
Reference in New Issue
Block a user