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.

56 lines
1.5 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 bytes
  16. require.Equal(t, a.Bytes(), a.Bytes())
  17. require.Equal(t, b.Bytes(), b.Bytes())
  18. require.Equal(t, a.Bytes(), b.Bytes())
  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 serializes differently
  22. var last []byte
  23. assert.Equal(t, last, a.Bytes()) // first one is empty
  24. for i, res := range results[1:] {
  25. bz := res.Bytes()
  26. assert.NotEqual(t, last, bz, "%d", i)
  27. last = bz
  28. }
  29. // Make sure that we can get a root hash from results and verify proofs.
  30. root := results.Hash()
  31. assert.NotEmpty(t, root)
  32. for i, res := range results {
  33. proof := results.ProveResult(i)
  34. valid := proof.Verify(root, res.Bytes())
  35. assert.NoError(t, valid, "%d", i)
  36. }
  37. }
  38. func TestABCIResultsBytes(t *testing.T) {
  39. results := NewResults([]*abci.ResponseDeliverTx{
  40. {Code: 0, Data: []byte{}},
  41. {Code: 0, Data: []byte("one")},
  42. {Code: 14, Data: nil},
  43. {Code: 14, Data: []byte("foo")},
  44. {Code: 14, Data: []byte("bar")},
  45. })
  46. assert.NotNil(t, results.Bytes())
  47. }