From d5b7fc54e7e7fc4fc78516b2e49d3a55e747be16 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Sat, 24 Aug 2024 13:03:16 +0300 Subject: [PATCH] manifest: deduplicate test logic a bit with slices.Concat LIkely it's more readable this way. Signed-off-by: Roman Khimov --- pkg/smartcontract/manifest/manifest_test.go | 27 +++++++++++---------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/pkg/smartcontract/manifest/manifest_test.go b/pkg/smartcontract/manifest/manifest_test.go index 308829e0e..b7c15fcde 100644 --- a/pkg/smartcontract/manifest/manifest_test.go +++ b/pkg/smartcontract/manifest/manifest_test.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "math/big" + "slices" "testing" "github.com/nspcc-dev/neo-go/internal/random" @@ -382,19 +383,19 @@ func TestManifest_FromStackItemErrors(t *testing.T) { errCases := map[string]stackitem.Item{ "not a struct": stackitem.NewArray([]stackitem.Item{}), "invalid length": stackitem.NewStruct([]stackitem.Item{}), - "invalid name type": stackitem.NewStruct(append([]stackitem.Item{stackitem.NewInterop(nil)}, goodSI[1:]...)), - "invalid Groups type": stackitem.NewStruct(append([]stackitem.Item{name, stackitem.Null{}}, goodSI[2:]...)), - "invalid group": stackitem.NewStruct(append([]stackitem.Item{name, stackitem.NewArray([]stackitem.Item{stackitem.Null{}})}, goodSI[2:]...)), - "invalid Features type": stackitem.NewStruct(append([]stackitem.Item{name, groups, stackitem.Null{}}, goodSI[3:]...)), - "invalid supported standards type": stackitem.NewStruct(append([]stackitem.Item{name, groups, features, stackitem.Null{}}, goodSI[4:]...)), - "invalid supported standard": stackitem.NewStruct(append([]stackitem.Item{name, groups, features, stackitem.NewArray([]stackitem.Item{stackitem.Null{}})}, goodSI[4:]...)), - "invalid ABI": stackitem.NewStruct(append([]stackitem.Item{name, groups, features, sStandards, stackitem.Null{}}, goodSI[5:]...)), - "invalid Permissions type": stackitem.NewStruct(append([]stackitem.Item{name, groups, features, sStandards, abi, stackitem.Null{}}, goodSI[6:]...)), - "invalid permission": stackitem.NewStruct(append([]stackitem.Item{name, groups, features, sStandards, abi, stackitem.NewArray([]stackitem.Item{stackitem.Null{}})}, goodSI[6:]...)), - "invalid Trusts type": stackitem.NewStruct(append([]stackitem.Item{name, groups, features, sStandards, abi, permissions, stackitem.NewInterop(nil)}, goodSI[7:]...)), - "invalid trust": stackitem.NewStruct(append([]stackitem.Item{name, groups, features, sStandards, abi, permissions, stackitem.NewArray([]stackitem.Item{stackitem.NewInterop(nil)})}, goodSI[7:]...)), - "invalid Uint160 trust": stackitem.NewStruct(append([]stackitem.Item{name, groups, features, sStandards, abi, permissions, stackitem.NewArray([]stackitem.Item{stackitem.NewByteArray([]byte{1, 2, 3})})}, goodSI[7:]...)), - "invalid extra type": stackitem.NewStruct([]stackitem.Item{name, groups, features, sStandards, abi, permissions, trusts, stackitem.Null{}}), + "invalid name type": stackitem.NewStruct(slices.Concat([]stackitem.Item{stackitem.NewInterop(nil)}, goodSI[1:])), + "invalid Groups type": stackitem.NewStruct(slices.Concat(goodSI[:1], []stackitem.Item{stackitem.Null{}}, goodSI[2:])), + "invalid group": stackitem.NewStruct(slices.Concat(goodSI[:1], []stackitem.Item{stackitem.NewArray([]stackitem.Item{stackitem.Null{}})}, goodSI[2:])), + "invalid Features type": stackitem.NewStruct(slices.Concat(goodSI[:2], []stackitem.Item{stackitem.Null{}}, goodSI[3:])), + "invalid supported standards type": stackitem.NewStruct(slices.Concat(goodSI[:3], []stackitem.Item{stackitem.Null{}}, goodSI[4:])), + "invalid supported standard": stackitem.NewStruct(slices.Concat(goodSI[:3], []stackitem.Item{stackitem.NewArray([]stackitem.Item{stackitem.Null{}})}, goodSI[4:])), + "invalid ABI": stackitem.NewStruct(slices.Concat(goodSI[:4], []stackitem.Item{stackitem.Null{}}, goodSI[5:])), + "invalid Permissions type": stackitem.NewStruct(slices.Concat(goodSI[:5], []stackitem.Item{stackitem.Null{}}, goodSI[6:])), + "invalid permission": stackitem.NewStruct(slices.Concat(goodSI[:5], []stackitem.Item{stackitem.NewArray([]stackitem.Item{stackitem.Null{}})}, goodSI[6:])), + "invalid Trusts type": stackitem.NewStruct(slices.Concat(goodSI[:6], []stackitem.Item{stackitem.NewInterop(nil)}, goodSI[7:])), + "invalid trust": stackitem.NewStruct(slices.Concat(goodSI[:6], []stackitem.Item{stackitem.NewArray([]stackitem.Item{stackitem.NewInterop(nil)})}, goodSI[7:])), + "invalid Uint160 trust": stackitem.NewStruct(slices.Concat(goodSI[:6], []stackitem.Item{stackitem.NewArray([]stackitem.Item{stackitem.NewByteArray([]byte{1, 2, 3})})}, goodSI[7:])), + "invalid extra type": stackitem.NewStruct(slices.Concat(goodSI[:7], []stackitem.Item{stackitem.Null{}})), } for name, errCase := range errCases { t.Run(name, func(t *testing.T) {