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.

63 lines
1.6 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. "github.com/tendermint/tendermint/types"
  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. genDoc, _ := types.GenesisDocFromFile(cfg.GenesisFile())
  17. chainID := genDoc.ChainID
  18. p := NewHTTPProvider(rpcAddr)
  19. require.NotNil(t, p)
  20. // let it produce some blocks
  21. err := rpcclient.WaitForHeight(p.(*provider).node, 6, nil)
  22. require.Nil(err)
  23. // let's get the highest block
  24. seed, err := p.LatestCommit()
  25. require.Nil(err, "%+v", err)
  26. sh := seed.Height()
  27. vhash := seed.Header.ValidatorsHash
  28. assert.True(sh < 5000)
  29. // let's check this is valid somehow
  30. assert.Nil(seed.ValidateBasic(chainID))
  31. cert := lite.NewStaticCertifier(chainID, seed.Validators)
  32. // historical queries now work :)
  33. lower := sh - 5
  34. seed, err = p.GetByHeight(lower)
  35. assert.Nil(err, "%+v", err)
  36. assert.Equal(lower, seed.Height())
  37. // also get by hash (given the match)
  38. seed, err = p.GetByHash(vhash)
  39. require.Nil(err, "%+v", err)
  40. require.Equal(vhash, seed.Header.ValidatorsHash)
  41. err = cert.Certify(seed.Commit)
  42. assert.Nil(err, "%+v", err)
  43. // get by hash fails without match
  44. seed, err = p.GetByHash([]byte("foobar"))
  45. assert.NotNil(err)
  46. assert.True(liteErr.IsCommitNotFoundErr(err))
  47. // storing the seed silently ignored
  48. err = p.StoreCommit(seed)
  49. assert.Nil(err, "%+v", err)
  50. }