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.5 KiB

  1. package client
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/stretchr/testify/require"
  6. "github.com/tendermint/tendermint/lite"
  7. liteErr "github.com/tendermint/tendermint/lite/errors"
  8. rpcclient "github.com/tendermint/tendermint/rpc/client"
  9. rpctest "github.com/tendermint/tendermint/rpc/test"
  10. )
  11. func TestProvider(t *testing.T) {
  12. assert, require := assert.New(t), require.New(t)
  13. cfg := rpctest.GetConfig()
  14. rpcAddr := cfg.RPC.ListenAddress
  15. chainID := cfg.ChainID
  16. p := NewHTTPProvider(rpcAddr)
  17. require.NotNil(t, p)
  18. // let it produce some blocks
  19. err := rpcclient.WaitForHeight(p.(*provider).node, 6, nil)
  20. require.Nil(err)
  21. // let's get the highest block
  22. seed, err := p.LatestCommit()
  23. require.Nil(err, "%+v", err)
  24. sh := seed.Height()
  25. vhash := seed.Header.ValidatorsHash
  26. assert.True(sh < 5000)
  27. // let's check this is valid somehow
  28. assert.Nil(seed.ValidateBasic(chainID))
  29. cert := lite.NewStatic(chainID, seed.Validators)
  30. // historical queries now work :)
  31. lower := sh - 5
  32. seed, err = p.GetByHeight(lower)
  33. assert.Nil(err, "%+v", err)
  34. assert.Equal(lower, seed.Height())
  35. // also get by hash (given the match)
  36. seed, err = p.GetByHash(vhash)
  37. require.Nil(err, "%+v", err)
  38. require.Equal(vhash, seed.Header.ValidatorsHash)
  39. err = cert.Certify(seed.Commit)
  40. assert.Nil(err, "%+v", err)
  41. // get by hash fails without match
  42. seed, err = p.GetByHash([]byte("foobar"))
  43. assert.NotNil(err)
  44. assert.True(liteErr.IsCommitNotFoundErr(err))
  45. // storing the seed silently ignored
  46. err = p.StoreCommit(seed)
  47. assert.Nil(err, "%+v", err)
  48. }