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.

61 lines
1.4 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. func TestMain(m *testing.M) {
  13. app := kvstore.NewKVStoreApplication()
  14. node := rpctest.StartTendermint(app)
  15. code := m.Run()
  16. rpctest.StopTendermint(node)
  17. os.Exit(code)
  18. }
  19. func TestProvider(t *testing.T) {
  20. assert, require := assert.New(t), require.New(t)
  21. cfg := rpctest.GetConfig()
  22. defer os.RemoveAll(cfg.RootDir)
  23. rpcAddr := cfg.RPC.ListenAddress
  24. genDoc, err := types.GenesisDocFromFile(cfg.GenesisFile())
  25. if err != nil {
  26. panic(err)
  27. }
  28. chainID := genDoc.ChainID
  29. t.Log("chainID:", chainID)
  30. p := NewHTTPProvider(chainID, rpcAddr)
  31. require.NotNil(t, p)
  32. // let it produce some blocks
  33. err = rpcclient.WaitForHeight(p.(*provider).client, 6, nil)
  34. require.Nil(err)
  35. // let's get the highest block
  36. fc, err := p.LatestFullCommit(chainID, 1, 1<<63-1)
  37. require.Nil(err, "%+v", err)
  38. sh := fc.Height()
  39. assert.True(sh < 5000)
  40. // let's check this is valid somehow
  41. assert.Nil(fc.ValidateFull(chainID))
  42. // historical queries now work :)
  43. lower := sh - 5
  44. fc, err = p.LatestFullCommit(chainID, lower, lower)
  45. assert.Nil(err, "%+v", err)
  46. assert.Equal(lower, fc.Height())
  47. }