Some checks are pending
docker-build-cometbft / vars (push) Waiting to run
docker-build-cometbft / build-images (amd64, ubuntu-24.04) (push) Blocked by required conditions
docker-build-cometbft / build-images (arm64, ubuntu-24.04-arm) (push) Blocked by required conditions
docker-build-cometbft / merge-images (push) Blocked by required conditions
docker-build-e2e-node / vars (push) Waiting to run
docker-build-e2e-node / build-images (amd64, ubuntu-24.04) (push) Blocked by required conditions
docker-build-e2e-node / build-images (arm64, ubuntu-24.04-arm) (push) Blocked by required conditions
docker-build-e2e-node / merge-images (push) Blocked by required conditions
28 lines
666 B
Go
28 lines
666 B
Go
package test
|
|
|
|
import (
|
|
cmtrand "github.com/cometbft/cometbft/libs/rand"
|
|
)
|
|
|
|
// 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 cmtrand.Int() % 2 {
|
|
case 0: // Mutate a single byte
|
|
bytez[cmtrand.Int()%len(bytez)] += byte(cmtrand.Int()%255 + 1)
|
|
case 1: // Remove an arbitrary byte
|
|
pos := cmtrand.Int() % len(bytez)
|
|
bytez = append(bytez[:pos], bytez[pos+1:]...)
|
|
}
|
|
return bytez
|
|
}
|