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.

38 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) }, "expected LeafHash size to be 32, got 10"},
  16. {"Too many Aunts", func(sp *SimpleProof) { sp.Aunts = make([][]byte, maxAunts+1) }, "expected no more than 100 aunts, got 101"},
  17. {"Invalid Aunt", func(sp *SimpleProof) { sp.Aunts[0] = make([]byte, 10) }, "expected Aunts#0 size to be 32, got 10"},
  18. }
  19. for _, tc := range testCases {
  20. tc := tc
  21. t.Run(tc.testName, func(t *testing.T) {
  22. _, proofs := SimpleProofsFromByteSlices([][]byte{
  23. []byte("apple"),
  24. []byte("watermelon"),
  25. []byte("kiwi"),
  26. })
  27. tc.malleateProof(proofs[0])
  28. err := proofs[0].ValidateBasic()
  29. if tc.errStr != "" {
  30. assert.Contains(t, err.Error(), tc.errStr)
  31. }
  32. })
  33. }
  34. }