core: refactor TestEngineLimits

Replace repetative hand-written code with generated one.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
Anna Shaleva 2024-10-18 19:10:47 +03:00
parent b5b89881b7
commit 7b09812069

View file

@ -2629,15 +2629,18 @@ func TestBlockchain_StoreAsTransaction_ExecutableConflict(t *testing.T) {
// sure that NeoGo node is not affected by https://github.com/neo-project/neo/issues/3300 and does not need // sure that NeoGo node is not affected by https://github.com/neo-project/neo/issues/3300 and does not need
// the https://github.com/neo-project/neo/pull/3301. // the https://github.com/neo-project/neo/pull/3301.
func TestEngineLimits(t *testing.T) { func TestEngineLimits(t *testing.T) {
const eArgsCount = 500
bc, acc := chain.NewSingle(t) bc, acc := chain.NewSingle(t)
e := neotest.NewExecutor(t, bc, acc, acc) e := neotest.NewExecutor(t, bc, acc, acc)
src := `package test args, _ := strings.CutSuffix(strings.Repeat(`"", `, eArgsCount), `, `)
src := fmt.Sprintf(`package test
import ( import (
"github.com/nspcc-dev/neo-go/pkg/interop/runtime" "github.com/nspcc-dev/neo-go/pkg/interop/runtime"
) )
// args is an array of LargeEvent parameters containing 500 empty strings. // args is an array of LargeEvent parameters containing 500 empty strings.
var args = []any{"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" }; var args = []any{%s};
func ProduceNumerousNotifications(count int) [][]any { func ProduceNumerousNotifications(count int) [][]any {
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
runtime.Notify("LargeEvent", args...) runtime.Notify("LargeEvent", args...)
@ -2657,8 +2660,7 @@ func TestEngineLimits(t *testing.T) {
res = append(res, smallObject...) res = append(res, smallObject...)
} }
return len(res) return len(res)
}` }`, args)
const eArgsCount = 500
eParams := make([]compiler.HybridParameter, eArgsCount) eParams := make([]compiler.HybridParameter, eArgsCount)
for i := range eParams { for i := range eParams {
eParams[i].Name = fmt.Sprintf("str%d", i) eParams[i].Name = fmt.Sprintf("str%d", i)
@ -2676,16 +2678,16 @@ func TestEngineLimits(t *testing.T) {
e.DeployContract(t, c, nil) e.DeployContract(t, c, nil)
// ProduceNumerousNotifications: 1 iteration, no limits are hit. // ProduceNumerousNotifications: 1 iteration, no limits are hit.
var args = make([]stackitem.Item, eArgsCount) var params = make([]stackitem.Item, eArgsCount)
for i := range args { for i := range params {
args[i] = stackitem.Make("") params[i] = stackitem.Make("")
} }
cInv := e.NewInvoker(c.Hash, acc) cInv := e.NewInvoker(c.Hash, acc)
cInv.Invoke(t, stackitem.Make([]stackitem.Item{ cInv.Invoke(t, stackitem.Make([]stackitem.Item{
stackitem.Make([]stackitem.Item{ stackitem.Make([]stackitem.Item{
stackitem.Make(c.Hash), stackitem.Make(c.Hash),
stackitem.Make("LargeEvent"), stackitem.Make("LargeEvent"),
stackitem.Make(args), stackitem.Make(params),
}), }),
}), "produceNumerousNotifications", 1) }), "produceNumerousNotifications", 1)