mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-20 15:04:22 +00:00
p2p: remove NodeInfo interface and rename DefaultNodeInfo struct (#5799)
The `NodeInfo` interface does not appear to serve any purpose at all, so I removed it and renamed the `DefaultNodeInfo` struct to `NodeInfo` (including the Protobuf representations). Let me know if this is actually needed for anything. Only the Protobuf rename is listed in the changelog, since we do not officially support API stability of the `p2p` package (according to `README.md`). The on-wire protocol remains compatible.
This commit is contained in:
+35
-40
@@ -9,7 +9,7 @@ import (
|
||||
func TestNodeInfoValidate(t *testing.T) {
|
||||
|
||||
// empty fails
|
||||
ni := DefaultNodeInfo{}
|
||||
ni := NodeInfo{}
|
||||
assert.Error(t, ni.Validate())
|
||||
|
||||
channels := make([]byte, maxNumChannels)
|
||||
@@ -26,54 +26,54 @@ func TestNodeInfoValidate(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
testName string
|
||||
malleateNodeInfo func(*DefaultNodeInfo)
|
||||
malleateNodeInfo func(*NodeInfo)
|
||||
expectErr bool
|
||||
}{
|
||||
{
|
||||
"Too Many Channels",
|
||||
func(ni *DefaultNodeInfo) { ni.Channels = append(channels, byte(maxNumChannels)) }, // nolint: gocritic
|
||||
func(ni *NodeInfo) { ni.Channels = append(channels, byte(maxNumChannels)) }, // nolint: gocritic
|
||||
true,
|
||||
},
|
||||
{"Duplicate Channel", func(ni *DefaultNodeInfo) { ni.Channels = dupChannels }, true},
|
||||
{"Good Channels", func(ni *DefaultNodeInfo) { ni.Channels = ni.Channels[:5] }, false},
|
||||
{"Duplicate Channel", func(ni *NodeInfo) { ni.Channels = dupChannels }, true},
|
||||
{"Good Channels", func(ni *NodeInfo) { ni.Channels = ni.Channels[:5] }, false},
|
||||
|
||||
{"Invalid NetAddress", func(ni *DefaultNodeInfo) { ni.ListenAddr = "not-an-address" }, true},
|
||||
{"Good NetAddress", func(ni *DefaultNodeInfo) { ni.ListenAddr = "0.0.0.0:26656" }, false},
|
||||
{"Invalid NetAddress", func(ni *NodeInfo) { ni.ListenAddr = "not-an-address" }, true},
|
||||
{"Good NetAddress", func(ni *NodeInfo) { ni.ListenAddr = "0.0.0.0:26656" }, false},
|
||||
|
||||
{"Non-ASCII Version", func(ni *DefaultNodeInfo) { ni.Version = nonASCII }, true},
|
||||
{"Empty tab Version", func(ni *DefaultNodeInfo) { ni.Version = emptyTab }, true},
|
||||
{"Empty space Version", func(ni *DefaultNodeInfo) { ni.Version = emptySpace }, true},
|
||||
{"Empty Version", func(ni *DefaultNodeInfo) { ni.Version = "" }, false},
|
||||
{"Non-ASCII Version", func(ni *NodeInfo) { ni.Version = nonASCII }, true},
|
||||
{"Empty tab Version", func(ni *NodeInfo) { ni.Version = emptyTab }, true},
|
||||
{"Empty space Version", func(ni *NodeInfo) { ni.Version = emptySpace }, true},
|
||||
{"Empty Version", func(ni *NodeInfo) { ni.Version = "" }, false},
|
||||
|
||||
{"Non-ASCII Moniker", func(ni *DefaultNodeInfo) { ni.Moniker = nonASCII }, true},
|
||||
{"Empty tab Moniker", func(ni *DefaultNodeInfo) { ni.Moniker = emptyTab }, true},
|
||||
{"Empty space Moniker", func(ni *DefaultNodeInfo) { ni.Moniker = emptySpace }, true},
|
||||
{"Empty Moniker", func(ni *DefaultNodeInfo) { ni.Moniker = "" }, true},
|
||||
{"Good Moniker", func(ni *DefaultNodeInfo) { ni.Moniker = "hey its me" }, false},
|
||||
{"Non-ASCII Moniker", func(ni *NodeInfo) { ni.Moniker = nonASCII }, true},
|
||||
{"Empty tab Moniker", func(ni *NodeInfo) { ni.Moniker = emptyTab }, true},
|
||||
{"Empty space Moniker", func(ni *NodeInfo) { ni.Moniker = emptySpace }, true},
|
||||
{"Empty Moniker", func(ni *NodeInfo) { ni.Moniker = "" }, true},
|
||||
{"Good Moniker", func(ni *NodeInfo) { ni.Moniker = "hey its me" }, false},
|
||||
|
||||
{"Non-ASCII TxIndex", func(ni *DefaultNodeInfo) { ni.Other.TxIndex = nonASCII }, true},
|
||||
{"Empty tab TxIndex", func(ni *DefaultNodeInfo) { ni.Other.TxIndex = emptyTab }, true},
|
||||
{"Empty space TxIndex", func(ni *DefaultNodeInfo) { ni.Other.TxIndex = emptySpace }, true},
|
||||
{"Empty TxIndex", func(ni *DefaultNodeInfo) { ni.Other.TxIndex = "" }, false},
|
||||
{"Off TxIndex", func(ni *DefaultNodeInfo) { ni.Other.TxIndex = "off" }, false},
|
||||
{"Non-ASCII TxIndex", func(ni *NodeInfo) { ni.Other.TxIndex = nonASCII }, true},
|
||||
{"Empty tab TxIndex", func(ni *NodeInfo) { ni.Other.TxIndex = emptyTab }, true},
|
||||
{"Empty space TxIndex", func(ni *NodeInfo) { ni.Other.TxIndex = emptySpace }, true},
|
||||
{"Empty TxIndex", func(ni *NodeInfo) { ni.Other.TxIndex = "" }, false},
|
||||
{"Off TxIndex", func(ni *NodeInfo) { ni.Other.TxIndex = "off" }, false},
|
||||
|
||||
{"Non-ASCII RPCAddress", func(ni *DefaultNodeInfo) { ni.Other.RPCAddress = nonASCII }, true},
|
||||
{"Empty tab RPCAddress", func(ni *DefaultNodeInfo) { ni.Other.RPCAddress = emptyTab }, true},
|
||||
{"Empty space RPCAddress", func(ni *DefaultNodeInfo) { ni.Other.RPCAddress = emptySpace }, true},
|
||||
{"Empty RPCAddress", func(ni *DefaultNodeInfo) { ni.Other.RPCAddress = "" }, false},
|
||||
{"Good RPCAddress", func(ni *DefaultNodeInfo) { ni.Other.RPCAddress = "0.0.0.0:26657" }, false},
|
||||
{"Non-ASCII RPCAddress", func(ni *NodeInfo) { ni.Other.RPCAddress = nonASCII }, true},
|
||||
{"Empty tab RPCAddress", func(ni *NodeInfo) { ni.Other.RPCAddress = emptyTab }, true},
|
||||
{"Empty space RPCAddress", func(ni *NodeInfo) { ni.Other.RPCAddress = emptySpace }, true},
|
||||
{"Empty RPCAddress", func(ni *NodeInfo) { ni.Other.RPCAddress = "" }, false},
|
||||
{"Good RPCAddress", func(ni *NodeInfo) { ni.Other.RPCAddress = "0.0.0.0:26657" }, false},
|
||||
}
|
||||
|
||||
nodeKey := GenNodeKey()
|
||||
name := "testing"
|
||||
|
||||
// test case passes
|
||||
ni = testNodeInfo(nodeKey.ID, name).(DefaultNodeInfo)
|
||||
ni = testNodeInfo(nodeKey.ID, name)
|
||||
ni.Channels = channels
|
||||
assert.NoError(t, ni.Validate())
|
||||
|
||||
for _, tc := range testCases {
|
||||
ni := testNodeInfo(nodeKey.ID, name).(DefaultNodeInfo)
|
||||
ni := testNodeInfo(nodeKey.ID, name)
|
||||
ni.Channels = channels
|
||||
tc.malleateNodeInfo(&ni)
|
||||
err := ni.Validate()
|
||||
@@ -95,30 +95,25 @@ func TestNodeInfoCompatible(t *testing.T) {
|
||||
var newTestChannel byte = 0x2
|
||||
|
||||
// test NodeInfo is compatible
|
||||
ni1 := testNodeInfo(nodeKey1.ID, name).(DefaultNodeInfo)
|
||||
ni2 := testNodeInfo(nodeKey2.ID, name).(DefaultNodeInfo)
|
||||
ni1 := testNodeInfo(nodeKey1.ID, name)
|
||||
ni2 := testNodeInfo(nodeKey2.ID, name)
|
||||
assert.NoError(t, ni1.CompatibleWith(ni2))
|
||||
|
||||
// add another channel; still compatible
|
||||
ni2.Channels = []byte{newTestChannel, testCh}
|
||||
assert.NoError(t, ni1.CompatibleWith(ni2))
|
||||
|
||||
// wrong NodeInfo type is not compatible
|
||||
_, netAddr := CreateRoutableAddr()
|
||||
ni3 := mockNodeInfo{netAddr}
|
||||
assert.Error(t, ni1.CompatibleWith(ni3))
|
||||
|
||||
testCases := []struct {
|
||||
testName string
|
||||
malleateNodeInfo func(*DefaultNodeInfo)
|
||||
malleateNodeInfo func(*NodeInfo)
|
||||
}{
|
||||
{"Wrong block version", func(ni *DefaultNodeInfo) { ni.ProtocolVersion.Block++ }},
|
||||
{"Wrong network", func(ni *DefaultNodeInfo) { ni.Network += "-wrong" }},
|
||||
{"No common channels", func(ni *DefaultNodeInfo) { ni.Channels = []byte{newTestChannel} }},
|
||||
{"Wrong block version", func(ni *NodeInfo) { ni.ProtocolVersion.Block++ }},
|
||||
{"Wrong network", func(ni *NodeInfo) { ni.Network += "-wrong" }},
|
||||
{"No common channels", func(ni *NodeInfo) { ni.Channels = []byte{newTestChannel} }},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
ni := testNodeInfo(nodeKey2.ID, name).(DefaultNodeInfo)
|
||||
ni := testNodeInfo(nodeKey2.ID, name)
|
||||
tc.malleateNodeInfo(&ni)
|
||||
assert.Error(t, ni1.CompatibleWith(ni))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user