2020-03-29 21:32:01 +08:00
|
|
|
package tester
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2020-10-22 14:22:31 +08:00
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
2020-04-28 17:08:21 +08:00
|
|
|
"github.com/meshplus/bitxhub/internal/app"
|
|
|
|
"github.com/meshplus/bitxhub/internal/coreapi"
|
|
|
|
"github.com/meshplus/bitxhub/internal/coreapi/api"
|
|
|
|
"github.com/meshplus/bitxhub/internal/loggers"
|
|
|
|
"github.com/meshplus/bitxhub/internal/repo"
|
|
|
|
"github.com/stretchr/testify/require"
|
2020-03-29 21:32:01 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestTester(t *testing.T) {
|
2020-04-28 17:08:21 +08:00
|
|
|
node1 := setupNode(t, "./test_data/config/node1")
|
|
|
|
node2 := setupNode(t, "./test_data/config/node2")
|
|
|
|
node3 := setupNode(t, "./test_data/config/node3")
|
|
|
|
node4 := setupNode(t, "./test_data/config/node4")
|
|
|
|
|
|
|
|
for {
|
|
|
|
if node1.Broker().OrderReady() &&
|
|
|
|
node2.Broker().OrderReady() &&
|
|
|
|
node3.Broker().OrderReady() &&
|
|
|
|
node4.Broker().OrderReady() {
|
|
|
|
break
|
2020-03-29 21:32:01 +08:00
|
|
|
}
|
|
|
|
|
2020-04-28 17:08:21 +08:00
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
}
|
2020-03-29 21:32:01 +08:00
|
|
|
|
2020-04-28 17:08:21 +08:00
|
|
|
suite.Run(t, &API{api: node1})
|
|
|
|
suite.Run(t, &RegisterAppchain{api: node2})
|
|
|
|
suite.Run(t, &Interchain{api: node3})
|
|
|
|
suite.Run(t, &Role{api: node4})
|
2020-07-02 16:03:53 +08:00
|
|
|
suite.Run(t, &Store{api: node1})
|
2020-04-28 17:08:21 +08:00
|
|
|
}
|
2020-03-29 21:32:01 +08:00
|
|
|
|
2020-04-28 17:08:21 +08:00
|
|
|
func setupNode(t *testing.T, path string) api.CoreAPI {
|
|
|
|
repoRoot, err := repo.PathRootWithDefault(path)
|
|
|
|
require.Nil(t, err)
|
2020-03-29 21:32:01 +08:00
|
|
|
|
2020-04-28 17:08:21 +08:00
|
|
|
repo, err := repo.Load(repoRoot)
|
|
|
|
require.Nil(t, err)
|
2020-03-29 21:32:01 +08:00
|
|
|
|
2020-04-28 17:08:21 +08:00
|
|
|
loggers.Initialize(repo.Config)
|
2020-03-29 21:32:01 +08:00
|
|
|
|
2020-04-28 17:08:21 +08:00
|
|
|
bxh, err := app.NewTesterBitXHub(repo)
|
|
|
|
require.Nil(t, err)
|
2020-03-29 21:32:01 +08:00
|
|
|
|
2020-04-28 17:08:21 +08:00
|
|
|
api, err := coreapi.New(bxh)
|
|
|
|
require.Nil(t, err)
|
2020-03-29 21:32:01 +08:00
|
|
|
|
2020-04-28 17:08:21 +08:00
|
|
|
go func() {
|
|
|
|
err = bxh.Start()
|
|
|
|
require.Nil(t, err)
|
|
|
|
}()
|
2020-03-29 21:32:01 +08:00
|
|
|
|
2020-04-28 17:08:21 +08:00
|
|
|
return api
|
2020-03-29 21:32:01 +08:00
|
|
|
}
|