mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-03 22:57:22 +00:00
Merge remote-tracking branch 'tmlibs/master' into bucky/merge-tmlibs
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func AssertPanics(t *testing.T, msg string, f func()) {
|
||||
defer func() {
|
||||
if err := recover(); err == nil {
|
||||
t.Errorf("Should have panic'd, but didn't: %v", msg)
|
||||
}
|
||||
}()
|
||||
f()
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
cmn "github.com/tendermint/tmlibs/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 cmn.RandInt() % 2 {
|
||||
case 0: // Mutate a single byte
|
||||
bytez[cmn.RandInt()%len(bytez)] += byte(cmn.RandInt()%255 + 1)
|
||||
case 1: // Remove an arbitrary byte
|
||||
pos := cmn.RandInt() % len(bytez)
|
||||
bytez = append(bytez[:pos], bytez[pos+1:]...)
|
||||
}
|
||||
return bytez
|
||||
}
|
||||
Reference in New Issue
Block a user