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.

43 lines
1.1 KiB

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