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

x/community and e2e test improvements #1766

Merged
merged 38 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0ec56f2
Initial e2e setup
drklee3 Sep 20, 2023
51b61da
Fix inflation disable tests
drklee3 Sep 22, 2023
22db348
Add upgrade handler
drklee3 Sep 22, 2023
fe8b430
Add param tests for after upgrade
drklee3 Sep 22, 2023
ad1eece
Replace deprecated grpc creds
drklee3 Sep 22, 2023
58f411e
Remove upgrade for e2e test
drklee3 Sep 27, 2023
0c7bedc
Update upgrade handler to set x/community params
drklee3 Oct 6, 2023
dcf0cf0
Remove params check in upgrade
drklee3 Oct 6, 2023
6c4968f
Update tests for switchover time and params check
drklee3 Oct 6, 2023
0674a31
wip inflation
drklee3 Oct 10, 2023
60f9097
Add attribute to disable inflation event
drklee3 Oct 10, 2023
4cfeb8e
Add before/after switchover mint and dist checks
drklee3 Oct 10, 2023
4313894
Add missing attribute to disable inflation test check
drklee3 Oct 10, 2023
7d92d45
Check mint events are 0
drklee3 Oct 10, 2023
07a6189
Check total supply doesn't change
drklee3 Oct 10, 2023
5d95939
Check inflation and events before switchover
drklee3 Oct 11, 2023
e3ce836
Check staking reward payouts from x/community
drklee3 Oct 11, 2023
fe7e19a
move events funcs to util
drklee3 Oct 11, 2023
d2c4a38
Add keyring to chain, fetch keys from kvtool and test withdrawal
drklee3 Oct 11, 2023
8836031
Remove duplicate KavaHomePath
drklee3 Oct 11, 2023
745bef2
Update subtest names to specify before/after switchover
drklee3 Oct 18, 2023
f6a3af9
Use blocktime for InflationStop event DisableTime
drklee3 Oct 18, 2023
24053d0
Test 5 blocks for staking rewards payout
drklee3 Oct 18, 2023
6482843
Remove logging and unused lines
drklee3 Oct 18, 2023
7c3bf2c
Check val claimed balance with queried
drklee3 Oct 18, 2023
c1c37fb
Enable and update consolidation tests
drklee3 Oct 20, 2023
c4732fb
Update test for modified EventTypeInflationStop time attr
drklee3 Oct 20, 2023
0a6b849
Test x/distribution community tax
drklee3 Oct 23, 2023
36ec571
Fix test names
drklee3 Oct 23, 2023
478c9a0
Update e2e tests for better live network test support (#1749)
drklee3 Oct 23, 2023
c2d8c4d
Log community params when set
drklee3 Oct 24, 2023
6d03e74
Make AttributeKeyInflationDisableTime more precise
drklee3 Oct 24, 2023
efe65ce
Add mainnet and testnet community params (#1753)
drklee3 Oct 25, 2023
ff2ce48
Re-enable ibc tests
drklee3 Oct 30, 2023
8e34a60
Remove duplicate types.EventTypeInflationStop emit
drklee3 Oct 30, 2023
b58577d
feat: set validator minimum commissions to at least 5% in upgrade han…
drklee3 Oct 31, 2023
af58c58
Remove upgrade related handlers and tests
drklee3 Oct 31, 2023
122fd6f
Update e2e x/community params proposal test to work without upgrade h…
drklee3 Oct 31, 2023
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
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
24 changes: 20 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,31 @@ func (suite *IntegrationTestSuite) TestCommunityUpdateParams_Authority() {
gasLimit := int64(2e5)
fee := ukava(200)

upgradeTime := time.Now().Add(24 * time.Hour).UTC()
// Wait until switchover actually happens
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",
)

// 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
sdkmath.LegacyNewDec(1111), // 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
Loading