Skip to content

Commit

Permalink
Enable AutoCLI for x/accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
DongLieu committed Dec 6, 2024
1 parent 40430fe commit 3455976
Show file tree
Hide file tree
Showing 22 changed files with 922 additions and 994 deletions.
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.

2 changes: 1 addition & 1 deletion crypto/keys/secp256k1/secp256k1.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (pubKey *PubKey) Address() crypto.Address {
}

sha := sha256.Sum256(pubKey.Key)
hasherRIPEMD160 := ripemd160.New() //nolint:gosec // keep around for backwards compatibility
hasherRIPEMD160 := ripemd160.New()
hasherRIPEMD160.Write(sha[:]) // does not error
return crypto.Address(hasherRIPEMD160.Sum(nil))
}
Expand Down
3 changes: 2 additions & 1 deletion simsx/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package simsx
import (
"cmp"
"context"
"iter"
"maps"
"math/rand"
"slices"
"strings"
"time"

"iter"

"cosmossdk.io/core/address"
"cosmossdk.io/core/log"

Expand Down
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
62 changes: 62 additions & 0 deletions x/accounts/autocli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package accounts

import (
"fmt"

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

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

// 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

0 comments on commit 3455976

Please sign in to comment.