diff --git a/CHANGELOG.md b/CHANGELOG.md index 32fdca07c..2f6177c70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -92,6 +92,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * Add `UpdateParams` and `Params` query rpc endpoints to modules. * `ibcratelimit` add `UpdateParams` endpoint and deprecate `GovUpdateParams` [#1984](https://github.com/provenance-io/provenance/pull/1984). * `attribute` add `UpdateParams` endpoint and cli [#1987](https://github.com/provenance-io/provenance/pull/1987). +* Update the exchange `commitment-settlement-fee-calc` cli query to utilize the keyring [#2001](https://github.com/provenance-io/provenance/pull/2001). ### Client Breaking diff --git a/x/exchange/client/cli/cli_test.go b/x/exchange/client/cli/cli_test.go index d65c037b4..19febb9ae 100644 --- a/x/exchange/client/cli/cli_test.go +++ b/x/exchange/client/cli/cli_test.go @@ -1312,9 +1312,11 @@ func getEncodingConfig(t *testing.T) params.EncodingConfig { return *encodingConfig } -// newClientContextWithCodec returns a new client.Context that has a useful Codec. -func newClientContextWithCodec(t *testing.T) client.Context { - return clientContextWithCodec(t, client.Context{}) +// newClientContext returns a new client.Context that has a codec and keyring. +func newClientContext(t *testing.T) client.Context { + ctx := client.Context{} + ctx = clientContextWithCodec(t, ctx) + return clientContextWithKeyring(t, ctx) } // clientContextWithCodec adds a useful Codec to the provided client context. @@ -1326,6 +1328,26 @@ func clientContextWithCodec(t *testing.T, clientCtx client.Context) client.Conte WithTxConfig(encCfg.TxConfig) } +const ( + keyringName = "keyringaddr" + keyringMnemonic = "pave kit dust loop forest symptom lobster tape note attitude aim cloth cat welcome basic head wet pistol hair funny library dove oak drift" + keyringAddr = "cosmos177zjzs7mh79j0cx6wcxq8dayetkftkx2crt4u6" +) + +// clientContextWithKeyring returns a client context that has a keyring and an entry for keyringName=>keyringAddr. +func clientContextWithKeyring(t *testing.T, clientCtx client.Context) client.Context { + kr, err := client.NewKeyringFromBackend(clientCtx, keyring.BackendMemory) + require.NoError(t, err, "NewKeyringFromBackend") + clientCtx = clientCtx.WithKeyring(kr) + + // This mnemonic was generated by using Keyring.NewAccount(). + // I then logged it (and the address) with t.Logf(...) and copy/pasted it into the constants above. + _, err = clientCtx.Keyring.NewAccount(keyringName, keyringMnemonic, keyring.DefaultBIP39Passphrase, hd.CreateHDPath(118, 0, 0).String(), hd.Secp256k1) + require.NoError(t, err, "adding %s to the keyring using NewAccount(...)", keyringName) + + return clientCtx +} + // newGovProp creates a new MsgSubmitProposal containing the provided messages, requiring it to not error. func newGovProp(t *testing.T, msgs ...sdk.Msg) *govv1.MsgSubmitProposal { rv := &govv1.MsgSubmitProposal{} @@ -1354,7 +1376,7 @@ func newTx(t *testing.T, msgs ...sdk.Msg) *txtypes.Tx { // writeFileAsJson writes the provided proto message as a json file, requiring it to not error. func writeFileAsJson(t *testing.T, filename string, content proto.Message) { - clientCtx := newClientContextWithCodec(t) + clientCtx := newClientContext(t) bz, err := clientCtx.Codec.MarshalJSON(content) require.NoError(t, err, "MarshalJSON(%T)", content) writeFile(t, filename, bz) diff --git a/x/exchange/client/cli/flags_test.go b/x/exchange/client/cli/flags_test.go index 77a983ae6..f431fec80 100644 --- a/x/exchange/client/cli/flags_test.go +++ b/x/exchange/client/cli/flags_test.go @@ -2541,7 +2541,7 @@ func TestReadTxFileFlag(t *testing.T) { err := tc.flagSet.Parse(args) require.NoError(t, err, "flagSet.Parse(%q)", args) - clientCtx := newClientContextWithCodec(t) + clientCtx := newClientContext(t) var actFilename string var actTx *txtypes.Tx @@ -2765,7 +2765,7 @@ func TestReadProposalFlag(t *testing.T) { err := tc.flagSet.Parse(args) require.NoError(t, err, "flagSet.Parse(%q)", args) - clientCtx := newClientContextWithCodec(t) + clientCtx := newClientContext(t) var actPropFN string var actAnys []*codectypes.Any @@ -2893,7 +2893,7 @@ func TestReadMsgGovCreateMarketRequestFromProposalFlag(t *testing.T) { err := flagSet.Parse(args) require.NoError(t, err, "flagSet.Parse(%q)", args) - clientCtx := newClientContextWithCodec(t) + clientCtx := newClientContext(t) var actual *exchange.MsgGovCreateMarketRequest testFunc := func() { @@ -3010,7 +3010,7 @@ func TestReadMsgGovManageFeesRequestFromProposalFlag(t *testing.T) { err := flagSet.Parse(args) require.NoError(t, err, "flagSet.Parse(%q)", args) - clientCtx := newClientContextWithCodec(t) + clientCtx := newClientContext(t) var actual *exchange.MsgGovManageFeesRequest testFunc := func() { @@ -3173,7 +3173,7 @@ func TestReadMsgMarketCommitmentSettleFromFileFlag(t *testing.T) { err := flagSet.Parse(args) require.NoError(t, err, "flagSet.Parse(%q)", args) - clientCtx := newClientContextWithCodec(t) + clientCtx := newClientContext(t) var actual *exchange.MsgMarketCommitmentSettleRequest testFunc := func() { @@ -3376,7 +3376,7 @@ func TestReadPaymentFromFileFlag(t *testing.T) { err := flagSet.Parse(args) require.NoError(t, err, "flagSet.Parse(%q)", args) - clientCtx := newClientContextWithCodec(t) + clientCtx := newClientContext(t) var actual exchange.Payment testFunc := func() { diff --git a/x/exchange/client/cli/query_setup.go b/x/exchange/client/cli/query_setup.go index a16e5ec4d..5b5cb8b16 100644 --- a/x/exchange/client/cli/query_setup.go +++ b/x/exchange/client/cli/query_setup.go @@ -474,7 +474,11 @@ func MakeQueryCommitmentSettlementFeeCalc(clientCtx client.Context, flagSet *pfl errs := make([]error, 4) clientCtx.From, errs[0] = flagSet.GetString(flags.FlagFrom) if len(clientCtx.From) > 0 { - clientCtx.FromAddress, errs[1] = sdk.AccAddressFromBech32(clientCtx.From) + if addr, err := sdk.AccAddressFromBech32(clientCtx.From); err == nil { + clientCtx.FromAddress = addr + } else { + clientCtx.FromAddress, clientCtx.From, _, errs[1] = client.GetFromFields(clientCtx, clientCtx.Keyring, clientCtx.From) + } } rv.Settlement, errs[2] = MakeMsgMarketCommitmentSettle(clientCtx, flagSet, args) rv.IncludeBreakdownFields, errs[3] = flagSet.GetBool(FlagDetails) diff --git a/x/exchange/client/cli/query_setup_test.go b/x/exchange/client/cli/query_setup_test.go index 5a648beef..12d159a63 100644 --- a/x/exchange/client/cli/query_setup_test.go +++ b/x/exchange/client/cli/query_setup_test.go @@ -68,7 +68,7 @@ func runQueryMakerTest[R any](t *testing.T, td queryMakerTestDef[R], tc queryMak err := cmd.Flags().Parse(tc.flags) require.NoError(t, err, "cmd.Flags().Parse(%q)", tc.flags) - clientCtx := newClientContextWithCodec(t) + clientCtx := newClientContext(t) var req *R testFunc := func() { @@ -1196,6 +1196,23 @@ func TestMakeQueryCommitmentSettlementFeeCalc(t *testing.T) { }, }, }, + { + name: "admin from keyring", + flags: []string{"--from", keyringName}, + expReq: &exchange.QueryCommitmentSettlementFeeCalcRequest{ + Settlement: &exchange.MsgMarketCommitmentSettleRequest{ + Admin: keyringAddr, + }, + }, + }, + { + name: "from flag is unknown name", + flags: []string{"--from", "notknown"}, + expReq: &exchange.QueryCommitmentSettlementFeeCalcRequest{ + Settlement: &exchange.MsgMarketCommitmentSettleRequest{}, + }, + expErr: joinErrs("notknown.info: key not found", "no provided"), + }, { name: "admin as authority", flags: []string{"--authority"}, diff --git a/x/exchange/client/cli/tx_setup_test.go b/x/exchange/client/cli/tx_setup_test.go index 3eaaf1858..49927ac99 100644 --- a/x/exchange/client/cli/tx_setup_test.go +++ b/x/exchange/client/cli/tx_setup_test.go @@ -732,7 +732,7 @@ func TestMakeMsgMarketCommitmentSettle(t *testing.T) { }, { name: "from file", - clientCtx: newClientContextWithCodec(t), + clientCtx: newClientContext(t), flags: []string{"--file", filename}, expMsg: fileMsg, }, @@ -742,7 +742,7 @@ func TestMakeMsgMarketCommitmentSettle(t *testing.T) { "--file", filename, "--tag", "new-thang", "--authority", "--outputs", "monroe:87plum", }, - clientCtx: newClientContextWithCodec(t), + clientCtx: newClientContext(t), expMsg: &exchange.MsgMarketCommitmentSettleRequest{ Admin: cli.AuthorityAddr.String(), MarketId: 4,