/
cli_helpers.go
145 lines (114 loc) · 4.92 KB
/
cli_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
137
138
139
140
141
142
143
144
145
package testutil
import (
"fmt"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/simapp/params"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/testutil"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli"
paramscli "github.com/cosmos/cosmos-sdk/x/params/client/cli"
liquidityapp "github.com/gravity-devs/liquidity/app"
liquiditycli "github.com/gravity-devs/liquidity/x/liquidity/client/cli"
dbm "github.com/tendermint/tm-db"
)
// NewConfig returns config that defines the necessary testing requirements
// used to bootstrap and start an in-process local testing network.
func NewConfig(dbm *dbm.MemDB) network.Config {
encCfg := simapp.MakeTestEncodingConfig()
cfg := network.DefaultConfig()
cfg.AppConstructor = NewAppConstructor(encCfg, dbm) // the ABCI application constructor
cfg.GenesisState = liquidityapp.ModuleBasics.DefaultGenesis(cfg.Codec) // liquidity genesis state to provide
return cfg
}
// NewAppConstructor returns a new network AppConstructor.
func NewAppConstructor(encodingCfg params.EncodingConfig, db *dbm.MemDB) network.AppConstructor {
return func(val network.Validator) servertypes.Application {
return liquidityapp.NewLiquidityApp(
val.Ctx.Logger, db, nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0,
liquidityapp.MakeEncodingConfig(),
simapp.EmptyAppOptions{},
baseapp.SetPruning(storetypes.NewPruningOptionsFromString(val.AppConfig.Pruning)),
baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices),
)
}
}
var commonArgs = []string{
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(10))).String()),
}
// MsgCreatePoolExec creates a transaction for creating liquidity pool.
func MsgCreatePoolExec(clientCtx client.Context, from, poolID, depositCoins string,
extraArgs ...string) (testutil.BufferWriter, error) {
args := append([]string{
poolID,
depositCoins,
fmt.Sprintf("--%s=%s", flags.FlagFrom, from),
}, commonArgs...)
args = append(args, commonArgs...)
return clitestutil.ExecTestCLICmd(clientCtx, liquiditycli.NewCreatePoolCmd(), args)
}
// MsgDepositWithinBatchExec creates a transaction to deposit new amounts to the pool.
func MsgDepositWithinBatchExec(clientCtx client.Context, from, poolID, depositCoins string,
extraArgs ...string) (testutil.BufferWriter, error) {
args := append([]string{
poolID,
depositCoins,
fmt.Sprintf("--%s=%s", flags.FlagFrom, from),
}, commonArgs...)
args = append(args, commonArgs...)
return clitestutil.ExecTestCLICmd(clientCtx, liquiditycli.NewDepositWithinBatchCmd(), args)
}
// MsgWithdrawWithinBatchExec creates a transaction to withraw pool coin amount from the pool.
func MsgWithdrawWithinBatchExec(clientCtx client.Context, from, poolID, poolCoin string,
extraArgs ...string) (testutil.BufferWriter, error) {
args := append([]string{
poolID,
poolCoin,
fmt.Sprintf("--%s=%s", flags.FlagFrom, from),
}, commonArgs...)
args = append(args, commonArgs...)
return clitestutil.ExecTestCLICmd(clientCtx, liquiditycli.NewWithdrawWithinBatchCmd(), args)
}
// MsgSwapWithinBatchExec creates a transaction to swap coins in the pool.
func MsgSwapWithinBatchExec(clientCtx client.Context, from, poolID, swapTypeID,
offerCoin, demandCoinDenom, orderPrice, swapFeeRate string, extraArgs ...string) (testutil.BufferWriter, error) {
args := append([]string{
poolID,
swapTypeID,
offerCoin,
demandCoinDenom,
orderPrice,
swapFeeRate,
fmt.Sprintf("--%s=%s", flags.FlagFrom, from),
}, commonArgs...)
args = append(args, commonArgs...)
return clitestutil.ExecTestCLICmd(clientCtx, liquiditycli.NewSwapWithinBatchCmd(), args)
}
// MsgParamChangeProposalExec creates a transaction for submitting param change proposal
func MsgParamChangeProposalExec(clientCtx client.Context, from string, file string) (testutil.BufferWriter, error) {
args := append([]string{
file,
fmt.Sprintf("--%s=%s", flags.FlagFrom, from),
}, commonArgs...)
paramChangeCmd := paramscli.NewSubmitParamChangeProposalTxCmd()
flags.AddTxFlagsToCmd(paramChangeCmd)
return clitestutil.ExecTestCLICmd(clientCtx, paramChangeCmd, args)
}
// MsgVote votes for a proposal
func MsgVote(clientCtx client.Context, from, id, vote string, extraArgs ...string) (testutil.BufferWriter, error) {
args := append([]string{
id,
vote,
fmt.Sprintf("--%s=%s", flags.FlagFrom, from),
}, commonArgs...)
args = append(args, extraArgs...)
return clitestutil.ExecTestCLICmd(clientCtx, govcli.NewCmdWeightedVote(), args)
}