Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add update-censorship cmd to x/foundation cli #1121

Merged
merged 6 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Improvements
* (third_party/proto) [\#1037](https://github.com/Finschia/finschia-sdk/pull/1037) change the proof.proto path to third_party/proto/confio
* (ostracon) [\#1057](https://github.com/Finschia/finschia-sdk/pull/1057) Bump up Ostracon from to v1.1.1
* (feat) [\#1121](https://github.com/Finschia/finschia-sdk/pull/1121) Add update-censorship cmd to x/foundation cli
zemyblue marked this conversation as resolved.
Show resolved Hide resolved

### Bug Fixes
* (ledger) [\#1040](https://github.com/Finschia/finschia-sdk/pull/1040) fix a bug(unable to connect nano S plus ledger on ubuntu)
Expand All @@ -59,4 +60,4 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Document Updates
* (readme) [\#997](https://github.com/finschia/finschia-sdk/pull/997) fix swagger url
* (docs) [\#1059](https://github.com/Finschia/finschia-sdk/pull/1059) create ERRORS.md for x/module
* (docs) [\#1059](https://github.com/Finschia/finschia-sdk/pull/1059) create ERRORS.md for x/module
57 changes: 57 additions & 0 deletions x/foundation/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ func voteOptionFromString(str string) (foundation.VoteOption, error) {
return foundation.VoteOption(vo), nil
}

// CensorshipAuthorityFromString returns a CensorshipAuthority from a string. It returns an error if the string is invalid.
func censorshipAuthorityFromString(str string) (foundation.CensorshipAuthority, error) {
ca, ok := foundation.CensorshipAuthority_value[str]
if !ok {
return foundation.CensorshipAuthorityUnspecified, fmt.Errorf("'%s' is not a valid censorship authority", str)
}
return foundation.CensorshipAuthority(ca), nil
}

func parseMsgs(cdc codec.Codec, msgsJSON string) ([]sdk.Msg, error) {
var cliMsgs []json.RawMessage
if err := json.Unmarshal([]byte(msgsJSON), &cliMsgs); err != nil {
Expand Down Expand Up @@ -549,6 +558,54 @@ func NewTxCmdExec() *cobra.Command {
return cmd
}

func NewTxCmdUpdateCensorship() *cobra.Command {
cmd := &cobra.Command{
Use: "update-censorship [authority] [msg-type-url] [new-authority]",
Args: cobra.ExactArgs(3),
Short: "Update censorship over a message",
Long: `Update censorship over a message

Parameters:
authority: the current authority of the censorship
msg-type-url: the message type url of the censorship
new-authority: a new authority of the censorship
CENSORSHIP_AUTHORITY_UNSPECIFIED: no authority, which means removing the censorship
CENSORSHIP_AUTHORITY_GOVERNANCE: x/gov
CENSORSHIP_AUTHORITY_FOUNDATION: x/foundation
zemyblue marked this conversation as resolved.
Show resolved Hide resolved
`,
RunE: func(cmd *cobra.Command, args []string) error {
if err := validateGenerateOnly(cmd); err != nil {
return err
}

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

newAuthority, err := censorshipAuthorityFromString(args[2])
if err != nil {
return err
}

msg := foundation.MsgUpdateCensorship{
Authority: args[0],
Censorship: foundation.Censorship{
MsgTypeUrl: args[1],
Authority: newAuthority,
},
}
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
}

flags.AddTxFlagsToCmd(cmd)
return cmd
}

func NewTxCmdLeaveFoundation() *cobra.Command {
cmd := &cobra.Command{
Use: "leave-foundation [address]",
Expand Down
55 changes: 55 additions & 0 deletions x/foundation/client/testutil/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,61 @@ func (s *IntegrationTestSuite) TestNewTxCmdExec() {
}
}

func (s *IntegrationTestSuite) TestNewTxCmdUpdateCensorship() {
val := s.network.Validators[0]
commonArgs := []string{
fmt.Sprintf("--%s", flags.FlagGenerateOnly),
}

testCases := map[string]struct {
args []string
valid bool
}{
"valid transaction": {
[]string{
s.authority.String(),
foundation.ReceiveFromTreasuryAuthorization{}.MsgTypeURL(),
foundation.CensorshipAuthorityGovernance.String(),
},
true,
},
"wrong number of args": {
[]string{
s.authority.String(),
foundation.ReceiveFromTreasuryAuthorization{}.MsgTypeURL(),
foundation.CensorshipAuthorityGovernance.String(),
"extra",
},
false,
},
"invalid new authority": {
[]string{
s.authority.String(),
foundation.ReceiveFromTreasuryAuthorization{}.MsgTypeURL(),
"invalid-new-authority",
},
false,
},
}

for name, tc := range testCases {
tc := tc

s.Run(name, func() {
cmd := cli.NewTxCmdUpdateCensorship()
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...))
if !tc.valid {
s.Require().Error(err)
return
}
s.Require().NoError(err)

var res txtypes.Tx
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out)
})
}
}

func (s *IntegrationTestSuite) TestNewTxCmdLeaveFoundation() {
val := s.network.Validators[0]
commonArgs := []string{
Expand Down