Skip to content

Commit

Permalink
chore: fix misc lints from v0.27 branch (backport #2049) (#2051)
Browse files Browse the repository at this point in the history
* chore: fix misc lints from v0.27 branch (#2049)

(cherry picked from commit 4af6545)

* chore: fix broken lints in upgrade handler

---------

Co-authored-by: Robert Pirtle <[email protected]>
  • Loading branch information
mergify[bot] and pirtleshell authored Nov 4, 2024
1 parent 63c630e commit a468e21
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 17 deletions.
20 changes: 20 additions & 0 deletions .github/mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pull_request_rules:
- release/v0.24.x
- release/v0.25.x
- release/v0.26.x
- release/v0.26.x-iavl-v1
- release/v0.27.x

- name: Backport patches to the release/v0.17.x branch
conditions:
Expand Down Expand Up @@ -99,3 +101,21 @@ pull_request_rules:
backport:
branches:
- release/v0.26.x

- name: Backport patches to the release/v0.26.x-iavl-v1 branch
conditions:
- base=master
- label=A:backport/v0.26.x-iavl-v1
actions:
backport:
branches:
- release/v0.26.x-iavl-v1

- name: Backport patches to the release/v0.27.x branch
conditions:
- base=master
- label=A:backport/v0.27.x
actions:
backport:
branches:
- release/v0.27.x
19 changes: 10 additions & 9 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,36 @@ package app
import (
"fmt"

errorsmod "cosmossdk.io/errors"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

const (
UpgradeName_Mainnet = "v0.27.0"
UpgradeName_Testnet = "v0.27.0-alpha.0"
UpgradeNameMainnet = "v0.27.0"
UpgradeNameTestnet = "v0.27.0-alpha.0"
)

// RegisterUpgradeHandlers registers the upgrade handlers for the app.
func (app App) RegisterUpgradeHandlers() {
app.upgradeKeeper.SetUpgradeHandler(
UpgradeName_Mainnet,
upgradeHandler(app, UpgradeName_Mainnet),
UpgradeNameMainnet,
upgradeHandler(app, UpgradeNameMainnet),
)
app.upgradeKeeper.SetUpgradeHandler(
UpgradeName_Testnet,
upgradeHandler(app, UpgradeName_Testnet),
UpgradeNameTestnet,
upgradeHandler(app, UpgradeNameTestnet),
)

upgradeInfo, err := app.upgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
}

doUpgrade := upgradeInfo.Name == UpgradeName_Mainnet ||
upgradeInfo.Name == UpgradeName_Testnet
doUpgrade := upgradeInfo.Name == UpgradeNameMainnet ||
upgradeInfo.Name == UpgradeNameTestnet

if doUpgrade && !app.upgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{}
Expand All @@ -57,7 +58,7 @@ func upgradeHandler(
// run migrations for all modules and return new consensus version map
versionMap, err := app.mm.RunMigrations(ctx, app.configurator, fromVM)
if err != nil {
return nil, err
return nil, errorsmod.Wrap(err, "failed to run migrations")
}

logger.Info("completed store migrations")
Expand Down
12 changes: 10 additions & 2 deletions tests/util/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"github.com/ethereum/go-ethereum/common"
)

const (
MnemonicEntropyBits = 128
)

func SdkToEvmAddress(addr sdk.AccAddress) common.Address {
return common.BytesToAddress(addr.Bytes())
}
Expand All @@ -17,9 +21,13 @@ func EvmToSdkAddress(addr common.Address) sdk.AccAddress {

// RandomMnemonic generates a random BIP39 mnemonic from 128 bits of entropy
func RandomMnemonic() (string, error) {
entropy, err := bip39.NewEntropy(128)
entropy, err := bip39.NewEntropy(MnemonicEntropyBits)
if err != nil {
return "", errorsmod.Wrap(err, "failed to generate entropy for new mnemonic")
}
return bip39.NewMnemonic(entropy)
mnemonic, err := bip39.NewMnemonic(entropy)
if err != nil {
return mnemonic, errorsmod.Wrap(err, "failed to create mnemonic")
}
return mnemonic, nil
}
9 changes: 5 additions & 4 deletions tests/util/evmsigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/evmos/ethermint/crypto/ethsecp256k1"
etherminttypes "github.com/evmos/ethermint/types"
)

var (
Expand Down Expand Up @@ -81,19 +82,19 @@ func NewEvmSigner(
}, nil
}

func NewEvmSignerFromMnemonic(evmClient *ethclient.Client, evmChainId *big.Int, mnemonic string) (*EvmSigner, error) {
hdPath := hd.CreateHDPath(60, 0, 0)
func NewEvmSignerFromMnemonic(evmClient *ethclient.Client, evmChainID *big.Int, mnemonic string) (*EvmSigner, error) {
hdPath := hd.CreateHDPath(etherminttypes.Bip44CoinType, 0, 0)
privKeyBytes, err := hd.Secp256k1.Derive()(mnemonic, "", hdPath.String())
if err != nil {
return nil, errorsmod.Wrap(err, "failed to derive private key from mnemonic")
}
privKey := &ethsecp256k1.PrivKey{Key: privKeyBytes}
ecdsaPrivKey, err := crypto.HexToECDSA(hex.EncodeToString(privKey.Bytes()))
if err != nil {
return nil, err
return nil, errorsmod.Wrap(err, "failed to convert hex to ECDSA")
}

return NewEvmSigner(evmClient, ecdsaPrivKey, evmChainId)
return NewEvmSigner(evmClient, ecdsaPrivKey, evmChainID)
}

func (s *EvmSigner) Run(requests <-chan EvmTxRequest) <-chan EvmTxResponse {
Expand Down
4 changes: 2 additions & 2 deletions x/hard/keeper/borrow_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
//nolint:lll // these tests have some long lines :D
package keeper_test

import (
"time"

"github.com/kava-labs/kava/x/hard/keeper"

sdkmath "cosmossdk.io/math"
"github.com/cometbft/cometbft/crypto"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmtime "github.com/cometbft/cometbft/types/time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/kava-labs/kava/app"
"github.com/kava-labs/kava/x/hard"
"github.com/kava-labs/kava/x/hard/keeper"
"github.com/kava-labs/kava/x/hard/types"
pricefeedtypes "github.com/kava-labs/kava/x/pricefeed/types"
)
Expand Down

0 comments on commit a468e21

Please sign in to comment.