/
test_helpers.go
84 lines (75 loc) · 2.47 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
package testutil
import (
"encoding/json"
"fmt"
"testing"
"github.com/osmosis-labs/osmosis/osmomath"
"github.com/osmosis-labs/osmosis/v24/app"
poolmanagercli "github.com/osmosis-labs/osmosis/v24/x/poolmanager/client/cli"
poolmanagertypes "github.com/osmosis-labs/osmosis/v24/x/poolmanager/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/testutil"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// commonArgs is args for CLI test commands.
var commonArgs = []string{
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, osmomath.NewInt(10))).String()),
}
// MsgCreatePool broadcast a pool creation message.
func MsgCreatePool(
t *testing.T,
clientCtx client.Context,
owner fmt.Stringer,
tokenWeights string,
initialDeposit string,
spreadFactor string,
exitFee string,
futureGovernor string,
extraArgs ...string,
) (testutil.BufferWriter, error) {
t.Helper()
args := []string{}
jsonFile := testutil.WriteToNewTempFile(t,
fmt.Sprintf(`
{
"%s": "%s",
"%s": "%s",
"%s": "%s",
"%s": "%s",
"%s": "%s"
}
`, poolmanagercli.PoolFileWeights,
tokenWeights,
poolmanagercli.PoolFileInitialDeposit,
initialDeposit,
poolmanagercli.PoolFileSwapFee,
spreadFactor,
poolmanagercli.PoolFileExitFee,
exitFee,
poolmanagercli.PoolFileExitFee,
exitFee,
),
)
args = append(args,
fmt.Sprintf("--%s=%s", poolmanagercli.FlagPoolFile, jsonFile.Name()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, owner.String()),
fmt.Sprintf("--%s=%d", flags.FlagGas, 400000),
)
args = append(args, commonArgs...)
return clitestutil.ExecTestCLICmd(clientCtx, poolmanagercli.NewCreatePoolCmd(), args)
}
// UpdateTxFeeDenom creates and modifies gamm genesis to pay fee with given denom.
func UpdateTxFeeDenom(cdc codec.Codec, denom string) map[string]json.RawMessage {
// modification to pay fee with test bond denom "stake"
genesisState := app.ModuleBasics.DefaultGenesis(cdc)
poolmanagerGen := poolmanagertypes.DefaultGenesis()
poolmanagerGen.Params.PoolCreationFee = sdk.Coins{sdk.NewInt64Coin(denom, 1000000)}
poolmanagerGenJson := cdc.MustMarshalJSON(poolmanagerGen)
genesisState[poolmanagertypes.ModuleName] = poolmanagerGenJson
return genesisState
}