Skip to content

Commit

Permalink
x/community events and e2e test improvements (#1766)
Browse files Browse the repository at this point in the history
* Initial e2e setup

* Fix inflation disable tests

* Add upgrade handler

* Add param tests for after upgrade

* Replace deprecated grpc creds

* Remove upgrade for e2e test

* Update upgrade handler to set x/community params

* Remove params check in upgrade

* Update tests for switchover time and params check

* wip inflation

* Add attribute to disable inflation event

* Add before/after switchover mint and dist checks

* Add missing attribute to disable inflation test check

* Check mint events are 0

* Check total supply doesn't change

* Check inflation and events before switchover

* Check staking reward payouts from x/community

* move events funcs to util

* Add keyring to chain, fetch keys from kvtool and test withdrawal

* Remove duplicate KavaHomePath

* Update subtest names to specify before/after switchover

Co-authored-by: Draco <draco@dracoli.com>

* Use blocktime for InflationStop event DisableTime

* Test 5 blocks for staking rewards payout

* Remove logging and unused lines

* Check val claimed balance with queried

* Enable and update consolidation tests

* Update test for modified EventTypeInflationStop time attr

* Test x/distribution community tax

* Fix test names

* Update e2e tests for better live network test support (#1749)

* Update e2e tests to support mirrornet

* Skip claim rewards on live network, require no errors for existing tests

* Update readme with upgrade height

* Update .env example with usdt contract address

* Restore .env file to original local e2e

* Log community params when set

* Make AttributeKeyInflationDisableTime more precise

* Add mainnet and testnet community params (#1753)

* Re-enable ibc tests

* Remove duplicate types.EventTypeInflationStop emit

* feat: set validator minimum commissions to at least 5% in upgrade handler (#1761)

* Update validator min commission in upgrade

* Add min commission upgrade test

* Update changelog

* Set validator MaxRate, call BeforeValidatorModified hook

* Check max commission and update time in tests

* Update e2e test for max rate

* Test val update time

* Use SdkBlock instead of Block

* Remove upgrade related handlers and tests

Preserve any module and test util changes

* Update e2e x/community params proposal test to work without upgrade handler

---------

Co-authored-by: Draco <draco@dracoli.com>
  • Loading branch information
drklee3 and DracoLi authored Oct 31, 2023
1 parent 84f84c4 commit 6998196
Show file tree
Hide file tree
Showing 22 changed files with 307 additions and 57 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/.env.live-network-example
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 27 additions & 4 deletions tests/e2e/e2e_community_update_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
)

Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/e2e_convert_cosmos_coins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions tests/e2e/e2e_min_fees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion tests/e2e/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions tests/e2e/runner/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/runner/live.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type LiveNodeRunnerConfig struct {
KavaRpcUrl string
KavaGrpcUrl string
KavaEvmRpcUrl string

UpgradeHeight int64
}

// LiveNodeRunner implements NodeRunner for an already-running chain.
Expand Down
28 changes: 25 additions & 3 deletions tests/e2e/testutil/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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 := &ethsecp256k1.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,
Expand All @@ -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(
Expand Down Expand Up @@ -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,
)

Expand Down
Loading

0 comments on commit 6998196

Please sign in to comment.