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.

41 lines
1003 B

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