forked from umee-network/umee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
suite.go
233 lines (200 loc) · 5.6 KB
/
suite.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
package tests
import (
"fmt"
"github.com/cosmos/cosmos-sdk/client/flags"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/suite"
"github.com/tendermint/tendermint/crypto/secp256k1"
tmcli "github.com/tendermint/tendermint/libs/cli"
appparams "github.com/mokitanetwork/katana/app/params"
"github.com/mokitanetwork/katana/x/oracle/client/cli"
"github.com/mokitanetwork/katana/x/oracle/types"
)
type IntegrationTestSuite struct {
suite.Suite
cfg network.Config
network *network.Network
}
func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite {
return &IntegrationTestSuite{cfg: cfg}
}
func (s *IntegrationTestSuite) SetupSuite() {
t := s.T()
t.Log("setting up integration test suite")
var err error
s.network, err = network.New(t, t.TempDir(), s.cfg)
s.Require().NoError(err)
_, err = s.network.WaitForHeight(1)
s.Require().NoError(err)
}
func (s *IntegrationTestSuite) TearDownSuite() {
s.T().Log("tearing down integration test suite")
s.network.Cleanup()
}
func (s *IntegrationTestSuite) TestDelegateFeedConsent() {
val := s.network.Validators[0]
testCases := []struct {
name string
args []string
expectErr bool
expectedCode uint32
respType proto.Message
}{
{
name: "invalid operator address",
args: []string{
"foo",
s.network.Validators[1].Address.String(),
},
expectErr: true,
respType: &sdk.TxResponse{},
},
{
name: "invalid feeder address",
args: []string{
val.Address.String(),
"foo",
},
expectErr: true,
respType: &sdk.TxResponse{},
},
{
name: "valid transaction",
args: []string{
val.Address.String(),
s.network.Validators[1].Address.String(),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagGasPrices, appparams.ProtocolMinGasPrice),
},
expectErr: false,
expectedCode: 0,
respType: &sdk.TxResponse{},
},
}
for _, tc := range testCases {
tc := tc
s.Run(tc.name, func() {
clientCtx := val.ClientCtx
out, err := clitestutil.ExecTestCLICmd(clientCtx, cli.GetCmdDelegateFeedConsent(), tc.args)
if tc.expectErr {
s.Require().Error(err)
} else {
s.Require().NoError(err)
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())
txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code)
}
})
}
}
func (s *IntegrationTestSuite) TestQueryFeedDelegate() {
val := s.network.Validators[0]
inactiveVal := sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address())
clientCtx := val.ClientCtx
testCases := []struct {
name string
args []string
expectErr bool
respType proto.Message
}{
{
name: "valid request",
args: []string{
val.ValAddress.String(),
},
expectErr: false,
respType: &types.QueryFeederDelegationResponse{},
},
{
name: "invalid address",
args: []string{
"invalid_address",
},
expectErr: true,
respType: &types.QueryFeederDelegationResponse{},
},
{
name: "non-existent validator",
args: []string{
inactiveVal.String(),
},
expectErr: true,
respType: &types.QueryFeederDelegationResponse{},
},
}
for _, tc := range testCases {
tc := tc
s.Run(tc.name, func() {
tc.args = append(tc.args, fmt.Sprintf("--%s=json", tmcli.OutputFlag))
out, err := clitestutil.ExecTestCLICmd(clientCtx, cli.GetCmdQueryFeederDelegation(), tc.args)
if tc.expectErr {
s.Require().Error(err)
} else {
s.Require().NoError(err)
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())
}
})
}
}
func (s *IntegrationTestSuite) TestQueryExchangeRates() {
val := s.network.Validators[0]
clientCtx := val.ClientCtx
args := []string{
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
}
out, err := clitestutil.ExecTestCLICmd(clientCtx, cli.GetCmdQueryExchangeRates(), args)
s.Require().NoError(err)
var res types.QueryExchangeRatesResponse
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &res))
s.Require().Len(res.ExchangeRates, 1)
s.Require().Equal(res.ExchangeRates[0].Denom, appparams.DisplayDenom)
s.Require().False(res.ExchangeRates[0].Amount.IsZero())
}
func (s *IntegrationTestSuite) TestQueryParams() {
val := s.network.Validators[0]
clientCtx := val.ClientCtx
args := []string{
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
}
out, err := clitestutil.ExecTestCLICmd(clientCtx, cli.GetCmdQueryParams(), args)
s.Require().NoError(err)
var res types.QueryParamsResponse
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &res))
s.Require().NotEmpty(res.Params.AcceptList)
}
func (s *IntegrationTestSuite) TestQueryExchangeRate() {
val := s.network.Validators[0]
clientCtx := val.ClientCtx
testCases := []struct {
name string
args []string
expectErr bool
respType proto.Message
}{
{
name: "valid denom",
args: []string{
"KATANA",
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
},
expectErr: false,
respType: &types.QueryExchangeRatesResponse{},
},
}
for _, tc := range testCases {
tc := tc
s.Run(tc.name, func() {
out, err := clitestutil.ExecTestCLICmd(clientCtx, cli.GetCmdQueryExchangeRate(), tc.args)
if tc.expectErr {
s.Require().Error(err)
} else {
s.Require().NoError(err)
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())
}
})
}
}