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

Update e2e tests for better live network test support #1749

Merged
merged 5 commits into from
Oct 23, 2023
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
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
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
4 changes: 4 additions & 0 deletions tests/e2e/e2e_min_fees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
)

func (suite *IntegrationTestSuite) TestEthGasPriceReturnsMinFee() {
suite.SkipIfKvtoolDisabled()

// read expected min fee from app.toml
minGasPrices, err := getMinFeeFromAppToml(util.KavaHomePath())
suite.NoError(err)
Expand All @@ -32,6 +34,8 @@ 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())
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
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
4 changes: 4 additions & 0 deletions tests/e2e/e2e_upgrade_inflation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
)

func (suite *IntegrationTestSuite) TestUpgradeInflation_Disable() {
suite.SkipIfUpgradeDisabled()

afterUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight)

// Get x/community for switchover time
Expand Down Expand Up @@ -370,6 +372,8 @@ func (suite *IntegrationTestSuite) TestUpgradeInflation_Disable() {

// Staking rewards can still be claimed
suite.Run("staking rewards claimable after switchover", func() {
suite.SkipIfKvtoolDisabled()

// Get the delegator of the only validator
validators, err := suite.Kava.Staking.Validators(
context.Background(),
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
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
16 changes: 15 additions & 1 deletion tests/e2e/testutil/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ type LiveNetworkConfig struct {
KavaRpcUrl string
KavaGrpcUrl string
KavaEvmRpcUrl string

UpgradeHeight int64
}

// ParseSuiteConfig builds a SuiteConfig from environment variables.
Expand Down Expand Up @@ -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`
Expand Down
6 changes: 5 additions & 1 deletion tests/e2e/testutil/init_evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions tests/e2e/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,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)
Expand All @@ -217,6 +221,20 @@ func (suite *E2eTestSuite) SkipIfIbcDisabled() {
// 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 {
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()
}
}

// SkipIfKvtoolDisabled should be called at the start of tests that require kvtool.
func (suite *E2eTestSuite) SkipIfKvtoolDisabled() {
if suite.config.Kvtool == nil {
suite.T().SkipNow()
}
}
Expand Down