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

refactor(x/account): Enable AutoCLI for x/accounts #22727

Closed
wants to merge 16 commits into from
357 changes: 208 additions & 149 deletions api/cosmos/accounts/v1/query.pulsar.go

Large diffs are not rendered by default.

525 changes: 283 additions & 242 deletions api/cosmos/accounts/v1/tx.pulsar.go

Large diffs are not rendered by default.

64 changes: 41 additions & 23 deletions tests/integration/accounts/multisig/account_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package multisig

import (
"encoding/json"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -141,12 +143,19 @@ func (s *IntegrationTestSuite) TestConfigUpdate() {
EarlyExecution: false,
},
}
anyUpdateMsg := codectypes.UnsafePackAny(updateMsg)

split := strings.Split(anyUpdateMsg.TypeUrl, "/")
nameTypeUrl := split[len(split)-1]
jsonReq, err := json.Marshal(updateMsg)
s.NoError(err)

msgExec := &accountsv1.MsgExecute{
Sender: accAddrStr,
Target: accAddrStr,
Message: codectypes.UnsafePackAny(updateMsg),
Funds: []sdk.Coin{},
Sender: accAddrStr,
Target: accAddrStr,
ExecuteMsgTypeUrl: nameTypeUrl,
JsonMessage: string(jsonReq),
Funds: []sdk.Coin{},
}

s.createProposal(ctx, accountAddr, s.members[0], codectypes.UnsafePackAny(msgExec))
Expand All @@ -157,7 +166,7 @@ func (s *IntegrationTestSuite) TestConfigUpdate() {
Vote: v1.VoteOption_VOTE_OPTION_YES,
}

err := s.executeTx(ctx, voteReq, accountAddr, s.members[0])
err = s.executeTx(ctx, voteReq, accountAddr, s.members[0])
s.NoError(err)

err = s.executeProposal(ctx, accountAddr, s.members[0], 0)
Expand All @@ -172,25 +181,34 @@ func (s *IntegrationTestSuite) TestConfigUpdate() {

// Try to remove a member, but it doesn't reach passing threshold
// create proposal
msgExec = &accountsv1.MsgExecute{
Sender: accAddrStr,
Target: accAddrStr,
Message: codectypes.UnsafePackAny(&v1.MsgUpdateConfig{
UpdateMembers: []*v1.Member{
{
Address: s.membersAddr[1],
Weight: 0,
},
},
Config: &v1.Config{
Threshold: 200, // 3 members with 100 power each, 2/3 majority
Quorum: 200,
VotingPeriod: 120,
Revote: false,
EarlyExecution: false,
msgUpdate := &v1.MsgUpdateConfig{
UpdateMembers: []*v1.Member{
{
Address: s.membersAddr[1],
Weight: 0,
},
}),
Funds: []sdk.Coin{},
},
Config: &v1.Config{
Threshold: 200, // 3 members with 100 power each, 2/3 majority
Quorum: 200,
VotingPeriod: 120,
Revote: false,
EarlyExecution: false,
},
}
anyMsgUpdate := codectypes.UnsafePackAny(msgUpdate)

split = strings.Split(anyMsgUpdate.TypeUrl, "/")
nameTypeUrl = split[len(split)-1]
jsonReq, err = json.Marshal(msgUpdate)
s.NoError(err)

msgExec = &accountsv1.MsgExecute{
Sender: accAddrStr,
Target: accAddrStr,
ExecuteMsgTypeUrl: nameTypeUrl,
JsonMessage: string(jsonReq),
Funds: []sdk.Coin{},
}

s.createProposal(ctx, accountAddr, s.members[0], codectypes.UnsafePackAny(msgExec))
Expand Down
61 changes: 61 additions & 0 deletions x/accounts/autocli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package accounts

import (
accountsv1 "cosmossdk.io/api/cosmos/accounts/v1"
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
"fmt"

"github.com/cosmos/cosmos-sdk/version"
)
Comment on lines +3 to +9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Organize imports according to Go conventions

The import statements are not properly grouped and ordered. According to the Go coding conventions and the Uber Go Style Guide, imports should be grouped in the following order: standard library packages, third-party packages, and project-specific packages, each separated by a blank line.

Apply this diff to organize the imports:

 import (
+	"fmt"

+	"github.com/cosmos/cosmos-sdk/version"

 	accountsv1 "cosmossdk.io/api/cosmos/accounts/v1"
 	autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
-	"fmt"

-	"github.com/cosmos/cosmos-sdk/version"
 )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import (
accountsv1 "cosmossdk.io/api/cosmos/accounts/v1"
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
"fmt"
"github.com/cosmos/cosmos-sdk/version"
)
import (
"fmt"
"github.com/cosmos/cosmos-sdk/version"
accountsv1 "cosmossdk.io/api/cosmos/accounts/v1"
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
)
🧰 Tools
🪛 golangci-lint (1.62.2)

3-3: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order

(gci)


6-6: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order

(gci)


// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface.
func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
return &autocliv1.ModuleOptions{
Query: &autocliv1.ServiceCommandDescriptor{
Service: accountsv1.Query_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "AccountQuery",
Use: "query <account-address> <query-request-type-url> <json-message>",
Short: "Query account state",
Example: fmt.Sprintf(`%s q accounts query cosmos1uds6tz96dxfllz7tz3s3tm8tlg6x95g0mc2987sx6psjz98qlpss89sheu cosmos.accounts.defaults.multisig.v1.QueryProposal '{"proposal_id":1}`, version.AppName),
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{ProtoField: "target"},
{ProtoField: "query_request_type_url"},
{ProtoField: "json_message"},
},
},
},
EnhanceCustomCommand: true,
},
Tx: &autocliv1.ServiceCommandDescriptor{
Service: accountsv1.Msg_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "Init",
Use: "init <account-type> <json-message>",
Short: "Initialize a new account",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{ProtoField: "sender"},
{ProtoField: "account_type"},
{ProtoField: "json_message"},
{ProtoField: "funds", Varargs: true},
},
},
{
RpcMethod: "Execute",
Use: "execute <account-address> <execute-msg-type-url> <json-message>",
Short: "Execute state transition to account",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{ProtoField: "sender"},
{ProtoField: "target"},
{ProtoField: "execute_msg_type_url"},
{ProtoField: "json_message"},
{ProtoField: "funds", Varargs: true},
},
},
},
EnhanceCustomCommand: true,
},
}
}
205 changes: 0 additions & 205 deletions x/accounts/cli/cli.go

This file was deleted.

Loading
Loading