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

Go kosu/rpc #174

Merged
merged 6 commits into from Jul 23, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

go-kosu: integration tests refactoring

  • Loading branch information
gchaincl committed Jul 23, 2019
commit 6696f711b28caa9fbba25d123f5e2c868b212e61
@@ -2,45 +2,20 @@ package rpc

import (
"context"
"io/ioutil"
"os"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go-kosu/abci"
"go-kosu/tests"

"github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"
)

// TODO use tests/support.go version of startServer
func startServer(t *testing.T, db db.DB) (*abci.App, func()) {
// Create a temp dir and initialize tendermint there
dir, err := ioutil.TempDir("/tmp", "/go-kosu-go-tests_")
require.NoError(t, err)

err = abci.InitTendermintWithLogger(dir, log.NewNopLogger())
require.NoError(t, err)

// Initialize the server
app := abci.NewApp(db, dir)
app.Config.LogFormat = "none"
app.Config.LogLevel = "app:error"
srv, err := abci.StartInProcessServer(app)
require.NoError(t, err)

// nolint
return app, func() {
srv.Stop()
os.RemoveAll(dir)
}
}

func TestRPCLatestHeight(t *testing.T) {
_, closer := startServer(t, db.NewMemDB())
_, closer := tests.StartServer(t, db.NewMemDB())
defer closer()
client := DialInProc(
NewServer(
@@ -2,8 +2,13 @@ package tests

import (
"go-kosu/abci"
"testing"

. "github.com/smartystreets/goconvey/convey" //nolint
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/tendermint/tendermint/libs/db"
)

type Suite struct {
@@ -12,3 +17,35 @@ type Suite struct {
client *abci.Client
app *abci.App
}

// GivenABCIServer a ABCI Server inside a Convey block
func GivenABCIServer(t *testing.T, suite *Suite, fn func(*testing.T)) {
Convey("Given an ABCI Server", t, func() {
app, closer := StartServer(t, db.NewMemDB())
defer closer()
suite.app = app

key, err := abci.LoadPrivateKey(app.Config.RootDir)
require.NoError(t, err)

suite.client = abci.NewHTTPClient("http://localhost:26657", key)
fn(t)
})
}

// BroadcastTxSync is a helper function to Broadcast a Tx under test
func BroadcastTxSync(t *testing.T, c *abci.Client, tx interface{}) *rpctypes.ResultBroadcastTx {
res, err := c.BroadcastTxSync(tx)
So(err, ShouldBeNil)
require.Zero(t, res.Code, res.Log)
return res
}

// BroadcastTxCommit is a helper function to Broadcast a Tx under test
func BroadcastTxCommit(t *testing.T, c *abci.Client, tx interface{}) *rpctypes.ResultBroadcastTxCommit {
res, err := c.BroadcastTxCommit(tx)
So(err, ShouldBeNil)
require.True(t, res.CheckTx.IsOK(), res.CheckTx.Log)
require.True(t, res.DeliverTx.IsOK(), res.DeliverTx.Log)
return res
}
@@ -6,31 +6,14 @@ import (
"testing"
"time"

. "github.com/smartystreets/goconvey/convey" //nolint
"github.com/stretchr/testify/require"

"github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"
rpctypes "github.com/tendermint/tendermint/rpc/core/types"

"go-kosu/abci"
)

// GivenABCIServer a ABCI Server inside a Convey block
func GivenABCIServer(t *testing.T, suite *Suite, fn func(*testing.T)) {
Convey("Given an ABCI Server", t, func() {
app, closer := StartServer(t, db.NewMemDB())
defer closer()
suite.app = app

key, err := abci.LoadPrivateKey(app.Config.RootDir)
require.NoError(t, err)

suite.client = abci.NewHTTPClient("http://localhost:26657", key)
fn(t)
})
}

// StartServer starts a kosud test server
func StartServer(t *testing.T, db db.DB) (*abci.App, func()) {
// Create a temp dir and initialize tendermint there
@@ -55,20 +38,3 @@ func StartServer(t *testing.T, db db.DB) (*abci.App, func()) {
os.RemoveAll(dir)
}
}

// BroadcastTxSync is a helper function to Broadcast a Tx under test
func BroadcastTxSync(t *testing.T, c *abci.Client, tx interface{}) *rpctypes.ResultBroadcastTx {
res, err := c.BroadcastTxSync(tx)
So(err, ShouldBeNil)
require.Zero(t, res.Code, res.Log)
return res
}

// BroadcastTxCommit is a helper function to Broadcast a Tx under test
func BroadcastTxCommit(t *testing.T, c *abci.Client, tx interface{}) *rpctypes.ResultBroadcastTxCommit {
res, err := c.BroadcastTxCommit(tx)
So(err, ShouldBeNil)
require.True(t, res.CheckTx.IsOK(), res.CheckTx.Log)
require.True(t, res.DeliverTx.IsOK(), res.DeliverTx.Log)
return res
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.