diff --git a/app/test_helpers.go b/app/test_helpers.go index 80e896cf..970f9c2b 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -170,8 +170,8 @@ func GenesisStateWithValSet(app *RealioNetwork, genesisState simapp.GenesisState CoinDenom: valMsCoin.Denom, }) - lockId := multistakingtypes.MultiStakingLockID(genAccs[0].GetAddress().String(), sdk.ValAddress(val.Address).String()) - lockRecord := multistakingtypes.NewMultiStakingLock(lockId, valMsCoin) + lockID := multistakingtypes.MultiStakingLockID(genAccs[0].GetAddress().String(), sdk.ValAddress(val.Address).String()) + lockRecord := multistakingtypes.NewMultiStakingLock(lockID, valMsCoin) locks = append(locks, lockRecord) lockCoins = lockCoins.Add(valMsCoin.ToCoin()) diff --git a/app/upgrades.go b/app/upgrades.go index f2ded4f7..577b7b68 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -20,15 +20,13 @@ func (app *RealioNetwork) setupUpgradeHandlers(appOpts servertypes.AppOptions) { appOpts, app.AppCodec(), app.BankKeeper, - app.MultiStakingKeeper, app.AccountKeeper, - app.keys, ), ) upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() if err != nil { - panic(fmt.Errorf("Failed to read upgrade info from disk: %w", err)) + panic(fmt.Errorf("failed to read upgrade info from disk: %w", err)) } if app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { @@ -37,8 +35,7 @@ func (app *RealioNetwork) setupUpgradeHandlers(appOpts servertypes.AppOptions) { var storeUpgrades *storetypes.StoreUpgrades - switch upgradeInfo.Name { - case multistaking.UpgradeName: + if upgradeInfo.Name == multistaking.UpgradeName { storeUpgrades = &storetypes.StoreUpgrades{ Added: []string{multistakingtypes.ModuleName}, } diff --git a/app/upgrades/multi-staking/types.go b/app/upgrades/multi-staking/types.go index 69c4f6f1..4ad02a2d 100644 --- a/app/upgrades/multi-staking/types.go +++ b/app/upgrades/multi-staking/types.go @@ -34,6 +34,7 @@ type Validator struct { // status is the validator status (bonded/unbonding/unbonded). Status string `protobuf:"varint,4,opt,name=status,proto3,enum=cosmos.staking.v1beta1.BondStatus" json:"status,omitempty"` // tokens define the delegated tokens (incl. self-delegation). + //nolint:staticcheck Tokens sdk.Int `protobuf:"bytes,5,opt,name=tokens,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"tokens"` // delegator_shares defines total shares issued to a validator's delegators. DelegatorShares sdk.Dec `protobuf:"bytes,6,opt,name=delegator_shares,json=delegatorShares,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"delegator_shares"` @@ -48,14 +49,16 @@ type Validator struct { // min_self_delegation is the validator's self declared minimum self delegation. // // Since: cosmos-sdk 0.46 + //nolint:staticcheck MinSelfDelegation sdk.Int `protobuf:"bytes,11,opt,name=min_self_delegation,json=minSelfDelegation,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"min_self_delegation"` } type GenesisState struct { - // params defines all the paramaters of related to deposit. + // params defines all the parameters of related to deposit. Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` // last_total_power tracks the total amounts of bonded tokens recorded during // the previous end block. + //nolint:staticcheck LastTotalPower sdk.Int `protobuf:"bytes,2,opt,name=last_total_power,json=lastTotalPower,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"last_total_power"` // last_validator_powers is a special index that provides a historical list // of the last-block's bonded validators. @@ -71,6 +74,7 @@ type GenesisState struct { Exported bool `protobuf:"varint,8,opt,name=exported,proto3" json:"exported,omitempty"` } +//nolint:revive type MultiStakingGenesisState struct { MultiStakingLocks []multistakingtypes.MultiStakingLock `protobuf:"bytes,1,rep,name=multi_staking_locks,json=multiStakingLocks,proto3" json:"multi_staking_locks"` MultiStakingUnlocks []multistakingtypes.MultiStakingUnlock `protobuf:"bytes,2,rep,name=multi_staking_unlocks,json=multiStakingUnlocks,proto3" json:"multi_staking_unlocks"` diff --git a/app/upgrades/multi-staking/upgrade.go b/app/upgrades/multi-staking/upgrade.go index 47660571..d96f41db 100644 --- a/app/upgrades/multi-staking/upgrade.go +++ b/app/upgrades/multi-staking/upgrade.go @@ -8,7 +8,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" servertypes "github.com/cosmos/cosmos-sdk/server/types" - storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -20,7 +19,6 @@ import ( authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - multistakingkeeper "github.com/realio-tech/multi-staking-module/x/multi-staking/keeper" "cosmossdk.io/math" multistakingtypes "github.com/realio-tech/multi-staking-module/x/multi-staking/types" @@ -43,9 +41,7 @@ func CreateUpgradeHandler( appOpts servertypes.AppOptions, cdc codec.Codec, bk bankkeeper.Keeper, - msk multistakingkeeper.Keeper, ak authkeeper.AccountKeeper, - keys map[string]*storetypes.KVStoreKey, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { ctx.Logger().Info("Starting upgrade for multi staking...") @@ -94,15 +90,24 @@ func migrateBank(ctx sdk.Context, bk bankkeeper.Keeper) { func convertStakingModulePoolBalances(ctx sdk.Context, bk bankkeeper.Keeper, accAddr sdk.AccAddress) { // Send coins from accAddr add same amout to multistaking account accountBalances := bk.GetAllBalances(ctx, accAddr) - bk.SendCoins(ctx, accAddr, multiStakingAddress, accountBalances) + err := bk.SendCoins(ctx, accAddr, multiStakingAddress, accountBalances) + if err != nil { + panic(err) + } // mint stake to bonded pool convertedCoinsAmount := math.ZeroInt() for _, coinAmount := range accountBalances { convertedCoinsAmount = convertedCoinsAmount.Add(coinAmount.Amount) } amount := sdk.NewCoins(sdk.NewCoin(newBondedCoinDenom, convertedCoinsAmount)) - bk.MintCoins(ctx, minttypes.ModuleName, amount) - bk.SendCoins(ctx, mintModuleAddress, accAddr, amount) + err = bk.MintCoins(ctx, minttypes.ModuleName, amount) + if err != nil { + panic(err) + } + err = bk.SendCoins(ctx, mintModuleAddress, accAddr, amount) + if err != nil { + panic(err) + } } func migrateMultiStaking(appState map[string]json.RawMessage) (map[string]json.RawMessage, error) { @@ -164,7 +169,6 @@ func migrateMultiStaking(appState map[string]json.RawMessage) (map[string]json.R } newState.MultiStakingLocks = append(newState.MultiStakingLocks, lock) } - } } diff --git a/x/mint/keeper/keeper_test.go b/x/mint/keeper/keeper_test.go index c61530d6..ed476e94 100644 --- a/x/mint/keeper/keeper_test.go +++ b/x/mint/keeper/keeper_test.go @@ -17,11 +17,11 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" + "cosmossdk.io/math" "github.com/realiotech/realio-network/app" realiotypes "github.com/realiotech/realio-network/types" "github.com/realiotech/realio-network/x/mint/types" abci "github.com/tendermint/tendermint/abci/types" - "cosmossdk.io/math" ) type KeeperTestSuite struct { @@ -102,7 +102,7 @@ func (suite *KeeperTestSuite) TestMintedCoinsEachBlock() { // block 1 vs block 2 currentSupply := suite.app.BankKeeper.GetSupply(suite.ctx, params.MintDenom).Amount - annualProvisions := minter.Inflation.MulInt(rioSupplyCap.Sub(currentSupply)) + annualProvisions := minter.Inflation.MulInt(rioSupplyCap.Sub(currentSupply)) blockProvision := annualProvisions.QuoInt(math.NewInt(int64(params.BlocksPerYear))).TruncateInt() currentHeight := suite.app.LastBlockHeight() @@ -117,7 +117,7 @@ func (suite *KeeperTestSuite) TestMintedCoinsEachBlock() { // block 2 vs block 3 currentSupply = suite.app.BankKeeper.GetSupply(suite.ctx, params.MintDenom).Amount - annualProvisions = minter.Inflation.MulInt(rioSupplyCap.Sub(currentSupply)) + annualProvisions = minter.Inflation.MulInt(rioSupplyCap.Sub(currentSupply)) blockProvision = annualProvisions.QuoInt(math.NewInt(int64(params.BlocksPerYear))).TruncateInt() currentHeight = suite.app.LastBlockHeight() @@ -132,7 +132,7 @@ func (suite *KeeperTestSuite) TestMintedCoinsEachBlock() { // block 3 vs block 4 currentSupply = suite.app.BankKeeper.GetSupply(suite.ctx, params.MintDenom).Amount - annualProvisions = minter.Inflation.MulInt(rioSupplyCap.Sub(currentSupply)) + annualProvisions = minter.Inflation.MulInt(rioSupplyCap.Sub(currentSupply)) blockProvision = annualProvisions.QuoInt(math.NewInt(int64(params.BlocksPerYear))).TruncateInt() currentHeight = suite.app.LastBlockHeight() @@ -147,7 +147,7 @@ func (suite *KeeperTestSuite) TestMintedCoinsEachBlock() { // block 4 vs block 5 currentSupply = suite.app.BankKeeper.GetSupply(suite.ctx, params.MintDenom).Amount - annualProvisions = minter.Inflation.MulInt(rioSupplyCap.Sub(currentSupply)) + annualProvisions = minter.Inflation.MulInt(rioSupplyCap.Sub(currentSupply)) blockProvision = annualProvisions.QuoInt(math.NewInt(int64(params.BlocksPerYear))).TruncateInt() currentHeight = suite.app.LastBlockHeight() @@ -162,7 +162,7 @@ func (suite *KeeperTestSuite) TestMintedCoinsEachBlock() { // block 5 vs block 6 currentSupply = suite.app.BankKeeper.GetSupply(suite.ctx, params.MintDenom).Amount - annualProvisions = minter.Inflation.MulInt(rioSupplyCap.Sub(currentSupply)) + annualProvisions = minter.Inflation.MulInt(rioSupplyCap.Sub(currentSupply)) blockProvision = annualProvisions.QuoInt(math.NewInt(int64(params.BlocksPerYear))).TruncateInt() currentHeight = suite.app.LastBlockHeight() @@ -174,4 +174,4 @@ func (suite *KeeperTestSuite) TestMintedCoinsEachBlock() { expectedMintedAmount = newSupply.Sub(currentSupply).String() calculatedMintedAmount = blockProvision.String() suite.Require().Equal(expectedMintedAmount, calculatedMintedAmount) -} \ No newline at end of file +}