From 88d2dbf7cc511b1878ac55cc21344060b5f8d962 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 15 Feb 2022 18:52:07 -0800 Subject: [PATCH 1/6] Various regression tests --- runtime/convertValues_test.go | 22 +++--- runtime/various_test.go | 144 ++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+), 10 deletions(-) create mode 100644 runtime/various_test.go diff --git a/runtime/convertValues_test.go b/runtime/convertValues_test.go index dd61b4017d..ff2c15a0f1 100644 --- a/runtime/convertValues_test.go +++ b/runtime/convertValues_test.go @@ -2099,25 +2099,27 @@ func TestRuntimeEnumValue(t *testing.T) { } func executeTestScript(t *testing.T, script string, arg cadence.Value) (cadence.Value, error) { - encodedArg, err := json.Encode(arg) - require.NoError(t, err) - rt := newTestInterpreterRuntime() - storage := newTestLedger(nil, nil) - runtimeInterface := &testRuntimeInterface{ - storage: storage, + storage: newTestLedger(nil, nil), decodeArgument: func(b []byte, t cadence.Type) (value cadence.Value, err error) { return json.Decode(b) }, } + scriptParam := Script{ + Source: []byte(script), + } + + if arg != nil { + encodedArg, err := json.Encode(arg) + require.NoError(t, err) + scriptParam.Arguments = [][]byte{encodedArg} + } + return rt.ExecuteScript( - Script{ - Source: []byte(script), - Arguments: [][]byte{encodedArg}, - }, + scriptParam, Context{ Interface: runtimeInterface, Location: TestLocation, diff --git a/runtime/various_test.go b/runtime/various_test.go new file mode 100644 index 0000000000..0bb60a8d05 --- /dev/null +++ b/runtime/various_test.go @@ -0,0 +1,144 @@ +/* + * Cadence - The resource-oriented smart contract programming language + * + * Copyright 2019-2020 Dapper Labs, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package runtime + +import ( + "fmt" + "testing" + + "github.com/onflow/cadence/runtime/parser2" + + "github.com/stretchr/testify/require" + + "github.com/onflow/cadence/runtime/sema" +) + +func TestVariousAgainstRegression(t *testing.T) { + t.Parallel() + + doTest := func(code string, verify func(t *testing.T, err error)) { + t.Run(code, func(t *testing.T) { + script := fmt.Sprintf(` + pub fun main() { + %s + }`, code) + _, err := executeTestScript(t, script, nil) + verify(t, err) + }) + } + + testChildErrors := func(t *testing.T, e error, childErrors []error) { + e2, ok := e.(interface{ ChildErrors() []error }) + require.Truef(t, ok, "Error does not implement ChildErrors(): %e", e) + require.Lenf(t, e2.ChildErrors(), len(childErrors), + "Error has the wrong number of children: %d != %d", len(e2.ChildErrors()), len(childErrors)) + for i, e3 := range childErrors { + require.IsType(t, childErrors[i], e3) + } + } + + doTest("paste your code in here", func(t *testing.T, err error) { + var e *ParsingCheckingError + require.ErrorAs(t, err, &e) + }) + + doTest("resource as { enum x : as { } }", func(t *testing.T, err error) { + var e *sema.CheckerError + require.ErrorAs(t, err, &e) + testChildErrors(t, e, []error{&sema.InvalidDeclarationError{}}) + }) + + doTest("resource interface struct{struct d:struct{ struct d:struct{ }struct d:struct{ struct d:struct{ }}}}", func(t *testing.T, err error) { + var e *sema.CheckerError + require.ErrorAs(t, err, &e) + testChildErrors(t, e, []error{&sema.InvalidDeclarationError{}}) + }) + + doTest("resource interface struct{struct d:struct{ contract d:struct{ contract x:struct{ struct d{} contract d:struct{ contract d:struct {}}}}}}", func(t *testing.T, err error) { + var e *sema.CheckerError + require.ErrorAs(t, err, &e) + testChildErrors(t, e, []error{&sema.InvalidDeclarationError{}}) + }) + + doTest("struct interface var { contract h : var { contract h { } contract h { contract h { } } } }", func(t *testing.T, err error) { + var e *sema.CheckerError + require.ErrorAs(t, err, &e) + testChildErrors(t, e, []error{&sema.InvalidDeclarationError{}}) + }) + + doTest("contract signatureAlgorithm { resource interface payer { contract fun : payer { contract fun { contract fun { } contract fun { contract interface account { } } contract account { } } } } }", func(t *testing.T, err error) { + var e *sema.CheckerError + require.ErrorAs(t, err, &e) + testChildErrors(t, e, []error{&sema.InvalidDeclarationError{}}) + }) + + doTest("# a ( b > c > d > e > f > g > h > i > j > k > l > m > n > o > p > q > r > s > t > u > v > w > x > y > z > A > B > C > D > E > F>", func(t *testing.T, err error) { + var e *ParsingCheckingError + require.ErrorAs(t, err, &e) + + require.IsType(t, e.Unwrap(), parser2.Error{}) + testChildErrors(t, e.Unwrap().(parser2.Error), []error{&parser2.SyntaxError{}}) + }) + + doTest("let b=0.0as!PublicKey.Contracts", func(t *testing.T, err error) { + var e *sema.CheckerError + require.ErrorAs(t, err, &e) + testChildErrors(t, e, []error{&sema.InvalidDeclarationError{}}) + }) + + doTest("let UInt64 = UInt64 ( 0b0 )", func(t *testing.T, err error) { + var e *sema.CheckerError + require.ErrorAs(t, err, &e) + testChildErrors(t, e, []error{&sema.RedeclarationError{}}) + }) + + doTest("contract enum{}let x = enum!", func(t *testing.T, err error) { + var e *ParsingCheckingError + require.ErrorAs(t, err, &e) + + require.IsType(t, e.Unwrap(), parser2.Error{}) + testChildErrors(t, e.Unwrap().(parser2.Error), []error{&parser2.SyntaxError{}}) + }) + + doTest("#0x0<{},>()", func(t *testing.T, err error) { + var e *ParsingCheckingError + require.ErrorAs(t, err, &e) + + require.IsType(t, e.Unwrap(), parser2.Error{}) + testChildErrors(t, e.Unwrap().(parser2.Error), []error{&parser2.SyntaxError{}}) + }) + + doTest("var a=[Type]", func(t *testing.T, err error) { + require.NoError(t, err) + }) + + doTest("var j={0.0:Type}", func(t *testing.T, err error) { + require.NoError(t, err) + }) + + doTest("let Type = Type", func(t *testing.T, err error) { + var e *sema.CheckerError + require.ErrorAs(t, err, &e) + testChildErrors(t, e, []error{&sema.RedeclarationError{}}) + }) + + doTest("let a = 0x0 as UInt64!as?UInt64!as?UInt64?!?.getType()", func(t *testing.T, err error) { + require.NoError(t, err) + }) +} From 14a73c0c5ffb459db0a14ca0264b0c1a934da896 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 2 Mar 2022 15:01:38 -0800 Subject: [PATCH 2/6] refactor regression tests --- runtime/parser2/parser_test.go | 23 +++- runtime/tests/checker/casting_test.go | 20 +++ runtime/tests/checker/contract_test.go | 40 ++++++ runtime/tests/checker/declaration_test.go | 34 +++++ runtime/tests/checker/interface_test.go | 21 ++++ runtime/tests/checker/nesting_test.go | 10 ++ runtime/tests/checker/resources_test.go | 62 ++++++++++ runtime/various_test.go | 144 ---------------------- 8 files changed, 207 insertions(+), 147 deletions(-) delete mode 100644 runtime/various_test.go diff --git a/runtime/parser2/parser_test.go b/runtime/parser2/parser_test.go index 9dc830214b..26bb82ba43 100644 --- a/runtime/parser2/parser_test.go +++ b/runtime/parser2/parser_test.go @@ -37,11 +37,28 @@ func TestMain(m *testing.M) { } func TestParseInvalid(t *testing.T) { - t.Parallel() - _, err := ParseProgram("X") - require.EqualError(t, err, "Parsing failed:\nerror: unexpected token: identifier\n --> :1:0\n |\n1 | X\n | ^\n") + type test struct { + msg string + code string + } + + unexpectedToken := "Parsing failed:\nerror: unexpected token: identifier" + expectedExpression := "Parsing failed:\nerror: expected expression" + missingTypeAnnotation := "Parsing failed:\nerror: missing type annotation after comma" + + for _, test := range []test{ + {unexpectedToken, "X"}, + {unexpectedToken, "paste your code in here"}, + {expectedExpression, "# a ( b > c > d > e > f > g > h > i > j > k > l > m > n > o > p > q > r > s > t > u > v > w > x > y > z > A > B > C > D > E > F>"}, + {missingTypeAnnotation, "#0x0<{},>()"}, + } { + t.Run(test.code, func(t *testing.T) { + _, err := ParseProgram(test.code) + require.ErrorContains(t, err, test.msg) + }) + } } func TestParseBuffering(t *testing.T) { diff --git a/runtime/tests/checker/casting_test.go b/runtime/tests/checker/casting_test.go index 646a0fbab6..a4f5345517 100644 --- a/runtime/tests/checker/casting_test.go +++ b/runtime/tests/checker/casting_test.go @@ -6676,3 +6676,23 @@ func TestCheckUnnecessaryCasts(t *testing.T) { }) }) } + +func TestCastResourceAsEnumAsEmptyDict(t *testing.T) { + t.Parallel() + + _, err := ParseAndCheck(t, "resource as { enum x : as { } }") + + errs := ExpectCheckerErrors(t, err, 1) + + assert.IsType(t, &sema.TypeMismatchError{}, errs[0]) +} + +// + +func TestCastNumbersManyTimesThenGetType(t *testing.T) { + t.Parallel() + + _, err := ParseAndCheck(t, "let a = 0x0 as UInt64!as?UInt64!as?UInt64?!?.getType()") + + assert.Nil(t, err) +} \ No newline at end of file diff --git a/runtime/tests/checker/contract_test.go b/runtime/tests/checker/contract_test.go index ed8a7a308a..671f016961 100644 --- a/runtime/tests/checker/contract_test.go +++ b/runtime/tests/checker/contract_test.go @@ -708,3 +708,43 @@ func TestCheckInvalidContractNestedTypeShadowing(t *testing.T) { }) } } + +func TestBadContractNesting(t *testing.T) { + t.Parallel() + + _, err := ParseAndCheck(t, "contract signatureAlgorithm { resource interface payer { contract fun : payer { contract fun { contract fun { } contract fun { contract interface account { } } contract account { } } } } }") + + errs := ExpectCheckerErrors(t, err, 14) + + assert.IsType(t, &sema.InvalidNestedDeclarationError{}, errs[0]) + assert.IsType(t, &sema.InvalidNestedDeclarationError{}, errs[1]) + assert.IsType(t, &sema.RedeclarationError{}, errs[2]) + assert.IsType(t, &sema.InvalidNestedDeclarationError{}, errs[3]) + assert.IsType(t, &sema.InvalidNestedDeclarationError{}, errs[4]) + assert.IsType(t, &sema.InvalidNestedDeclarationError{}, errs[5]) + assert.IsType(t, &sema.RedeclarationError{}, errs[6]) + assert.IsType(t, &sema.RedeclarationError{}, errs[7]) + assert.IsType(t, &sema.InvalidNestedDeclarationError{}, errs[8]) + assert.IsType(t, &sema.RedeclarationError{}, errs[9]) + assert.IsType(t, &sema.CompositeKindMismatchError{}, errs[10]) + assert.IsType(t, &sema.MissingConformanceError{}, errs[11]) + assert.IsType(t, &sema.RedeclarationError{}, errs[12]) + assert.IsType(t, &sema.RedeclarationError{}, errs[13]) +} + +func TestCheckContractEnumAccessRestricted(t *testing.T) { + t.Parallel() + + _, err := ParseAndCheckWithOptions(t, "contract enum{}let x = enum!", + ParseAndCheckOptions{ + Options: []sema.Option{ + sema.WithAccessCheckMode(sema.AccessCheckModeStrict), + }, + }, + ) + + errs := ExpectCheckerErrors(t, err, 2) + + assert.IsType(t, &sema.MissingAccessModifierError{}, errs[0]) + assert.IsType(t, &sema.MissingAccessModifierError{}, errs[1]) +} diff --git a/runtime/tests/checker/declaration_test.go b/runtime/tests/checker/declaration_test.go index aaf08feade..11083c88f7 100644 --- a/runtime/tests/checker/declaration_test.go +++ b/runtime/tests/checker/declaration_test.go @@ -677,3 +677,37 @@ func TestCheckBuiltinRedeclaration(t *testing.T) { }, ) } + +func TestCheckUint64RedeclarationFails(t *testing.T) { + t.Parallel() + + _, err := ParseAndCheck(t, "let UInt64 = UInt64 ( 0b0 )") + + errs := ExpectCheckerErrors(t, err, 1) + + assert.IsType(t, &sema.RedeclarationError{}, errs[0]) +} + +func TestCheckTypeRedeclarationFails(t *testing.T) { + t.Parallel() + + _, err := ParseAndCheck(t, "let Type = Type") + + errs := ExpectCheckerErrors(t, err, 1) + + assert.IsType(t, &sema.RedeclarationError{}, errs[0]) +} + +func TestCheckSetToTypeList(t *testing.T) { + t.Parallel() + + _, err := ParseAndCheck(t, "var a=[Type]") + assert.Nil(t, err) +} + +func TestCheckSetToDictWithType(t *testing.T) { + t.Parallel() + + _, err := ParseAndCheck(t, "var j={0.0:Type}") + assert.Nil(t, err) +} diff --git a/runtime/tests/checker/interface_test.go b/runtime/tests/checker/interface_test.go index 10812e4d90..0f9d78356b 100644 --- a/runtime/tests/checker/interface_test.go +++ b/runtime/tests/checker/interface_test.go @@ -1991,3 +1991,24 @@ func TestCheckInvalidInterfaceUseAsTypeSuggestion(t *testing.T) { errs[0].(*sema.InvalidInterfaceTypeError).ExpectedType, ) } + +func TestBadStructInterface(t *testing.T) { + t.Parallel() + + _, err := ParseAndCheck(t, "struct interface var { contract h : var { contract h { } contract h { contract h { } } } }") + + errs := ExpectCheckerErrors(t, err, 12) + + assert.IsType(t, &sema.InvalidNestedDeclarationError{}, errs[0]) + assert.IsType(t, &sema.InvalidNestedDeclarationError{}, errs[1]) + assert.IsType(t, &sema.InvalidNestedDeclarationError{}, errs[2]) + assert.IsType(t, &sema.RedeclarationError{}, errs[3]) + assert.IsType(t, &sema.RedeclarationError{}, errs[4]) + assert.IsType(t, &sema.InvalidNestedDeclarationError{}, errs[5]) + assert.IsType(t, &sema.RedeclarationError{}, errs[6]) + assert.IsType(t, &sema.RedeclarationError{}, errs[7]) + assert.IsType(t, &sema.RedeclarationError{}, errs[8]) + assert.IsType(t, &sema.RedeclarationError{}, errs[9]) + assert.IsType(t, &sema.CompositeKindMismatchError{}, errs[10]) + assert.IsType(t, &sema.RedeclarationError{}, errs[11]) +} \ No newline at end of file diff --git a/runtime/tests/checker/nesting_test.go b/runtime/tests/checker/nesting_test.go index c66414b52b..d146472399 100644 --- a/runtime/tests/checker/nesting_test.go +++ b/runtime/tests/checker/nesting_test.go @@ -323,3 +323,13 @@ func TestCheckNestedTypeInvalidChildType(t *testing.T) { }) } } + +func TestCheckNestedTypeUnsupportedPublicKey(t *testing.T) { + t.Parallel() + + _, err := ParseAndCheck(t, "let b=0.0as!PublicKey.Contracts") + + errs := ExpectCheckerErrors(t, err, 1) + + assert.IsType(t, &sema.InvalidNestedTypeError{}, errs[0]) +} diff --git a/runtime/tests/checker/resources_test.go b/runtime/tests/checker/resources_test.go index c9ae20df57..5690cf0dbe 100644 --- a/runtime/tests/checker/resources_test.go +++ b/runtime/tests/checker/resources_test.go @@ -3190,6 +3190,7 @@ func TestCheckResourceInterfaceUseAsType(t *testing.T) { require.NoError(t, err) } + func TestCheckResourceArrayIndexing(t *testing.T) { t.Parallel() @@ -8616,3 +8617,64 @@ func TestCheckResourceInvalidationWithConditionalExprInDestroy(t *testing.T) { assert.IsType(t, &sema.InvalidConditionalResourceOperandError{}, errs[0]) assert.IsType(t, &sema.InvalidConditionalResourceOperandError{}, errs[1]) } + +func TestBadResourceInterface(t *testing.T) { + t.Parallel() + + t.Run("bad resource interface: shorter", func(t *testing.T) { + + _, err := ParseAndCheck(t, "resource interface struct{struct d:struct{ struct d:struct{ }struct d:struct{ struct d:struct{ }}}}") + + errs := ExpectCheckerErrors(t, err, 17) + + assert.IsType(t, &sema.InvalidNestedDeclarationError{}, errs[0]) + assert.IsType(t, &sema.InvalidNestedDeclarationError{}, errs[1]) + assert.IsType(t, &sema.RedeclarationError{}, errs[2]) + assert.IsType(t, &sema.RedeclarationError{}, errs[3]) + assert.IsType(t, &sema.InvalidNestedDeclarationError{}, errs[4]) + assert.IsType(t, &sema.RedeclarationError{}, errs[5]) + assert.IsType(t, &sema.RedeclarationError{}, errs[6]) + assert.IsType(t, &sema.RedeclarationError{}, errs[7]) + assert.IsType(t, &sema.RedeclarationError{}, errs[8]) + assert.IsType(t, &sema.CompositeKindMismatchError{}, errs[9]) + assert.IsType(t, &sema.RedeclarationError{}, errs[10]) + assert.IsType(t, &sema.CompositeKindMismatchError{}, errs[11]) + assert.IsType(t, &sema.ConformanceError{}, errs[12]) + assert.IsType(t, &sema.CompositeKindMismatchError{}, errs[13]) + assert.IsType(t, &sema.ConformanceError{}, errs[14]) + assert.IsType(t, &sema.CompositeKindMismatchError{}, errs[15]) + assert.IsType(t, &sema.ConformanceError{}, errs[16]) + }) + + t.Run("bad resource interface: longer", func(t *testing.T) { + + _, err := ParseAndCheck(t, "resource interface struct{struct d:struct{ contract d:struct{ contract x:struct{ struct d{} contract d:struct{ contract d:struct {}}}}}}") + + errs := ExpectCheckerErrors(t, err, 24) + + assert.IsType(t, &sema.InvalidNestedDeclarationError{}, errs[0]) + assert.IsType(t, &sema.InvalidNestedDeclarationError{}, errs[1]) + assert.IsType(t, &sema.RedeclarationError{}, errs[2]) + assert.IsType(t, &sema.InvalidNestedDeclarationError{}, errs[3]) + assert.IsType(t, &sema.InvalidNestedDeclarationError{}, errs[4]) + assert.IsType(t, &sema.RedeclarationError{}, errs[5]) + assert.IsType(t, &sema.RedeclarationError{}, errs[6]) + assert.IsType(t, &sema.InvalidNestedDeclarationError{}, errs[7]) + assert.IsType(t, &sema.RedeclarationError{}, errs[8]) + assert.IsType(t, &sema.RedeclarationError{}, errs[9]) + assert.IsType(t, &sema.RedeclarationError{}, errs[10]) + assert.IsType(t, &sema.CompositeKindMismatchError{}, errs[11]) + assert.IsType(t, &sema.CompositeKindMismatchError{}, errs[12]) + assert.IsType(t, &sema.ConformanceError{}, errs[13]) + assert.IsType(t, &sema.CompositeKindMismatchError{}, errs[14]) + assert.IsType(t, &sema.ConformanceError{}, errs[15]) + assert.IsType(t, &sema.RedeclarationError{}, errs[16]) + assert.IsType(t, &sema.CompositeKindMismatchError{}, errs[17]) + assert.IsType(t, &sema.RedeclarationError{}, errs[18]) + assert.IsType(t, &sema.CompositeKindMismatchError{}, errs[19]) + assert.IsType(t, &sema.CompositeKindMismatchError{}, errs[20]) + assert.IsType(t, &sema.ConformanceError{}, errs[21]) + assert.IsType(t, &sema.CompositeKindMismatchError{}, errs[22]) + assert.IsType(t, &sema.ConformanceError{}, errs[23]) + }) +} diff --git a/runtime/various_test.go b/runtime/various_test.go deleted file mode 100644 index 0bb60a8d05..0000000000 --- a/runtime/various_test.go +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Cadence - The resource-oriented smart contract programming language - * - * Copyright 2019-2020 Dapper Labs, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package runtime - -import ( - "fmt" - "testing" - - "github.com/onflow/cadence/runtime/parser2" - - "github.com/stretchr/testify/require" - - "github.com/onflow/cadence/runtime/sema" -) - -func TestVariousAgainstRegression(t *testing.T) { - t.Parallel() - - doTest := func(code string, verify func(t *testing.T, err error)) { - t.Run(code, func(t *testing.T) { - script := fmt.Sprintf(` - pub fun main() { - %s - }`, code) - _, err := executeTestScript(t, script, nil) - verify(t, err) - }) - } - - testChildErrors := func(t *testing.T, e error, childErrors []error) { - e2, ok := e.(interface{ ChildErrors() []error }) - require.Truef(t, ok, "Error does not implement ChildErrors(): %e", e) - require.Lenf(t, e2.ChildErrors(), len(childErrors), - "Error has the wrong number of children: %d != %d", len(e2.ChildErrors()), len(childErrors)) - for i, e3 := range childErrors { - require.IsType(t, childErrors[i], e3) - } - } - - doTest("paste your code in here", func(t *testing.T, err error) { - var e *ParsingCheckingError - require.ErrorAs(t, err, &e) - }) - - doTest("resource as { enum x : as { } }", func(t *testing.T, err error) { - var e *sema.CheckerError - require.ErrorAs(t, err, &e) - testChildErrors(t, e, []error{&sema.InvalidDeclarationError{}}) - }) - - doTest("resource interface struct{struct d:struct{ struct d:struct{ }struct d:struct{ struct d:struct{ }}}}", func(t *testing.T, err error) { - var e *sema.CheckerError - require.ErrorAs(t, err, &e) - testChildErrors(t, e, []error{&sema.InvalidDeclarationError{}}) - }) - - doTest("resource interface struct{struct d:struct{ contract d:struct{ contract x:struct{ struct d{} contract d:struct{ contract d:struct {}}}}}}", func(t *testing.T, err error) { - var e *sema.CheckerError - require.ErrorAs(t, err, &e) - testChildErrors(t, e, []error{&sema.InvalidDeclarationError{}}) - }) - - doTest("struct interface var { contract h : var { contract h { } contract h { contract h { } } } }", func(t *testing.T, err error) { - var e *sema.CheckerError - require.ErrorAs(t, err, &e) - testChildErrors(t, e, []error{&sema.InvalidDeclarationError{}}) - }) - - doTest("contract signatureAlgorithm { resource interface payer { contract fun : payer { contract fun { contract fun { } contract fun { contract interface account { } } contract account { } } } } }", func(t *testing.T, err error) { - var e *sema.CheckerError - require.ErrorAs(t, err, &e) - testChildErrors(t, e, []error{&sema.InvalidDeclarationError{}}) - }) - - doTest("# a ( b > c > d > e > f > g > h > i > j > k > l > m > n > o > p > q > r > s > t > u > v > w > x > y > z > A > B > C > D > E > F>", func(t *testing.T, err error) { - var e *ParsingCheckingError - require.ErrorAs(t, err, &e) - - require.IsType(t, e.Unwrap(), parser2.Error{}) - testChildErrors(t, e.Unwrap().(parser2.Error), []error{&parser2.SyntaxError{}}) - }) - - doTest("let b=0.0as!PublicKey.Contracts", func(t *testing.T, err error) { - var e *sema.CheckerError - require.ErrorAs(t, err, &e) - testChildErrors(t, e, []error{&sema.InvalidDeclarationError{}}) - }) - - doTest("let UInt64 = UInt64 ( 0b0 )", func(t *testing.T, err error) { - var e *sema.CheckerError - require.ErrorAs(t, err, &e) - testChildErrors(t, e, []error{&sema.RedeclarationError{}}) - }) - - doTest("contract enum{}let x = enum!", func(t *testing.T, err error) { - var e *ParsingCheckingError - require.ErrorAs(t, err, &e) - - require.IsType(t, e.Unwrap(), parser2.Error{}) - testChildErrors(t, e.Unwrap().(parser2.Error), []error{&parser2.SyntaxError{}}) - }) - - doTest("#0x0<{},>()", func(t *testing.T, err error) { - var e *ParsingCheckingError - require.ErrorAs(t, err, &e) - - require.IsType(t, e.Unwrap(), parser2.Error{}) - testChildErrors(t, e.Unwrap().(parser2.Error), []error{&parser2.SyntaxError{}}) - }) - - doTest("var a=[Type]", func(t *testing.T, err error) { - require.NoError(t, err) - }) - - doTest("var j={0.0:Type}", func(t *testing.T, err error) { - require.NoError(t, err) - }) - - doTest("let Type = Type", func(t *testing.T, err error) { - var e *sema.CheckerError - require.ErrorAs(t, err, &e) - testChildErrors(t, e, []error{&sema.RedeclarationError{}}) - }) - - doTest("let a = 0x0 as UInt64!as?UInt64!as?UInt64?!?.getType()", func(t *testing.T, err error) { - require.NoError(t, err) - }) -} From f67db5bfa8833af082cef4c5db93ef9c5a86e0d0 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 2 Mar 2022 15:39:23 -0800 Subject: [PATCH 3/6] fix TestCastResourceAsEnumAsEmptyDict, gofmt --- runtime/parser2/parser_test.go | 2 +- runtime/tests/checker/casting_test.go | 7 ++++--- runtime/tests/checker/interface_test.go | 2 +- runtime/tests/checker/resources_test.go | 1 - 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/runtime/parser2/parser_test.go b/runtime/parser2/parser_test.go index 26bb82ba43..919a02c4e1 100644 --- a/runtime/parser2/parser_test.go +++ b/runtime/parser2/parser_test.go @@ -40,7 +40,7 @@ func TestParseInvalid(t *testing.T) { t.Parallel() type test struct { - msg string + msg string code string } diff --git a/runtime/tests/checker/casting_test.go b/runtime/tests/checker/casting_test.go index a4f5345517..232cdbd270 100644 --- a/runtime/tests/checker/casting_test.go +++ b/runtime/tests/checker/casting_test.go @@ -6682,9 +6682,10 @@ func TestCastResourceAsEnumAsEmptyDict(t *testing.T) { _, err := ParseAndCheck(t, "resource as { enum x : as { } }") - errs := ExpectCheckerErrors(t, err, 1) + errs := ExpectCheckerErrors(t, err, 2) - assert.IsType(t, &sema.TypeMismatchError{}, errs[0]) + assert.IsType(t, &sema.InvalidNestedDeclarationError{}, errs[0]) + assert.IsType(t, &sema.InvalidEnumRawTypeError{}, errs[1]) } // @@ -6695,4 +6696,4 @@ func TestCastNumbersManyTimesThenGetType(t *testing.T) { _, err := ParseAndCheck(t, "let a = 0x0 as UInt64!as?UInt64!as?UInt64?!?.getType()") assert.Nil(t, err) -} \ No newline at end of file +} diff --git a/runtime/tests/checker/interface_test.go b/runtime/tests/checker/interface_test.go index 0f9d78356b..2263e7b84b 100644 --- a/runtime/tests/checker/interface_test.go +++ b/runtime/tests/checker/interface_test.go @@ -2011,4 +2011,4 @@ func TestBadStructInterface(t *testing.T) { assert.IsType(t, &sema.RedeclarationError{}, errs[9]) assert.IsType(t, &sema.CompositeKindMismatchError{}, errs[10]) assert.IsType(t, &sema.RedeclarationError{}, errs[11]) -} \ No newline at end of file +} diff --git a/runtime/tests/checker/resources_test.go b/runtime/tests/checker/resources_test.go index 5690cf0dbe..921f27145c 100644 --- a/runtime/tests/checker/resources_test.go +++ b/runtime/tests/checker/resources_test.go @@ -3190,7 +3190,6 @@ func TestCheckResourceInterfaceUseAsType(t *testing.T) { require.NoError(t, err) } - func TestCheckResourceArrayIndexing(t *testing.T) { t.Parallel() From a10796f9c68d2831ba34c3dea67380f7b4102fb5 Mon Sep 17 00:00:00 2001 From: "Robert E. Davidson III" <45945043+robert-e-davidson3@users.noreply.github.com> Date: Thu, 3 Mar 2022 10:57:42 -0800 Subject: [PATCH 4/6] Update runtime/tests/checker/contract_test.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Müller --- runtime/tests/checker/contract_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/tests/checker/contract_test.go b/runtime/tests/checker/contract_test.go index 671f016961..09b999b807 100644 --- a/runtime/tests/checker/contract_test.go +++ b/runtime/tests/checker/contract_test.go @@ -709,7 +709,7 @@ func TestCheckInvalidContractNestedTypeShadowing(t *testing.T) { } } -func TestBadContractNesting(t *testing.T) { +func TestCheckBadContractNesting(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, "contract signatureAlgorithm { resource interface payer { contract fun : payer { contract fun { contract fun { } contract fun { contract interface account { } } contract account { } } } } }") From 7b865956f62e459e1346c54c15939d04d5ba2d19 Mon Sep 17 00:00:00 2001 From: "Robert E. Davidson III" <45945043+robert-e-davidson3@users.noreply.github.com> Date: Thu, 3 Mar 2022 10:57:47 -0800 Subject: [PATCH 5/6] Update runtime/tests/checker/interface_test.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Müller --- runtime/tests/checker/interface_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/tests/checker/interface_test.go b/runtime/tests/checker/interface_test.go index 2263e7b84b..30fd655e77 100644 --- a/runtime/tests/checker/interface_test.go +++ b/runtime/tests/checker/interface_test.go @@ -1992,7 +1992,7 @@ func TestCheckInvalidInterfaceUseAsTypeSuggestion(t *testing.T) { ) } -func TestBadStructInterface(t *testing.T) { +func TestCheckBadStructInterface(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, "struct interface var { contract h : var { contract h { } contract h { contract h { } } } }") From 57cf01ca88c815be89cf1aa03c87ce2dbb654f24 Mon Sep 17 00:00:00 2001 From: "Robert E. Davidson III" <45945043+robert-e-davidson3@users.noreply.github.com> Date: Thu, 3 Mar 2022 10:57:52 -0800 Subject: [PATCH 6/6] Update runtime/tests/checker/resources_test.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Müller --- runtime/tests/checker/resources_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/tests/checker/resources_test.go b/runtime/tests/checker/resources_test.go index 921f27145c..21a32a58f7 100644 --- a/runtime/tests/checker/resources_test.go +++ b/runtime/tests/checker/resources_test.go @@ -8617,7 +8617,7 @@ func TestCheckResourceInvalidationWithConditionalExprInDestroy(t *testing.T) { assert.IsType(t, &sema.InvalidConditionalResourceOperandError{}, errs[1]) } -func TestBadResourceInterface(t *testing.T) { +func TestCheckBadResourceInterface(t *testing.T) { t.Parallel() t.Run("bad resource interface: shorter", func(t *testing.T) {