Skip to content

Commit

Permalink
Update to SDK v0.40.0 (#219)
Browse files Browse the repository at this point in the history
* Update to SDK v0.40.0

* Fix test

* Update app/app.go

Co-authored-by: Robert Zaremba <[email protected]>

Co-authored-by: Robert Zaremba <[email protected]>
  • Loading branch information
amaury1093 and robert-zaremba authored Jan 14, 2021
1 parent 21a1d3e commit 98b2e63
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 87 deletions.
24 changes: 15 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

baseapp "github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
Expand Down Expand Up @@ -206,9 +207,9 @@ type RegenApp struct {
func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool,
homePath string, invCheckPeriod uint, encodingConfig simappparams.EncodingConfig, baseAppOptions ...func(*baseapp.BaseApp)) *RegenApp {

// TODO: Remove cdc in favor of appCodec once all modules are migrated.
// TODO: Remove cdc legacyAmino in favor of appCodec once all modules are migrated.
appCodec := encodingConfig.Marshaler
cdc := encodingConfig.Amino
legacyAmino := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry

bApp := baseapp.NewBaseApp(appName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
Expand All @@ -229,7 +230,7 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest

var app = &RegenApp{
BaseApp: bApp,
cdc: cdc,
cdc: legacyAmino,
appCodec: appCodec,
interfaceRegistry: interfaceRegistry,
invCheckPeriod: invCheckPeriod,
Expand All @@ -238,8 +239,7 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
memKeys: memKeys,
}

// init params keeper and subspaces
app.ParamsKeeper = initParamsKeeper(appCodec, cdc, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])
app.ParamsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])

// set the BaseApp's parameter store
bApp.SetParamStore(app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramskeeper.ConsensusParamsKeyTable()))
Expand Down Expand Up @@ -287,7 +287,7 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest

// Create IBC Keeper
app.IBCKeeper = ibckeeper.NewKeeper(
appCodec, keys[ibchost.StoreKey], app.StakingKeeper, scopedIBCKeeper,
appCodec, keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName), app.StakingKeeper, scopedIBCKeeper,
)

// register the proposal types
Expand Down Expand Up @@ -387,7 +387,7 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
ibc.NewAppModule(app.IBCKeeper),
params.NewAppModule(app.ParamsKeeper),
transferModule,
wasm.NewAppModule(app.wasmKeeper),
wasm.NewAppModule(&app.wasmKeeper),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand Down Expand Up @@ -433,7 +433,7 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
evidence.NewAppModule(app.EvidenceKeeper),
ibc.NewAppModule(app.IBCKeeper),
transferModule,
wasm.NewAppModule(app.wasmKeeper),
wasm.NewAppModule(&app.wasmKeeper),
)

app.sm.RegisterStoreDecoders()
Expand Down Expand Up @@ -597,7 +597,7 @@ func (app *RegenApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIC
authrest.RegisterTxRoutes(clientCtx, apiSvr.Router)

ModuleBasics.RegisterRESTRoutes(clientCtx, apiSvr.Router)
ModuleBasics.RegisterGRPCGatewayRoutes(apiSvr.ClientCtx, apiSvr.GRPCRouter)
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// register swagger API from root so that other applications can override easily
if apiConfig.Swagger {
Expand All @@ -610,6 +610,11 @@ func (app *RegenApp) RegisterTxService(clientCtx client.Context) {
tx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry)
}

// RegisterTendermintService implements the Application.RegisterTendermintService method.
func (app *RegenApp) RegisterTendermintService(clientCtx client.Context) {
tmservice.RegisterTendermintService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.interfaceRegistry)
}

// RegisterSwaggerAPI registers swagger route with API Server
func RegisterSwaggerAPI(ctx client.Context, rtr *mux.Router) {
statikFS, err := fs.New()
Expand Down Expand Up @@ -643,6 +648,7 @@ func initParamsKeeper(appCodec codec.BinaryMarshaler, legacyAmino *codec.LegacyA
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(wasm.ModuleName)

return paramsKeeper
Expand Down
37 changes: 16 additions & 21 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,40 @@ import (
"testing"

"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
db "github.com/tendermint/tm-db"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"
)

func TestRegenExport(t *testing.T) {
db := db.NewMemDB()
func TestSimAppExportAndBlockedAddrs(t *testing.T) {
encCfg := MakeEncodingConfig()
db := dbm.NewMemDB()
app := NewRegenApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg)

for acc := range maccPerms {
require.Equal(t, !allowedReceivingModAcc[acc], app.BankKeeper.BlockedAddr(app.AccountKeeper.GetModuleAddress(acc)),
"ensure that blocked addresses are properly set in bank keeper")
}

regenApp := NewRegenApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig())
genesisState := NewDefaultGenesisState()
genesisState := NewDefaultGenesisState(encCfg.Marshaler)
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
require.NoError(t, err)

// Initialize the chain
regenApp.InitChain(
app.InitChain(
abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
AppStateBytes: stateBytes,
},
)
regenApp.Commit()
app.Commit()

// Making a new app object with the db, so that initchain hasn't been called
newRegenApp := NewRegenApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig())
_, err = newRegenApp.ExportAppStateAndValidators(false, []string{})
app2 := NewRegenApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg)
_, err = app2.ExportAppStateAndValidators(false, []string{})
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
}

