github.com/btcsuite/btcd@v0.24.0/wire/protocol_test.go (about) 1 // Copyright (c) 2013-2016 The btcsuite developers 2 // Use of this source code is governed by an ISC 3 // license that can be found in the LICENSE file. 4 5 package wire 6 7 import ( 8 "testing" 9 10 "github.com/stretchr/testify/require" 11 ) 12 13 // TestServiceFlagStringer tests the stringized output for service flag types. 14 func TestServiceFlagStringer(t *testing.T) { 15 tests := []struct { 16 in ServiceFlag 17 want string 18 }{ 19 {0, "0x0"}, 20 {SFNodeNetwork, "SFNodeNetwork"}, 21 {SFNodeGetUTXO, "SFNodeGetUTXO"}, 22 {SFNodeBloom, "SFNodeBloom"}, 23 {SFNodeWitness, "SFNodeWitness"}, 24 {SFNodeXthin, "SFNodeXthin"}, 25 {SFNodeBit5, "SFNodeBit5"}, 26 {SFNodeCF, "SFNodeCF"}, 27 {SFNode2X, "SFNode2X"}, 28 {SFNodeNetworkLimited, "SFNodeNetworkLimited"}, 29 {0xffffffff, "SFNodeNetwork|SFNodeGetUTXO|SFNodeBloom|SFNodeWitness|SFNodeXthin|SFNodeBit5|SFNodeCF|SFNode2X|SFNodeNetworkLimited|0xfffffb00"}, 30 } 31 32 t.Logf("Running %d tests", len(tests)) 33 for i, test := range tests { 34 result := test.in.String() 35 if result != test.want { 36 t.Errorf("String #%d\n got: %s want: %s", i, result, 37 test.want) 38 continue 39 } 40 } 41 } 42 43 // TestBitcoinNetStringer tests the stringized output for bitcoin net types. 44 func TestBitcoinNetStringer(t *testing.T) { 45 tests := []struct { 46 in BitcoinNet 47 want string 48 }{ 49 {MainNet, "MainNet"}, 50 {TestNet, "TestNet"}, 51 {TestNet3, "TestNet3"}, 52 {SimNet, "SimNet"}, 53 {0xffffffff, "Unknown BitcoinNet (4294967295)"}, 54 } 55 56 t.Logf("Running %d tests", len(tests)) 57 for i, test := range tests { 58 result := test.in.String() 59 if result != test.want { 60 t.Errorf("String #%d\n got: %s want: %s", i, result, 61 test.want) 62 continue 63 } 64 } 65 } 66 67 func TestHasFlag(t *testing.T) { 68 tests := []struct { 69 in ServiceFlag 70 check ServiceFlag 71 want bool 72 }{ 73 {0, SFNodeNetwork, false}, 74 {SFNodeNetwork | SFNodeNetworkLimited | SFNodeWitness, SFNodeBloom, false}, 75 {SFNodeNetwork | SFNodeNetworkLimited | SFNodeWitness, SFNodeNetworkLimited, true}, 76 } 77 78 for _, test := range tests { 79 require.Equal(t, test.want, test.in.HasFlag(test.check)) 80 } 81 }