Skip to content

Commit

Permalink
remove legacy address converter & ValidateBasic
Browse files Browse the repository at this point in the history
  • Loading branch information
tkxkd0159 committed Feb 27, 2024
1 parent 7bd0f44 commit eb53ff0
Show file tree
Hide file tree
Showing 20 changed files with 1,102 additions and 1,504 deletions.
27 changes: 0 additions & 27 deletions scripts/mockgen.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,5 @@
#!/usr/bin/env bash

mockgen_cmd="mockgen"
$mockgen_cmd -source=baseapp/abci_utils.go -package mock -destination baseapp/testutil/mock/mocks.go
$mockgen_cmd -source=client/account_retriever.go -package mock -destination testutil/mock/account_retriever.go
$mockgen_cmd -package mock -destination store/mock/cosmos_cosmos_db_DB.go github.com/cosmos/cosmos-db DB
$mockgen_cmd -source=types/module/module.go -package mock -destination testutil/mock/types_module_module.go
$mockgen_cmd -source=types/module/mock_appmodule_test.go -package mock -destination testutil/mock/types_mock_appmodule.go
$mockgen_cmd -source=types/invariant.go -package mock -destination testutil/mock/types_invariant.go
$mockgen_cmd -package mock -destination testutil/mock/grpc_server.go github.com/cosmos/gogoproto/grpc Server
$mockgen_cmd -package mock -destination testutil/mock/logger.go cosmossdk.io/log Logger
$mockgen_cmd -source=orm/model/ormtable/hooks.go -package ormmocks -destination orm/testing/ormmocks/hooks.go
$mockgen_cmd -source=x/nft/expected_keepers.go -package testutil -destination x/nft/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/feegrant/expected_keepers.go -package testutil -destination x/feegrant/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/mint/types/expected_keepers.go -package testutil -destination x/mint/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/params/proposal_handler_test.go -package testutil -destination x/params/testutil/staking_keeper_mock.go
$mockgen_cmd -source=x/crisis/types/expected_keepers.go -package testutil -destination x/crisis/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/auth/tx/config/expected_keepers.go -package testutil -destination x/auth/tx/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/auth/types/expected_keepers.go -package testutil -destination x/auth/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/auth/ante/expected_keepers.go -package testutil -destination x/auth/ante/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/authz/expected_keepers.go -package testutil -destination x/authz/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/bank/types/expected_keepers.go -package testutil -destination x/bank/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/group/testutil/expected_keepers.go -package testutil -destination x/group/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/evidence/types/expected_keepers.go -package testutil -destination x/evidence/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/distribution/types/expected_keepers.go -package testutil -destination x/distribution/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/slashing/types/expected_keepers.go -package testutil -destination x/slashing/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/genutil/types/expected_keepers.go -package testutil -destination x/genutil/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/gov/testutil/expected_keepers.go -package testutil -destination x/gov/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/staking/types/expected_keepers.go -package testutil -destination x/staking/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/auth/vesting/types/expected_keepers.go -package testutil -destination x/auth/vesting/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/foundation/expected_keepers.go -package testutil -destination x/foundation/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/stakingplus/expected_keepers.go -package testutil -destination x/stakingplus/testutil/expected_keepers_mocks.go
6 changes: 4 additions & 2 deletions tests/e2e/collection/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,13 @@ func (s *E2ETestSuite) TestStatisticsGRPC() {
},
{
"invalid request (wrong contract ID) - Minted",
fmt.Sprintf("%s/lbm/collection/v1/contracts/%s/token_types/%s/supply", val.APIAddress, "wrong ID", s.nftClassID),
fmt.Sprintf("%s/lbm/collection/v1/contracts/%s/token_types/%s/minted", val.APIAddress, "wrong ID", s.nftClassID),
true,
&collection.QueryNFTMintedResponse{},
},
{
"invalid request (wrong contract ID) - Burnt",
fmt.Sprintf("%s/lbm/collection/v1/contracts/%s/token_types/%s/supply", val.APIAddress, "wrong ID", s.nftClassID),
fmt.Sprintf("%s/lbm/collection/v1/contracts/%s/token_types/%s/burnt", val.APIAddress, "wrong ID", s.nftClassID),
true,
&collection.QueryNFTBurntResponse{},
},
Expand Down Expand Up @@ -487,6 +487,8 @@ func (s *E2ETestSuite) TestGranteeGrantsGRPC() {
val := s.network.Validators[0]
s.grant(s.contractID, s.vendor, s.stranger, collection.PermissionIssue)
dummyAddr := "link1hcpqj6w2eq30jcdggs7892lmask0cacvynqg7d"
_, err := s.ac.StringToBytes(dummyAddr)
s.Require().NoError(err)

testCases := []struct {
name string
Expand Down
12 changes: 7 additions & 5 deletions tests/e2e/collection/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"github.com/cosmos/gogoproto/proto"
"github.com/stretchr/testify/suite"

"cosmossdk.io/core/address"
cmath "cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/testutil"
Expand All @@ -26,6 +26,7 @@ type E2ETestSuite struct {
suite.Suite

cfg network.Config
ac address.Codec
network *network.Network
setupHeight int64

Expand Down Expand Up @@ -54,6 +55,7 @@ func (s *E2ETestSuite) SetupSuite() {
var err error
s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg)
s.Require().NoError(err)
s.ac = s.network.Config.InterfaceRegistry.SigningContext().AddressCodec()

s.commonArgs = []string{
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
Expand Down Expand Up @@ -144,7 +146,7 @@ func (s *E2ETestSuite) mintNFT(contractID string, operator, to sdk.AccAddress, c
fmt.Sprintf("--%s=%s", cli.FlagName, "arctic fox"),
}, s.commonArgs...)

out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cli.NewTxCmdMintNFT(), args)
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cli.NewTxCmdMintNFT(s.ac), args)
s.Require().NoError(err)
txResp := s.getTxResp(out, 0)
var event collection.EventMintedNFT
Expand Down Expand Up @@ -185,7 +187,7 @@ func (s *E2ETestSuite) grant(contractID string, granter, grantee sdk.AccAddress,
collection.LegacyPermission(permission).String(),
}, s.commonArgs...)

