routing: add representation of blinded payments

This commit adds a representation of blinded payments, which include a
blinded path and aggregate routing parameters to be used in payment to
the path.
This commit is contained in:
Carla Kirk-Cohen
2023-05-31 15:28:09 -04:00
committed by Olaoluwa Osuntokun
parent 20e7e801c0
commit 539a275faa
2 changed files with 149 additions and 0 deletions

70
routing/blinding_test.go Normal file
View File

@ -0,0 +1,70 @@
package routing
import (
"testing"
sphinx "github.com/lightningnetwork/lightning-onion"
"github.com/stretchr/testify/require"
)
// TestBlindedPathValidation tests validation of blinded paths.
func TestBlindedPathValidation(t *testing.T) {
t.Parallel()
tests := []struct {
name string
payment *BlindedPayment
err error
}{
{
name: "no path",
payment: &BlindedPayment{},
err: ErrNoBlindedPath,
},
{
name: "insufficient hops",
payment: &BlindedPayment{
BlindedPath: &sphinx.BlindedPath{
BlindedHops: []*sphinx.BlindedHopInfo{},
},
},
err: ErrInsufficientBlindedHops,
},
{
name: "maximum < minimum",
payment: &BlindedPayment{
BlindedPath: &sphinx.BlindedPath{
BlindedHops: []*sphinx.BlindedHopInfo{
{},
},
},
HtlcMaximum: 10,
HtlcMinimum: 20,
},
err: ErrHTLCRestrictions,
},
{
name: "valid",
payment: &BlindedPayment{
BlindedPath: &sphinx.BlindedPath{
BlindedHops: []*sphinx.BlindedHopInfo{
{},
},
},
HtlcMaximum: 15,
HtlcMinimum: 5,
},
},
}
for _, testCase := range tests {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()
err := testCase.payment.Validate()
require.ErrorIs(t, err, testCase.err)
})
}
}