-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add-test-1 * add test keys * add tests * add test * fix fail test * fix function * add tunnel relayer test * refac keys.go * fix conflict * update go mod version * fix band types and add testcases * add provider test * fix multiply gas logic * refactor app_test and add chaincmdtest * merge main into unit-test * declare a new viper variable * fix band testcase * fix config test * fix provider test * fix unit-test keys * refactor tunnel_relayer_test.go * fix app test * fix test * fix tunnel relayer test * change func name * remove t.parallel and new viper object --------- Co-authored-by: Tanut Lertwarachai <tanutlertwarachai@Tanuts-MacBook-Pro.local> Co-authored-by: nkitlabs <natthakunk0109@gmail.com>
- Loading branch information
1 parent
fdedade
commit adec895
Showing
26 changed files
with
3,265 additions
and
404 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package cmd_test | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/pelletier/go-toml/v2" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/bandprotocol/falcon/internal/relayertest" | ||
) | ||
|
||
func TestChainsListEmpty(t *testing.T) { | ||
sys := relayertest.NewSystem(t) | ||
|
||
res := sys.RunWithInput(t, "config", "init") | ||
require.NoError(t, res.Err) | ||
|
||
res = sys.RunWithInput(t, "chains", "list") | ||
require.Empty(t, res.Stdout.String()) | ||
} | ||
|
||
func TestChainsAdd(t *testing.T) { | ||
sys := relayertest.NewSystem(t) | ||
|
||
res := sys.RunWithInput(t, "config", "init") | ||
require.NoError(t, res.Err) | ||
|
||
chainCfgPath := path.Join(sys.HomeDir, "chain_config.toml") | ||
err := os.WriteFile(chainCfgPath, []byte(relayertest.ChainCfgText), 0o600) | ||
require.NoError(t, err) | ||
|
||
require.FileExists(t, chainCfgPath) | ||
|
||
// Add chain | ||
res = sys.RunWithInput(t, "chains", "add", "testnet", chainCfgPath) | ||
require.Empty(t, res.Stdout.String()) | ||
require.Empty(t, res.Stderr.String()) | ||
|
||
// Add another chain | ||
res = sys.RunWithInput(t, "ch", "a", "testnet2", chainCfgPath) | ||
require.Empty(t, res.Stdout.String()) | ||
require.Empty(t, res.Stderr.String()) | ||
|
||
// Add existing chain | ||
res = sys.RunWithInput(t, "ch", "a", "testnet", chainCfgPath) | ||
require.Empty(t, res.Stdout.String()) | ||
require.Error(t, res.Err, "existing chain name") | ||
|
||
// List chains to check | ||
res = sys.RunWithInput(t, "chains", "list") | ||
require.Regexp(t, regexp.MustCompile(`\d+: ([\w-]+) -> type\((\w+)\)`), res.Stdout.String()) | ||
require.Empty(t, res.Stderr.String()) | ||
} | ||
|
||
func TestChainsDelete(t *testing.T) { | ||
sys := relayertest.NewSystem(t) | ||
|
||
res := sys.RunWithInput(t, "config", "init") | ||
require.NoError(t, res.Err) | ||
|
||
chainCfgPath := path.Join(sys.HomeDir, "chain_config.toml") | ||
err := os.WriteFile(chainCfgPath, []byte(relayertest.ChainCfgText), 0o600) | ||
require.NoError(t, err) | ||
|
||
require.FileExists(t, chainCfgPath) | ||
|
||
// Add chain | ||
res = sys.RunWithInput(t, "chains", "add", "testnet", chainCfgPath) | ||
require.Empty(t, res.Stdout.String()) | ||
require.Empty(t, res.Stderr.String()) | ||
|
||
// Add another chain | ||
res = sys.RunWithInput(t, "chains", "add", "testnet2", chainCfgPath) | ||
require.Empty(t, res.Stdout.String()) | ||
require.Empty(t, res.Stderr.String()) | ||
|
||
// List chains | ||
res = sys.RunWithInput(t, "chains", "list") | ||
require.Regexp(t, regexp.MustCompile(`\d+: ([\w-]+) -> type\((\w+)\)`), res.Stdout.String()) | ||
require.Empty(t, res.Stderr.String()) | ||
|
||
// Delete chain | ||
res = sys.RunWithInput(t, "chains", "delete", "testnet") | ||
require.Empty(t, res.Stdout.String()) | ||
require.Empty(t, res.Stderr.String()) | ||
|
||
res = sys.RunWithInput(t, "ch", "d", "testnet2") | ||
require.Empty(t, res.Stdout.String()) | ||
require.Empty(t, res.Stderr.String()) | ||
|
||
// List chain with shorthand command | ||
res = sys.RunWithInput(t, "ch", "l") | ||
require.Empty(t, res.Stdout.String()) | ||
} | ||
|
||
func TestChainsShow(t *testing.T) { | ||
sys := relayertest.NewSystem(t) | ||
|
||
res := sys.RunWithInput(t, "config", "init") | ||
require.NoError(t, res.Err) | ||
|
||
chainCfgPath := path.Join(sys.HomeDir, "chain_config.toml") | ||
err := os.WriteFile(chainCfgPath, []byte(relayertest.ChainCfgText), 0o600) | ||
require.NoError(t, err) | ||
|
||
require.FileExists(t, chainCfgPath) | ||
|
||
// Add chain | ||
res = sys.RunWithInput(t, "chains", "add", "testnet", chainCfgPath) | ||
require.Empty(t, res.Stdout.String()) | ||
require.Empty(t, res.Stderr.String()) | ||
|
||
// Show chain configuration | ||
res = sys.RunWithInput(t, "chains", "show", "testnet") | ||
|
||
var expectedChainCfg map[string]interface{} | ||
err = toml.Unmarshal(res.Stdout.Bytes(), &expectedChainCfg) | ||
require.NoError(t, err) | ||
|
||
var actualChainCfg map[string]interface{} | ||
err = toml.Unmarshal([]byte(relayertest.ChainCfgText), &actualChainCfg) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, expectedChainCfg, actualChainCfg) | ||
} |
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
Oops, something went wrong.