// ensure that blocked addresses are properly set in bank keeper
func TestBlockedAddrs(t *testing.T) {
db := db.NewMemDB()
app := NewRegenApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig())

for acc := range maccPerms {
require.Equal(t, !allowedReceivingModAcc[acc], app.BankKeeper.BlockedAddr(app.AccountKeeper.GetModuleAddress(acc)))
}
}

func TestGetMaccPerms(t *testing.T) {
dup := GetMaccPerms()
require.Equal(t, maccPerms, dup, "duplicated module account permissions differed from actual module account permissions")
Expand Down
9 changes: 5 additions & 4 deletions app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package app

import (
"encoding/json"

"github.com/cosmos/cosmos-sdk/codec"
)

// The genesis state of the blockchain is represented here as a map of raw json
Expand All @@ -14,8 +16,7 @@ import (
// object provided to it during init.
type GenesisState map[string]json.RawMessage

// NewDefaultGenesisState generates the default state for regen.
func NewDefaultGenesisState() GenesisState {
encCfg := MakeEncodingConfig()
return ModuleBasics.DefaultGenesis(encCfg.Marshaler)
// NewDefaultGenesisState generates the default state for the application.
func NewDefaultGenesisState(cdc codec.JSONMarshaler) GenesisState {
return ModuleBasics.DefaultGenesis(cdc)
}
4 changes: 2 additions & 2 deletions app/regen/cmd/genaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
addr = info.GetAddress()
}

coins, err := sdk.ParseCoins(args[1])
coins, err := sdk.ParseCoinsNormalized(args[1])
if err != nil {
return fmt.Errorf("failed to parse coins: %w", err)
}
Expand All @@ -76,7 +76,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
vestingEnd, _ := cmd.Flags().GetInt64(flagVestingEnd)
vestingAmtStr, _ := cmd.Flags().GetString(flagVestingAmt)

vestingAmt, err := sdk.ParseCoins(vestingAmtStr)
vestingAmt, err := sdk.ParseCoinsNormalized(vestingAmtStr)
if err != nil {
return fmt.Errorf("failed to parse vesting amount: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion app/regen/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
genutilcli.MigrateGenesisCmd(),
genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
genutilcli.ValidateGenesisCmd(app.ModuleBasics, encodingConfig.TxConfig),
genutilcli.ValidateGenesisCmd(app.ModuleBasics),
AddGenesisAccountCmd(app.DefaultNodeHome),
tmcli.NewCompletionCmd(rootCmd, true),
debug.Cmd(),
Expand Down
17 changes: 7 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,26 @@ module github.com/regen-network/regen-ledger
go 1.15

require (
github.com/CosmWasm/wasmd v0.12.0-alpha1.0.20201105090402-41cf73dae976
github.com/CosmWasm/wasmd v0.14.0
github.com/btcsuite/btcutil v1.0.2
github.com/cockroachdb/apd/v2 v2.0.2
github.com/cosmos/cosmos-sdk v0.40.0-rc2
github.com/cosmos/cosmos-sdk v0.40.0
github.com/enigmampc/btcutil v1.0.3-0.20200723161021-e2fb6adb2a25
github.com/gogo/protobuf v1.3.1
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.15.2
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/ipfs/go-cid v0.0.7
github.com/lib/pq v1.8.0 // indirect
github.com/multiformats/go-multihash v0.0.14
github.com/rakyll/statik v0.1.7
github.com/spf13/afero v1.3.4 // indirect
github.com/spf13/cast v1.3.1
github.com/spf13/cobra v1.1.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.6.1
github.com/tendermint/tendermint v0.34.0-rc5
github.com/tendermint/tm-db v0.6.2
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c // indirect
google.golang.org/genproto v0.0.0-20201204160425-06b3db808446 // indirect
google.golang.org/grpc v1.33.0
gopkg.in/yaml.v2 v2.3.0
github.com/tendermint/tendermint v0.34.1
github.com/tendermint/tm-db v0.6.3
google.golang.org/grpc v1.34.0
gopkg.in/yaml.v2 v2.4.0
)

replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.4
Loading

0 comments on commit 98b2e63

Please sign in to comment.