out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cli.NewTxCmdGrantPermission(), args)
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cli.NewTxCmdGrantPermission(s.ac), args)
s.Require().NoError(err)
_ = s.getTxResp(out, 0)
}
Expand All @@ -198,7 +200,7 @@ func (s *E2ETestSuite) authorizeOperator(contractID string, holder, operator sdk
operator.String(),
}, s.commonArgs...)

out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cli.NewTxCmdAuthorizeOperator(), args)
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cli.NewTxCmdAuthorizeOperator(s.ac), args)
s.Require().NoError(err)
_ = s.getTxResp(out, 0)
}
Expand All @@ -225,7 +227,7 @@ func (s *E2ETestSuite) createAccount(uid string) sdk.AccAddress {
addr, err := keyInfo.GetAddress()
s.Require().NoError(err)

out, err := clitestutil.MsgSendExec(val.ClientCtx, val.Address, addr, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, cmath.NewInt(1000000))), address.NewBech32Codec("link"), s.commonArgs...)
out, err := clitestutil.MsgSendExec(val.ClientCtx, val.Address, addr, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, cmath.NewInt(1000000))), s.ac, s.commonArgs...)
s.Require().NoError(err)
s.getTxResp(out, 0)
return addr
Expand Down
14 changes: 7 additions & 7 deletions tests/e2e/collection/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (s *E2ETestSuite) TestNewTxCmdSendNFT() {
tc := tc

s.Run(name, func() {
cmd := cli.NewTxCmdSendNFT()
cmd := cli.NewTxCmdSendNFT(s.ac)
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, s.commonArgs...))
if !tc.valid {
s.Require().Error(err)
Expand Down Expand Up @@ -141,7 +141,7 @@ func (s *E2ETestSuite) TestNewTxCmdOperatorSendNFT() {
tc := tc

s.Run(name, func() {
cmd := cli.NewTxCmdOperatorSendNFT()
cmd := cli.NewTxCmdOperatorSendNFT(s.ac)
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, s.commonArgs...))
if !tc.valid {
s.Require().Error(err)
Expand Down Expand Up @@ -308,7 +308,7 @@ func (s *E2ETestSuite) TestNewTxCmdMintNFT() {
tc := tc

s.Run(name, func() {
cmd := cli.NewTxCmdMintNFT()
cmd := cli.NewTxCmdMintNFT(s.ac)
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, s.commonArgs...))
if !tc.valid {
s.Require().Error(err)
Expand Down Expand Up @@ -443,7 +443,7 @@ func (s *E2ETestSuite) TestNewTxCmdOperatorOperatorBurnNFT() {
tc := tc

s.Run(name, func() {
cmd := cli.NewTxCmdOperatorBurnNFT()
cmd := cli.NewTxCmdOperatorBurnNFT(s.ac)
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, s.commonArgs...))
if !tc.valid {
s.Require().Error(err)
Expand Down Expand Up @@ -568,7 +568,7 @@ func (s *E2ETestSuite) TestNewTxCmdGrantPermission() {
tc := tc

s.Run(name, func() {
cmd := cli.NewTxCmdGrantPermission()
cmd := cli.NewTxCmdGrantPermission(s.ac)
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, s.commonArgs...))
if !tc.valid {
s.Require().Error(err)
Expand Down Expand Up @@ -666,7 +666,7 @@ func (s *E2ETestSuite) TestNewTxCmdAuthorizeOperator() {
tc := tc

s.Run(name, func() {
cmd := cli.NewTxCmdAuthorizeOperator()
cmd := cli.NewTxCmdAuthorizeOperator(s.ac)
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, s.commonArgs...))
if !tc.valid {
s.Require().Error(err)
Expand Down Expand Up @@ -715,7 +715,7 @@ func (s *E2ETestSuite) TestNewTxCmdRevokeOperator() {
tc := tc

s.Run(name, func() {
cmd := cli.NewTxCmdRevokeOperator()
cmd := cli.NewTxCmdRevokeOperator(s.ac)
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, s.commonArgs...))
if !tc.valid {
s.Require().Error(err)
Expand Down
37 changes: 19 additions & 18 deletions x/collection/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (

"github.com/spf13/cobra"

"cosmossdk.io/core/address"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"

"github.com/Finschia/finschia-sdk/x/collection"
Expand All @@ -18,7 +19,7 @@ const (
)

// NewQueryCmd returns the cli query commands for this module
func NewQueryCmd() *cobra.Command {
func NewQueryCmd(ac address.Codec) *cobra.Command {
queryCmd := &cobra.Command{
Use: collection.ModuleName,
Short: fmt.Sprintf("Querying commands for the %s module", collection.ModuleName),
Expand All @@ -29,22 +30,22 @@ func NewQueryCmd() *cobra.Command {
}

queryCmd.AddCommand(
NewQueryCmdBalances(),
NewQueryCmdBalances(ac),
NewQueryCmdNFTSupply(),
NewQueryCmdNFTMinted(),
NewQueryCmdNFTBurnt(),
NewQueryCmdContract(),
NewQueryCmdToken(),
NewQueryCmdTokenType(),
NewQueryCmdGranteeGrants(),
NewQueryCmdIsOperatorFor(),
NewQueryCmdHoldersByOperator(),
NewQueryCmdGranteeGrants(ac),
NewQueryCmdIsOperatorFor(ac),
NewQueryCmdHoldersByOperator(ac),
)

return queryCmd
}

func NewQueryCmdBalances() *cobra.Command {
func NewQueryCmdBalances(ac address.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "balances [contract-id] [address]",
Args: cobra.ExactArgs(2),
Expand All @@ -61,8 +62,8 @@ func NewQueryCmdBalances() *cobra.Command {
return err
}

address := args[1]
if _, err := sdk.AccAddressFromBech32(address); err != nil {
addr := args[1]
if _, err := ac.StringToBytes(addr); err != nil {
return err
}

Expand All @@ -80,7 +81,7 @@ func NewQueryCmdBalances() *cobra.Command {

req := &collection.QueryAllBalancesRequest{
ContractId: contractID,
Address: address,
Address: addr,
Pagination: pageReq,
}
res, err := queryClient.AllBalances(cmd.Context(), req)
Expand All @@ -96,7 +97,7 @@ func NewQueryCmdBalances() *cobra.Command {

req := &collection.QueryBalanceRequest{
ContractId: contractID,
Address: address,
Address: addr,
TokenId: tokenID,
}
res, err := queryClient.Balance(cmd.Context(), req)
Expand Down Expand Up @@ -342,7 +343,7 @@ func NewQueryCmdToken() *cobra.Command {
return cmd
}

func NewQueryCmdGranteeGrants() *cobra.Command {
func NewQueryCmdGranteeGrants(ac address.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "grantee-grants [contract-id] [grantee]",
Args: cobra.ExactArgs(2),
Expand All @@ -360,7 +361,7 @@ func NewQueryCmdGranteeGrants() *cobra.Command {
}

grantee := args[1]
if _, err := sdk.AccAddressFromBech32(grantee); err != nil {
if _, err := ac.StringToBytes(grantee); err != nil {
return err
}

Expand All @@ -381,7 +382,7 @@ func NewQueryCmdGranteeGrants() *cobra.Command {
return cmd
}

func NewQueryCmdIsOperatorFor() *cobra.Command {
func NewQueryCmdIsOperatorFor(ac address.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "approved [contract-id] [operator] [holder]",
Args: cobra.ExactArgs(3),
Expand All @@ -399,12 +400,12 @@ func NewQueryCmdIsOperatorFor() *cobra.Command {
}

operator := args[1]
if _, err := sdk.AccAddressFromBech32(operator); err != nil {
if _, err := ac.StringToBytes(operator); err != nil {
return err
}

holder := args[2]
if _, err := sdk.AccAddressFromBech32(holder); err != nil {
if _, err := ac.StringToBytes(holder); err != nil {
return err
}

Expand All @@ -426,7 +427,7 @@ func NewQueryCmdIsOperatorFor() *cobra.Command {
return cmd
}

func NewQueryCmdHoldersByOperator() *cobra.Command {
func NewQueryCmdHoldersByOperator(ac address.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "approvers [contract-id] [operator]",
Args: cobra.ExactArgs(2),
Expand All @@ -444,7 +445,7 @@ func NewQueryCmdHoldersByOperator() *cobra.Command {
}

operator := args[1]
if _, err := sdk.AccAddressFromBech32(operator); err != nil {
if _, err := ac.StringToBytes(operator); err != nil {
return err
}

Expand Down
Loading

0 comments on commit eb53ff0

Please sign in to comment.