2021-03-11 11:39:51 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2024-06-27 10:47:18 +00:00
|
|
|
"bytes"
|
|
|
|
"fmt"
|
2023-11-20 17:04:09 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2021-03-11 11:39:51 +00:00
|
|
|
"testing"
|
|
|
|
|
2024-06-27 10:47:18 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/config"
|
2023-11-20 17:04:09 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
2021-03-11 11:39:51 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2024-06-27 10:47:18 +00:00
|
|
|
"gopkg.in/yaml.v3"
|
2021-03-11 11:39:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const testConfigPath = "./testdata/protocol.test.yml"
|
|
|
|
|
|
|
|
func TestUnexpectedNativeUpdateHistoryContract(t *testing.T) {
|
|
|
|
_, err := LoadFile(testConfigPath)
|
|
|
|
require.Error(t, err)
|
|
|
|
}
|
2023-11-20 17:04:09 +00:00
|
|
|
|
|
|
|
func TestUnknownConfigFields(t *testing.T) {
|
|
|
|
tmp := t.TempDir()
|
|
|
|
cfg := filepath.Join(tmp, "protocol.testnet.yml")
|
|
|
|
require.NoError(t, os.WriteFile(cfg, []byte(`UnknownConfigurationField: 123`), os.ModePerm))
|
|
|
|
|
|
|
|
t.Run("LoadFile", func(t *testing.T) {
|
|
|
|
_, err := LoadFile(cfg)
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Contains(t, err.Error(), "field UnknownConfigurationField not found in type config.Config")
|
|
|
|
})
|
|
|
|
t.Run("Load", func(t *testing.T) {
|
|
|
|
_, err := Load(tmp, netmode.TestNet)
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Contains(t, err.Error(), "field UnknownConfigurationField not found in type config.Config")
|
|
|
|
})
|
|
|
|
}
|
2024-06-27 10:47:18 +00:00
|
|
|
|
|
|
|
func TestLoadFileWithMissingDefaultConfigPath(t *testing.T) {
|
|
|
|
var cfgPrivNet Config
|
|
|
|
cfg, err := LoadFile(fmt.Sprintf("%s/protocol.%s.yml", DefaultConfigPath, netmode.PrivNet))
|
|
|
|
require.Nil(t, err)
|
|
|
|
decoder := yaml.NewDecoder(bytes.NewReader(config.PrivNet))
|
|
|
|
err = decoder.Decode(&cfgPrivNet)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, cfg, cfgPrivNet)
|
|
|
|
|
|
|
|
_, err = LoadFile(fmt.Sprintf("%s/protocol.%s.yml", os.TempDir(), netmode.PrivNet))
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Contains(t, err.Error(), "doesn't exist and no matching embedded config was found")
|
|
|
|
|
|
|
|
_, err = LoadFile(fmt.Sprintf("%s/protocol.%s.yml", DefaultConfigPath, "aaa"))
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Contains(t, err.Error(), "doesn't exist and no matching embedded config was found")
|
|
|
|
}
|