-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
97 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/spf13/afero" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestDefaultConfig(t *testing.T) { | ||
cfg := DefaultConfig() | ||
require.Equal(t, cfg.EthRPC, EthRPC) | ||
require.Equal(t, cfg.ZetaURL, ZetaURL) | ||
require.Equal(t, cfg.TssAddressBTC, TssAddressBTC) | ||
require.Equal(t, cfg.TssAddressEVM, TssAddressEVM) | ||
require.Equal(t, cfg.BtcExplorer, BtcExplorer) | ||
require.Equal(t, cfg.ConnectorAddress, ConnectorAddress) | ||
require.Equal(t, cfg.CustodyAddress, CustodyAddress) | ||
require.Equal(t, cfg.EvmStartBlock, EvmStartBlock) | ||
require.Equal(t, cfg.EvmMaxRange, EvmMaxRange) | ||
} | ||
|
||
func TestGetConfig(t *testing.T) { | ||
AppFs = afero.NewMemMapFs() | ||
defaultCfg := DefaultConfig() | ||
|
||
t.Run("No config file specified", func(t *testing.T) { | ||
cfg, err := GetConfig("") | ||
require.NoError(t, err) | ||
require.Equal(t, cfg, defaultCfg) | ||
|
||
exists, err := afero.Exists(AppFs, defaultCfgFileName) | ||
require.NoError(t, err) | ||
require.True(t, exists) | ||
}) | ||
|
||
t.Run("config file specified", func(t *testing.T) { | ||
cfg, err := GetConfig(defaultCfgFileName) | ||
require.NoError(t, err) | ||
require.Equal(t, cfg, defaultCfg) | ||
}) | ||
} | ||
|
||
func TestConfig_Read(t *testing.T) { | ||
AppFs = afero.NewMemMapFs() | ||
cfg, err := GetConfig("") | ||
require.NoError(t, err) | ||
|
||
t.Run("read existing file", func(t *testing.T) { | ||
c := &Config{} | ||
err := c.Read(defaultCfgFileName) | ||
require.NoError(t, err) | ||
require.Equal(t, c, cfg) | ||
}) | ||
|
||
t.Run("read non-existent file", func(t *testing.T) { | ||
err := AppFs.Remove(defaultCfgFileName) | ||
require.NoError(t, err) | ||
c := &Config{} | ||
err = c.Read(defaultCfgFileName) | ||
require.ErrorContains(t, err, "file does not exist") | ||
require.NotEqual(t, c, cfg) | ||
}) | ||
} | ||
|
||
func TestConfig_Save(t *testing.T) { | ||
AppFs = afero.NewMemMapFs() | ||
cfg := DefaultConfig() | ||
cfg.EvmMaxRange = uint64(2000) | ||
|
||
t.Run("save modified cfg", func(t *testing.T) { | ||
err := cfg.Save() | ||
require.NoError(t, err) | ||
|
||
newCfg, err := GetConfig(defaultCfgFileName) | ||
require.NoError(t, err) | ||
require.Equal(t, cfg, newCfg) | ||
}) | ||
|
||
// Should test invalid json encoding but currently not able to without interface | ||
} |