-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtopics_test.go
More file actions
129 lines (115 loc) · 3.69 KB
/
topics_test.go
File metadata and controls
129 lines (115 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package p2p
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestTopicName_Mainnet(t *testing.T) {
topic := TopicName("main", TopicBlock)
assert.Equal(t, "teranode/bitcoin/1.0.0/mainnet-block", topic)
}
func TestTopicName_AllNetworks(t *testing.T) {
tests := []struct {
name string
network string
topic string
expected string
}{
{
name: "mainnet block using short name",
network: "main",
topic: TopicBlock,
expected: "teranode/bitcoin/1.0.0/mainnet-block",
},
{
name: "mainnet block using full name",
network: NetworkMainnet,
topic: TopicBlock,
expected: "teranode/bitcoin/1.0.0/mainnet-block",
},
{
name: "testnet subtree using short name",
network: "test",
topic: TopicSubtree,
expected: "teranode/bitcoin/1.0.0/testnet-subtree",
},
{
name: "testnet subtree using full name",
network: NetworkTestnet,
topic: TopicSubtree,
expected: "teranode/bitcoin/1.0.0/testnet-subtree",
},
{
name: "stn rejected-tx",
network: NetworkSTN,
topic: TopicRejectedTx,
expected: "teranode/bitcoin/1.0.0/stn-rejected-tx",
},
{
name: "teratestnet node_status using short name",
network: "teratest",
topic: TopicNodeStatus,
expected: "teranode/bitcoin/1.0.0/teratestnet-node_status",
},
{
name: "teratestnet node_status using full name",
network: NetworkTeratestnet,
topic: TopicNodeStatus,
expected: "teranode/bitcoin/1.0.0/teratestnet-node_status",
},
{
name: "unknown network passes through unchanged",
network: "custom",
topic: TopicBlock,
expected: "teranode/bitcoin/1.0.0/custom-block",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := TopicName(tt.network, tt.topic)
assert.Equal(t, tt.expected, result)
})
}
}
func TestAllTopics(t *testing.T) {
topics := AllTopics("main")
require.Len(t, topics, 4)
assert.Contains(t, topics, "teranode/bitcoin/1.0.0/mainnet-block")
assert.Contains(t, topics, "teranode/bitcoin/1.0.0/mainnet-subtree")
assert.Contains(t, topics, "teranode/bitcoin/1.0.0/mainnet-rejected-tx")
assert.Contains(t, topics, "teranode/bitcoin/1.0.0/mainnet-node_status")
}
func TestAllTopics_Testnet(t *testing.T) {
topics := AllTopics(NetworkTestnet)
require.Len(t, topics, 4)
assert.Contains(t, topics, "teranode/bitcoin/1.0.0/testnet-block")
assert.Contains(t, topics, "teranode/bitcoin/1.0.0/testnet-subtree")
assert.Contains(t, topics, "teranode/bitcoin/1.0.0/testnet-rejected-tx")
assert.Contains(t, topics, "teranode/bitcoin/1.0.0/testnet-node_status")
}
func TestNetworkMapping(t *testing.T) {
mapping := getNetworkToTopic()
// Test that short names map correctly
assert.Equal(t, NetworkMainnet, mapping["main"])
assert.Equal(t, NetworkTestnet, mapping["test"])
assert.Equal(t, NetworkTeratestnet, mapping["teratest"])
// Test that full names map to themselves
assert.Equal(t, NetworkMainnet, mapping[NetworkMainnet])
assert.Equal(t, NetworkTestnet, mapping[NetworkTestnet])
assert.Equal(t, NetworkSTN, mapping[NetworkSTN])
assert.Equal(t, NetworkTeratestnet, mapping[NetworkTeratestnet])
}
func TestTopicConstants(t *testing.T) {
// Verify topic constants have expected values
assert.Equal(t, "block", TopicBlock)
assert.Equal(t, "subtree", TopicSubtree)
assert.Equal(t, "rejected-tx", TopicRejectedTx)
assert.Equal(t, "node_status", TopicNodeStatus)
}
func TestNetworkConstants(t *testing.T) {
// Verify network constants have expected values
assert.Equal(t, "mainnet", NetworkMainnet)
assert.Equal(t, "testnet", NetworkTestnet)
assert.Equal(t, "stn", NetworkSTN)
assert.Equal(t, "teratestnet", NetworkTeratestnet)
}