-
Notifications
You must be signed in to change notification settings - Fork 206
/
test_helpers.go
136 lines (102 loc) · 4.51 KB
/
test_helpers.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
package cli
import (
"context"
"fmt"
"github.com/cosmos/cosmos-sdk/client"
sdktest "github.com/cosmos/cosmos-sdk/testutil"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
sdk "github.com/cosmos/cosmos-sdk/types"
types "github.com/akash-network/akash-api/go/node/deployment/v1beta3"
testutilcli "github.com/akash-network/node/testutil/cli"
)
const key string = types.StoreKey
// XXX: WHY TF DON'T THESE RETURN OBJECTS
// TxCreateDeploymentExec is used for testing create deployment tx
func TxCreateDeploymentExec(clientCtx client.Context, from fmt.Stringer, filePath string, extraArgs ...string) (sdktest.BufferWriter, error) {
args := []string{
fmt.Sprintf("--from=%s", from.String()),
filePath,
}
args = append(args, extraArgs...)
return testutilcli.ExecTestCLICmd(context.Background(), clientCtx, cmdCreate(key), args...)
}
// TxUpdateDeploymentExec is used for testing update deployment tx
func TxUpdateDeploymentExec(clientCtx client.Context, from fmt.Stringer, filePath string, extraArgs ...string) (sdktest.BufferWriter, error) {
args := []string{
fmt.Sprintf("--from=%s", from.String()),
filePath,
}
args = append(args, extraArgs...)
return testutilcli.ExecTestCLICmd(context.Background(), clientCtx, cmdUpdate(key), args...)
}
// TxCloseDeploymentExec is used for testing close deployment tx
// requires --dseq, --fees
func TxCloseDeploymentExec(clientCtx client.Context, from fmt.Stringer, extraArgs ...string) (sdktest.BufferWriter, error) {
args := []string{
fmt.Sprintf("--from=%s", from.String()),
}
args = append(args, extraArgs...)
return testutilcli.ExecTestCLICmd(context.Background(), clientCtx, cmdClose(key), args...)
}
// TxDepositDeploymentExec is used for testing deposit deployment tx
func TxDepositDeploymentExec(clientCtx client.Context, deposit sdk.Coin, from fmt.Stringer, extraArgs ...string) (sdktest.BufferWriter, error) {
args := []string{
deposit.String(),
fmt.Sprintf("--from=%s", from.String()),
}
args = append(args, extraArgs...)
return testutilcli.ExecTestCLICmd(context.Background(), clientCtx, cmdDeposit(key), args...)
}
// TxCloseGroupExec is used for testing close group tx
func TxCloseGroupExec(clientCtx client.Context, groupID types.GroupID, from fmt.Stringer, extraArgs ...string) (sdktest.BufferWriter, error) {
args := []string{
fmt.Sprintf("--from=%s", from.String()),
fmt.Sprintf("--owner=%s", groupID.Owner),
fmt.Sprintf("--dseq=%v", groupID.DSeq),
fmt.Sprintf("--gseq=%v", groupID.GSeq),
}
args = append(args, extraArgs...)
return testutilcli.ExecTestCLICmd(context.Background(), clientCtx, cmdGroupClose(key), args...)
}
// QueryDeploymentsExec is used for testing deployments query
func QueryDeploymentsExec(clientCtx client.Context, extraArgs ...string) (sdktest.BufferWriter, error) {
return testutilcli.ExecTestCLICmd(context.Background(), clientCtx, cmdDeployments(), extraArgs...)
}
// QueryDeploymentExec is used for testing deployment query
func QueryDeploymentExec(clientCtx client.Context, id types.DeploymentID, extraArgs ...string) (sdktest.BufferWriter, error) {
args := []string{
fmt.Sprintf("--owner=%s", id.Owner),
fmt.Sprintf("--dseq=%v", id.DSeq),
}
args = append(args, extraArgs...)
return testutilcli.ExecTestCLICmd(context.Background(), clientCtx, cmdDeployment(), args...)
}
// QueryGroupExec is used for testing group query
func QueryGroupExec(clientCtx client.Context, id types.GroupID, extraArgs ...string) (sdktest.BufferWriter, error) {
args := []string{
fmt.Sprintf("--owner=%s", id.Owner),
fmt.Sprintf("--dseq=%v", id.DSeq),
fmt.Sprintf("--gseq=%v", id.GSeq),
}
args = append(args, extraArgs...)
return testutilcli.ExecTestCLICmd(context.Background(), clientCtx, cmdGetGroup(), args...)
}
func TxGrantAuthorizationExec(clientCtx client.Context, granter, grantee sdk.AccAddress, extraArgs ...string) (sdktest.BufferWriter, error) {
dmin, _ := types.DefaultParams().MinDepositFor("uakt")
spendLimit := sdk.NewCoin(dmin.Denom, dmin.Amount.MulRaw(3))
args := []string{
grantee.String(),
spendLimit.String(),
fmt.Sprintf("--from=%s", granter.String()),
}
args = append(args, extraArgs...)
return clitestutil.ExecTestCLICmd(clientCtx, cmdGrantAuthorization(), args)
}
func TxRevokeAuthorizationExec(clientCtx client.Context, granter, grantee sdk.AccAddress, extraArgs ...string) (sdktest.BufferWriter, error) {
args := []string{
grantee.String(),
fmt.Sprintf("--from=%s", granter.String()),
}
args = append(args, extraArgs...)
return clitestutil.ExecTestCLICmd(clientCtx, cmdRevokeAuthorization(), args)
}