Skip to content

Commit

Permalink
feat(mint): update mint module for sdk047
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed Apr 7, 2023
1 parent fdae447 commit e8d4f90
Show file tree
Hide file tree
Showing 27 changed files with 834 additions and 554 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,11 @@ func New(
app.MintKeeper = mintkeeper.NewKeeper(
appCodec,
keys[minttypes.StoreKey],
authtypes.NewModuleAddress(govtypes.ModuleName),
app.StakingKeeper,
app.AccountKeeper,
app.BankKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName),
)

app.DistrKeeper = distrkeeper.NewKeeper(
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ require (
github.com/stretchr/testify v1.8.2
google.golang.org/genproto v0.0.0-20230216225411-c8e22ba71e44
google.golang.org/grpc v1.53.0
gotest.tools/v3 v3.4.0
sigs.k8s.io/yaml v1.3.0
)

Expand Down
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1878,9 +1878,9 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o=
gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
28 changes: 20 additions & 8 deletions proto/mint/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,42 @@ syntax = "proto3";
package mint.v1beta1;

import "cosmos/msg/v1/msg.proto";
import "amino/amino.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "mint/v1beta1/mint.proto";

option go_package = "github.com/okp4/okp4d/x/mint/types";

// MsgService defines the service for the logic module.
// Do nothing for now as the service is without any side effects.
service MsgService {
// UpdateParams defined a governance operation for updating the x/mint module parameters.
// The authority is hard-coded to the Cosmos SDK x/gov module account
// Msg defines the x/mint Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;

// UpdateParams defines a governance operation for updating the x/mint module
// parameters. The authority is defaults to the x/gov module account.
//
// Since: cosmos-sdk 0.47
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

// MsgUpdateParams defines a Msg for updating the x/mint module parameters.
// MsgUpdateParams is the Msg/UpdateParams request type.
//
// Since: cosmos-sdk 0.47
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";
// authority is the address of the governance account.
option (amino.name) = "cosmos-sdk/x/mint/MsgUpdateParams";

// authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// params defines the x/mint parameters to update.
//
// NOTE: All parameters must be supplied.
Params params = 2 [(gogoproto.nullable) = false];
Params params = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}

// MsgUpdateParamsResponse defines the response structure for executing a
// MsgUpdateParams message.
//
// Since: cosmos-sdk 0.47
message MsgUpdateParamsResponse {}
204 changes: 204 additions & 0 deletions x/mint/client/cli/query_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
package cli_test

import (
"context"
"fmt"
"io"
"strings"
"testing"

rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock"
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"

"github.com/cosmos/cosmos-sdk/crypto/keyring"
testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/okp4/okp4d/x/mint"
mintcli "github.com/okp4/okp4d/x/mint/client/cli"
)

func TestGetCmdQueryParams(t *testing.T) {
encCfg := testutilmod.MakeTestEncodingConfig(mint.AppModuleBasic{})
kr := keyring.NewInMemory(encCfg.Codec)
baseCtx := client.Context{}.
WithKeyring(kr).
WithTxConfig(encCfg.TxConfig).
WithCodec(encCfg.Codec).
WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}).
WithAccountRetriever(client.MockAccountRetriever{}).
WithOutput(io.Discard).
WithChainID("test-chain")

cmd := mintcli.GetCmdQueryParams()

testCases := []struct {
name string
flagArgs []string
expCmdOutput string
expectedOutput string
}{
{
"json output",
[]string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=json", flags.FlagOutput)},
`[--height=1 --output=json]`,
`{"mint_denom":"","annual_reduction_factor":"0","blocks_per_year":"0"}`,
},
{
"text output",
[]string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=text", flags.FlagOutput)},
`[--height=1 --output=text]`,
`annual_reduction_factor: "0"
blocks_per_year: "0"
mint_denom: ""`,
},
}

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

t.Run(tc.name, func(t *testing.T) {
ctx := svrcmd.CreateExecuteContext(context.Background())

cmd.SetOut(io.Discard)
require.NotNil(t, cmd)

cmd.SetContext(ctx)
cmd.SetArgs(tc.flagArgs)

require.NoError(t, client.SetCmdClientContextHandler(baseCtx, cmd))

if len(tc.flagArgs) != 0 {
require.Contains(t, fmt.Sprint(cmd), "params [] [] Query the current minting parameters")
require.Contains(t, fmt.Sprint(cmd), tc.expCmdOutput)
}

out, err := clitestutil.ExecTestCLICmd(baseCtx, cmd, tc.flagArgs)
require.NoError(t, err)
require.Equal(t, tc.expectedOutput, strings.TrimSpace(out.String()))
})
}
}

