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