lnwire: add feature vector update validation helpers
This commit is contained in:
2 files changed
+157
No files matched your search
@@ -396,3 +396,103 @@ func TestIsEmptyFeatureVector(t *testing.T) {
|
||||
fv.Unset(StaticRemoteKeyOptional)
|
||||
require.True(t, fv.IsEmpty())
|
||||
}
|
||||
|
||||
// TestValidatePairs tests that feature vectors can only set the required or
|
||||
// optional feature bit in a pair, not both.
|
||||
func TestValidatePairs(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
rfv := NewRawFeatureVector(
|
||||
StaticRemoteKeyOptional,
|
||||
StaticRemoteKeyRequired,
|
||||
)
|
||||
require.Equal(t, ErrFeaturePairExists, rfv.ValidatePairs())
|
||||
|
||||
rfv = NewRawFeatureVector(
|
||||
StaticRemoteKeyOptional,
|
||||
PaymentAddrRequired,
|
||||
)
|
||||
require.Nil(t, rfv.ValidatePairs())
|
||||
}
|
||||
|
||||
// TestValidateUpdate tests validation of an update to a feature vector.
|
||||
func TestValidateUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
currentFeatures []FeatureBit
|
||||
newFeatures []FeatureBit
|
||||
err error
|
||||
}{
|
||||
{
|
||||
name: "defined feature bit set, can include",
|
||||
currentFeatures: []FeatureBit{
|
||||
StaticRemoteKeyOptional,
|
||||
},
|
||||
newFeatures: []FeatureBit{
|
||||
StaticRemoteKeyOptional,
|
||||
},
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
name: "defined feature bit not already set",
|
||||
currentFeatures: []FeatureBit{
|
||||
StaticRemoteKeyOptional,
|
||||
},
|
||||
newFeatures: []FeatureBit{
|
||||
StaticRemoteKeyOptional,
|
||||
PaymentAddrRequired,
|
||||
},
|
||||
err: ErrFeatureStandard,
|
||||
},
|
||||
{
|
||||
name: "known feature missing",
|
||||
currentFeatures: []FeatureBit{
|
||||
StaticRemoteKeyOptional,
|
||||
PaymentAddrRequired,
|
||||
},
|
||||
newFeatures: []FeatureBit{
|
||||
StaticRemoteKeyOptional,
|
||||
},
|
||||
err: ErrFeatureStandard,
|
||||
},
|
||||
{
|
||||
name: "can set unknown feature",
|
||||
currentFeatures: []FeatureBit{
|
||||
StaticRemoteKeyOptional,
|
||||
},
|
||||
newFeatures: []FeatureBit{
|
||||
StaticRemoteKeyOptional,
|
||||
FeatureBit(1001),
|
||||
},
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
name: "can unset unknown feature",
|
||||
currentFeatures: []FeatureBit{
|
||||
StaticRemoteKeyOptional,
|
||||
FeatureBit(1001),
|
||||
},
|
||||
newFeatures: []FeatureBit{
|
||||
StaticRemoteKeyOptional,
|
||||
},
|
||||
err: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
testCase := testCase
|
||||
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
currentFV := NewRawFeatureVector(
|
||||
testCase.currentFeatures...,
|
||||
)
|
||||
newFV := NewRawFeatureVector(testCase.newFeatures...)
|
||||
|
||||
err := currentFV.ValidateUpdate(newFV)
|
||||
require.ErrorIs(t, err, testCase.err)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user