-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchains_test.go
128 lines (95 loc) · 3.6 KB
/
chains_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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)
}