2021-06-01 17:42:57 +00:00
|
|
|
package nodeconfig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-05-31 08:55:38 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
2021-06-01 17:42:57 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
|
|
|
configtest "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/test"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/network"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNodeSection(t *testing.T) {
|
|
|
|
t.Run("defaults", func(t *testing.T) {
|
|
|
|
empty := configtest.EmptyConfig()
|
|
|
|
|
2021-07-13 08:43:51 +00:00
|
|
|
require.Panics(
|
2021-06-01 17:42:57 +00:00
|
|
|
t,
|
|
|
|
func() {
|
|
|
|
Key(empty)
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2021-06-22 17:35:56 +00:00
|
|
|
require.Panics(
|
2021-06-01 17:42:57 +00:00
|
|
|
t,
|
|
|
|
func() {
|
2021-06-22 17:35:56 +00:00
|
|
|
BootstrapAddresses(empty)
|
2021-06-01 17:42:57 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
attribute := Attributes(empty)
|
|
|
|
relay := Relay(empty)
|
2021-09-06 13:03:43 +00:00
|
|
|
persistatePath := PersistentState(empty).Path()
|
2021-06-01 17:42:57 +00:00
|
|
|
|
|
|
|
require.Empty(t, attribute)
|
|
|
|
require.Equal(t, false, relay)
|
2021-09-06 13:03:43 +00:00
|
|
|
require.Equal(t, PersistentStatePathDefault, persistatePath)
|
2021-11-28 12:06:07 +00:00
|
|
|
|
|
|
|
var subnetCfg SubnetConfig
|
|
|
|
|
|
|
|
subnetCfg.Init(*empty)
|
|
|
|
|
|
|
|
require.False(t, subnetCfg.ExitZero())
|
|
|
|
|
|
|
|
called := false
|
|
|
|
|
|
|
|
subnetCfg.IterateSubnets(func(string) {
|
|
|
|
called = true
|
|
|
|
})
|
|
|
|
|
|
|
|
require.False(t, called)
|
2021-06-01 17:42:57 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
const path = "../../../../config/example/node"
|
|
|
|
|
|
|
|
var fileConfigTest = func(c *config.Config) {
|
|
|
|
key := Key(c)
|
2021-06-24 12:41:19 +00:00
|
|
|
addrs := BootstrapAddresses(c)
|
2021-06-01 17:42:57 +00:00
|
|
|
attributes := Attributes(c)
|
|
|
|
relay := Relay(c)
|
2021-05-31 08:55:38 +00:00
|
|
|
wKey := Wallet(c)
|
2021-09-06 13:03:43 +00:00
|
|
|
persistatePath := PersistentState(c).Path()
|
2021-06-01 17:42:57 +00:00
|
|
|
|
2021-06-24 12:41:19 +00:00
|
|
|
expectedAddr := []struct {
|
|
|
|
str string
|
|
|
|
host string
|
|
|
|
tls bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
str: "/dns4/localhost/tcp/8083/tls",
|
|
|
|
host: "localhost:8083",
|
|
|
|
tls: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
str: "/dns4/s01.neofs.devenv/tcp/8080",
|
|
|
|
host: "s01.neofs.devenv:8080",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
str: "/dns4/s02.neofs.devenv/tcp/8081",
|
|
|
|
host: "s02.neofs.devenv:8081",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
str: "/ip4/127.0.0.1/tcp/8082",
|
|
|
|
host: "127.0.0.1:8082",
|
|
|
|
},
|
|
|
|
}
|
2021-06-01 17:42:57 +00:00
|
|
|
|
2021-06-03 15:24:09 +00:00
|
|
|
require.Equal(t, "NbUgTSFvPmsRxmGeWpuuGeJUoRoi6PErcM", key.Address())
|
2021-06-24 12:41:19 +00:00
|
|
|
|
|
|
|
require.EqualValues(t, len(expectedAddr), addrs.Len())
|
|
|
|
|
|
|
|
ind := 0
|
|
|
|
|
|
|
|
addrs.IterateAddresses(func(addr network.Address) bool {
|
|
|
|
require.Equal(t, expectedAddr[ind].str, addr.String())
|
|
|
|
require.Equal(t, expectedAddr[ind].host, addr.HostAddr())
|
|
|
|
require.Equal(t, expectedAddr[ind].tls, addr.TLSEnabled())
|
|
|
|
|
|
|
|
ind++
|
|
|
|
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
|
2021-06-01 17:42:57 +00:00
|
|
|
require.Equal(t, true, relay)
|
|
|
|
|
|
|
|
require.Len(t, attributes, 2)
|
|
|
|
require.Equal(t, "Price:11", attributes[0])
|
|
|
|
require.Equal(t, "UN-LOCODE:RU MSK", attributes[1])
|
2021-05-31 08:55:38 +00:00
|
|
|
|
|
|
|
require.NotNil(t, wKey)
|
|
|
|
require.Equal(t,
|
|
|
|
config.StringSafe(c.Sub("node").Sub("wallet"), "address"),
|
|
|
|
address.Uint160ToString(wKey.GetScriptHash()))
|
2021-09-06 13:03:43 +00:00
|
|
|
|
|
|
|
require.Equal(t, "/state", persistatePath)
|
2021-11-28 12:06:07 +00:00
|
|
|
|
|
|
|
var subnetCfg SubnetConfig
|
|
|
|
|
|
|
|
subnetCfg.Init(*c)
|
|
|
|
|
|
|
|
require.True(t, subnetCfg.ExitZero())
|
|
|
|
|
|
|
|
var ids []string
|
|
|
|
|
|
|
|
subnetCfg.IterateSubnets(func(id string) {
|
|
|
|
ids = append(ids, id)
|
|
|
|
})
|
|
|
|
|
|
|
|
require.Equal(t, []string{"123", "456", "789"}, ids)
|
2021-06-01 17:42:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
configtest.ForEachFileType(path, fileConfigTest)
|
|
|
|
|
|
|
|
t.Run("ENV", func(t *testing.T) {
|
|
|
|
configtest.ForEnvFileType(path, fileConfigTest)
|
|
|
|
})
|
|
|
|
}
|