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.

73 lines
1.7 KiB

  1. package client
  2. import (
  3. "os"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/stretchr/testify/require"
  7. "github.com/tendermint/tendermint/abci/example/kvstore"
  8. rpcclient "github.com/tendermint/tendermint/rpc/client"
  9. rpctest "github.com/tendermint/tendermint/rpc/test"
  10. "github.com/tendermint/tendermint/types"
  11. )
  12. // TODO fix tests!!
  13. func TestMain(m *testing.M) {
  14. app := kvstore.NewKVStoreApplication()
  15. node := rpctest.StartTendermint(app)
  16. code := m.Run()
  17. node.Stop()
  18. node.Wait()
  19. os.Exit(code)
  20. }
  21. func TestProvider(t *testing.T) {
  22. assert, require := assert.New(t), require.New(t)
  23. cfg := rpctest.GetConfig()
  24. rpcAddr := cfg.RPC.ListenAddress
  25. genDoc, err := types.GenesisDocFromFile(cfg.GenesisFile())
  26. if err != nil {
  27. panic(err)
  28. }
  29. chainID := genDoc.ChainID
  30. t.Log("chainID:", chainID)
  31. p := NewHTTPProvider(chainID, rpcAddr)
  32. require.NotNil(t, p)
  33. // let it produce some blocks
  34. err = rpcclient.WaitForHeight(p.(*provider).client, 6, nil)
  35. require.Nil(err)
  36. // let's get the highest block
  37. fc, err := p.LatestFullCommit(chainID, 1, 1<<63-1)
  38. require.Nil(err, "%+v", err)
  39. sh := fc.Height()
  40. assert.True(sh < 5000)
  41. // let's check this is valid somehow
  42. assert.Nil(fc.ValidateFull(chainID))
  43. // historical queries now work :)
  44. lower := sh - 5
  45. fc, err = p.LatestFullCommit(chainID, lower, lower)
  46. assert.Nil(err, "%+v", err)
  47. assert.Equal(lower, fc.Height())
  48. /*
  49. // also get by hash (given the match)
  50. fc, err = p.GetByHash(vhash)
  51. require.Nil(err, "%+v", err)
  52. require.Equal(vhash, fc.Header.ValidatorsHash)
  53. // get by hash fails without match
  54. fc, err = p.GetByHash([]byte("foobar"))
  55. assert.NotNil(err)
  56. assert.True(liteErr.IsCommitNotFoundErr(err))
  57. */
  58. }