diff --git a/CHANGELOG.md b/CHANGELOG.md index 4abe6a0ea2..a3bce3ee13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,7 +54,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ - (community) [#1729] Consolidate community funds from `x/distribution` and `x/kavadist` to `x/community` - (community) [#1752] Set `x/distribution` CommunityTax to zero on inflation disable upgrade - (community) [#1755] Keep funds in `x/community` in `CommunityPoolLendWithdrawProposal` handler - +- (staking) [#1761] Set validator minimum commission to 5% for all validators under 5% ## [v0.24.1](https://github.com/Kava-Labs/kava/releases/tag/v0.24.1) @@ -303,6 +303,7 @@ the [changelog](https://github.com/cosmos/cosmos-sdk/blob/v0.38.4/CHANGELOG.md). large-scale simulations remotely using aws-batch [#1755]: https://github.com/Kava-Labs/kava/pull/1755 +[#1761]: https://github.com/Kava-Labs/kava/pull/1761 [#1752]: https://github.com/Kava-Labs/kava/pull/1752 [#1751]: https://github.com/Kava-Labs/kava/pull/1751 [#1745]: https://github.com/Kava-Labs/kava/pull/1745 diff --git a/tests/e2e/.env.live-network-example b/tests/e2e/.env.live-network-example index 7b8fe24714..273f3d8977 100644 --- a/tests/e2e/.env.live-network-example +++ b/tests/e2e/.env.live-network-example @@ -20,4 +20,5 @@ E2E_INCLUDE_IBC_TESTS=false # - the evmutil params must support conversion & deposits to mint in eip712 messages # # These requirements are verified on test startup in ./testutil/init_evm.go -E2E_KAVA_ERC20_ADDRESS=0xeA7100edA2f805356291B0E55DaD448599a72C6d +# This address is a USDT contract +E2E_KAVA_ERC20_ADDRESS=0x919c1c267bc06a7039e03fcc2ef738525769109c diff --git a/tests/e2e/e2e_community_update_params_test.go b/tests/e2e/e2e_community_update_params_test.go index 5990fe1465..98a3c80f3e 100644 --- a/tests/e2e/e2e_community_update_params_test.go +++ b/tests/e2e/e2e_community_update_params_test.go @@ -72,15 +72,38 @@ func (suite *IntegrationTestSuite) TestCommunityUpdateParams_Authority() { gasLimit := int64(2e5) fee := ukava(200) - upgradeTime := time.Now().Add(24 * time.Hour).UTC() + // Wait until switchover actually happens - When testing without the upgrade + // handler that sets a relative switchover time, the switchover time in + // genesis should be set in the past so it runs immediately. + suite.Require().Eventually( + func() bool { + params, err := suite.Kava.Community.Params( + context.Background(), + &communitytypes.QueryParamsRequest{}, + ) + suite.Require().NoError(err) + + return params.Params.UpgradeTimeDisableInflation.Equal(time.Time{}) + }, + 20*time.Second, + 1*time.Second, + "switchover should happen", + ) + + // Add 1 to the staking rewards per second + newStakingRewardsPerSecond := communityParamsResInitial.Params. + StakingRewardsPerSecond. + Add(sdkmath.LegacyNewDec(1)) // 1. Proposal + // Only modify stakingRewardsPerSecond, as to not re-run the switchover and + // to not influence other tests updateParamsMsg := communitytypes.NewMsgUpdateParams( authtypes.NewModuleAddress(govtypes.ModuleName), // authority communitytypes.NewParams( - upgradeTime, - sdkmath.LegacyNewDec(1111), // stakingRewardsPerSecond - sdkmath.LegacyNewDec(2222), // upgradeTimeSetstakingRewardsPerSecond + time.Time{}, // after switchover, is empty + newStakingRewardsPerSecond, // only modify stakingRewardsPerSecond + communityParamsResInitial.Params.UpgradeTimeSetStakingRewardsPerSecond, ), ) diff --git a/tests/e2e/e2e_convert_cosmos_coins_test.go b/tests/e2e/e2e_convert_cosmos_coins_test.go index fc88bc14b4..e7f86dbb64 100644 --- a/tests/e2e/e2e_convert_cosmos_coins_test.go +++ b/tests/e2e/e2e_convert_cosmos_coins_test.go @@ -198,8 +198,8 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() { suite.NoError(err) suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code) - _, err = util.WaitForSdkTxCommit(suite.Kava.Tx, res.TxResponse.TxHash, 6*time.Second) - suite.NoError(err) + _, err = util.WaitForSdkTxCommit(suite.Kava.Tx, res.TxResponse.TxHash, 12*time.Second) + suite.Require().NoError(err) // query for the deployed contract deployedContracts, err := suite.Kava.Evmutil.DeployedCosmosCoinContracts( @@ -394,7 +394,7 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() { Data: "bob transfers alice's funds, allowed because he's approved", } res = bob.SignAndBroadcastEvmTx(transferJustRightTx) - suite.NoError(res.Err) + suite.Require().NoError(res.Err) // alice should have amount deducted erc20Balance := suite.Kava.GetErc20Balance(contractAddress.Address, alice.EvmAddress) diff --git a/tests/e2e/e2e_min_fees_test.go b/tests/e2e/e2e_min_fees_test.go index cfde3836f9..0ff51ce8a2 100644 --- a/tests/e2e/e2e_min_fees_test.go +++ b/tests/e2e/e2e_min_fees_test.go @@ -17,8 +17,10 @@ import ( ) func (suite *IntegrationTestSuite) TestEthGasPriceReturnsMinFee() { + suite.SkipIfKvtoolDisabled() + // read expected min fee from app.toml - minGasPrices, err := getMinFeeFromAppToml(suite.KavaHomePath()) + minGasPrices, err := getMinFeeFromAppToml(util.KavaHomePath()) suite.NoError(err) // evm uses akava, get akava min fee @@ -32,12 +34,14 @@ func (suite *IntegrationTestSuite) TestEthGasPriceReturnsMinFee() { } func (suite *IntegrationTestSuite) TestEvmRespectsMinFee() { + suite.SkipIfKvtoolDisabled() + // setup sender & receiver sender := suite.Kava.NewFundedAccount("evm-min-fee-test-sender", sdk.NewCoins(ukava(1e3))) randoReceiver := util.SdkToEvmAddress(app.RandomAddress()) // get min gas price for evm (from app.toml) - minFees, err := getMinFeeFromAppToml(suite.KavaHomePath()) + minFees, err := getMinFeeFromAppToml(util.KavaHomePath()) suite.NoError(err) minGasPrice := minFees.AmountOf("akava").TruncateInt() diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 06d2b83880..8663b294bb 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -41,7 +41,7 @@ func TestIntegrationTestSuite(t *testing.T) { // example test that queries kava via SDK and EVM func (suite *IntegrationTestSuite) TestChainID() { - expectedEvmNetworkId, err := emtypes.ParseChainID(suite.Kava.ChainId) + expectedEvmNetworkId, err := emtypes.ParseChainID(suite.Kava.ChainID) suite.NoError(err) // EVM query @@ -52,7 +52,7 @@ func (suite *IntegrationTestSuite) TestChainID() { // SDK query nodeInfo, err := suite.Kava.Tm.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{}) suite.NoError(err) - suite.Equal(suite.Kava.ChainId, nodeInfo.DefaultNodeInfo.Network) + suite.Equal(suite.Kava.ChainID, nodeInfo.DefaultNodeInfo.Network) } // example test that funds a new account & queries its balance @@ -99,7 +99,7 @@ func (suite *IntegrationTestSuite) TestTransferOverEVM() { Data: "any ol' data to track this through the system", } res := acc.SignAndBroadcastEvmTx(req) - suite.NoError(res.Err) + suite.Require().NoError(res.Err) suite.Equal(ethtypes.ReceiptStatusSuccessful, res.Receipt.Status) // evm txs refund unused gas. so to know the expected balance we need to know how much gas was used. diff --git a/tests/e2e/kvtool b/tests/e2e/kvtool index 6184dc56e9..e1085562d2 160000 --- a/tests/e2e/kvtool +++ b/tests/e2e/kvtool @@ -1 +1 @@ -Subproject commit 6184dc56e9b8ee94a2fe9a1e0c165d6c1129fa42 +Subproject commit e1085562d203fd81c5dd8576170b29715b2de9ef diff --git a/tests/e2e/readme.md b/tests/e2e/readme.md index 573e4d0f78..1c0c677454 100644 --- a/tests/e2e/readme.md +++ b/tests/e2e/readme.md @@ -27,12 +27,17 @@ The end-to-end tests support being run on a live network. The primary toggle for * `E2E_KAVA_RPC_URL` * `E2E_KAVA_GRPC_URL` * `E2E_KAVA_EVM_RPC_URL` +* `E2E_KAVA_UPGRADE_HEIGHT` - the height at which an existing upgrade was run See an example environment configuration with full description of all supported configurations in [`.env.live-network-example`](./.env.live-network-example). This example expects a local kvtool network to be running: `kvtool testnet bootstrap`. When run against a live network, the suite will automatically return all the sdk funds sent to `SigningAccount`s on the chain, and will return any ERC20 balance from those accounts if the ERC20 is registered via `Chain.RegisterERC20`. The pre-deployed ERC20 that is required for the tests is registered on setup. -At this time, live-network tests do not support `E2E_INCLUDE_IBC_TESTS=true` and they do not support automated upgrades. +At this time, live-network tests do not support `E2E_INCLUDE_IBC_TESTS=true`. + +`E2E_KAVA_UPGRADE_HEIGHT` is supported for an existing upgrade height, and can +be used to verify before / after upgrade state. This doesn't run automatically +any upgrades. ## `Chain`s diff --git a/tests/e2e/runner/chain.go b/tests/e2e/runner/chain.go index 2dcffa16ba..94f8ac9823 100644 --- a/tests/e2e/runner/chain.go +++ b/tests/e2e/runner/chain.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/ethereum/go-ethereum/ethclient" + rpchttpclient "github.com/tendermint/tendermint/rpc/client/http" "google.golang.org/grpc" "github.com/kava-labs/kava/tests/util" @@ -34,6 +35,11 @@ func (c ChainDetails) GrpcConn() (*grpc.ClientConn, error) { return util.NewGrpcConnection(c.GrpcUrl) } +// RpcConn creates a new connection to the underlying Rpc url. +func (c ChainDetails) RpcConn() (*rpchttpclient.HTTP, error) { + return rpchttpclient.New(c.RpcUrl, "/websocket") +} + // Chains wraps a map of name -> details about how to connect to a chain. // It prevents registering multiple chains with the same name & encapsulates // panicking if attempting to access a chain that does not exist. diff --git a/tests/e2e/runner/live.go b/tests/e2e/runner/live.go index 317deb58ed..87134f427d 100644 --- a/tests/e2e/runner/live.go +++ b/tests/e2e/runner/live.go @@ -14,6 +14,8 @@ type LiveNodeRunnerConfig struct { KavaRpcUrl string KavaGrpcUrl string KavaEvmRpcUrl string + + UpgradeHeight int64 } // LiveNodeRunner implements NodeRunner for an already-running chain. diff --git a/tests/e2e/testutil/account.go b/tests/e2e/testutil/account.go index 19b5b7fbb8..487a6bdc78 100644 --- a/tests/e2e/testutil/account.go +++ b/tests/e2e/testutil/account.go @@ -14,6 +14,7 @@ import ( sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/types" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/go-bip39" @@ -37,7 +38,7 @@ type SigningAccount struct { name string mnemonic string - evmPrivKey *ethsecp256k1.PrivKey + evmPrivKey cryptotypes.PrivKey evmSigner *util.EvmSigner evmReqChan chan<- util.EvmTxRequest evmResChan <-chan util.EvmTxResponse @@ -76,6 +77,27 @@ func (chain *Chain) AddNewSigningAccount(name string, hdPath *hd.BIP44Params, ch require.NoErrorf(chain.t, err, "failed to derive private key from mnemonic for %s: %s", name, err) privKey := ðsecp256k1.PrivKey{Key: privKeyBytes} + return chain.AddNewSigningAccountFromPrivKey( + name, + privKey, + mnemonic, + chainId, + ) +} + +// AddNewSigningAccountFromPrivKey sets up a new account with a signer for SDK and EVM transactions, +// using the given private key. +func (chain *Chain) AddNewSigningAccountFromPrivKey( + name string, + privKey cryptotypes.PrivKey, + mnemonic string, // optional + chainId string, +) *SigningAccount { + if _, found := chain.accounts[name]; found { + chain.t.Fatalf("account with name %s already exists", name) + } + + // Kava signing account for SDK side kavaSigner := util.NewKavaSigner( chainId, chain.EncodingConfig, @@ -92,7 +114,7 @@ func (chain *Chain) AddNewSigningAccount(name string, hdPath *hd.BIP44Params, ch // Kava signing account for EVM side evmChainId, err := emtypes.ParseChainID(chainId) require.NoErrorf(chain.t, err, "unable to parse ethermint-compatible chain id from %s", chainId) - ecdsaPrivKey, err := crypto.HexToECDSA(hex.EncodeToString(privKeyBytes)) + ecdsaPrivKey, err := crypto.HexToECDSA(hex.EncodeToString(privKey.Bytes())) require.NoError(chain.t, err, "failed to generate ECDSA private key from bytes") evmSigner, err := util.NewEvmSigner( @@ -201,7 +223,7 @@ func (chain *Chain) NewFundedAccount(name string, funds sdk.Coins) *SigningAccou acc := chain.AddNewSigningAccount( name, hd.CreateHDPath(app.Bip44CoinType, 0, 0), - chain.ChainId, + chain.ChainID, mnemonic, ) diff --git a/tests/e2e/testutil/chain.go b/tests/e2e/testutil/chain.go index 7a9e5d8fc3..7636fc9c88 100644 --- a/tests/e2e/testutil/chain.go +++ b/tests/e2e/testutil/chain.go @@ -10,12 +10,19 @@ import ( "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" "github.com/cosmos/cosmos-sdk/crypto/hd" + "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" txtypes "github.com/cosmos/cosmos-sdk/types/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" govv1types "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + evmhd "github.com/evmos/ethermint/crypto/hd" + tmclient "github.com/tendermint/tendermint/rpc/client" + coretypes "github.com/tendermint/tendermint/rpc/core/types" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" @@ -32,6 +39,7 @@ import ( communitytypes "github.com/kava-labs/kava/x/community/types" earntypes "github.com/kava-labs/kava/x/earn/types" evmutiltypes "github.com/kava-labs/kava/x/evmutil/types" + kavadisttypes "github.com/kava-labs/kava/x/kavadist/types" ) // Chain wraps query clients & accounts for a network @@ -40,7 +48,8 @@ type Chain struct { t *testing.T StakingDenom string - ChainId string + ChainID string + Keyring keyring.Keyring EvmClient *ethclient.Client ContractAddrs map[string]common.Address @@ -48,18 +57,24 @@ type Chain struct { EncodingConfig kavaparams.EncodingConfig - Auth authtypes.QueryClient - Bank banktypes.QueryClient - Cdp cdptypes.QueryClient - Committee committeetypes.QueryClient - Community communitytypes.QueryClient - Earn earntypes.QueryClient - Evm evmtypes.QueryClient - Evmutil evmutiltypes.QueryClient - Gov govv1types.QueryClient - Tm tmservice.ServiceClient - Tx txtypes.ServiceClient - Upgrade upgradetypes.QueryClient + Auth authtypes.QueryClient + Bank banktypes.QueryClient + Cdp cdptypes.QueryClient + Committee committeetypes.QueryClient + Community communitytypes.QueryClient + Distribution distrtypes.QueryClient + Kavadist kavadisttypes.QueryClient + Earn earntypes.QueryClient + Evm evmtypes.QueryClient + Evmutil evmutiltypes.QueryClient + Gov govv1types.QueryClient + Mint minttypes.QueryClient + Staking stakingtypes.QueryClient + Tm tmservice.ServiceClient + Tx txtypes.ServiceClient + Upgrade upgradetypes.QueryClient + + TmSignClient tmclient.SignClient } // NewChain creates the query clients & signing account management for a chain run on a set of ports. @@ -69,12 +84,26 @@ func NewChain(t *testing.T, details *runner.ChainDetails, fundedAccountMnemonic chain := &Chain{ t: t, StakingDenom: details.StakingDenom, - ChainId: details.ChainId, + ChainID: details.ChainId, ContractAddrs: make(map[string]common.Address), erc20s: make(map[common.Address]struct{}), } chain.EncodingConfig = app.MakeEncodingConfig() + // setup keyring + kr, err := keyring.New( + sdk.KeyringServiceName(), + keyring.BackendTest, + util.KavaHomePath(), + nil, + chain.EncodingConfig.Marshaler, + evmhd.EthSecp256k1Option(), + ) + if err != nil { + return nil, err + } + chain.Keyring = kr + grpcConn, err := details.GrpcConn() if err != nil { return chain, err @@ -85,15 +114,24 @@ func NewChain(t *testing.T, details *runner.ChainDetails, fundedAccountMnemonic return chain, err } + chain.TmSignClient, err = details.RpcConn() + if err != nil { + return chain, err + } + chain.Auth = authtypes.NewQueryClient(grpcConn) chain.Bank = banktypes.NewQueryClient(grpcConn) chain.Cdp = cdptypes.NewQueryClient(grpcConn) chain.Committee = committeetypes.NewQueryClient(grpcConn) chain.Community = communitytypes.NewQueryClient(grpcConn) + chain.Distribution = distrtypes.NewQueryClient(grpcConn) + chain.Kavadist = kavadisttypes.NewQueryClient(grpcConn) chain.Earn = earntypes.NewQueryClient(grpcConn) chain.Evm = evmtypes.NewQueryClient(grpcConn) chain.Evmutil = evmutiltypes.NewQueryClient(grpcConn) chain.Gov = govv1types.NewQueryClient(grpcConn) + chain.Mint = minttypes.NewQueryClient(grpcConn) + chain.Staking = stakingtypes.NewQueryClient(grpcConn) chain.Tm = tmservice.NewServiceClient(grpcConn) chain.Tx = txtypes.NewServiceClient(grpcConn) chain.Upgrade = upgradetypes.NewQueryClient(grpcConn) @@ -104,12 +142,12 @@ func NewChain(t *testing.T, details *runner.ChainDetails, fundedAccountMnemonic whale := chain.AddNewSigningAccount( FundedAccountName, hd.CreateHDPath(Bip44CoinType, 0, 0), - chain.ChainId, + chain.ChainID, fundedAccountMnemonic, ) // check that funded account is actually funded. - fmt.Printf("[%s] account used for funding (%s) address: %s\n", chain.ChainId, FundedAccountName, whale.SdkAddress) + fmt.Printf("[%s] account used for funding (%s) address: %s\n", chain.ChainID, FundedAccountName, whale.SdkAddress) whaleFunds := chain.QuerySdkForBalances(whale.SdkAddress) if whaleFunds.IsZero() { chain.t.Fatal("funded account mnemonic is for account with no funds") @@ -202,3 +240,64 @@ func (chain *Chain) GetErc20Balance(contract, address common.Address) *big.Int { return new(big.Int).SetBytes(resData) } + +func (chain *Chain) GetBeginBlockEventsFromQuery( + ctx context.Context, + query string, +) (sdk.StringEvents, int64, error) { + // 1) Block search to find auction_start event and corresponding height + // https://rpc.kava.io/block_search?query=%22auction_start.auction_id=16837%22 + + blocks, err := chain.QueryBlock(ctx, query) + if err != nil { + return nil, 0, err + } + + if len(blocks) == 0 { + return nil, 0, fmt.Errorf("no blocks found") + } + + // 2) Block results to query events from height + // https://rpc.kava.io/block_results?height=3146803 + events, err := chain.GetBeginBlockEvents(ctx, blocks[0].Block.Height) + return events, blocks[0].Block.Height, err +} + +func (chain *Chain) QueryBlock(ctx context.Context, query string) ([]*coretypes.ResultBlock, error) { + page := 1 + perPage := 100 + + res, err := chain.TmSignClient.BlockSearch( + ctx, + query, + &page, + &perPage, + "desc", + ) + + if err != nil { + return nil, fmt.Errorf("failed BlockSearch: %w", err) + } + + return res.Blocks, nil +} + +func (chain *Chain) GetBeginBlockEvents(ctx context.Context, height int64) (sdk.StringEvents, error) { + res, err := chain.TmSignClient.BlockResults( + ctx, + &height, + ) + + if err != nil { + return nil, fmt.Errorf("failed BlockResults: %w", err) + } + + // Do not use sdk.StringifyEvents as it flattens events which makes it + // more difficult to parse. + strEvents := make(sdk.StringEvents, 0, len(res.BeginBlockEvents)) + for _, e := range res.BeginBlockEvents { + strEvents = append(strEvents, sdk.StringifyEvent(e)) + } + + return strEvents, nil +} diff --git a/tests/e2e/testutil/config.go b/tests/e2e/testutil/config.go index 6cf38d8161..bf78e7ecd3 100644 --- a/tests/e2e/testutil/config.go +++ b/tests/e2e/testutil/config.go @@ -56,6 +56,8 @@ type LiveNetworkConfig struct { KavaRpcUrl string KavaGrpcUrl string KavaEvmRpcUrl string + + UpgradeHeight int64 } // ParseSuiteConfig builds a SuiteConfig from environment variables. @@ -107,11 +109,23 @@ func ParseKvtoolConfig() KvtoolConfig { // ParseLiveNetworkConfig builds a LiveNetworkConfig from environment variables. func ParseLiveNetworkConfig() LiveNetworkConfig { - return LiveNetworkConfig{ + config := LiveNetworkConfig{ KavaRpcUrl: nonemptyStringEnv("E2E_KAVA_RPC_URL"), KavaGrpcUrl: nonemptyStringEnv("E2E_KAVA_GRPC_URL"), KavaEvmRpcUrl: nonemptyStringEnv("E2E_KAVA_EVM_RPC_URL"), } + + upgradeHeight := os.Getenv("E2E_KAVA_UPGRADE_HEIGHT") + if upgradeHeight != "" { + parsedHeight, err := strconv.ParseInt(upgradeHeight, 10, 64) + if err != nil { + panic(fmt.Sprintf("E2E_KAVA_UPGRADE_HEIGHT must be a number: %s", err)) + } + + config.UpgradeHeight = parsedHeight + } + + return config } // mustParseBool is a helper method that panics if the env variable `name` diff --git a/tests/e2e/testutil/eip712.go b/tests/e2e/testutil/eip712.go index 7cc45d46ad..7c70922d7a 100644 --- a/tests/e2e/testutil/eip712.go +++ b/tests/e2e/testutil/eip712.go @@ -35,7 +35,7 @@ func (suite *E2eTestSuite) NewEip712TxBuilder( accNumber := accDetails.GetAccountNumber() // get chain id - pc, err := emtypes.ParseChainID(chain.ChainId) + pc, err := emtypes.ParseChainID(chain.ChainID) suite.NoError(err) ethChainId := pc.Uint64() @@ -47,7 +47,7 @@ func (suite *E2eTestSuite) NewEip712TxBuilder( // build EIP712 tx // -- untyped data untypedData := eip712.ConstructUntypedEIP712Data( - chain.ChainId, + chain.ChainID, accNumber, nonce, 0, // no timeout diff --git a/tests/e2e/testutil/init_evm.go b/tests/e2e/testutil/init_evm.go index 823992eeba..b159d927d9 100644 --- a/tests/e2e/testutil/init_evm.go +++ b/tests/e2e/testutil/init_evm.go @@ -20,7 +20,11 @@ func (suite *E2eTestSuite) InitKavaEvmData() { // ensure funded account has nonzero erc20 balance balance := suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress) if balance.Cmp(big.NewInt(0)) != 1 { - panic(fmt.Sprintf("expected funded account (%s) to have erc20 balance", whale.EvmAddress.Hex())) + panic(fmt.Sprintf( + "expected funded account (%s) to have erc20 balance of token %s", + whale.EvmAddress.Hex(), + suite.DeployedErc20.Address.Hex(), + )) } // expect the erc20 to be enabled for conversion to sdk.Coin diff --git a/tests/e2e/testutil/suite.go b/tests/e2e/testutil/suite.go index ff3eae9874..5c0d93bb22 100644 --- a/tests/e2e/testutil/suite.go +++ b/tests/e2e/testutil/suite.go @@ -3,7 +3,6 @@ package testutil import ( "fmt" "math/big" - "path/filepath" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/suite" @@ -194,12 +193,16 @@ func (suite *E2eTestSuite) SetupLiveNetworkNodeRunner() *runner.LiveNodeRunner { if suite.config.IncludeIbcTests { panic("ibc tests not supported for live network configuration") } + + // Manually set upgrade height for live networks + suite.UpgradeHeight = suite.config.LiveNetwork.UpgradeHeight suite.enableRefunds = true runnerConfig := runner.LiveNodeRunnerConfig{ KavaRpcUrl: suite.config.LiveNetwork.KavaRpcUrl, KavaGrpcUrl: suite.config.LiveNetwork.KavaGrpcUrl, KavaEvmRpcUrl: suite.config.LiveNetwork.KavaEvmRpcUrl, + UpgradeHeight: suite.config.LiveNetwork.UpgradeHeight, } return runner.NewLiveNodeRunner(runnerConfig) @@ -217,15 +220,23 @@ func (suite *E2eTestSuite) SkipIfIbcDisabled() { // It gracefully skips the current test if upgrades are dissabled. // Note: automated upgrade tests are currently only enabled for Kvtool suite runs. func (suite *E2eTestSuite) SkipIfUpgradeDisabled() { - if suite.config.Kvtool != nil && suite.config.Kvtool.IncludeAutomatedUpgrade { + if suite.config.Kvtool != nil && !suite.config.Kvtool.IncludeAutomatedUpgrade { + fmt.Println("skipping upgrade test, kvtool automated upgrade is disabled") + suite.T().SkipNow() + } + + // If there isn't a manual upgrade height set in the config, skip the test + if suite.config.LiveNetwork != nil && suite.config.LiveNetwork.UpgradeHeight == 0 { + fmt.Println("skipping upgrade test, live network upgrade height is not set") suite.T().SkipNow() } } -// KavaHomePath returns the OS-specific filepath for the kava home directory -// Assumes network is running with kvtool installed from the sub-repository in tests/e2e/kvtool -func (suite *E2eTestSuite) KavaHomePath() string { - return filepath.Join("kvtool", "full_configs", "generated", "kava", "initstate", ".kava") +// SkipIfKvtoolDisabled should be called at the start of tests that require kvtool. +func (suite *E2eTestSuite) SkipIfKvtoolDisabled() { + if suite.config.Kvtool == nil { + suite.T().SkipNow() + } } // BigIntsEqual is a helper method for comparing the equality of two big ints diff --git a/tests/util/events.go b/tests/util/events.go new file mode 100644 index 0000000000..26bdc5fc45 --- /dev/null +++ b/tests/util/events.go @@ -0,0 +1,31 @@ +package util + +import ( + abci "github.com/tendermint/tendermint/abci/types" +) + +// FilterEventsByType returns a slice of events that match the given type. +func FilterEventsByType(events []abci.Event, eventType string) []abci.Event { + filteredEvents := []abci.Event{} + + for _, event := range events { + if event.Type == eventType { + filteredEvents = append(filteredEvents, event) + } + } + + return filteredEvents +} + +// FilterTxEventsByType returns a slice of events that match the given type +// from any and all txs in a slice of ResponseDeliverTx. +func FilterTxEventsByType(txs []*abci.ResponseDeliverTx, eventType string) []abci.Event { + filteredEvents := []abci.Event{} + + for _, tx := range txs { + events := FilterEventsByType(tx.Events, eventType) + filteredEvents = append(filteredEvents, events...) + } + + return filteredEvents +} diff --git a/tests/util/grpc.go b/tests/util/grpc.go index d7c17ba517..5785a8e886 100644 --- a/tests/util/grpc.go +++ b/tests/util/grpc.go @@ -9,6 +9,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials" + "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/metadata" grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" @@ -21,17 +22,17 @@ func NewGrpcConnection(endpoint string) (*grpc.ClientConn, error) { return nil, err } - var secureOpt grpc.DialOption + var creds credentials.TransportCredentials switch grpcUrl.Scheme { case "http": - secureOpt = grpc.WithInsecure() + creds = insecure.NewCredentials() case "https": - creds := credentials.NewTLS(&tls.Config{}) - secureOpt = grpc.WithTransportCredentials(creds) + creds = credentials.NewTLS(&tls.Config{}) default: return nil, fmt.Errorf("unknown grpc url scheme: %s", grpcUrl.Scheme) } + secureOpt := grpc.WithTransportCredentials(creds) grpcConn, err := grpc.Dial(grpcUrl.Host, secureOpt) if err != nil { return nil, err diff --git a/tests/util/kvtool.go b/tests/util/kvtool.go new file mode 100644 index 0000000000..8a0429aff6 --- /dev/null +++ b/tests/util/kvtool.go @@ -0,0 +1,11 @@ +package util + +import ( + "path/filepath" +) + +// KavaHomePath returns the OS-specific filepath for the kava home directory +// Assumes network is running with kvtool installed from the sub-repository in tests/e2e/kvtool +func KavaHomePath() string { + return filepath.Join("kvtool", "full_configs", "generated", "kava", "initstate", ".kava") +} diff --git a/x/community/keeper/disable_inflation.go b/x/community/keeper/disable_inflation.go index 6eecabfc3e..7c44c9ca8f 100644 --- a/x/community/keeper/disable_inflation.go +++ b/x/community/keeper/disable_inflation.go @@ -28,18 +28,22 @@ func (k Keeper) CheckAndDisableMintAndKavaDistInflation(ctx sdk.Context) { logger.Info("disable inflation upgrade finished successfully!") - ctx.EventManager().EmitEvent( - sdk.NewEvent( - types.EventTypeInflationStop, - ), - ) - // reset disable inflation time to ensure next call is a no-op params.UpgradeTimeDisableInflation = time.Time{} // set staking rewards to provided intial value params.StakingRewardsPerSecond = params.UpgradeTimeSetStakingRewardsPerSecond k.SetParams(ctx, params) + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeInflationStop, + sdk.NewAttribute( + types.AttributeKeyInflationDisableTime, + ctx.BlockTime().Format(time.RFC3339), + ), + ), + ) + if err := k.StartCommunityFundConsolidation(ctx); err != nil { panic(err) } diff --git a/x/community/testutil/disable_inflation.go b/x/community/testutil/disable_inflation.go index 68b99013bc..6868fd4fae 100644 --- a/x/community/testutil/disable_inflation.go +++ b/x/community/testutil/disable_inflation.go @@ -106,7 +106,17 @@ func (suite *disableInflationTestSuite) TestDisableInflation() { msgSuffix = "after upgrade" - suite.Require().NoError(app.EventsContains(suite.Ctx.EventManager().Events(), sdk.NewEvent(types.EventTypeInflationStop))) + suite.Require().NoError( + app.EventsContains( + suite.Ctx.EventManager().Events(), + sdk.NewEvent( + types.EventTypeInflationStop, + sdk.NewAttribute( + types.AttributeKeyInflationDisableTime, + suite.Ctx.BlockTime().Format(time.RFC3339), + ), + ), + )) } suite.Require().Equal(expectedMintState.Params.InflationMin, mintParams.InflationMin, msg+": expected mint inflation min to match state "+msgSuffix) diff --git a/x/community/types/events.go b/x/community/types/events.go index 75b1db5ddc..c9c0d12636 100644 --- a/x/community/types/events.go +++ b/x/community/types/events.go @@ -5,7 +5,8 @@ const ( EventTypeInflationStop = "inflation_stop" EventTypeStakingRewardsPaid = "staking_rewards_paid" - AttributeKeyStakingRewardAmount = "staking_reward_amount" + AttributeKeyStakingRewardAmount = "staking_reward_amount" + AttributeKeyInflationDisableTime = "inflation_disable_time" AttributeValueFundCommunityPool = "fund_community_pool" AttributeValueCategory = ModuleName