2016-08-08 18:42:54 +02:00
|
|
|
// Copyright (c) 2013-2016 The btcsuite developers
|
2013-05-08 21:31:00 +02:00
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2016-08-08 18:42:54 +02:00
|
|
|
package wire
|
2013-05-08 21:31:00 +02:00
|
|
|
|
2023-11-07 02:57:45 +01:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
2013-05-08 21:31:00 +02:00
|
|
|
|
|
|
|
// TestServiceFlagStringer tests the stringized output for service flag types.
|
|
|
|
func TestServiceFlagStringer(t *testing.T) {
|
|
|
|
tests := []struct {
|
2016-08-08 18:42:54 +02:00
|
|
|
in ServiceFlag
|
2013-05-08 21:31:00 +02:00
|
|
|
want string
|
|
|
|
}{
|
|
|
|
{0, "0x0"},
|
2016-08-08 18:42:54 +02:00
|
|
|
{SFNodeNetwork, "SFNodeNetwork"},
|
|
|
|
{SFNodeGetUTXO, "SFNodeGetUTXO"},
|
|
|
|
{SFNodeBloom, "SFNodeBloom"},
|
2016-10-19 00:54:27 +02:00
|
|
|
{SFNodeWitness, "SFNodeWitness"},
|
2017-10-13 03:37:27 +02:00
|
|
|
{SFNodeXthin, "SFNodeXthin"},
|
|
|
|
{SFNodeBit5, "SFNodeBit5"},
|
2017-01-18 09:09:05 +01:00
|
|
|
{SFNodeCF, "SFNodeCF"},
|
2017-10-13 03:37:27 +02:00
|
|
|
{SFNode2X, "SFNode2X"},
|
2023-01-26 06:29:16 +01:00
|
|
|
{SFNodeNetworkLimited, "SFNodeNetworkLimited"},
|
|
|
|
{0xffffffff, "SFNodeNetwork|SFNodeGetUTXO|SFNodeBloom|SFNodeWitness|SFNodeXthin|SFNodeBit5|SFNodeCF|SFNode2X|SFNodeNetworkLimited|0xfffffb00"},
|
2013-05-08 21:31:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("Running %d tests", len(tests))
|
|
|
|
for i, test := range tests {
|
|
|
|
result := test.in.String()
|
|
|
|
if result != test.want {
|
|
|
|
t.Errorf("String #%d\n got: %s want: %s", i, result,
|
|
|
|
test.want)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-03 15:36:11 +01:00
|
|
|
|
|
|
|
// TestBitcoinNetStringer tests the stringized output for bitcoin net types.
|
|
|
|
func TestBitcoinNetStringer(t *testing.T) {
|
|
|
|
tests := []struct {
|
2016-08-08 18:42:54 +02:00
|
|
|
in BitcoinNet
|
2014-01-03 15:36:11 +01:00
|
|
|
want string
|
|
|
|
}{
|
2016-08-08 18:42:54 +02:00
|
|
|
{MainNet, "MainNet"},
|
|
|
|
{TestNet, "TestNet"},
|
|
|
|
{TestNet3, "TestNet3"},
|
|
|
|
{SimNet, "SimNet"},
|
2014-01-03 15:36:11 +01:00
|
|
|
{0xffffffff, "Unknown BitcoinNet (4294967295)"},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("Running %d tests", len(tests))
|
|
|
|
for i, test := range tests {
|
|
|
|
result := test.in.String()
|
|
|
|
if result != test.want {
|
|
|
|
t.Errorf("String #%d\n got: %s want: %s", i, result,
|
|
|
|
test.want)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-07 02:57:45 +01:00
|
|
|
|
|
|
|
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))
|
|
|
|
}
|
|
|
|
}
|