Files
wasmd/x/wasm/internal/keeper/test_fuzz.go
Alexander Peters 774f6d7876 Introduce Wasmgovd (#189)
* Introduce wasmgovd; disable wasm proposals with wasmd

* Update changelog

* Setup wasmgov with permission Nobody

* Review feedback
2020-07-16 16:47:44 +02:00

54 lines
1.3 KiB
Go

package keeper
import (
"github.com/CosmWasm/wasmd/x/wasm/internal/types"
sdk "github.com/cosmos/cosmos-sdk/types"
fuzz "github.com/google/gofuzz"
tmBytes "github.com/tendermint/tendermint/libs/bytes"
)
func FuzzAddr(m *sdk.AccAddress, c fuzz.Continue) {
*m = make([]byte, 20)
c.Read(*m)
}
func FuzzAbsoluteTxPosition(m *types.AbsoluteTxPosition, c fuzz.Continue) {
m.BlockHeight = int64(c.RandUint64()) // can't be negative
m.TxIndex = c.RandUint64()
}
func FuzzContractInfo(m *types.ContractInfo, c fuzz.Continue) {
const maxSize = 1024
m.CodeID = c.RandUint64()
FuzzAddr(&m.Creator, c)
FuzzAddr(&m.Admin, c)
m.Label = c.RandString()
m.InitMsg = make([]byte, c.RandUint64()%maxSize)
c.Read(m.InitMsg)
c.Fuzz(&m.Created)
c.Fuzz(&m.LastUpdated)
m.PreviousCodeID = c.RandUint64()
}
func FuzzStateModel(m *types.Model, c fuzz.Continue) {
m.Key = tmBytes.HexBytes(c.RandString())
c.Fuzz(&m.Value)
}
func FuzzAccessType(m *types.AccessType, c fuzz.Continue) {
pos := c.Int() % len(types.AllAccessTypes)
for k, _ := range types.AllAccessTypes {
if pos == 0 {
*m = k
return
}
pos--
}
}
func FuzzAccessConfig(m *types.AccessConfig, c fuzz.Continue) {
FuzzAccessType(&m.Type, c)
var add sdk.AccAddress
FuzzAddr(&add, c)
*m = m.Type.With(add)
}