From c6f9fbab33b83dd8870ccdf7fe0ab1ee0d625702 Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Tue, 14 May 2024 10:32:59 -0600 Subject: [PATCH] update proposal command and tests --- x/msgfees/client/cli/cli_test.go | 63 ++++++++++++++++++++++++++++++-- x/msgfees/client/cli/tx.go | 7 ++++ 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/x/msgfees/client/cli/cli_test.go b/x/msgfees/client/cli/cli_test.go index b23df3386..0f5f48c47 100644 --- a/x/msgfees/client/cli/cli_test.go +++ b/x/msgfees/client/cli/cli_test.go @@ -178,9 +178,64 @@ func (s *IntegrationTestSuite) TestMsgFeesProposal() { signer: s.accountAddresses[0].String(), }, { - name: "failure - invalid proposal type", - args: []string{"invalid-type"}, - expectErrMsg: "unable to resolve type URL ", + name: "failure - invalid proposal type", + args: []string{ + "invalid-type", + "--msg-type=/provenance.metadata.v1.MsgWriteRecordRequest", + }, + expectErrMsg: `unknown proposal type "invalid-type"`, + signer: s.accountAddresses[0].String(), + }, + { + name: "success - add msg fee with recipient and bips", + args: []string{ + "add", + "--msg-type=/provenance.metadata.v1.MsgWriteRecordRequest", + "--additional-fee=612nhash", + fmt.Sprintf("--recipient=%v", s.account2Addr.String()), + "--bips=100", + "--deposit=1000000stake", + }, + expectedCode: 0, + signer: s.accountAddresses[0].String(), + }, + { + name: "success - update msg fee with recipient and bips", + args: []string{ + "update", + "--msg-type=/provenance.metadata.v1.MsgWriteRecordRequest", + "--additional-fee=612000nhash", + fmt.Sprintf("--recipient=%v", s.account2Addr.String()), + "--bips=100", + "--deposit=1000000stake", + }, + expectedCode: 0, + signer: s.accountAddresses[0].String(), + }, + { + name: "failure - invalid recipient format", + args: []string{ + "add", + "--msg-type=/provenance.metadata.v1.MsgWriteRecordRequest", + "--additional-fee=612nhash", + "--recipient=invalid-recipient", + "--bips=100", + "--deposit=1000000stake", + }, + expectErrMsg: "error validating basis points args: decoding bech32 failed: invalid separator index -1", + signer: s.accountAddresses[0].String(), + }, + { + name: "failure - bips out of range", + args: []string{ + "add", + "--msg-type=/provenance.metadata.v1.MsgWriteRecordRequest", + "--additional-fee=612nhash", + fmt.Sprintf("--recipient=%v", s.account2Addr.String()), + "--bips=10001", + "--deposit=1000000stake", + }, + expectErrMsg: "error validating basis points args: recipient basis points can only be between 0 and 10,000 : 10001", signer: s.accountAddresses[0].String(), }, } @@ -189,7 +244,7 @@ func (s *IntegrationTestSuite) TestMsgFeesProposal() { s.Run(tc.name, func() { cmd := cli.GetCmdMsgFeesProposal() tc.args = append(tc.args, - "--title", "msg fees proposal", "--summary", "See title.", + "--title", "Update nhash per usd mil proposal", "--summary", "Updates the nhash per usd mil rate.", fmt.Sprintf("--%s=%s", flags.FlagFrom, tc.signer), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), diff --git a/x/msgfees/client/cli/tx.go b/x/msgfees/client/cli/tx.go index fc49058b2..13d4e2aeb 100644 --- a/x/msgfees/client/cli/tx.go +++ b/x/msgfees/client/cli/tx.go @@ -87,6 +87,13 @@ $ %[1]s tx msgfees remove --msg-type=/provenance.metadata.v1.MsgWriteRecordReque return err } + if len(recipient) > 0 || len(bips) > 0 { + if err := types.ValidateBips(recipient, bips); err != nil { + return fmt.Errorf("error validating basis points args: %v", err) + } + + } + var addFee sdk.Coin if proposalType != "remove" { additionalFee, errMinFee := flagSet.GetString(FlagMinFee)