Skip to content

Commit

Permalink
wip: autocli
Browse files Browse the repository at this point in the history
  • Loading branch information
Lockwarr committed Jul 12, 2024
1 parent 45c5b94 commit f6631e8
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 25 deletions.
2 changes: 1 addition & 1 deletion cmd/nolusd/genwasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func addGenesisWasmMsgCmd(defaultNodeHome string) *cobra.Command {
txCmd := &cobra.Command{
Use: "add-wasm-message",
Use: "add-wasm-genesis-message",
Short: "Wasm genesis subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
Expand Down
47 changes: 42 additions & 5 deletions cmd/nolusd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"cosmossdk.io/store/snapshots"
snapshottypes "cosmossdk.io/store/snapshots/types"
storetypes "cosmossdk.io/store/types"
confixcmd "cosmossdk.io/tools/confix/cmd"

"github.com/CosmWasm/wasmd/x/wasm"

tmcfg "github.com/cometbft/cometbft/config"
tmcli "github.com/cometbft/cometbft/libs/cli"
tmtypes "github.com/cometbft/cometbft/types"

db "github.com/cosmos/cosmos-db"

Expand All @@ -27,9 +27,11 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/server"
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
"github.com/cosmos/cosmos-sdk/types/module"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
"github.com/cosmos/cosmos-sdk/x/auth/types"
Expand All @@ -38,6 +40,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/genutil"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"

"github.com/spf13/cast"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -135,6 +138,18 @@ func NewRootCmd(
rootOptions := newRootOptions()
encodingConfig := app.MakeEncodingConfig(moduleBasics)

tempApp := app.New(
log.NewNopLogger(),
db.NewMemDB(),
nil,
true,
nil,
tempDir(),
0,
encodingConfig,
simtestutil.NewAppOptionsWithFlagHome(tempDir()),
)

initClientCtx := client.Context{}.
WithCodec(encodingConfig.Marshaler).
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
Expand Down Expand Up @@ -180,6 +195,17 @@ func NewRootCmd(
moduleBasics,
rootOptions,
)

// add keyring to autocli opts
autoCliOpts := tempApp.AutoCliOpts()
initClientCtx, _ = config.ReadDefaultValuesFromDefaultClientConfig(initClientCtx)
autoCliOpts.Keyring, _ = keyring.NewAutoCLIKeyring(initClientCtx.Keyring)
autoCliOpts.ClientCtx = initClientCtx

if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil {
panic(err)
}

overwriteFlagDefaults(rootCmd, map[string]string{
flags.FlagChainID: defaultChainID,
flags.FlagKeyringBackend: "test",
Expand Down Expand Up @@ -214,8 +240,7 @@ func initRootCmd(
addGenesisWasmMsgCmd(defaultNodeHome),
tmcli.NewCompletionCmd(rootCmd, true),
debug.Cmd(),
// TODO: cmd/nolusd/config.go
// ConfigCmd(),
confixcmd.ConfigCommand(),

// TODO: test and decide if we need those two new pruning/snapshot commands
// pruning.Cmd(newApp, simapp.DefaultNodeHome),
Expand Down Expand Up @@ -292,15 +317,17 @@ func txCommand(moduleBasics module.BasicManager) *cobra.Command {
authcmd.GetSignCommand(),
authcmd.GetSignBatchCommand(),
authcmd.GetMultiSignCommand(),
authcmd.GetMultiSignBatchCmd(),
authcmd.GetValidateSignaturesCommand(),
flags.LineBreak,
authcmd.GetBroadcastCommand(),
authcmd.GetEncodeCommand(),
authcmd.GetDecodeCommand(),
authcmd.GetSimulateCmd(),
)

// TODO: autocli
moduleBasics.AddTxCommands(cmd)
// moduleBasics.AddTxCommands(cmd)
cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")

return cmd
Expand Down Expand Up @@ -372,7 +399,7 @@ func (a appCreator) newApp(
chainID := cast.ToString(appOpts.Get(flags.FlagChainID))
if chainID == "" {
// fallback to genesis chain-id
appGenesis, err := tmtypes.GenesisDocFromFile(filepath.Join(homePath, "config", "genesis.json"))
appGenesis, err := genutiltypes.AppGenesisFromFile(filepath.Join(homePath, "config", "genesis.json"))
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -500,3 +527,13 @@ lru_size = 0`

return customAppTemplate, customAppConfig
}

var tempDir = func() string {
dir, err := os.MkdirTemp("", "nolusd")
if err != nil {
panic("failed to create temp dir: " + err.Error())
}
defer os.RemoveAll(dir)

return dir
}
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ require (
cosmossdk.io/log v1.3.1
cosmossdk.io/math v1.3.0
cosmossdk.io/store v1.0.2
cosmossdk.io/tools/confix v0.1.1
cosmossdk.io/x/evidence v0.1.0
cosmossdk.io/x/feegrant v0.1.0
cosmossdk.io/x/tx v0.13.0
cosmossdk.io/x/upgrade v0.1.1
github.com/cosmos/cosmos-db v1.0.0
github.com/cosmos/cosmos-proto v1.0.0-beta.4
Expand All @@ -51,7 +53,6 @@ require (
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/x/circuit v0.1.0 // indirect
cosmossdk.io/x/tx v0.13.0 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.2 // indirect
Expand Down Expand Up @@ -83,6 +84,8 @@ require (
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/interchain-security/v5 v5.0.0-alpha1 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
github.com/creachadair/atomicfile v0.3.1 // indirect
github.com/creachadair/tomledit v0.0.24 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE=
cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k=
cosmossdk.io/store v1.0.2 h1:lSg5BTvJBHUDwswNNyeh4K/CbqiHER73VU4nDNb8uk0=
cosmossdk.io/store v1.0.2/go.mod h1:EFtENTqVTuWwitGW1VwaBct+yDagk7oG/axBMPH+FXs=
cosmossdk.io/tools/confix v0.1.1 h1:aexyRv9+y15veH3Qw16lxQwo+ki7r2I+g0yNTEFEQM8=
cosmossdk.io/tools/confix v0.1.1/go.mod h1:nQVvP1tHsGXS83PonPVWJtSbddIqyjEw99L4M3rPJyQ=
cosmossdk.io/x/circuit v0.1.0 h1:IAej8aRYeuOMritczqTlljbUVHq1E85CpBqaCTwYgXs=
cosmossdk.io/x/circuit v0.1.0/go.mod h1:YDzblVE8+E+urPYQq5kq5foRY/IzhXovSYXb4nwd39w=
cosmossdk.io/x/evidence v0.1.0 h1:J6OEyDl1rbykksdGynzPKG5R/zm6TacwW2fbLTW4nCk=
Expand Down Expand Up @@ -382,6 +384,10 @@ github.com/cosmos/ledger-cosmos-go v0.13.3/go.mod h1:HENcEP+VtahZFw38HZ3+LS3Iv5X
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creachadair/atomicfile v0.3.1 h1:yQORkHjSYySh/tv5th1dkKcn02NEW5JleB84sjt+W4Q=
github.com/creachadair/atomicfile v0.3.1/go.mod h1:mwfrkRxFKwpNAflYZzytbSwxvbK6fdGRRlp0KEQc0qU=
github.com/creachadair/tomledit v0.0.24 h1:5Xjr25R2esu1rKCbQEmjZYlrhFkDspoAbAKb6QKQDhQ=
github.com/creachadair/tomledit v0.0.24/go.mod h1:9qHbShRWQzSCcn617cMzg4eab1vbLCOjOshAWSzWr8U=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/danieljoos/wincred v1.2.0 h1:ozqKHaLK0W/ii4KVbbvluM91W2H3Sh0BncbUNPS7jLE=
Expand Down
6 changes: 3 additions & 3 deletions scripts/init-local-network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ while [[ $# -gt 0 ]]; do
done

__config_client() {
run_cmd "$USER_DIR" config chain-id "$CHAIN_ID"
run_cmd "$USER_DIR" config keyring-backend "test"
run_cmd "$USER_DIR" config node "tcp://${NOLUS_NETWORK_ADDR}:$(first_node_rpc_port)"
run_cmd "$USER_DIR" config set client chain-id "$CHAIN_ID"
run_cmd "$USER_DIR" config set client keyring-backend "test"
run_cmd "$USER_DIR" config set client node "tcp://${NOLUS_NETWORK_ADDR}:$(first_node_rpc_port)"
}

verify_dir_exist "$WASM_SCRIPT_PATH" "WASM sripts path"
Expand Down
9 changes: 5 additions & 4 deletions scripts/internal/genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ __generate_proto_genesis_no_wasm() {
local -a wasm_allowed_addresses=("$admin_contract_addr" "$store_code_privileged_addr")

run_cmd "$genesis_home_dir" init genesis_manager --chain-id "$chain_id"
run_cmd "$genesis_home_dir" config keyring-backend test
run_cmd "$genesis_home_dir" config chain-id "$chain_id"
run_cmd "$genesis_home_dir" config set client keyring-backend test
run_cmd "$genesis_home_dir" config set client chain-id "$chain_id"

__set_token_denominations "$genesis_file" "$native_currency"
__set_tax_recipient "$genesis_file" "$treasury_addr"
Expand Down Expand Up @@ -230,8 +230,9 @@ __set_gov_parameters() {

< "$genesis_file" \
jq '.app_state["gov"]["deposit_params"]["max_deposit_period"]="'"$max_deposit_period"'"' \
| jq '.app_state["gov"]["params"]["voting_period"]="'"$voting_period"'"' \
| jq '.app_state["gov"]["voting_params"]["voting_period"]="'"$voting_period"'"' > "$genesis_tmp_file"
| jq '.app_state["gov"]["params"]["voting_period"]="'"$gov_voting_period"'"' \
| jq '.app_state["gov"]["params"]["expedited_voting_period"]="'"$voting_period"'"' \
| jq '.app_state["gov"]["voting_params"]["voting_period"]="'"$gov_voting_period"'"' > "$genesis_tmp_file"
mv "$genesis_tmp_file" "$genesis_file"
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/internal/validators-manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ init_val_mngr_sh() {
val_mngr_home_dir="$1"
val_mngr_chain_id="$2"

run_cmd "$val_mngr_home_dir" config chain-id "$val_mngr_chain_id"
run_cmd "$val_mngr_home_dir" config keyring-backend test
run_cmd "$val_mngr_home_dir" config set client chain-id "$val_mngr_chain_id"
run_cmd "$val_mngr_home_dir" config set client keyring-backend test
}

# outputs the generated create validator transaction to the standard output
Expand Down
9 changes: 0 additions & 9 deletions x/tax/keeper/custom_tx_fee_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import (
"testing"

"cosmossdk.io/math"
<<<<<<< HEAD
=======

>>>>>>> d6418d5 (wip: fix some unit-tests)
keepertest "github.com/Nolus-Protocol/nolus-core/testutil/keeper"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -140,13 +136,8 @@ func TestCustomTxFeeCheckerSuccessfulInNLS(t *testing.T) {
}

// Fail to pay fees in unsupported denom.
<<<<<<< HEAD
func TestCustomTxFeeCheckerFailWhenUnsupportedDenom(t *testing.T) {
taxKeeper, ctx, _ := keepertest.TaxKeeper(t, true, sdk.DecCoins{sdk.NewDecCoin("unls", sdk.NewInt(1))})
=======
func TestCustomTxFeeCheckerSuccessfulInUnsupportedDenom(t *testing.T) {
taxKeeper, ctx, _ := keepertest.TaxKeeper(t, true, sdk.DecCoins{sdk.NewDecCoin("unls", math.NewInt(1))})
>>>>>>> d6418d5 (wip: fix some unit-tests)
// create a new CustomTxFeeChecker
feeTx := keepertest.MockFeeTx{
Msgs: []sdk.Msg{},
Expand Down

0 comments on commit f6631e8

Please sign in to comment.