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
1.2 KiB

  1. package merkle
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestSimpleProofValidateBasic(t *testing.T) {
  7. testCases := []struct {
  8. testName string
  9. malleateProof func(*SimpleProof)
  10. errStr string
  11. }{
  12. {"Good", func(sp *SimpleProof) {}, ""},
  13. {"Negative Total", func(sp *SimpleProof) { sp.Total = -1 }, "negative Total"},
  14. {"Negative Index", func(sp *SimpleProof) { sp.Index = -1 }, "negative Index"},
  15. {"Invalid LeafHash", func(sp *SimpleProof) { sp.LeafHash = make([]byte, 10) },
  16. "expected LeafHash size to be 32, got 10"},
  17. {"Too many Aunts", func(sp *SimpleProof) { sp.Aunts = make([][]byte, MaxAunts+1) },
  18. "expected no more than 100 aunts, got 101"},
  19. {"Invalid Aunt", func(sp *SimpleProof) { sp.Aunts[0] = make([]byte, 10) },
  20. "expected Aunts#0 size to be 32, got 10"},
  21. }
  22. for _, tc := range testCases {
  23. tc := tc
  24. t.Run(tc.testName, func(t *testing.T) {
  25. _, proofs := SimpleProofsFromByteSlices([][]byte{
  26. []byte("apple"),
  27. []byte("watermelon"),
  28. []byte("kiwi"),
  29. })
  30. tc.malleateProof(proofs[0])
  31. err := proofs[0].ValidateBasic()
  32. if tc.errStr != "" {
  33. assert.Contains(t, err.Error(), tc.errStr)
  34. }
  35. })
  36. }
  37. }