htlcswitch/test: align test invoice cltv expiry

This commit is contained in:
Joost Jager 2019-04-05 11:13:52 +02:00
parent af7d0e5ff5
commit 1b2816006f
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
2 changed files with 10 additions and 4 deletions

@ -728,6 +728,8 @@ func newDB() (*channeldb.DB, func(), error) {
return cdb, cleanUp, nil
}
const testInvoiceCltvExpiry = 4
type mockInvoiceRegistry struct {
settleChan chan lntypes.Hash
@ -743,7 +745,7 @@ func newMockRegistry(minDelta uint32) *mockInvoiceRegistry {
}
decodeExpiry := func(invoice string) (uint32, error) {
return 3, nil
return testInvoiceCltvExpiry, nil
}
registry := invoices.NewRegistry(cdb, decodeExpiry)

@ -527,6 +527,12 @@ func generatePaymentWithPreimage(invoiceAmt, htlcAmt lnwire.MilliSatoshi,
preimage, rhash [32]byte) (*channeldb.Invoice, *lnwire.UpdateAddHTLC,
error) {
// Create the db invoice. Normally the payment requests needs to be set,
// because it is decoded in InvoiceRegistry to obtain the cltv expiry.
// But because the mock registry used in tests is mocking the decode
// step and always returning the value of testInvoiceCltvExpiry, we
// don't need to bother here with creating and signing a payment
// request.
invoice := &channeldb.Invoice{
CreationDate: time.Now(),
Terms: channeldb.ContractTerm{
@ -602,8 +608,6 @@ type threeHopNetwork struct {
func generateHops(payAmt lnwire.MilliSatoshi, startingHeight uint32,
path ...*channelLink) (lnwire.MilliSatoshi, uint32, []ForwardingInfo) {
lastHop := path[len(path)-1]
totalTimelock := startingHeight
runningAmt := payAmt
@ -620,7 +624,7 @@ func generateHops(payAmt lnwire.MilliSatoshi, startingHeight uint32,
// If this is the last, hop, then the time lock will be their
// specified delta policy plus our starting height.
if i == len(path)-1 {
totalTimelock += lastHop.cfg.FwrdingPolicy.TimeLockDelta
totalTimelock += testInvoiceCltvExpiry
timeLock = totalTimelock
} else {
// Otherwise, the outgoing time lock should be the