2023-02-22 23:40:56 +00:00
|
|
|
package testutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"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-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-02-22 23:40:56 +00:00
|
|
|
|
2023-03-07 22:37:45 +00:00
|
|
|
runnerConfig := runner.Config{
|
|
|
|
IncludeIBC: suiteConfig.IncludeIbcTests,
|
|
|
|
ImageTag: "local",
|
2023-02-22 23:40:56 +00:00
|
|
|
}
|
2023-03-07 22:37:45 +00:00
|
|
|
suite.runner = runner.NewKavaNode(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-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-07 22:37:45 +00:00
|
|
|
if !suite.config.SkipShutdown {
|
|
|
|
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
|
|
|
}
|