lnwire: add new RequiresFeature method
In this commit, we add a new RequiresFeature method to the feature vector struct. This method allows us to check if the set of features we're examining *require* that the even portion of a bit pair be set. This can be used to check if new behavior should be allowed (after we flip new bits to be required) for existing contexts.
This commit is contained in:
2 files changed
+43
-1
No files matched your search
+29
-1
@@ -5,6 +5,8 @@ import (
|
||||
"reflect"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var testFeatureNames = map[FeatureBit]string{
|
||||
@@ -87,6 +89,7 @@ func TestFeatureVectorSetUnset(t *testing.T) {
|
||||
t.Errorf("Expectation failed in case %d, bit %d", i, j)
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for _, bit := range test.bits {
|
||||
@@ -95,6 +98,31 @@ func TestFeatureVectorSetUnset(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestFeatureVectorRequiresFeature tests that if a feature vector only
|
||||
// includes a required feature bit (it's even), then the RequiresFeature method
|
||||
// will return true for both that bit as well as it's optional counter party.
|
||||
func TestFeatureVectorRequiresFeature(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Create a new feature vector with the features above, and set only
|
||||
// the set of required bits. These will be all the even features
|
||||
// referenced above.
|
||||
fv := NewFeatureVector(nil, testFeatureNames)
|
||||
fv.Set(0)
|
||||
fv.Set(4)
|
||||
|
||||
// Next we'll query for those exact bits, these should show up as being
|
||||
// required.
|
||||
require.True(t, fv.RequiresFeature(0))
|
||||
require.True(t, fv.RequiresFeature(4))
|
||||
|
||||
// If we query for the odd (optional) counter party to each of the
|
||||
// features, the method should still return that the backing feature
|
||||
// vector requires the feature to be set.
|
||||
require.True(t, fv.RequiresFeature(1))
|
||||
require.True(t, fv.RequiresFeature(5))
|
||||
}
|
||||
|
||||
func TestFeatureVectorEncodeDecode(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -277,7 +305,7 @@ func TestIsRequired(t *testing.T) {
|
||||
}
|
||||
|
||||
// TestFeatures asserts that the Features() method on a FeatureVector properly
|
||||
// returns the set of feature bits it stores internallly.
|
||||
// returns the set of feature bits it stores internally.
|
||||
func TestFeatures(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
Reference in new issue
Block a user