func TestGetCmdQueryInflation(t *testing.T) {
encCfg := testutilmod.MakeTestEncodingConfig(mint.AppModuleBasic{})
kr := keyring.NewInMemory(encCfg.Codec)
baseCtx := client.Context{}.
WithKeyring(kr).
WithTxConfig(encCfg.TxConfig).
WithCodec(encCfg.Codec).
WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}).
WithAccountRetriever(client.MockAccountRetriever{}).
WithOutput(io.Discard).
WithChainID("test-chain")

cmd := mintcli.GetCmdQueryInflation()

testCases := []struct {
name string
flagArgs []string
expCmdOutput string
expectedOutput string
}{
{
"json output",
[]string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=json", flags.FlagOutput)},
`[--height=1 --output=json]`,
`<nil>`,
},
{
"text output",
[]string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=text", flags.FlagOutput)},
`[--height=1 --output=text]`,
`<nil>`,
},
}

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

t.Run(tc.name, func(t *testing.T) {
ctx := svrcmd.CreateExecuteContext(context.Background())

cmd.SetOut(io.Discard)
require.NotNil(t, cmd)

cmd.SetContext(ctx)
cmd.SetArgs(tc.flagArgs)

require.NoError(t, client.SetCmdClientContextHandler(baseCtx, cmd))

if len(tc.flagArgs) != 0 {
require.Contains(t, fmt.Sprint(cmd), "inflation [] [] Query the current minting inflation value")
require.Contains(t, fmt.Sprint(cmd), tc.expCmdOutput)
}

out, err := clitestutil.ExecTestCLICmd(baseCtx, cmd, tc.flagArgs)
require.NoError(t, err)
require.Equal(t, tc.expectedOutput, strings.TrimSpace(out.String()))
})
}
}

func TestGetCmdQueryAnnualProvisions(t *testing.T) {
encCfg := testutilmod.MakeTestEncodingConfig(mint.AppModuleBasic{})
kr := keyring.NewInMemory(encCfg.Codec)
baseCtx := client.Context{}.
WithKeyring(kr).
WithTxConfig(encCfg.TxConfig).
WithCodec(encCfg.Codec).
WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}).
WithAccountRetriever(client.MockAccountRetriever{}).
WithOutput(io.Discard).
WithChainID("test-chain")

cmd := mintcli.GetCmdQueryAnnualProvisions()

testCases := []struct {
name string
flagArgs []string
expCmdOutput string
expectedOutput string
}{
{
"json output",
[]string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=json", flags.FlagOutput)},
`[--height=1 --output=json]`,
`<nil>`,
},
{
"text output",
[]string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=text", flags.FlagOutput)},
`[--height=1 --output=text]`,
`<nil>`,
},
}

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

t.Run(tc.name, func(t *testing.T) {
ctx := svrcmd.CreateExecuteContext(context.Background())

cmd.SetOut(io.Discard)
require.NotNil(t, cmd)

cmd.SetContext(ctx)
cmd.SetArgs(tc.flagArgs)

require.NoError(t, client.SetCmdClientContextHandler(baseCtx, cmd))

if len(tc.flagArgs) != 0 {
require.Contains(t, fmt.Sprint(cmd), "annual-provisions [] [] Query the current minting annual provisions value")
require.Contains(t, fmt.Sprint(cmd), tc.expCmdOutput)
}

out, err := clitestutil.ExecTestCLICmd(baseCtx, cmd, tc.flagArgs)
require.NoError(t, err)
require.Equal(t, tc.expectedOutput, strings.TrimSpace(out.String()))
})
}
}
18 changes: 0 additions & 18 deletions x/mint/client/testutil/cli_test.go

This file was deleted.

63 changes: 0 additions & 63 deletions x/mint/client/testutil/grpc_test.go

This file was deleted.

Loading

0 comments on commit e8d4f90

Please sign in to comment.