neo-go/pkg/vm/fuzz_test.go
Evgeniy Stratonikov 9712be78fd vm: optimize refcounter
```
name                    old time/op    new time/op    delta
RefCounter_Add-8          9.47ns ± 4%    2.75ns ± 1%   -70.92%  (p=0.000 n=10+9)
RefCounter_AddRemove-8    88.9ns ±20%     5.5ns ± 4%   -93.78%  (p=0.000 n=10+10)

name                    old alloc/op   new alloc/op   delta
RefCounter_Add-8           0.00B          0.00B           ~     (all equal)
RefCounter_AddRemove-8     48.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)

name                    old allocs/op  new allocs/op  delta
RefCounter_Add-8            0.00           0.00           ~     (all equal)
RefCounter_AddRemove-8      2.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
```

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2022-08-23 13:18:06 +03:00

59 lines
1.5 KiB
Go

//go:build go1.18
package vm
import (
"testing"
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
"github.com/stretchr/testify/require"
)
var fuzzSeedValidScripts = [][]byte{
makeProgram(opcode.PUSH1, opcode.PUSH10, opcode.ADD),
makeProgram(opcode.PUSH10, opcode.JMP, 3, opcode.ABORT, opcode.RET),
makeProgram(opcode.PUSHINT16, 1, 2, opcode.PUSHINT32, 3, 4, opcode.DROP),
makeProgram(opcode.PUSH2, opcode.NEWARRAY, opcode.DUP, opcode.PUSH0, opcode.PUSH1, opcode.SETITEM, opcode.VALUES),
append([]byte{byte(opcode.PUSHDATA1), 10}, randomBytes(10)...),
append([]byte{byte(opcode.PUSHDATA1), 100}, randomBytes(100)...),
// Simplified version of fuzzer output from #2659.
{byte(opcode.CALL), 3, byte(opcode.ASSERT),
byte(opcode.CALL), 3, byte(opcode.ASSERT),
byte(opcode.DEPTH), byte(opcode.PACKSTRUCT), byte(opcode.DUP),
byte(opcode.UNPACK), byte(opcode.PACKSTRUCT), byte(opcode.POPITEM),
byte(opcode.DEPTH)},
}
func FuzzIsScriptCorrect(f *testing.F) {
for _, s := range fuzzSeedValidScripts {
f.Add(s)
}
f.Fuzz(func(t *testing.T, script []byte) {
require.NotPanics(t, func() {
_ = IsScriptCorrect(script, nil)
})
})
}
func FuzzVMDontPanic(f *testing.F) {
for _, s := range fuzzSeedValidScripts {
f.Add(s)
}
f.Fuzz(func(t *testing.T, script []byte) {
if IsScriptCorrect(script, nil) != nil {
return
}
v := load(script)
// Prevent infinite loops from being reported as fail.
v.GasLimit = 1000
v.getPrice = func(opcode.Opcode, []byte) int64 {
return 1
}
require.NotPanics(t, func() {
_ = v.Run()
})
})
}