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.

62 lines
1.5 KiB

  1. package client_test
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/stretchr/testify/require"
  7. rpctest "github.com/tendermint/tendermint/rpc/test"
  8. "github.com/tendermint/tendermint/certifiers"
  9. "github.com/tendermint/tendermint/certifiers/client"
  10. certerr "github.com/tendermint/tendermint/certifiers/errors"
  11. )
  12. func TestProvider(t *testing.T) {
  13. assert, require := assert.New(t), require.New(t)
  14. cfg := rpctest.GetConfig()
  15. rpcAddr := cfg.RPC.ListenAddress
  16. chainID := cfg.ChainID
  17. p := client.NewHTTPProvider(rpcAddr)
  18. require.NotNil(t, p)
  19. // let it produce some blocks
  20. time.Sleep(500 * time.Millisecond)
  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 := certifiers.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(certerr.IsCommitNotFoundErr(err))
  45. // storing the seed silently ignored
  46. err = p.StoreCommit(seed)
  47. assert.Nil(err, "%+v", err)
  48. }