0g-chain/tests/e2e/testutil/init_evm.go

83 lines
2.7 KiB
Go
Raw Normal View History

package testutil
import (
"context"
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
2024-04-24 07:10:22 +00:00
"github.com/0glabs/0g-chain/tests/e2e/contracts/greeter"
// "github.com/0glabs/0g-chain/x/cdp/types"
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
)
// InitKavaEvmData is run after the chain is running, but before the tests are run.
// It is used to initialize some EVM state, such as deploying contracts.
func (suite *E2eTestSuite) InitKavaEvmData() {
whale := suite.Kava.GetAccount(FundedAccountName)
// ensure funded account has nonzero erc20 balance
balance := suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
if balance.Cmp(big.NewInt(0)) != 1 {
`x/community` events and e2e test improvements (#1766) * 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>
2023-10-31 23:37:40 +00:00
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
params, err := suite.Kava.Grpc.Query.Evmutil.Params(context.Background(), &evmutiltypes.QueryParamsRequest{})
if err != nil {
panic(fmt.Sprintf("failed to fetch evmutil params during init: %s", err))
}
found := false
erc20Addr := suite.DeployedErc20.Address.Hex()
for _, p := range params.Params.EnabledConversionPairs {
2024-04-24 07:10:22 +00:00
if common.BytesToAddress(p.ZgchainERC20Address).Hex() == erc20Addr {
found = true
suite.DeployedErc20.CosmosDenom = p.Denom
}
}
if !found {
panic(fmt.Sprintf("erc20 %s must be enabled for conversion to cosmos coin", erc20Addr))
}
suite.Kava.RegisterErc20(suite.DeployedErc20.Address)
// expect the erc20's cosmos denom to be a supported cdp collateral type
2024-04-24 06:30:36 +00:00
// cdpParams, err := suite.Kava.Grpc.Query.Cdp.Params(context.Background(), &types.QueryParamsRequest{})
// suite.Require().NoError(err)
// found = false
// for _, cp := range cdpParams.Params.CollateralParams {
// if cp.Denom == suite.DeployedErc20.CosmosDenom {
// found = true
// suite.DeployedErc20.CdpCollateralType = cp.Type
// }
// }
// if !found {
// panic(fmt.Sprintf(
// "erc20's cosmos denom %s must be valid cdp collateral type",
// suite.DeployedErc20.CosmosDenom),
// )
// }
// deploy an example contract
greeterAddr, _, _, err := greeter.DeployGreeter(
whale.evmSigner.Auth,
whale.evmSigner.EvmClient,
"what's up!",
)
suite.NoError(err, "failed to deploy a contract to the EVM")
suite.Kava.ContractAddrs["greeter"] = greeterAddr
}
// FundKavaErc20Balance sends the pre-deployed ERC20 token to the `toAddress`.
func (suite *E2eTestSuite) FundKavaErc20Balance(toAddress common.Address, amount *big.Int) EvmTxResponse {
// funded account should have erc20 balance
whale := suite.Kava.GetAccount(FundedAccountName)
res, err := whale.TransferErc20(suite.DeployedErc20.Address, toAddress, amount)
suite.NoError(err)
return res
}