2023-02-22 23:40:56 +00:00
|
|
|
package testutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-04-06 17:51:13 +00:00
|
|
|
"math/big"
|
2023-03-31 17:30:37 +00:00
|
|
|
"path/filepath"
|
2023-02-22 23:40:56 +00:00
|
|
|
|
2023-04-06 17:51:13 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2023-02-22 23:40:56 +00:00
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
|
|
|
"github.com/kava-labs/kava/app"
|
|
|
|
"github.com/kava-labs/kava/tests/e2e/runner"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
FundedAccountName = "whale"
|
2023-03-02 01:05:53 +00:00
|
|
|
// use coin type 60 so we are compatible with accounts from `kava add keys --eth <name>`
|
|
|
|
// these accounts use the ethsecp256k1 signing algorithm that allows the signing client
|
|
|
|
// to manage both sdk & evm txs.
|
|
|
|
Bip44CoinType = 60
|
2023-03-07 22:37:45 +00:00
|
|
|
|
|
|
|
IbcPort = "transfer"
|
|
|
|
IbcChannel = "channel-0"
|
2023-02-22 23:40:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type E2eTestSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
2023-03-07 22:37:45 +00:00
|
|
|
config SuiteConfig
|
|
|
|
runner runner.NodeRunner
|
2023-02-22 23:40:56 +00:00
|
|
|
|
2023-03-07 22:37:45 +00:00
|
|
|
Kava *Chain
|
|
|
|
Ibc *Chain
|
2023-03-28 22:32:36 +00:00
|
|
|
|
2023-04-06 17:51:13 +00:00
|
|
|
UpgradeHeight int64
|
|
|
|
DeployedErc20Address common.Address
|
2023-02-22 23:40:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *E2eTestSuite) SetupSuite() {
|
2023-03-07 22:37:45 +00:00
|
|
|
var err error
|
2023-03-02 01:05:53 +00:00
|
|
|
fmt.Println("setting up test suite.")
|
2023-02-22 23:40:56 +00:00
|
|
|
app.SetSDKConfig()
|
|
|
|
|
2023-03-07 22:37:45 +00:00
|
|
|
suiteConfig := ParseSuiteConfig()
|
|
|
|
suite.config = suiteConfig
|
2023-04-06 17:51:13 +00:00
|
|
|
suite.DeployedErc20Address = common.HexToAddress(suiteConfig.KavaErc20Address)
|
2023-02-22 23:40:56 +00:00
|
|
|
|
2023-06-20 16:29:25 +00:00
|
|
|
if suiteConfig.Kvtool != nil {
|
|
|
|
suite.UpgradeHeight = suiteConfig.Kvtool.KavaUpgradeHeight
|
2023-03-28 22:32:36 +00:00
|
|
|
|
2023-06-20 16:29:25 +00:00
|
|
|
runnerConfig := runner.KvtoolRunnerConfig{
|
|
|
|
KavaConfigTemplate: suiteConfig.Kvtool.KavaConfigTemplate,
|
2023-03-28 22:32:36 +00:00
|
|
|
|
2023-06-20 16:29:25 +00:00
|
|
|
IncludeIBC: suiteConfig.IncludeIbcTests,
|
|
|
|
ImageTag: "local",
|
2023-03-28 22:32:36 +00:00
|
|
|
|
2023-06-20 16:29:25 +00:00
|
|
|
EnableAutomatedUpgrade: suiteConfig.Kvtool.IncludeAutomatedUpgrade,
|
|
|
|
KavaUpgradeName: suiteConfig.Kvtool.KavaUpgradeName,
|
|
|
|
KavaUpgradeHeight: suiteConfig.Kvtool.KavaUpgradeHeight,
|
|
|
|
KavaUpgradeBaseImageTag: suiteConfig.Kvtool.KavaUpgradeBaseImageTag,
|
|
|
|
|
|
|
|
SkipShutdown: suiteConfig.SkipShutdown,
|
|
|
|
}
|
|
|
|
suite.runner = runner.NewKvtoolRunner(runnerConfig)
|
2023-02-22 23:40:56 +00:00
|
|
|
}
|
|
|
|
|
2023-03-07 22:37:45 +00:00
|
|
|
chains := suite.runner.StartChains()
|
|
|
|
kavachain := chains.MustGetChain("kava")
|
|
|
|
suite.Kava, err = NewChain(suite.T(), kavachain, suiteConfig.FundedAccountMnemonic)
|
2023-02-22 23:40:56 +00:00
|
|
|
if err != nil {
|
|
|
|
suite.runner.Shutdown()
|
2023-03-07 22:37:45 +00:00
|
|
|
suite.T().Fatalf("failed to create kava chain querier: %s", err)
|
2023-02-22 23:40:56 +00:00
|
|
|
}
|
|
|
|
|
2023-03-07 22:37:45 +00:00
|
|
|
if suiteConfig.IncludeIbcTests {
|
|
|
|
ibcchain := chains.MustGetChain("ibc")
|
|
|
|
suite.Ibc, err = NewChain(suite.T(), ibcchain, suiteConfig.FundedAccountMnemonic)
|
|
|
|
if err != nil {
|
|
|
|
suite.runner.Shutdown()
|
|
|
|
suite.T().Fatalf("failed to create ibc chain querier: %s", err)
|
|
|
|
}
|
2023-03-02 01:05:53 +00:00
|
|
|
}
|
2023-04-03 16:58:45 +00:00
|
|
|
|
|
|
|
suite.InitKavaEvmData()
|
2023-02-22 23:40:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *E2eTestSuite) TearDownSuite() {
|
2023-03-02 01:05:53 +00:00
|
|
|
fmt.Println("tearing down test suite.")
|
2023-02-22 23:40:56 +00:00
|
|
|
// close all account request channels
|
2023-03-07 22:37:45 +00:00
|
|
|
suite.Kava.Shutdown()
|
|
|
|
if suite.Ibc != nil {
|
|
|
|
suite.Ibc.Shutdown()
|
2023-02-22 23:40:56 +00:00
|
|
|
}
|
|
|
|
// gracefully shutdown docker container(s)
|
2023-03-28 22:32:36 +00:00
|
|
|
suite.runner.Shutdown()
|
2023-02-22 23:40:56 +00:00
|
|
|
}
|
2023-03-02 01:05:53 +00:00
|
|
|
|
2023-03-07 22:37:45 +00:00
|
|
|
func (suite *E2eTestSuite) SkipIfIbcDisabled() {
|
|
|
|
if !suite.config.IncludeIbcTests {
|
|
|
|
suite.T().SkipNow()
|
|
|
|
}
|
2023-03-02 01:05:53 +00:00
|
|
|
}
|
2023-03-28 22:32:36 +00:00
|
|
|
|
|
|
|
func (suite *E2eTestSuite) SkipIfUpgradeDisabled() {
|
2023-06-20 16:29:25 +00:00
|
|
|
if suite.config.Kvtool != nil && suite.config.Kvtool.IncludeAutomatedUpgrade {
|
2023-03-28 22:32:36 +00:00
|
|
|
suite.T().SkipNow()
|
|
|
|
}
|
|
|
|
}
|
2023-03-31 17:30:37 +00:00
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
2023-04-06 17:51:13 +00:00
|
|
|
|
|
|
|
// BigIntsEqual is a helper method for comparing the equality of two big ints
|
|
|
|
func (suite *E2eTestSuite) BigIntsEqual(expected *big.Int, actual *big.Int, msg string) {
|
|
|
|
suite.Truef(expected.Cmp(actual) == 0, "%s (expected: %s, actual: %s)", msg, expected.String(), actual.String())
|
|
|
|
}
|