mirror of
https://github.com/btcsuite/btcd.git
synced 2024-11-19 01:40:07 +01:00
wire: add HasFlag method
This commit is contained in:
parent
1012f1e4ba
commit
a09e7b224a
@ -126,6 +126,11 @@ var orderedSFStrings = []ServiceFlag{
|
||||
SFNodeNetworkLimited,
|
||||
}
|
||||
|
||||
// HasFlag returns a bool indicating if the service has the given flag.
|
||||
func (f ServiceFlag) HasFlag(s ServiceFlag) bool {
|
||||
return f&s == s
|
||||
}
|
||||
|
||||
// String returns the ServiceFlag in human-readable form.
|
||||
func (f ServiceFlag) String() string {
|
||||
// No flags are set.
|
||||
|
@ -4,7 +4,11 @@
|
||||
|
||||
package wire
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// TestServiceFlagStringer tests the stringized output for service flag types.
|
||||
func TestServiceFlagStringer(t *testing.T) {
|
||||
@ -59,3 +63,19 @@ func TestBitcoinNetStringer(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasFlag(t *testing.T) {
|
||||
tests := []struct {
|
||||
in ServiceFlag
|
||||
check ServiceFlag
|
||||
want bool
|
||||
}{
|
||||
{0, SFNodeNetwork, false},
|
||||
{SFNodeNetwork | SFNodeNetworkLimited | SFNodeWitness, SFNodeBloom, false},
|
||||
{SFNodeNetwork | SFNodeNetworkLimited | SFNodeWitness, SFNodeNetworkLimited, true},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
require.Equal(t, test.want, test.in.HasFlag(test.check))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user