Merkle proofs!

This commit is contained in:
Jae Kwon
2015-05-24 14:19:46 -07:00
parent b5df5f6642
commit fdf0e720bc
9 changed files with 371 additions and 78 deletions
+4
View File
@@ -62,6 +62,10 @@ func RandUint() uint {
return uint(rand.Int())
}
func RandInt() int {
return rand.Int()
}
// Distributed pseudo-exponentially to test for various cases
func RandUint16Exp() uint16 {
bits := rand.Uint32() % 16
+28
View File
@@ -0,0 +1,28 @@
package test
import (
. "github.com/tendermint/tendermint/common"
)
// Contract: !bytes.Equal(input, output) && len(input) >= len(output)
func MutateByteSlice(bytez []byte) []byte {
// If bytez is empty, panic
if len(bytez) == 0 {
panic("Cannot mutate an empty bytez")
}
// Copy bytez
mBytez := make([]byte, len(bytez))
copy(mBytez, bytez)
bytez = mBytez
// Try a random mutation
switch RandInt() % 2 {
case 0: // Mutate a single byte
bytez[RandInt()%len(bytez)] += byte(RandInt()%255 + 1)
case 1: // Remove an arbitrary byte
pos := RandInt() % len(bytez)
bytez = append(bytez[:pos], bytez[pos+1:]...)
}
return bytez
}