github.com/lbryio/lbcd@v0.22.119/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 "testing"
     8  
     9  // TestServiceFlagStringer tests the stringized output for service flag types.
    10  func TestServiceFlagStringer(t *testing.T) {
    11  	tests := []struct {
    12  		in   ServiceFlag
    13  		want string
    14  	}{
    15  		{0, "0x0"},
    16  		{SFNodeNetwork, "SFNodeNetwork"},
    17  		{SFNodeGetUTXO, "SFNodeGetUTXO"},
    18  		{SFNodeBloom, "SFNodeBloom"},
    19  		{SFNodeWitness, "SFNodeWitness"},
    20  		{SFNodeXthin, "SFNodeXthin"},
    21  		{SFNodeBit5, "SFNodeBit5"},
    22  		{SFNodeCF, "SFNodeCF"},
    23  		{SFNode2X, "SFNode2X"},
    24  		{0xffffffff, "SFNodeNetwork|SFNodeGetUTXO|SFNodeBloom|SFNodeWitness|SFNodeXthin|SFNodeBit5|SFNodeCF|SFNode2X|0xffffff00"},
    25  	}
    26  
    27  	t.Logf("Running %d tests", len(tests))
    28  	for i, test := range tests {
    29  		result := test.in.String()
    30  		if result != test.want {
    31  			t.Errorf("String #%d\n got: %s want: %s", i, result,
    32  				test.want)
    33  			continue
    34  		}
    35  	}
    36  }
    37  
    38  // TestBitcoinNetStringer tests the stringized output for bitcoin net types.
    39  func TestBitcoinNetStringer(t *testing.T) {
    40  	tests := []struct {
    41  		in   BitcoinNet
    42  		want string
    43  	}{
    44  		{MainNet, "MainNet"},
    45  		{TestNet, "TestNet"},
    46  		{TestNet3, "TestNet3"},
    47  		{SimNet, "SimNet"},
    48  		{0xffffffff, "Unknown BitcoinNet (4294967295)"},
    49  	}
    50  
    51  	t.Logf("Running %d tests", len(tests))
    52  	for i, test := range tests {
    53  		result := test.in.String()
    54  		if result != test.want {
    55  			t.Errorf("String #%d\n got: %s want: %s", i, result,
    56  				test.want)
    57  			continue
    58  		}
    59  	}
    60  }