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.

55 lines
1.4 KiB

  1. package types
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/stretchr/testify/require"
  6. abci "github.com/tendermint/tendermint/abci/types"
  7. )
  8. func TestABCIResults(t *testing.T) {
  9. a := ABCIResult{Code: 0, Data: nil}
  10. b := ABCIResult{Code: 0, Data: []byte{}}
  11. c := ABCIResult{Code: 0, Data: []byte("one")}
  12. d := ABCIResult{Code: 14, Data: nil}
  13. e := ABCIResult{Code: 14, Data: []byte("foo")}
  14. f := ABCIResult{Code: 14, Data: []byte("bar")}
  15. // Nil and []byte{} should produce the same hash.
  16. require.Equal(t, a.Hash(), a.Hash())
  17. require.Equal(t, b.Hash(), b.Hash())
  18. require.Equal(t, a.Hash(), b.Hash())
  19. // a and b should be the same, don't go in results.
  20. results := ABCIResults{a, c, d, e, f}
  21. // Make sure each result hashes properly.
  22. var last []byte
  23. for i, res := range results {
  24. h := res.Hash()
  25. assert.NotEqual(t, last, h, "%d", i)
  26. last = h
  27. }
  28. // Make sure that we can get a root hash from results and verify proofs.
  29. root := results.Hash()
  30. assert.NotEmpty(t, root)
  31. for i, res := range results {
  32. proof := results.ProveResult(i)
  33. valid := proof.Verify(i, len(results), res.Hash(), root)
  34. assert.True(t, valid, "%d", i)
  35. }
  36. }
  37. func TestABCIBytes(t *testing.T) {
  38. results := NewResults([]*abci.ResponseDeliverTx{
  39. {Code: 0, Data: []byte{}},
  40. {Code: 0, Data: []byte("one")},
  41. {Code: 14, Data: nil},
  42. {Code: 14, Data: []byte("foo")},
  43. {Code: 14, Data: []byte("bar")},
  44. })
  45. assert.NotNil(t, results.Bytes())
  46. }