/
test_fuzz.go
67 lines (59 loc) 路 1.66 KB
/
test_fuzz.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package keeper
import (
"github.com/enigmampc/SecretNetwork/x/compute/internal/types"
sdk "github.com/cosmos/cosmos-sdk/types"
fuzz "github.com/google/gofuzz"
tmBytes "github.com/tendermint/tendermint/libs/bytes"
)
var ModelFuzzers = []interface{}{FuzzAddr, FuzzAbsoluteTxPosition, FuzzContractInfo, FuzzStateModel /*FuzzAccessType, FuzzAccessConfig FuzzContractCodeHistory */}
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) {
m.CodeID = c.RandUint64()
FuzzAddr(&m.Creator, c)
// FuzzAddr(&m.Admin, c)
m.Label = c.RandString()
c.Fuzz(&m.Created)
}
/*
func FuzzContractCodeHistory(m *types.ContractCodeHistoryEntry, c fuzz.Continue) {
const maxMsgSize = 128
m.CodeID = c.RandUint64()
msg := make([]byte, c.RandUint64()%maxMsgSize)
c.Read(msg)
var err error
if m.Msg, err = json.Marshal(msg); err != nil {
panic(err)
}
c.Fuzz(&m.Updated)
m.Operation = types.AllCodeHistoryTypes[c.Int()%len(types.AllCodeHistoryTypes)]
}
*/
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)
}
*/