You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.1 KiB

  1. package client_test
  2. import (
  3. "context"
  4. "fmt"
  5. "io/ioutil"
  6. "os"
  7. "testing"
  8. "github.com/stretchr/testify/assert"
  9. "github.com/stretchr/testify/require"
  10. "github.com/tendermint/tendermint/abci/example/kvstore"
  11. "github.com/tendermint/tendermint/config"
  12. "github.com/tendermint/tendermint/libs/service"
  13. rpctest "github.com/tendermint/tendermint/rpc/test"
  14. )
  15. func NodeSuite(t *testing.T) (service.Service, *config.Config) {
  16. t.Helper()
  17. ctx, cancel := context.WithCancel(context.Background())
  18. conf, err := rpctest.CreateConfig(t.Name())
  19. require.NoError(t, err)
  20. // start a tendermint node in the background to test against
  21. dir, err := ioutil.TempDir("/tmp", fmt.Sprint("rpc-client-test-", t.Name()))
  22. require.NoError(t, err)
  23. app := kvstore.NewPersistentKVStoreApplication(dir)
  24. node, closer, err := rpctest.StartTendermint(ctx, conf, app, rpctest.SuppressStdout)
  25. require.NoError(t, err)
  26. t.Cleanup(func() {
  27. cancel()
  28. assert.NoError(t, node.Stop())
  29. assert.NoError(t, closer(ctx))
  30. assert.NoError(t, app.Close())
  31. node.Wait()
  32. _ = os.RemoveAll(dir)
  33. })
  34. return node, conf
  35. }