Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: eliminate lsm and non-lsm version api incompatibility issues #23

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions app/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,17 +423,17 @@ func (suite AnteTestSuite) TestAnteHandler() {
return txBuilder.GetTx()
}, false, false, true,
},
{
"success- DeliverTx EIP712 edit validator",
func() sdk.Tx {
from := acc.GetAddress()
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, sdk.NewInt(20))
amount := sdk.NewCoins(coinAmount)
gas := uint64(200000)
txBuilder := suite.CreateTestEIP712MsgEditValidator(from, privKey, "ethermint_9000-1", gas, amount)
return txBuilder.GetTx()
}, false, false, true,
},
// {
// "success- DeliverTx EIP712 edit validator",
// func() sdk.Tx {
// from := acc.GetAddress()
// coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, sdk.NewInt(20))
// amount := sdk.NewCoins(coinAmount)
// gas := uint64(200000)
// txBuilder := suite.CreateTestEIP712MsgEditValidator(from, privKey, "ethermint_9000-1", gas, amount)
// return txBuilder.GetTx()
// }, false, false, true,
// },
{
"success- DeliverTx EIP712 submit evidence",
func() sdk.Tx {
Expand Down
26 changes: 15 additions & 11 deletions app/ante/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
"github.com/evmos/ethermint/app/ante"
"github.com/evmos/ethermint/encoding"
"github.com/evmos/ethermint/tests"
ethermint "github.com/evmos/ethermint/types"
"github.com/evmos/ethermint/x/evm/statedb"
evmtypes "github.com/evmos/ethermint/x/evm/types"
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
Expand Down Expand Up @@ -311,12 +312,13 @@ func (suite *AnteTestSuite) CreateTestEIP712MsgCreateValidator(from sdk.AccAddre
// Build MsgCreateValidator
valAddr := sdk.ValAddress(from.Bytes())
privEd := ed25519.GenPrivKey()
msgCreate, err := stakingtypes.NewMsgCreateValidator(
msgCreate, err := ethermint.NewMsgCreateValidator(
valAddr,
privEd.PubKey(),
sdk.NewCoin(evmtypes.DefaultEVMDenom, sdk.NewInt(20)),
stakingtypes.NewDescription("moniker", "indentity", "website", "security_contract", "details"),
stakingtypes.NewCommissionRates(sdk.OneDec(), sdk.OneDec(), sdk.OneDec()),
sdk.NewInt(0),
)
suite.Require().NoError(err)
return suite.CreateTestEIP712SingleMessageTxBuilder(priv, chainId, gas, gasAmount, msgCreate)
Expand All @@ -326,13 +328,14 @@ func (suite *AnteTestSuite) CreateTestEIP712MsgCreateValidator2(from sdk.AccAddr
// Build MsgCreateValidator
valAddr := sdk.ValAddress(from.Bytes())
privEd := ed25519.GenPrivKey()
msgCreate, err := stakingtypes.NewMsgCreateValidator(
msgCreate, err := ethermint.NewMsgCreateValidator(
valAddr,
privEd.PubKey(),
sdk.NewCoin(evmtypes.DefaultEVMDenom, sdk.NewInt(20)),
// Ensure optional fields can be left blank
stakingtypes.NewDescription("moniker", "indentity", "", "", ""),
stakingtypes.NewCommissionRates(sdk.OneDec(), sdk.OneDec(), sdk.OneDec()),
sdk.NewInt(0),
)
suite.Require().NoError(err)
return suite.CreateTestEIP712SingleMessageTxBuilder(priv, chainId, gas, gasAmount, msgCreate)
Expand Down Expand Up @@ -360,15 +363,16 @@ func (suite *AnteTestSuite) CreateTestEIP712GrantAllowance(from sdk.AccAddress,
return suite.CreateTestEIP712SingleMessageTxBuilder(priv, chainId, gas, gasAmount, msgGrant)
}

func (suite *AnteTestSuite) CreateTestEIP712MsgEditValidator(from sdk.AccAddress, priv cryptotypes.PrivKey, chainId string, gas uint64, gasAmount sdk.Coins) client.TxBuilder {
valAddr := sdk.ValAddress(from.Bytes())
msgEdit := stakingtypes.NewMsgEditValidator(
valAddr,
stakingtypes.NewDescription("moniker", "identity", "website", "security_contract", "details"),
nil,
)
return suite.CreateTestEIP712SingleMessageTxBuilder(priv, chainId, gas, gasAmount, msgEdit)
}
// func (suite *AnteTestSuite) CreateTestEIP712MsgEditValidator(from sdk.AccAddress, priv cryptotypes.PrivKey, chainId string, gas uint64, gasAmount sdk.Coins) client.TxBuilder {
// valAddr := sdk.ValAddress(from.Bytes())
// msgEdit := ethermint.NewMsgEditValidator(
// valAddr,
// stakingtypes.NewDescription("moniker", "identity", "website", "security_contract", "details"),
// nil,
// sdk.ZeroInt(),
// )
// return suite.CreateTestEIP712SingleMessageTxBuilder(priv, chainId, gas, gasAmount, msgEdit)
// }

func (suite *AnteTestSuite) CreateTestEIP712MsgSubmitEvidence(from sdk.AccAddress, priv cryptotypes.PrivKey, chainId string, gas uint64, gasAmount sdk.Coins) client.TxBuilder {
pk := ed25519.GenPrivKey()
Expand Down
3 changes: 2 additions & 1 deletion client/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,13 @@
})

valTokens := sdk.TokensFromConsensusPower(100, ethermint.PowerReduction)
createValMsg, err := stakingtypes.NewMsgCreateValidator(
createValMsg, err := ethermint.NewMsgCreateValidator(
sdk.ValAddress(addr),
valPubKeys[i],
sdk.NewCoin(ethermint.AttoPhoton, valTokens),
stakingtypes.NewDescription(nodeDirName, "", "", "", ""),
stakingtypes.NewCommissionRates(sdk.OneDec(), sdk.OneDec(), sdk.OneDec()),
sdk.ZeroInt(),
)
if err != nil {
return err
Expand Down Expand Up @@ -491,7 +492,7 @@
return err
}

nodeAppState, err := genutil.GenAppStateFromConfig(clientCtx.Codec, clientCtx.TxConfig, nodeConfig, initCfg, *genDoc, genBalIterator, gtypes.DefaultMessageValidator)

Check failure on line 495 in client/testnet.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

line is 167 characters (lll)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/cometbft/cometbft v0.37.4
github.com/cometbft/cometbft-db v0.7.0
github.com/cosmos/cosmos-proto v1.0.0-beta.4
github.com/cosmos/cosmos-sdk v0.47.9-ics-lsm
github.com/cosmos/cosmos-sdk v0.47.9
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-go/v7 v7.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ github.com/cosmos/btcutil v1.0.5 h1:t+ZFcX77LpKtDBhjucvnOH8C2l2ioGsBNEQ3jef8xFk=
github.com/cosmos/btcutil v1.0.5/go.mod h1:IyB7iuqZMJlthe2tkIFL33xPyzbFYP0XVdS8P5lUPis=
github.com/cosmos/cosmos-proto v1.0.0-beta.4 h1:aEL7tU/rLOmxZQ9z4i7mzxcLbSCY48OdY7lIWTLG7oU=
github.com/cosmos/cosmos-proto v1.0.0-beta.4/go.mod h1:oeB+FyVzG3XrQJbJng0EnV8Vljfk9XvTIpGILNU/9Co=
github.com/cosmos/cosmos-sdk v0.47.9-ics-lsm h1:IBZd1wBRSqlqrls+YzzQfR67HWBFLXyTqH6zwEsVpKU=
github.com/cosmos/cosmos-sdk v0.47.9-ics-lsm/go.mod h1:Vks1CurTEJIWcjLkXZ4hLpdXsnVRRBmBRr6tygK9vHc=
github.com/cosmos/cosmos-sdk v0.47.9 h1:D51VLkF59D53PMLsbNtp6JyWR+6MbetFyomrH88+y08=
github.com/cosmos/cosmos-sdk v0.47.9/go.mod h1:cmAawe8FV/52oPKbgeHLt4UpNkrNu8R5KD+kw0kxJFc=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
Expand Down
3 changes: 2 additions & 1 deletion testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,13 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
return nil, err
}

createValMsg, err := stakingtypes.NewMsgCreateValidator(
createValMsg, err := ethermint.NewMsgCreateValidator(
sdk.ValAddress(addr),
valPubKeys[i],
sdk.NewCoin(cfg.BondDenom, cfg.BondedTokens),
stakingtypes.NewDescription(nodeDirName, "", "", "", ""),
stakingtypes.NewCommissionRates(commission, sdk.OneDec(), sdk.OneDec()),
sdk.ZeroInt(),
)
if err != nil {
return nil, err
Expand Down
45 changes: 45 additions & 0 deletions types/chain_id.go → types/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
"strings"

errorsmod "cosmossdk.io/errors"
"cosmossdk.io/math"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

var (
Expand Down Expand Up @@ -80,3 +85,43 @@

return chainIDInt, nil
}


Check failure on line 89 in types/extensions.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

File is not `gofumpt`-ed (gofumpt)
// NewMsgCreateValidator creates a new MsgCreateValidator instance.
//
// Parameters:
// - valAddr: validator address
// - pubKey: public key
// - selfDelegation: self-delegation amount
// - description: validator description
// - commission: commission rates
// - minSelfDelegation: minimum self-delegation amount
//
// Returns:
// - *stakingtypes.MsgCreateValidator
// - error
func NewMsgCreateValidator(
valAddr sdk.ValAddress,
pubKey cryptotypes.PubKey, //nolint:interfacer
selfDelegation sdk.Coin,
description stakingtypes.Description,
commission stakingtypes.CommissionRates,
minSelfDelegation math.Int,
) (*stakingtypes.MsgCreateValidator, error) {
var pkAny *codectypes.Any
if pubKey != nil {
var err error
if pkAny, err = codectypes.NewAnyWithValue(pubKey); err != nil {
return nil, err
}
}
return &stakingtypes.MsgCreateValidator{
Description: description,
DelegatorAddress: sdk.AccAddress(valAddr).String(),
ValidatorAddress: valAddr.String(),
Pubkey: pkAny,
Value: selfDelegation,
Commission: commission,
MinSelfDelegation: minSelfDelegation,
}, nil
}
Loading