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.

54 lines
1.3 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 := &abci.ExecTxResult{Code: 0, Data: nil}
  10. b := &abci.ExecTxResult{Code: 0, Data: []byte{}}
  11. c := &abci.ExecTxResult{Code: 0, Data: []byte("one")}
  12. d := &abci.ExecTxResult{Code: 14, Data: nil}
  13. e := &abci.ExecTxResult{Code: 14, Data: []byte("foo")}
  14. f := &abci.ExecTxResult{Code: 14, Data: []byte("bar")}
  15. // Nil and []byte{} should produce the same bytes
  16. bzA, err := a.Marshal()
  17. require.NoError(t, err)
  18. bzB, err := b.Marshal()
  19. require.NoError(t, err)
  20. require.Equal(t, bzA, bzB)
  21. // a and b should be the same, don't go in results.
  22. results := ABCIResults{a, c, d, e, f}
  23. // Make sure each result serializes differently
  24. last := []byte{}
  25. assert.Equal(t, last, bzA) // first one is empty
  26. for i, res := range results[1:] {
  27. bz, err := res.Marshal()
  28. require.NoError(t, err)
  29. assert.NotEqual(t, last, bz, "%d", i)
  30. last = bz
  31. }
  32. // Make sure that we can get a root hash from results and verify proofs.
  33. root := results.Hash()
  34. assert.NotEmpty(t, root)
  35. for i, res := range results {
  36. bz, err := res.Marshal()
  37. require.NoError(t, err)
  38. proof := results.ProveResult(i)
  39. valid := proof.Verify(root, bz)
  40. assert.NoError(t, valid, "%d", i)
  41. }
  42. }