Skip to content

Commit

Permalink
feat: migrate x/auth/vesting to use app wiring
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Jun 19, 2022
1 parent c5c7f31 commit 7580b1c
Show file tree
Hide file tree
Showing 11 changed files with 666 additions and 37 deletions.
503 changes: 503 additions & 0 deletions api/cosmos/vesting/module/v1/module.pulsar.go

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions proto/cosmos/vesting/module/v1/module.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";

package cosmos.vesting.module.v1;

import "cosmos/app/v1alpha1/module.proto";

// Module is the config object of the vesting module.
message Module {
option (cosmos.app.v1alpha1.module) = {
go_import: "github.com/cosmos/cosmos-sdk/x/auth/vesting"
};
}
1 change: 0 additions & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ func NewSimApp(
// NOTE: Any module instantiated in the module manager that is later modified
// must be passed by reference here.
if err := app.RegisterModules(
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants),
gov.NewAppModule(app.appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
upgrade.NewAppModule(app.UpgradeKeeper),
Expand Down
4 changes: 4 additions & 0 deletions simapp/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,7 @@ modules:
- name: distribution
config:
"@type": cosmos.distribution.module.v1.Module

- name: vesting
config:
"@type": cosmos.vesting.module.v1.Module
23 changes: 14 additions & 9 deletions x/auth/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,25 +213,30 @@ func provideModuleBasic() runtime.AppModuleBasicWrapper {
return runtime.WrapAppModuleBasic(AppModuleBasic{})
}

type authInputs struct {
depinject.In

Config *modulev1.Module
Key *store.KVStoreKey
Cdc codec.Codec
Subspace paramtypes.Subspace
}

type authOutputs struct {
depinject.Out

AccountKeeper keeper.AccountKeeper
Module runtime.AppModuleWrapper
}

func provideModule(
config *modulev1.Module,
key *store.KVStoreKey,
cdc codec.Codec,
subspace paramtypes.Subspace,
) authOutputs {
func provideModule(in authInputs) authOutputs {
maccPerms := map[string][]string{}
for _, permission := range config.ModuleAccountPermissions {
for _, permission := range in.Config.ModuleAccountPermissions {
maccPerms[permission.Account] = permission.Permissions
}

k := keeper.NewAccountKeeper(cdc, key, subspace, types.ProtoBaseAccount, maccPerms, config.Bech32Prefix)
m := NewAppModule(cdc, k, simulation.RandomGenesisAccounts)
k := keeper.NewAccountKeeper(in.Cdc, in.Key, in.Subspace, types.ProtoBaseAccount, maccPerms, in.Config.Bech32Prefix)
m := NewAppModule(in.Cdc, k, simulation.RandomGenesisAccounts)

return authOutputs{AccountKeeper: k, Module: runtime.WrapAppModule(m)}
}
9 changes: 6 additions & 3 deletions x/auth/vesting/client/testutil/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ package testutil
import (
"testing"

"github.com/cosmos/cosmos-sdk/testutil/network"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/x/auth/vesting/testutil"
)

func TestIntegrationTestSuite(t *testing.T) {
cfg := network.DefaultConfig()
cfg, err := network.DefaultConfigWithAppConfig(testutil.AppConfig)
require.NoError(t, err)
cfg.NumValidators = 1
suite.Run(t, NewIntegrationTestSuite(cfg))
}
42 changes: 40 additions & 2 deletions x/auth/vesting/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ package vesting
import (
"encoding/json"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/depinject"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"

modulev1 "cosmossdk.io/api/cosmos/vesting/module/v1"
"cosmossdk.io/core/appmodule"
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
"github.com/cosmos/cosmos-sdk/x/auth/vesting/client/cli"
"github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
Expand Down Expand Up @@ -55,7 +60,7 @@ func (AppModuleBasic) ValidateGenesis(_ codec.JSONCodec, _ client.TxEncodingConf

// RegisterGRPCGatewayRoutes registers the module's gRPC Gateway routes. Currently, this
// is a no-op.
func (a AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) {}
func (a AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *gwruntime.ServeMux) {}

// GetTxCmd returns the root tx command for the auth module.
func (AppModuleBasic) GetTxCmd() *cobra.Command {
Expand Down Expand Up @@ -126,3 +131,36 @@ func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONCodec) json.RawMe

// ConsensusVersion implements AppModule/ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 1 }

//
// New App Wiring Setup
//

func init() {
appmodule.Register(&modulev1.Module{},
appmodule.Provide(provideModuleBasic, provideModule),
)
}

func provideModuleBasic() runtime.AppModuleBasicWrapper {
return runtime.WrapAppModuleBasic(AppModuleBasic{})
}

type vestingInputs struct {
depinject.In

AccountKeeper keeper.AccountKeeper
BankKeeper types.BankKeeper
}

type vestingOutputs struct {
depinject.Out

Module runtime.AppModuleWrapper
}

func provideModule(in vestingInputs) vestingOutputs {
m := NewAppModule(in.AccountKeeper, in.BankKeeper)

return vestingOutputs{Module: runtime.WrapAppModule(m)}
}
45 changes: 45 additions & 0 deletions x/auth/vesting/testutil/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
modules:
- name: runtime
config:
"@type": cosmos.app.runtime.v1alpha1.Module

app_name: VestingApp

begin_blockers: [staking, auth, bank, genutil, params, vesting]
end_blockers: [staking, auth, bank, genutil, params, vesting]
init_genesis: [auth, bank, staking, genutil, params, vesting]

- name: auth
config:
"@type": cosmos.auth.module.v1.Module
bech32_prefix: cosmos
module_account_permissions:
- account: fee_collector
- account: bonded_tokens_pool
permissions: [burner, staking]
- account: not_bonded_tokens_pool
permissions: [burner, staking]

- name: bank
config:
"@type": cosmos.bank.module.v1.Module

- name: params
config:
"@type": cosmos.params.module.v1.Module

- name: tx
config:
"@type": cosmos.tx.module.v1.Module

- name: staking
config:
"@type": cosmos.staking.module.v1.Module

- name: genutil
config:
"@type": cosmos.genutil.module.v1.Module

- name: vesting
config:
"@type": cosmos.vesting.module.v1.Module
19 changes: 19 additions & 0 deletions x/auth/vesting/testutil/app_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package testutil

import (
_ "embed"

"cosmossdk.io/core/appconfig"
_ "github.com/cosmos/cosmos-sdk/x/auth"
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/module"
_ "github.com/cosmos/cosmos-sdk/x/auth/vesting"
_ "github.com/cosmos/cosmos-sdk/x/bank"
_ "github.com/cosmos/cosmos-sdk/x/genutil"
_ "github.com/cosmos/cosmos-sdk/x/params"
_ "github.com/cosmos/cosmos-sdk/x/staking"
)

//go:embed app.yaml
var appConfig []byte

var AppConfig = appconfig.LoadYAML(appConfig)
42 changes: 20 additions & 22 deletions x/auth/vesting/types/vesting_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import (
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/simapp"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting/testutil"
"github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
)

Expand All @@ -25,15 +27,15 @@ var (
type VestingAccountTestSuite struct {
suite.Suite

app *simapp.SimApp
ctx sdk.Context
ctx sdk.Context
accountKeeper keeper.AccountKeeper
}

func (s *VestingAccountTestSuite) SetupTest() {
checkTx := false
s.app = simapp.Setup(s.T(), checkTx)
app, err := simtestutil.Setup(testutil.AppConfig, &s.accountKeeper)
require.NoError(s.T(), err)

s.ctx = s.app.BaseApp.NewContext(checkTx, tmproto.Header{Height: 1})
s.ctx = app.BaseApp.NewContext(false, tmproto.Header{Height: 1})
}

func TestGetVestedCoinsContVestingAcc(t *testing.T) {
Expand Down Expand Up @@ -754,79 +756,75 @@ func TestGenesisAccountValidate(t *testing.T) {
}

func (s *VestingAccountTestSuite) TestContinuousVestingAccountMarshal() {
app := s.app
require := s.Require()
baseAcc, coins := initBaseAccount()
baseVesting := types.NewBaseVestingAccount(baseAcc, coins, time.Now().Unix())
acc := types.NewContinuousVestingAccountRaw(baseVesting, baseVesting.EndTime)

bz, err := app.AccountKeeper.MarshalAccount(acc)
bz, err := s.accountKeeper.MarshalAccount(acc)
require.Nil(err)

acc2, err := app.AccountKeeper.UnmarshalAccount(bz)
acc2, err := s.accountKeeper.UnmarshalAccount(bz)
require.Nil(err)
require.IsType(&types.ContinuousVestingAccount{}, acc2)
require.Equal(acc.String(), acc2.String())

// error on bad bytes
_, err = app.AccountKeeper.UnmarshalAccount(bz[:len(bz)/2])
_, err = s.accountKeeper.UnmarshalAccount(bz[:len(bz)/2])
require.NotNil(err)
}

func (s *VestingAccountTestSuite) TestPeriodicVestingAccountMarshal() {
app := s.app
require := s.Require()
baseAcc, coins := initBaseAccount()
acc := types.NewPeriodicVestingAccount(baseAcc, coins, time.Now().Unix(), types.Periods{types.Period{3600, coins}})

bz, err := app.AccountKeeper.MarshalAccount(acc)
bz, err := s.accountKeeper.MarshalAccount(acc)
require.Nil(err)

acc2, err := app.AccountKeeper.UnmarshalAccount(bz)
acc2, err := s.accountKeeper.UnmarshalAccount(bz)
require.Nil(err)
require.IsType(&types.PeriodicVestingAccount{}, acc2)
require.Equal(acc.String(), acc2.String())

// error on bad bytes
_, err = app.AccountKeeper.UnmarshalAccount(bz[:len(bz)/2])
_, err = s.accountKeeper.UnmarshalAccount(bz[:len(bz)/2])
require.NotNil(err)
}

func (s *VestingAccountTestSuite) TestDelayedVestingAccountMarshal() {
app := s.app
require := s.Require()
baseAcc, coins := initBaseAccount()
acc := types.NewDelayedVestingAccount(baseAcc, coins, time.Now().Unix())

bz, err := app.AccountKeeper.MarshalAccount(acc)
bz, err := s.accountKeeper.MarshalAccount(acc)
require.Nil(err)

acc2, err := app.AccountKeeper.UnmarshalAccount(bz)
acc2, err := s.accountKeeper.UnmarshalAccount(bz)
require.Nil(err)
require.IsType(&types.DelayedVestingAccount{}, acc2)
require.Equal(acc.String(), acc2.String())

// error on bad bytes
_, err = app.AccountKeeper.UnmarshalAccount(bz[:len(bz)/2])
_, err = s.accountKeeper.UnmarshalAccount(bz[:len(bz)/2])
require.NotNil(err)
}

func (s *VestingAccountTestSuite) TestPermanentLockedAccountMarshal() {
app := s.app
require := s.Require()
baseAcc, coins := initBaseAccount()
acc := types.NewPermanentLockedAccount(baseAcc, coins)

bz, err := app.AccountKeeper.MarshalAccount(acc)
bz, err := s.accountKeeper.MarshalAccount(acc)
require.Nil(err)

acc2, err := app.AccountKeeper.UnmarshalAccount(bz)
acc2, err := s.accountKeeper.UnmarshalAccount(bz)
require.Nil(err)
require.IsType(&types.PermanentLockedAccount{}, acc2)
require.Equal(acc.String(), acc2.String())

// error on bad bytes
_, err = app.AccountKeeper.UnmarshalAccount(bz[:len(bz)/2])
_, err = s.accountKeeper.UnmarshalAccount(bz[:len(bz)/2])
require.NotNil(err)
}

Expand Down
3 changes: 3 additions & 0 deletions x/nft/client/testutil/cli_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build norace
// +build norace

package testutil

import (
Expand Down

0 comments on commit 7580b1c

Please sign in to comment.