diff --git a/.github/workflows/compatibility-check-template.yml b/.github/workflows/compatibility-check-template.yml index 3a6b1c1130..2f69e88045 100644 --- a/.github/workflows/compatibility-check-template.yml +++ b/.github/workflows/compatibility-check-template.yml @@ -108,6 +108,7 @@ jobs: path: | ./tmp/output-old.txt ./tmp/output-new.txt + ./tmp/contracts.csv # Check Diff diff --git a/.github/workflows/get-contracts.yml b/.github/workflows/get-contracts.yml new file mode 100644 index 0000000000..93a1f4ffbc --- /dev/null +++ b/.github/workflows/get-contracts.yml @@ -0,0 +1,52 @@ +name: Get contracts + +on: + workflow_call: + inputs: + chain: + required: true + type: string + secrets: + FLOWDIVER_API_KEY: + required: true + +env: + GO_VERSION: '1.22' + +concurrency: + group: ${{ github.workflow }}-${{ github.run_id }}-${{ inputs.chain }} + cancel-in-progress: true + +jobs: + check: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + cache: true + + - name: Make output dirs + run: | + mkdir tmp + + # Get contracts + + - name: Download contracts + env: + FLOWDIVER_API_KEY: ${{ secrets.FLOWDIVER_API_KEY }} + working-directory: ./tools/get-contracts + run: | + go run . --chain=${{ inputs.chain }} --apiKey="$FLOWDIVER_API_KEY" > ../../tmp/contracts.csv + + # Upload + + - name: Upload + uses: actions/upload-artifact@v3 + with: + name: ${{ inputs.chain }}-contracts + path: | + ./tmp/contracts.csv diff --git a/Makefile b/Makefile index c14880b9f5..16b7bd328f 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,7 @@ ci: # test all packages go test -coverprofile=coverage.txt -covermode=atomic -parallel 8 -race -coverpkg $(COVERPKGS) ./... # run interpreter smoke tests. results from run above are reused, so no tests runs are duplicated - go test -count=5 ./tests/interpreter/... -runSmokeTests=true -validateAtree=false + go test -count=5 ./interpreter/... -runSmokeTests=true -validateAtree=false # remove coverage of empty functions from report sed -i -e 's/^.* 0 0$$//' coverage.txt diff --git a/ast/elementtype.go b/ast/elementtype.go index 1ceee39f3e..2369cf5080 100644 --- a/ast/elementtype.go +++ b/ast/elementtype.go @@ -85,4 +85,5 @@ const ( ElementTypeForceExpression ElementTypePathExpression ElementTypeAttachExpression + ElementTypeStringTemplateExpression ) diff --git a/ast/elementtype_string.go b/ast/elementtype_string.go index 9f2e36d996..07044923bb 100644 --- a/ast/elementtype_string.go +++ b/ast/elementtype_string.go @@ -60,11 +60,12 @@ func _() { _ = x[ElementTypeForceExpression-49] _ = x[ElementTypePathExpression-50] _ = x[ElementTypeAttachExpression-51] + _ = x[ElementTypeStringTemplateExpression-52] } -const _ElementType_name = "ElementTypeUnknownElementTypeProgramElementTypeBlockElementTypeFunctionBlockElementTypeFunctionDeclarationElementTypeSpecialFunctionDeclarationElementTypeCompositeDeclarationElementTypeInterfaceDeclarationElementTypeEntitlementDeclarationElementTypeEntitlementMappingDeclarationElementTypeAttachmentDeclarationElementTypeFieldDeclarationElementTypeEnumCaseDeclarationElementTypePragmaDeclarationElementTypeImportDeclarationElementTypeTransactionDeclarationElementTypeReturnStatementElementTypeBreakStatementElementTypeContinueStatementElementTypeIfStatementElementTypeSwitchStatementElementTypeWhileStatementElementTypeForStatementElementTypeEmitStatementElementTypeVariableDeclarationElementTypeAssignmentStatementElementTypeSwapStatementElementTypeExpressionStatementElementTypeRemoveStatementElementTypeVoidExpressionElementTypeBoolExpressionElementTypeNilExpressionElementTypeIntegerExpressionElementTypeFixedPointExpressionElementTypeArrayExpressionElementTypeDictionaryExpressionElementTypeIdentifierExpressionElementTypeInvocationExpressionElementTypeMemberExpressionElementTypeIndexExpressionElementTypeConditionalExpressionElementTypeUnaryExpressionElementTypeBinaryExpressionElementTypeFunctionExpressionElementTypeStringExpressionElementTypeCastingExpressionElementTypeCreateExpressionElementTypeDestroyExpressionElementTypeReferenceExpressionElementTypeForceExpressionElementTypePathExpressionElementTypeAttachExpression" +const _ElementType_name = "ElementTypeUnknownElementTypeProgramElementTypeBlockElementTypeFunctionBlockElementTypeFunctionDeclarationElementTypeSpecialFunctionDeclarationElementTypeCompositeDeclarationElementTypeInterfaceDeclarationElementTypeEntitlementDeclarationElementTypeEntitlementMappingDeclarationElementTypeAttachmentDeclarationElementTypeFieldDeclarationElementTypeEnumCaseDeclarationElementTypePragmaDeclarationElementTypeImportDeclarationElementTypeTransactionDeclarationElementTypeReturnStatementElementTypeBreakStatementElementTypeContinueStatementElementTypeIfStatementElementTypeSwitchStatementElementTypeWhileStatementElementTypeForStatementElementTypeEmitStatementElementTypeVariableDeclarationElementTypeAssignmentStatementElementTypeSwapStatementElementTypeExpressionStatementElementTypeRemoveStatementElementTypeVoidExpressionElementTypeBoolExpressionElementTypeNilExpressionElementTypeIntegerExpressionElementTypeFixedPointExpressionElementTypeArrayExpressionElementTypeDictionaryExpressionElementTypeIdentifierExpressionElementTypeInvocationExpressionElementTypeMemberExpressionElementTypeIndexExpressionElementTypeConditionalExpressionElementTypeUnaryExpressionElementTypeBinaryExpressionElementTypeFunctionExpressionElementTypeStringExpressionElementTypeCastingExpressionElementTypeCreateExpressionElementTypeDestroyExpressionElementTypeReferenceExpressionElementTypeForceExpressionElementTypePathExpressionElementTypeAttachExpressionElementTypeStringTemplateExpression" -var _ElementType_index = [...]uint16{0, 18, 36, 52, 76, 106, 143, 174, 205, 238, 278, 310, 337, 367, 395, 423, 456, 482, 507, 535, 557, 583, 608, 631, 655, 685, 715, 739, 769, 795, 820, 845, 869, 897, 928, 954, 985, 1016, 1047, 1074, 1100, 1132, 1158, 1185, 1214, 1241, 1269, 1296, 1324, 1354, 1380, 1405, 1432} +var _ElementType_index = [...]uint16{0, 18, 36, 52, 76, 106, 143, 174, 205, 238, 278, 310, 337, 367, 395, 423, 456, 482, 507, 535, 557, 583, 608, 631, 655, 685, 715, 739, 769, 795, 820, 845, 869, 897, 928, 954, 985, 1016, 1047, 1074, 1100, 1132, 1158, 1185, 1214, 1241, 1269, 1296, 1324, 1354, 1380, 1405, 1432, 1467} func (i ElementType) String() string { if i >= ElementType(len(_ElementType_index)-1) { diff --git a/ast/expression.go b/ast/expression.go index 097b8a7311..cb72d9d8c8 100644 --- a/ast/expression.go +++ b/ast/expression.go @@ -220,6 +220,81 @@ func (*StringExpression) precedence() precedence { return precedenceLiteral } +// StringTemplateExpression + +type StringTemplateExpression struct { + // Values and Expressions are assumed to be interleaved, V[0] + E[0] + V[1] + ... + E[n-1] + V[n] + // this is enforced in the parser e.g. "a\(b)c" will be parsed as follows + // Values: []string{"a","c"} + // Expressions: []Expression{b} + Values []string + Expressions []Expression + Range +} + +var _ Expression = &StringTemplateExpression{} + +func NewStringTemplateExpression( + gauge common.MemoryGauge, + values []string, + exprs []Expression, + exprRange Range, +) *StringTemplateExpression { + common.UseMemory(gauge, common.NewStringTemplateExpressionMemoryUsage(len(values)+len(exprs))) + if len(values) != len(exprs)+1 { + // assert string template alternating structure + panic(errors.NewUnreachableError()) + } + return &StringTemplateExpression{ + Values: values, + Expressions: exprs, + Range: exprRange, + } +} + +var _ Element = &StringExpression{} +var _ Expression = &StringExpression{} + +func (*StringTemplateExpression) ElementType() ElementType { + return ElementTypeStringTemplateExpression +} + +func (*StringTemplateExpression) isExpression() {} + +func (*StringTemplateExpression) isIfStatementTest() {} + +func (e *StringTemplateExpression) Walk(walkChild func(Element)) { + walkExpressions(walkChild, e.Expressions) +} + +func (e *StringTemplateExpression) String() string { + return Prettier(e) +} + +func (e *StringTemplateExpression) Doc() prettier.Doc { + if len(e.Expressions) == 0 { + return prettier.Text(QuoteString(e.Values[0])) + } + + // TODO: must reproduce expressions as literals + panic("not implemented") +} + +func (e *StringTemplateExpression) MarshalJSON() ([]byte, error) { + type Alias StringTemplateExpression + return json.Marshal(&struct { + *Alias + Type string + }{ + Type: "StringTemplateExpression", + Alias: (*Alias)(e), + }) +} + +func (*StringTemplateExpression) precedence() precedence { + return precedenceLiteral +} + // IntegerExpression type IntegerExpression struct { @@ -1416,7 +1491,7 @@ func FunctionDocument( } // NOTE: not all functions have a parameter list, - // e.g. the `destroy` special function + // e.g. the `init` (initializer, special function) if parameterList != nil { signatureDoc = append( diff --git a/ast/expression_extractor.go b/ast/expression_extractor.go index 002ff7794d..e3b52c71e8 100644 --- a/ast/expression_extractor.go +++ b/ast/expression_extractor.go @@ -48,6 +48,10 @@ type StringExtractor interface { ExtractString(extractor *ExpressionExtractor, expression *StringExpression) ExpressionExtraction } +type StringTemplateExtractor interface { + ExtractStringTemplate(extractor *ExpressionExtractor, expression *StringTemplateExpression) ExpressionExtraction +} + type ArrayExtractor interface { ExtractArray(extractor *ExpressionExtractor, expression *ArrayExpression) ExpressionExtraction } @@ -117,31 +121,32 @@ type AttachExtractor interface { } type ExpressionExtractor struct { - IndexExtractor IndexExtractor - ForceExtractor ForceExtractor - BoolExtractor BoolExtractor - NilExtractor NilExtractor - IntExtractor IntExtractor - FixedPointExtractor FixedPointExtractor - StringExtractor StringExtractor - ArrayExtractor ArrayExtractor - DictionaryExtractor DictionaryExtractor - IdentifierExtractor IdentifierExtractor - AttachExtractor AttachExtractor - MemoryGauge common.MemoryGauge - VoidExtractor VoidExtractor - UnaryExtractor UnaryExtractor - ConditionalExtractor ConditionalExtractor - InvocationExtractor InvocationExtractor - BinaryExtractor BinaryExtractor - FunctionExtractor FunctionExtractor - CastingExtractor CastingExtractor - CreateExtractor CreateExtractor - DestroyExtractor DestroyExtractor - ReferenceExtractor ReferenceExtractor - MemberExtractor MemberExtractor - PathExtractor PathExtractor - nextIdentifier int + IndexExtractor IndexExtractor + ForceExtractor ForceExtractor + BoolExtractor BoolExtractor + NilExtractor NilExtractor + IntExtractor IntExtractor + FixedPointExtractor FixedPointExtractor + StringExtractor StringExtractor + StringTemplateExtractor StringTemplateExtractor + ArrayExtractor ArrayExtractor + DictionaryExtractor DictionaryExtractor + IdentifierExtractor IdentifierExtractor + AttachExtractor AttachExtractor + MemoryGauge common.MemoryGauge + VoidExtractor VoidExtractor + UnaryExtractor UnaryExtractor + ConditionalExtractor ConditionalExtractor + InvocationExtractor InvocationExtractor + BinaryExtractor BinaryExtractor + FunctionExtractor FunctionExtractor + CastingExtractor CastingExtractor + CreateExtractor CreateExtractor + DestroyExtractor DestroyExtractor + ReferenceExtractor ReferenceExtractor + MemberExtractor MemberExtractor + PathExtractor PathExtractor + nextIdentifier int } var _ ExpressionVisitor[ExpressionExtraction] = &ExpressionExtractor{} @@ -271,6 +276,35 @@ func (extractor *ExpressionExtractor) ExtractString(expression *StringExpression return rewriteExpressionAsIs(expression) } +func (extractor *ExpressionExtractor) VisitStringTemplateExpression(expression *StringTemplateExpression) ExpressionExtraction { + + // delegate to child extractor, if any, + // or call default implementation + + if extractor.StringTemplateExtractor != nil { + return extractor.StringTemplateExtractor.ExtractStringTemplate(extractor, expression) + } + return extractor.ExtractStringTemplate(expression) +} + +func (extractor *ExpressionExtractor) ExtractStringTemplate(expression *StringTemplateExpression) ExpressionExtraction { + + // copy the expression + newExpression := *expression + + // rewrite all value expressions + + rewrittenExpressions, extractedExpressions := + extractor.VisitExpressions(expression.Expressions) + + newExpression.Expressions = rewrittenExpressions + + return ExpressionExtraction{ + RewrittenExpression: &newExpression, + ExtractedExpressions: extractedExpressions, + } +} + func (extractor *ExpressionExtractor) VisitArrayExpression(expression *ArrayExpression) ExpressionExtraction { // delegate to child extractor, if any, diff --git a/ast/precedence.go b/ast/precedence.go index 3e42f6a8f1..fcc78d259f 100644 --- a/ast/precedence.go +++ b/ast/precedence.go @@ -83,6 +83,7 @@ const ( // - BoolExpression // - NilExpression // - StringExpression + // - StringTemplateExpression // - IntegerExpression // - FixedPointExpression // - ArrayExpression diff --git a/ast/string_template_test.go b/ast/string_template_test.go new file mode 100644 index 0000000000..ebfc9e422f --- /dev/null +++ b/ast/string_template_test.go @@ -0,0 +1,48 @@ +/* + * Cadence - The resource-oriented smart contract programming language + * + * Copyright Flow Foundation + * + * 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 ast + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/turbolent/prettier" +) + +func TestStringTemplate_Doc(t *testing.T) { + + t.Parallel() + + stmt := &StringTemplateExpression{ + Values: []string{ + "abc", + }, + Expressions: []Expression{}, + Range: Range{ + StartPos: Position{Offset: 4, Line: 2, Column: 3}, + EndPos: Position{Offset: 11, Line: 2, Column: 10}, + }, + } + + assert.Equal(t, + prettier.Text("\"abc\""), + stmt.Doc(), + ) +} diff --git a/ast/visitor.go b/ast/visitor.go index dba16b2678..b4d946ec08 100644 --- a/ast/visitor.go +++ b/ast/visitor.go @@ -183,6 +183,7 @@ type ExpressionVisitor[T any] interface { VisitNilExpression(*NilExpression) T VisitBoolExpression(*BoolExpression) T VisitStringExpression(*StringExpression) T + VisitStringTemplateExpression(*StringTemplateExpression) T VisitIntegerExpression(*IntegerExpression) T VisitFixedPointExpression(*FixedPointExpression) T VisitDictionaryExpression(*DictionaryExpression) T @@ -219,6 +220,9 @@ func AcceptExpression[T any](expression Expression, visitor ExpressionVisitor[T] case ElementTypeStringExpression: return visitor.VisitStringExpression(expression.(*StringExpression)) + case ElementTypeStringTemplateExpression: + return visitor.VisitStringTemplateExpression(expression.(*StringTemplateExpression)) + case ElementTypeIntegerExpression: return visitor.VisitIntegerExpression(expression.(*IntegerExpression)) diff --git a/bbq/compiler/compiler.go b/bbq/compiler/compiler.go index 1bbd5647b4..e9bc6581b9 100644 --- a/bbq/compiler/compiler.go +++ b/bbq/compiler/compiler.go @@ -972,6 +972,11 @@ func (c *Compiler) VisitStringExpression(expression *ast.StringExpression) (_ st return } +func (c *Compiler) VisitStringTemplateExpression(_ *ast.StringTemplateExpression) (_ struct{}) { + // TODO + panic(errors.NewUnreachableError()) +} + func (c *Compiler) VisitCastingExpression(expression *ast.CastingExpression) (_ struct{}) { c.compileExpression(expression.Expression) diff --git a/bbq/compiler/compiler_test.go b/bbq/compiler/compiler_test.go index ce4d20c2a4..1b03948467 100644 --- a/bbq/compiler/compiler_test.go +++ b/bbq/compiler/compiler_test.go @@ -26,7 +26,7 @@ import ( "github.com/onflow/cadence/bbq" "github.com/onflow/cadence/bbq/constantkind" "github.com/onflow/cadence/bbq/opcode" - . "github.com/onflow/cadence/tests/checker" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCompileRecursionFib(t *testing.T) { diff --git a/bbq/vm/config.go b/bbq/vm/config.go index 0d8acb77c9..8f8876d48d 100644 --- a/bbq/vm/config.go +++ b/bbq/vm/config.go @@ -24,7 +24,7 @@ import ( "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - "github.com/onflow/cadence/tests/utils" + "github.com/onflow/cadence/test_utils/common_utils" ) type Config struct { @@ -68,7 +68,7 @@ func (c *Config) interpreter() *interpreter.Interpreter { if c.inter == nil { inter, err := interpreter.NewInterpreter( nil, - utils.TestLocation, + common_utils.TestLocation, &interpreter.Config{ Storage: c.Storage, ImportLocationHandler: nil, diff --git a/bbq/vm/test/ft_test.go b/bbq/vm/test/ft_test.go index 3aff054238..9598bba5ef 100644 --- a/bbq/vm/test/ft_test.go +++ b/bbq/vm/test/ft_test.go @@ -30,7 +30,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/runtime_utils" + "github.com/onflow/cadence/test_utils/runtime_utils" ) func TestFTTransfer(t *testing.T) { diff --git a/bbq/vm/test/interpreter_test.go b/bbq/vm/test/interpreter_test.go index ae723ebc46..abf497211d 100644 --- a/bbq/vm/test/interpreter_test.go +++ b/bbq/vm/test/interpreter_test.go @@ -3,6 +3,9 @@ package test import ( "encoding/hex" "fmt" + "github.com/onflow/cadence/test_utils/interpreter_utils" + "github.com/onflow/cadence/test_utils/runtime_utils" + "github.com/onflow/cadence/test_utils/sema_utils" "strings" "testing" @@ -19,9 +22,6 @@ import ( "github.com/onflow/cadence/runtime" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - "github.com/onflow/cadence/tests/checker" - "github.com/onflow/cadence/tests/runtime_utils" - "github.com/onflow/cadence/tests/utils" ) type ParseCheckAndInterpretOptions struct { @@ -53,9 +53,9 @@ func parseCheckAndInterpretWithOptionsAndMemoryMetering( err error, ) { - checker, err := checker.ParseAndCheckWithOptionsAndMemoryMetering(t, + checker, err := sema_utils.ParseAndCheckWithOptionsAndMemoryMetering(t, code, - checker.ParseAndCheckOptions{ + sema_utils.ParseAndCheckOptions{ Location: location, Config: options.CheckerConfig, }, @@ -854,7 +854,7 @@ func BenchmarkRuntimeFungibleTokenTransfer(b *testing.B) { err := interpreterRuntime.ExecuteTransaction( runtime.Script{ - Source: utils.DeploymentTransaction( + Source: runtime_utils.DeploymentTransaction( "FungibleToken", []byte(realFungibleTokenContractInterface), ), @@ -968,7 +968,7 @@ func BenchmarkRuntimeFungibleTokenTransfer(b *testing.B) { sum := interpreter.NewUnmeteredIntValueFromInt64(0) - inter := runtime_utils.NewTestInterpreter(b) + inter := interpreter_utils.NewTestInterpreter(b) nextScriptLocation := runtime_utils.NewScriptLocationGenerator() @@ -999,7 +999,7 @@ func BenchmarkRuntimeFungibleTokenTransfer(b *testing.B) { sum = sum.Plus(inter, value, interpreter.EmptyLocationRange).(interpreter.IntValue) } - utils.RequireValuesEqual(b, nil, mintAmountValue, sum) + interpreter_utils.RequireValuesEqual(b, nil, mintAmountValue, sum) } func encodeArgs(argValues []cadence.Value) [][]byte { @@ -1013,3 +1013,47 @@ func encodeArgs(argValues []cadence.Value) [][]byte { } return args } + +func TestInterpreterImperativeFib(t *testing.T) { + + t.Parallel() + + scriptLocation := runtime_utils.NewScriptLocationGenerator() + + inter, err := parseCheckAndInterpretWithOptions( + t, + imperativeFib, + scriptLocation(), + ParseCheckAndInterpretOptions{}, + ) + require.NoError(t, err) + + var value interpreter.Value = interpreter.NewUnmeteredIntValueFromInt64(7) + + result, err := inter.Invoke("fib", value) + require.NoError(t, err) + require.Equal(t, interpreter.NewUnmeteredIntValueFromInt64(13), result) +} + +func BenchmarkInterpreterImperativeFib(b *testing.B) { + + scriptLocation := runtime_utils.NewScriptLocationGenerator() + + inter, err := parseCheckAndInterpretWithOptions( + b, + imperativeFib, + scriptLocation(), + ParseCheckAndInterpretOptions{}, + ) + require.NoError(b, err) + + var value interpreter.Value = interpreter.NewUnmeteredIntValueFromInt64(14) + + b.ReportAllocs() + b.ResetTimer() + + for i := 0; i < b.N; i++ { + _, err := inter.Invoke("fib", value) + require.NoError(b, err) + } +} diff --git a/bbq/vm/test/runtime_test.go b/bbq/vm/test/runtime_test.go index 7585d3d342..5fb73400b4 100644 --- a/bbq/vm/test/runtime_test.go +++ b/bbq/vm/test/runtime_test.go @@ -27,7 +27,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" - "github.com/onflow/cadence/tests/runtime_utils" + "github.com/onflow/cadence/test_utils/runtime_utils" "github.com/onflow/cadence/bbq" "github.com/onflow/cadence/bbq/vm" diff --git a/bbq/vm/test/utils.go b/bbq/vm/test/utils.go index 6a0ac428b9..e9cf42e391 100644 --- a/bbq/vm/test/utils.go +++ b/bbq/vm/test/utils.go @@ -30,8 +30,8 @@ import ( "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - "github.com/onflow/cadence/tests/checker" - "github.com/onflow/cadence/tests/runtime_utils" + "github.com/onflow/cadence/test_utils/runtime_utils" + "github.com/onflow/cadence/test_utils/sema_utils" "github.com/onflow/cadence/bbq" "github.com/onflow/cadence/bbq/commons" @@ -427,10 +427,10 @@ func parseAndCheck( location common.Location, programs map[common.Location]compiledProgram, ) *sema.Checker { - checker, err := checker.ParseAndCheckWithOptions( + checker, err := sema_utils.ParseAndCheckWithOptions( t, code, - checker.ParseAndCheckOptions{ + sema_utils.ParseAndCheckOptions{ Location: location, Config: &sema.Config{ ImportHandler: func(_ *sema.Checker, location common.Location, _ ast.Range) (sema.Import, error) { diff --git a/bbq/vm/test/vm_bench_test.go b/bbq/vm/test/vm_bench_test.go index 116e594f22..97adb3b1f4 100644 --- a/bbq/vm/test/vm_bench_test.go +++ b/bbq/vm/test/vm_bench_test.go @@ -12,8 +12,8 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/checker" - "github.com/onflow/cadence/tests/runtime_utils" + "github.com/onflow/cadence/test_utils/runtime_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" "github.com/onflow/cadence/bbq/compiler" "github.com/onflow/cadence/bbq/vm" diff --git a/bbq/vm/test/vm_test.go b/bbq/vm/test/vm_test.go index 64893423a7..41601f527d 100644 --- a/bbq/vm/test/vm_test.go +++ b/bbq/vm/test/vm_test.go @@ -29,9 +29,9 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/checker" - "github.com/onflow/cadence/tests/runtime_utils" - "github.com/onflow/cadence/tests/utils" + "github.com/onflow/cadence/test_utils/common_utils" + "github.com/onflow/cadence/test_utils/runtime_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" "github.com/onflow/cadence/bbq" "github.com/onflow/cadence/bbq/commons" @@ -340,7 +340,7 @@ func TestImport(t *testing.T) { `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: common_utils.ImportedLocation, }, ) require.NoError(t, err) diff --git a/cmd/info/main.go b/cmd/info/main.go index 5f737ba99c..7ca71664cc 100644 --- a/cmd/info/main.go +++ b/cmd/info/main.go @@ -31,7 +31,7 @@ import ( "github.com/onflow/cadence/parser" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - "github.com/onflow/cadence/tests/checker" + "github.com/onflow/cadence/test_utils/sema_utils" ) type command struct { @@ -80,7 +80,7 @@ var commands = map[string]command{ func dumpBuiltinTypes() { - allBaseSemaTypes := checker.AllBaseSemaTypes() + allBaseSemaTypes := sema_utils.AllBaseSemaTypes() types := make([]sema.Type, 0, len(allBaseSemaTypes)) @@ -239,7 +239,7 @@ func dumpBuiltinValues() { ty sema.Type } - allBaseSemaValueTypes := checker.AllBaseSemaValueTypes() + allBaseSemaValueTypes := sema_utils.AllBaseSemaValueTypes() standardLibraryValues := stdlib.DefaultScriptStandardLibraryValues(nil) valueTypes := make([]valueType, 0, len(allBaseSemaValueTypes)+len(standardLibraryValues)) diff --git a/common/memorykind.go b/common/memorykind.go index 06e6748e9a..0754c397f5 100644 --- a/common/memorykind.go +++ b/common/memorykind.go @@ -204,6 +204,7 @@ const ( MemoryKindIntegerExpression MemoryKindFixedPointExpression MemoryKindArrayExpression + MemoryKindStringTemplateExpression MemoryKindDictionaryExpression MemoryKindIdentifierExpression MemoryKindInvocationExpression diff --git a/common/memorykind_string.go b/common/memorykind_string.go index 9b022e9495..67d6a0b8f8 100644 --- a/common/memorykind_string.go +++ b/common/memorykind_string.go @@ -165,56 +165,57 @@ func _() { _ = x[MemoryKindIntegerExpression-154] _ = x[MemoryKindFixedPointExpression-155] _ = x[MemoryKindArrayExpression-156] - _ = x[MemoryKindDictionaryExpression-157] - _ = x[MemoryKindIdentifierExpression-158] - _ = x[MemoryKindInvocationExpression-159] - _ = x[MemoryKindMemberExpression-160] - _ = x[MemoryKindIndexExpression-161] - _ = x[MemoryKindConditionalExpression-162] - _ = x[MemoryKindUnaryExpression-163] - _ = x[MemoryKindBinaryExpression-164] - _ = x[MemoryKindFunctionExpression-165] - _ = x[MemoryKindCastingExpression-166] - _ = x[MemoryKindCreateExpression-167] - _ = x[MemoryKindDestroyExpression-168] - _ = x[MemoryKindReferenceExpression-169] - _ = x[MemoryKindForceExpression-170] - _ = x[MemoryKindPathExpression-171] - _ = x[MemoryKindAttachExpression-172] - _ = x[MemoryKindConstantSizedType-173] - _ = x[MemoryKindDictionaryType-174] - _ = x[MemoryKindFunctionType-175] - _ = x[MemoryKindInstantiationType-176] - _ = x[MemoryKindNominalType-177] - _ = x[MemoryKindOptionalType-178] - _ = x[MemoryKindReferenceType-179] - _ = x[MemoryKindIntersectionType-180] - _ = x[MemoryKindVariableSizedType-181] - _ = x[MemoryKindPosition-182] - _ = x[MemoryKindRange-183] - _ = x[MemoryKindElaboration-184] - _ = x[MemoryKindActivation-185] - _ = x[MemoryKindActivationEntries-186] - _ = x[MemoryKindVariableSizedSemaType-187] - _ = x[MemoryKindConstantSizedSemaType-188] - _ = x[MemoryKindDictionarySemaType-189] - _ = x[MemoryKindOptionalSemaType-190] - _ = x[MemoryKindIntersectionSemaType-191] - _ = x[MemoryKindReferenceSemaType-192] - _ = x[MemoryKindEntitlementSemaType-193] - _ = x[MemoryKindEntitlementMapSemaType-194] - _ = x[MemoryKindEntitlementRelationSemaType-195] - _ = x[MemoryKindCapabilitySemaType-196] - _ = x[MemoryKindInclusiveRangeSemaType-197] - _ = x[MemoryKindOrderedMap-198] - _ = x[MemoryKindOrderedMapEntryList-199] - _ = x[MemoryKindOrderedMapEntry-200] - _ = x[MemoryKindLast-201] + _ = x[MemoryKindStringTemplateExpression-157] + _ = x[MemoryKindDictionaryExpression-158] + _ = x[MemoryKindIdentifierExpression-159] + _ = x[MemoryKindInvocationExpression-160] + _ = x[MemoryKindMemberExpression-161] + _ = x[MemoryKindIndexExpression-162] + _ = x[MemoryKindConditionalExpression-163] + _ = x[MemoryKindUnaryExpression-164] + _ = x[MemoryKindBinaryExpression-165] + _ = x[MemoryKindFunctionExpression-166] + _ = x[MemoryKindCastingExpression-167] + _ = x[MemoryKindCreateExpression-168] + _ = x[MemoryKindDestroyExpression-169] + _ = x[MemoryKindReferenceExpression-170] + _ = x[MemoryKindForceExpression-171] + _ = x[MemoryKindPathExpression-172] + _ = x[MemoryKindAttachExpression-173] + _ = x[MemoryKindConstantSizedType-174] + _ = x[MemoryKindDictionaryType-175] + _ = x[MemoryKindFunctionType-176] + _ = x[MemoryKindInstantiationType-177] + _ = x[MemoryKindNominalType-178] + _ = x[MemoryKindOptionalType-179] + _ = x[MemoryKindReferenceType-180] + _ = x[MemoryKindIntersectionType-181] + _ = x[MemoryKindVariableSizedType-182] + _ = x[MemoryKindPosition-183] + _ = x[MemoryKindRange-184] + _ = x[MemoryKindElaboration-185] + _ = x[MemoryKindActivation-186] + _ = x[MemoryKindActivationEntries-187] + _ = x[MemoryKindVariableSizedSemaType-188] + _ = x[MemoryKindConstantSizedSemaType-189] + _ = x[MemoryKindDictionarySemaType-190] + _ = x[MemoryKindOptionalSemaType-191] + _ = x[MemoryKindIntersectionSemaType-192] + _ = x[MemoryKindReferenceSemaType-193] + _ = x[MemoryKindEntitlementSemaType-194] + _ = x[MemoryKindEntitlementMapSemaType-195] + _ = x[MemoryKindEntitlementRelationSemaType-196] + _ = x[MemoryKindCapabilitySemaType-197] + _ = x[MemoryKindInclusiveRangeSemaType-198] + _ = x[MemoryKindOrderedMap-199] + _ = x[MemoryKindOrderedMapEntryList-200] + _ = x[MemoryKindOrderedMapEntry-201] + _ = x[MemoryKindLast-202] } -const _MemoryKind_name = "UnknownAddressValueStringValueCharacterValueNumberValueArrayValueBaseDictionaryValueBaseCompositeValueBaseSimpleCompositeValueBaseOptionalValueTypeValuePathValueCapabilityValueStorageReferenceValueEphemeralReferenceValueInterpretedFunctionValueHostFunctionValueBoundFunctionValueBigIntSimpleCompositeValuePublishedValueStorageCapabilityControllerValueAccountCapabilityControllerValueAtreeArrayDataSlabAtreeArrayMetaDataSlabAtreeArrayElementOverheadAtreeMapDataSlabAtreeMapMetaDataSlabAtreeMapElementOverheadAtreeMapPreAllocatedElementAtreeEncodedSlabPrimitiveStaticTypeCompositeStaticTypeInterfaceStaticTypeVariableSizedStaticTypeConstantSizedStaticTypeDictionaryStaticTypeInclusiveRangeStaticTypeOptionalStaticTypeIntersectionStaticTypeEntitlementSetStaticAccessEntitlementMapStaticAccessReferenceStaticTypeCapabilityStaticTypeFunctionStaticTypeCadenceVoidValueCadenceOptionalValueCadenceBoolValueCadenceStringValueCadenceCharacterValueCadenceAddressValueCadenceIntValueCadenceNumberValueCadenceArrayValueBaseCadenceArrayValueLengthCadenceDictionaryValueCadenceInclusiveRangeValueCadenceKeyValuePairCadenceStructValueBaseCadenceStructValueSizeCadenceResourceValueBaseCadenceAttachmentValueBaseCadenceResourceValueSizeCadenceAttachmentValueSizeCadenceEventValueBaseCadenceEventValueSizeCadenceContractValueBaseCadenceContractValueSizeCadenceEnumValueBaseCadenceEnumValueSizeCadencePathValueCadenceTypeValueCadenceCapabilityValueCadenceDeprecatedPathCapabilityTypeCadenceFunctionValueCadenceOptionalTypeCadenceDeprecatedRestrictedTypeCadenceVariableSizedArrayTypeCadenceConstantSizedArrayTypeCadenceDictionaryTypeCadenceInclusiveRangeTypeCadenceFieldCadenceParameterCadenceTypeParameterCadenceStructTypeCadenceResourceTypeCadenceAttachmentTypeCadenceEventTypeCadenceContractTypeCadenceStructInterfaceTypeCadenceResourceInterfaceTypeCadenceContractInterfaceTypeCadenceFunctionTypeCadenceEntitlementSetAccessCadenceEntitlementMapAccessCadenceReferenceTypeCadenceIntersectionTypeCadenceCapabilityTypeCadenceEnumTypeRawStringAddressLocationBytesVariableCompositeTypeInfoCompositeFieldInvocationStorageMapStorageKeyTypeTokenErrorTokenSpaceTokenProgramIdentifierArgumentBlockFunctionBlockParameterParameterListTypeParameterTypeParameterListTransferMembersTypeAnnotationDictionaryEntryFunctionDeclarationCompositeDeclarationAttachmentDeclarationInterfaceDeclarationEntitlementDeclarationEntitlementMappingElementEntitlementMappingDeclarationEnumCaseDeclarationFieldDeclarationTransactionDeclarationImportDeclarationVariableDeclarationSpecialFunctionDeclarationPragmaDeclarationAssignmentStatementBreakStatementContinueStatementEmitStatementExpressionStatementForStatementIfStatementReturnStatementSwapStatementSwitchStatementWhileStatementRemoveStatementBooleanExpressionVoidExpressionNilExpressionStringExpressionIntegerExpressionFixedPointExpressionArrayExpressionDictionaryExpressionIdentifierExpressionInvocationExpressionMemberExpressionIndexExpressionConditionalExpressionUnaryExpressionBinaryExpressionFunctionExpressionCastingExpressionCreateExpressionDestroyExpressionReferenceExpressionForceExpressionPathExpressionAttachExpressionConstantSizedTypeDictionaryTypeFunctionTypeInstantiationTypeNominalTypeOptionalTypeReferenceTypeIntersectionTypeVariableSizedTypePositionRangeElaborationActivationActivationEntriesVariableSizedSemaTypeConstantSizedSemaTypeDictionarySemaTypeOptionalSemaTypeIntersectionSemaTypeReferenceSemaTypeEntitlementSemaTypeEntitlementMapSemaTypeEntitlementRelationSemaTypeCapabilitySemaTypeInclusiveRangeSemaTypeOrderedMapOrderedMapEntryListOrderedMapEntryLast" +const _MemoryKind_name = "UnknownAddressValueStringValueCharacterValueNumberValueArrayValueBaseDictionaryValueBaseCompositeValueBaseSimpleCompositeValueBaseOptionalValueTypeValuePathValueCapabilityValueStorageReferenceValueEphemeralReferenceValueInterpretedFunctionValueHostFunctionValueBoundFunctionValueBigIntSimpleCompositeValuePublishedValueStorageCapabilityControllerValueAccountCapabilityControllerValueAtreeArrayDataSlabAtreeArrayMetaDataSlabAtreeArrayElementOverheadAtreeMapDataSlabAtreeMapMetaDataSlabAtreeMapElementOverheadAtreeMapPreAllocatedElementAtreeEncodedSlabPrimitiveStaticTypeCompositeStaticTypeInterfaceStaticTypeVariableSizedStaticTypeConstantSizedStaticTypeDictionaryStaticTypeInclusiveRangeStaticTypeOptionalStaticTypeIntersectionStaticTypeEntitlementSetStaticAccessEntitlementMapStaticAccessReferenceStaticTypeCapabilityStaticTypeFunctionStaticTypeCadenceVoidValueCadenceOptionalValueCadenceBoolValueCadenceStringValueCadenceCharacterValueCadenceAddressValueCadenceIntValueCadenceNumberValueCadenceArrayValueBaseCadenceArrayValueLengthCadenceDictionaryValueCadenceInclusiveRangeValueCadenceKeyValuePairCadenceStructValueBaseCadenceStructValueSizeCadenceResourceValueBaseCadenceAttachmentValueBaseCadenceResourceValueSizeCadenceAttachmentValueSizeCadenceEventValueBaseCadenceEventValueSizeCadenceContractValueBaseCadenceContractValueSizeCadenceEnumValueBaseCadenceEnumValueSizeCadencePathValueCadenceTypeValueCadenceCapabilityValueCadenceDeprecatedPathCapabilityTypeCadenceFunctionValueCadenceOptionalTypeCadenceDeprecatedRestrictedTypeCadenceVariableSizedArrayTypeCadenceConstantSizedArrayTypeCadenceDictionaryTypeCadenceInclusiveRangeTypeCadenceFieldCadenceParameterCadenceTypeParameterCadenceStructTypeCadenceResourceTypeCadenceAttachmentTypeCadenceEventTypeCadenceContractTypeCadenceStructInterfaceTypeCadenceResourceInterfaceTypeCadenceContractInterfaceTypeCadenceFunctionTypeCadenceEntitlementSetAccessCadenceEntitlementMapAccessCadenceReferenceTypeCadenceIntersectionTypeCadenceCapabilityTypeCadenceEnumTypeRawStringAddressLocationBytesVariableCompositeTypeInfoCompositeFieldInvocationStorageMapStorageKeyTypeTokenErrorTokenSpaceTokenProgramIdentifierArgumentBlockFunctionBlockParameterParameterListTypeParameterTypeParameterListTransferMembersTypeAnnotationDictionaryEntryFunctionDeclarationCompositeDeclarationAttachmentDeclarationInterfaceDeclarationEntitlementDeclarationEntitlementMappingElementEntitlementMappingDeclarationEnumCaseDeclarationFieldDeclarationTransactionDeclarationImportDeclarationVariableDeclarationSpecialFunctionDeclarationPragmaDeclarationAssignmentStatementBreakStatementContinueStatementEmitStatementExpressionStatementForStatementIfStatementReturnStatementSwapStatementSwitchStatementWhileStatementRemoveStatementBooleanExpressionVoidExpressionNilExpressionStringExpressionIntegerExpressionFixedPointExpressionArrayExpressionStringTemplateExpressionDictionaryExpressionIdentifierExpressionInvocationExpressionMemberExpressionIndexExpressionConditionalExpressionUnaryExpressionBinaryExpressionFunctionExpressionCastingExpressionCreateExpressionDestroyExpressionReferenceExpressionForceExpressionPathExpressionAttachExpressionConstantSizedTypeDictionaryTypeFunctionTypeInstantiationTypeNominalTypeOptionalTypeReferenceTypeIntersectionTypeVariableSizedTypePositionRangeElaborationActivationActivationEntriesVariableSizedSemaTypeConstantSizedSemaTypeDictionarySemaTypeOptionalSemaTypeIntersectionSemaTypeReferenceSemaTypeEntitlementSemaTypeEntitlementMapSemaTypeEntitlementRelationSemaTypeCapabilitySemaTypeInclusiveRangeSemaTypeOrderedMapOrderedMapEntryListOrderedMapEntryLast" -var _MemoryKind_index = [...]uint16{0, 7, 19, 30, 44, 55, 69, 88, 106, 130, 143, 152, 161, 176, 197, 220, 244, 261, 279, 285, 305, 319, 351, 383, 401, 423, 448, 464, 484, 507, 534, 550, 569, 588, 607, 630, 653, 673, 697, 715, 737, 763, 789, 808, 828, 846, 862, 882, 898, 916, 937, 956, 971, 989, 1010, 1033, 1055, 1081, 1100, 1122, 1144, 1168, 1194, 1218, 1244, 1265, 1286, 1310, 1334, 1354, 1374, 1390, 1406, 1428, 1463, 1483, 1502, 1533, 1562, 1591, 1612, 1637, 1649, 1665, 1685, 1702, 1721, 1742, 1758, 1777, 1803, 1831, 1859, 1878, 1905, 1932, 1952, 1975, 1996, 2011, 2020, 2035, 2040, 2048, 2065, 2079, 2089, 2099, 2109, 2118, 2128, 2138, 2145, 2155, 2163, 2168, 2181, 2190, 2203, 2216, 2233, 2241, 2248, 2262, 2277, 2296, 2316, 2337, 2357, 2379, 2404, 2433, 2452, 2468, 2490, 2507, 2526, 2552, 2569, 2588, 2602, 2619, 2632, 2651, 2663, 2674, 2689, 2702, 2717, 2731, 2746, 2763, 2777, 2790, 2806, 2823, 2843, 2858, 2878, 2898, 2918, 2934, 2949, 2970, 2985, 3001, 3019, 3036, 3052, 3069, 3088, 3103, 3117, 3133, 3150, 3164, 3176, 3193, 3204, 3216, 3229, 3245, 3262, 3270, 3275, 3286, 3296, 3313, 3334, 3355, 3373, 3389, 3409, 3426, 3445, 3467, 3494, 3512, 3534, 3544, 3563, 3578, 3582} +var _MemoryKind_index = [...]uint16{0, 7, 19, 30, 44, 55, 69, 88, 106, 130, 143, 152, 161, 176, 197, 220, 244, 261, 279, 285, 305, 319, 351, 383, 401, 423, 448, 464, 484, 507, 534, 550, 569, 588, 607, 630, 653, 673, 697, 715, 737, 763, 789, 808, 828, 846, 862, 882, 898, 916, 937, 956, 971, 989, 1010, 1033, 1055, 1081, 1100, 1122, 1144, 1168, 1194, 1218, 1244, 1265, 1286, 1310, 1334, 1354, 1374, 1390, 1406, 1428, 1463, 1483, 1502, 1533, 1562, 1591, 1612, 1637, 1649, 1665, 1685, 1702, 1721, 1742, 1758, 1777, 1803, 1831, 1859, 1878, 1905, 1932, 1952, 1975, 1996, 2011, 2020, 2035, 2040, 2048, 2065, 2079, 2089, 2099, 2109, 2118, 2128, 2138, 2145, 2155, 2163, 2168, 2181, 2190, 2203, 2216, 2233, 2241, 2248, 2262, 2277, 2296, 2316, 2337, 2357, 2379, 2404, 2433, 2452, 2468, 2490, 2507, 2526, 2552, 2569, 2588, 2602, 2619, 2632, 2651, 2663, 2674, 2689, 2702, 2717, 2731, 2746, 2763, 2777, 2790, 2806, 2823, 2843, 2858, 2882, 2902, 2922, 2942, 2958, 2973, 2994, 3009, 3025, 3043, 3060, 3076, 3093, 3112, 3127, 3141, 3157, 3174, 3188, 3200, 3217, 3228, 3240, 3253, 3269, 3286, 3294, 3299, 3310, 3320, 3337, 3358, 3379, 3397, 3413, 3433, 3450, 3469, 3491, 3518, 3536, 3558, 3568, 3587, 3602, 3606} func (i MemoryKind) String() string { if i >= MemoryKind(len(_MemoryKind_index)-1) { diff --git a/common/metering.go b/common/metering.go index 43dce778d8..ec728f87cd 100644 --- a/common/metering.go +++ b/common/metering.go @@ -795,6 +795,13 @@ func NewArrayExpressionMemoryUsage(length int) MemoryUsage { } } +func NewStringTemplateExpressionMemoryUsage(length int) MemoryUsage { + return MemoryUsage{ + Kind: MemoryKindStringTemplateExpression, + Amount: uint64(length), + } +} + func NewDictionaryExpressionMemoryUsage(length int) MemoryUsage { return MemoryUsage{ Kind: MemoryKindDictionaryExpression, diff --git a/compat/main.py b/compat/main.py index 999d451fbd..e767937bba 100644 --- a/compat/main.py +++ b/compat/main.py @@ -17,6 +17,7 @@ from dacite import from_dict SUITE_PATH = Path("suite").resolve() +CLI_PATH = SUITE_PATH / "flow-cli" / "cmd" / "flow" @contextmanager def cwd(path): @@ -27,39 +28,78 @@ def cwd(path): finally: os.chdir(oldpwd) +def cadence_replacement(cadence_version: Optional[str]) -> str: + if cadence_version: + return f'github.com/onflow/cadence@{cadence_version}' + # default: point to local cadence repo + return shlex.quote(Path.cwd().parent.absolute().resolve().as_posix()) + +def flowgo_replacement(flowgo_version: Optional[str]) -> str: + if flowgo_version: + return f'github.com/onflow/flow-go@{flowgo_version}' + # default: use the newest version of flow-go available + return 'github.com/onflow/flow-go@latest' + +def build_cli( + cadence_version: Optional[str], + flowgo_version: Optional[str] +): + logger.info("Building CLI ...") + + with cwd(SUITE_PATH): + working_dir = SUITE_PATH / "flow-cli" + Git.clone("https://github.com/onflow/flow-cli.git", "master", working_dir) + with cwd(working_dir): + Go.replace_dependencies( + cadence_version=cadence_version, + flowgo_version=flowgo_version + ) + logger.info("Compiling CLI binary") + subprocess.run( + ["make", "binary"], + check=True + ) + + logger.info("Built CLI") + @dataclass class GoTest: path: str command: str - def run(self, working_dir: Path, prepare: bool, cadence_version: Optional[str], flowgo_version: Optional[str]) -> bool: - if cadence_version: - cadence_replacement = f'github.com/onflow/cadence@{cadence_version}' - else: - # default: point to local cadence repo - cadence_replacement = shlex.quote(Path.cwd().parent.absolute().resolve().as_posix()) - - if flowgo_version: - flowgo_replacement = f'github.com/onflow/flow-go@{flowgo_version}' - else: - # default: use the newest version of flow-go available - flowgo_replacement = 'github.com/onflow/flow-go@latest' + def run( + self, + working_dir: Path, + prepare: bool, + cadence_version: Optional[str], + flowgo_version: Optional[str] + ) -> bool: with cwd(working_dir / self.path): if prepare: - logger.info("Editing dependencies") - subprocess.run([ - "go", "get", flowgo_replacement, - ]) - subprocess.run([ - "go", "mod", "edit", "-replace", f'github.com/onflow/cadence={cadence_replacement}', - ]) - logger.info("Downloading dependencies") - subprocess.run([ - "go", "get", "-t", ".", - ]) - - result = subprocess.run(shlex.split(self.command)) + Go.replace_dependencies(cadence_version, flowgo_version) + + result = subprocess.run(self.command, shell=True) + return result.returncode == 0 + +@dataclass +class CadenceTest: + path: str + command: str + + def run( + self, + working_dir: Path, + prepare: bool, + cadence_version: Optional[str], + flowgo_version: Optional[str] + ) -> bool: + + env = os.environ.copy() + env["PATH"] = f"{shlex.quote(str(CLI_PATH))}:{env['PATH']}" + + with cwd(working_dir / self.path): + result = subprocess.run(self.command, shell=True, env=env) return result.returncode == 0 def load_index(path: Path) -> List[str]: @@ -73,6 +113,7 @@ class Description: url: str branch: str go_tests: List[GoTest] = field(default_factory=list) + cadence_tests: List[CadenceTest] = field(default_factory=list) @staticmethod def load(name: str) -> Description: @@ -85,69 +126,105 @@ def load(name: str) -> Description: def from_dict(cls, data: Dict): return from_dict(data_class=cls, data=data) - def _clone(self, working_dir: Path): - if working_dir.exists(): - for root, dirs, files in os.walk(working_dir): - for dir in dirs: - os.chmod(os.path.join(root, dir), stat.S_IRUSR | stat.S_IWUSR) - for file in files: - os.chmod(os.path.join(root, file), stat.S_IRUSR | stat.S_IWUSR) - shutil.rmtree(working_dir) - - logger.info(f"Cloning {self.url} ({self.branch})") - - Git.clone(self.url, self.branch, working_dir) - def run( self, name: str, prepare: bool, go_test: bool, + cadence_test: bool, cadence_version: Optional[str], flowgo_version: Optional[str], ) -> (bool): + logger.info(f"Running tests for {name} ...") + working_dir = SUITE_PATH / name if prepare: - self._clone(working_dir) + Git.clone(self.url, self.branch, working_dir) go_tests_succeeded = True if go_test: for test in self.go_tests: - if not test.run(working_dir, prepare=prepare, cadence_version=cadence_version, flowgo_version=flowgo_version): + if not test.run( + working_dir, + prepare=prepare, + cadence_version=cadence_version, + flowgo_version=flowgo_version + ): go_tests_succeeded = False - succeeded = go_tests_succeeded + cadence_tests_succeeded = True + if cadence_test: + for test in self.cadence_tests: + if not test.run( + working_dir, + prepare=prepare, + cadence_version=cadence_version, + flowgo_version=flowgo_version + ): + cadence_tests_succeeded = False + + return go_tests_succeeded and cadence_tests_succeeded - return succeeded +class Go: + + @staticmethod + def mod_replace(original: str, replacement: str): + subprocess.run( + ["go", "mod", "edit", "-replace", f'{original}={replacement}'], + check=True + ) + + @staticmethod + def mod_tidy(): + subprocess.run( + ["go", "mod", "tidy"], + check=True + ) + + @staticmethod + def replace_dependencies( + cadence_version: Optional[str], + flowgo_version: Optional[str] + ): + logger.info("Editing dependencies") + Go.mod_replace("github.com/onflow/cadence", cadence_replacement(cadence_version)) + Go.mod_replace("github.com/onflow/flow-go", flowgo_replacement(flowgo_version)) + Go.mod_tidy() class Git: @staticmethod def clone(url: str, branch: str, working_dir: Path): - subprocess.run([ - "git", "clone", "--depth", "1", "--branch", - branch, url, working_dir - ]) + if working_dir.exists(): + Git._clean(working_dir) + + logger.info(f"Cloning {url} ({branch})") + + subprocess.run( + ["git", "clone", "--depth", "1", "--branch", branch, url, working_dir], + check=True + ) + + @staticmethod + def _clean(working_dir: Path): + for root, dirs, files in os.walk(working_dir): + for dir in dirs: + os.chmod(os.path.join(root, dir), stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) + for file in files: + os.chmod(os.path.join(root, file), stat.S_IRUSR | stat.S_IWUSR) + shutil.rmtree(working_dir) @staticmethod def get_head_ref() -> str: completed_process = subprocess.run( ["git", "rev-parse", "--abbrev-ref", "HEAD"], capture_output=True, + check=True ) - if completed_process.returncode != 0: - raise Exception('failed to get current Git ref') return completed_process.stdout.decode("utf-8").strip() - @staticmethod - def checkout(ref: str): - completed_process = subprocess.run(["git", "checkout", ref]) - if completed_process.returncode != 0: - raise Exception(f'failed to checkout ref {ref}') - - @click.command() @click.option( "--rerun", @@ -161,6 +238,12 @@ def checkout(ref: str): default=True, help="Run the suite Go tests" ) +@click.option( + "--cadence-test/--no-cadence-test", + is_flag=True, + default=True, + help="Run the suite Cadence tests" +) @click.option( "--cadence-version", default=None, @@ -176,20 +259,34 @@ def checkout(ref: str): nargs=-1, ) def main( - rerun: bool, - go_test: bool, - cadence_version: str, - flowgo_version: str, - names: Collection[str] + rerun: bool, + go_test: bool, + cadence_test: bool, + cadence_version: str, + flowgo_version: str, + names: Collection[str] ): + logger.info( + f'Chosen versions: ' + + f'cadence@{ cadence_version if cadence_version else "local version" }, ' + + f'flow-go@{flowgo_version if flowgo_version else "latest"}' + ) + prepare = not rerun + if cadence_test and prepare: + build_cli( + cadence_version=cadence_version, + flowgo_version=flowgo_version, + ) + # Run for the current checkout current_success = run( prepare=prepare, go_test=go_test, + cadence_test=cadence_test, cadence_version=cadence_version, flowgo_version=flowgo_version, names=names @@ -200,17 +297,16 @@ def main( def run( - prepare: bool, - go_test: bool, - cadence_version: str, - flowgo_version: str, - names: Collection[str] + prepare: bool, + go_test: bool, + cadence_test: bool, + cadence_version: str, + flowgo_version: str, + names: Collection[str] ) -> (bool): all_succeeded = True - logger.info(f'Chosen versions: cadence@{ cadence_version if cadence_version else "local version" }, flow-go@{flowgo_version if flowgo_version else "latest"}') - if not names: names = load_index(SUITE_PATH / "index.yaml") @@ -222,6 +318,7 @@ def run( name, prepare=prepare, go_test=go_test, + cadence_test=cadence_test, cadence_version=cadence_version, flowgo_version=flowgo_version, ) diff --git a/compat/suite/flow-core-contracts.yaml b/compat/suite/flow-core-contracts.yaml index 0be3807e9f..eee8583a9d 100644 --- a/compat/suite/flow-core-contracts.yaml +++ b/compat/suite/flow-core-contracts.yaml @@ -7,3 +7,6 @@ branch: master go_tests: - path: lib/go/test command: make test +cadence_tests: +- path: . + command: flow test tests/*.cdc diff --git a/compat/suite/green-goo-dao-flow-utils.yaml b/compat/suite/green-goo-dao-flow-utils.yaml new file mode 100644 index 0000000000..82f2925875 --- /dev/null +++ b/compat/suite/green-goo-dao-flow-utils.yaml @@ -0,0 +1,8 @@ +description: Green Goo Dao flow-utils +maintainers: + - bastian.mueller@flowfoundation.org +url: https://github.com/turbolent/flow-utils.git +branch: improvements +cadence_tests: +- path: . + command: npm i && ./run-tests.sh diff --git a/compiler/compiler.go b/compiler/compiler.go index e879b50d46..d7fefc2a14 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -246,6 +246,11 @@ func (compiler *Compiler) VisitFunctionExpression(_ *ast.FunctionExpression) ir. panic(errors.NewUnreachableError()) } +func (compiler *Compiler) VisitStringTemplateExpression(e *ast.StringTemplateExpression) ir.Expr { + // TODO + panic(errors.NewUnreachableError()) +} + func (compiler *Compiler) VisitStringExpression(e *ast.StringExpression) ir.Expr { return &ir.Const{ Constant: ir.String{ diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go index 17acf177d1..b9a0e2d866 100644 --- a/compiler/compiler_test.go +++ b/compiler/compiler_test.go @@ -24,12 +24,12 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/compiler/ir" - "github.com/onflow/cadence/tests/checker" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCompilerSimple(t *testing.T) { - checker, err := checker.ParseAndCheck(t, ` + checker, err := ParseAndCheck(t, ` fun inc(a: Int): Int { let mod = 1 return a + mod diff --git a/runtime/runtime.monopic b/docs/architecture.monopic similarity index 100% rename from runtime/runtime.monopic rename to docs/architecture.monopic diff --git a/runtime/runtime.png b/docs/architecture.png similarity index 100% rename from runtime/runtime.png rename to docs/architecture.png diff --git a/runtime/runtime.svg b/docs/architecture.svg similarity index 100% rename from runtime/runtime.svg rename to docs/architecture.svg diff --git a/docs/cadence.ebnf b/docs/cadence.ebnf index 25f86ec3e6..89057552c7 100644 --- a/docs/cadence.ebnf +++ b/docs/cadence.ebnf @@ -106,9 +106,7 @@ importDeclaration access : (* Not specified *) - | Priv - | Pub ( '(' Set ')' )? - | Access '(' ( Self | Contract | Account | All ) ')' + | Access '(' ( Self | Contract | Account | All | identifier) ')' ; compositeDeclaration @@ -224,7 +222,7 @@ nominalType ; functionType - : Fun '(' + : Fun '(' ( typeAnnotation ( ',' typeAnnotation )* )? ')' ( ':' typeAnnotation )? diff --git a/docs/development.md b/docs/development.md index 4a166bba19..75a0db5eac 100644 --- a/docs/development.md +++ b/docs/development.md @@ -73,7 +73,7 @@ contains command-line tools that are useful when working on the implementation f ``` ``` - $ echo 'pub fun main () { log("Hello, world!") }' > hello.cdc + $ echo 'access(all) fun main () { log("Hello, world!") }' > hello.cdc $ go run ./cmd/main hello.cdc "Hello, world!" ``` @@ -83,7 +83,7 @@ contains command-line tools that are useful when working on the implementation f Run the checker tests with the `cadence.checkConcurrently` flag, e.g. ```shell -go test -race -v ./tests/checker -cadence.checkConcurrently=10 +go test -race -v ./sema/... -cadence.checkConcurrently=10 ``` This runs each check of a checker test 10 times, concurrently, diff --git a/docs/go.md b/docs/go.md new file mode 100644 index 0000000000..e799fd7ffd --- /dev/null +++ b/docs/go.md @@ -0,0 +1,42 @@ +# Go + +## Patterns + +- To ensure interface cannot be implemented in other packages, + add a private function (first character must be lower-case) named "is" + type name, + which takes no arguments, returns nothing, and has an empty body. + + For example: + + ```go + type I interface { + isI() + } + ``` + + See https://go.dev/doc/faq#guarantee_satisfies_interface + +- To ensure a type implements an interface at compile-time, + use the "interface guard" pattern: + Introduce a global variable named `_`, type it as the interface, + and assign an empty value of the concrete type to it. + + For example: + + ```go + type T struct { + //... + } + + var _ io.ReadWriter = (*T)(nil) + + func (t *T) Read(p []byte) (n int, err error) { + // ... + ``` + + See + - https://go.dev/doc/faq#guarantee_satisfies_interface + - https://rednafi.com/go/interface_guards/ + - https://github.com/uber-go/guide/blob/master/style.md#verify-interface-compliance + - https://medium.com/@matryer/golang-tip-compile-time-checks-to-ensure-your-type-satisfies-an-interface-c167afed3aae + diff --git a/encoding/ccf/ccf_test.go b/encoding/ccf/ccf_test.go index db427edd67..c4513037ae 100644 --- a/encoding/ccf/ccf_test.go +++ b/encoding/ccf/ccf_test.go @@ -38,9 +38,9 @@ import ( "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/runtime" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/checker" - "github.com/onflow/cadence/tests/runtime_utils" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) var deterministicEncMode, _ = ccf.EncOptions{ @@ -100,7 +100,7 @@ func TestEncodeOptional(t *testing.T) { newStructType := func() *cadence.StructType { return cadence.NewStructType( - utils.TestLocation, + TestLocation, "Foo", []cadence.Field{ { @@ -122,7 +122,7 @@ func TestEncodeOptional(t *testing.T) { newStructTypeWithOptionalAbstractField := func() *cadence.StructType { return cadence.NewStructType( - utils.TestLocation, + TestLocation, "Foo", []cadence.Field{ { @@ -807,7 +807,7 @@ func TestEncodeOptional(t *testing.T) { val: func() cadence.Value { structTypeWithOptionalAbstractField := newStructTypeWithOptionalAbstractField() simpleStructType := cadence.NewStructType( - utils.TestLocation, + TestLocation, "FooStruct", []cadence.Field{ { @@ -3576,7 +3576,7 @@ func TestEncodeArray(t *testing.T) { name: "Resource Interface Array", val: func() cadence.Value { resourceInterfaceType := cadence.NewResourceInterfaceType( - utils.TestLocation, + TestLocation, "Bar", nil, nil, @@ -3930,13 +3930,13 @@ func TestEncodeArray(t *testing.T) { name: "Struct Interface Array", val: func() cadence.Value { structInterfaceType := cadence.NewStructInterfaceType( - utils.TestLocation, + TestLocation, "FooStructInterface", nil, nil, ) structType := cadence.NewStructType( - utils.TestLocation, + TestLocation, "FooStruct", []cadence.Field{ { @@ -4075,13 +4075,13 @@ func TestEncodeArray(t *testing.T) { name: "Contract Interface Array", val: func() cadence.Value { contractInterfaceType := cadence.NewContractInterfaceType( - utils.TestLocation, + TestLocation, "FooContractInterface", nil, nil, ) contractType := cadence.NewContractType( - utils.TestLocation, + TestLocation, "FooContract", []cadence.Field{ { @@ -4949,7 +4949,7 @@ func TestEncodeSortedDictionary(t *testing.T) { } func exportFromScript(t *testing.T, code string) cadence.Value { - checker, err := checker.ParseAndCheck(t, code) + checker, err := ParseAndCheck(t, code) require.NoError(t, err) var uuid uint64 @@ -5414,7 +5414,7 @@ func TestEncodeStruct(t *testing.T) { name: "no field", val: func() cadence.Value { noFieldStructType := cadence.NewStructType( - utils.TestLocation, + TestLocation, "FooStruct", []cadence.Field{}, nil, @@ -5473,7 +5473,7 @@ func TestEncodeStruct(t *testing.T) { name: "Simple", val: func() cadence.Value { simpleStructType := cadence.NewStructType( - utils.TestLocation, + TestLocation, "FooStruct", []cadence.Field{ { @@ -5824,7 +5824,7 @@ func TestEncodeEvent(t *testing.T) { name: "Simple", val: func() cadence.Value { simpleEventType := cadence.NewEventType( - utils.TestLocation, + TestLocation, "FooEvent", []cadence.Field{ { @@ -5928,7 +5928,7 @@ func TestEncodeEvent(t *testing.T) { name: "abstract event", val: func() cadence.Value { abstractEventType := cadence.NewEventType( - utils.TestLocation, + TestLocation, "FooEvent", []cadence.Field{ { @@ -5943,7 +5943,7 @@ func TestEncodeEvent(t *testing.T) { nil, ) simpleStructType := cadence.NewStructType( - utils.TestLocation, + TestLocation, "FooStruct", []cadence.Field{ { @@ -6090,7 +6090,7 @@ func TestEncodeEvent(t *testing.T) { val: func() cadence.Value { fooResourceType := newFooResourceType() resourceEventType := cadence.NewEventType( - utils.TestLocation, + TestLocation, "FooEvent", []cadence.Field{ { @@ -6238,7 +6238,7 @@ func TestEncodeEvent(t *testing.T) { t.Run(tc.name, func(t *testing.T) { actualCBOR, err := ccf.EventsEncMode.Encode(tc.val) require.NoError(t, err) - utils.AssertEqualWithDiff(t, tc.expected, actualCBOR) + AssertEqualWithDiff(t, tc.expected, actualCBOR) decodedVal, err := ccf.EventsDecMode.Decode(nil, actualCBOR) require.NoError(t, err) @@ -6259,7 +6259,7 @@ func TestEncodeContract(t *testing.T) { name: "Simple", val: func() cadence.Value { simpleContractType := cadence.NewContractType( - utils.TestLocation, + TestLocation, "FooContract", []cadence.Field{ { @@ -6363,7 +6363,7 @@ func TestEncodeContract(t *testing.T) { name: "abstract contract", val: func() cadence.Value { simpleStructType := cadence.NewStructType( - utils.TestLocation, + TestLocation, "FooStruct", []cadence.Field{ { @@ -6374,7 +6374,7 @@ func TestEncodeContract(t *testing.T) { nil, ) abstractContractType := cadence.NewContractType( - utils.TestLocation, + TestLocation, "FooContract", []cadence.Field{ { @@ -6525,7 +6525,7 @@ func TestEncodeContract(t *testing.T) { val: func() cadence.Value { fooResourceType := newFooResourceType() resourceContractType := cadence.NewContractType( - utils.TestLocation, + TestLocation, "FooContract", []cadence.Field{ { @@ -6677,7 +6677,7 @@ func TestEncodeEnum(t *testing.T) { name: "Simple", val: func() cadence.Value { simpleEnumType := cadence.NewEnumType( - utils.TestLocation, + TestLocation, "FooEnum", nil, []cadence.Field{ @@ -6764,7 +6764,7 @@ func TestEncodeAttachment(t *testing.T) { name: "no field", val: func() cadence.Value { attachmentType := cadence.NewAttachmentType( - utils.TestLocation, + TestLocation, "FooAttachment", nil, []cadence.Field{}, @@ -6825,7 +6825,7 @@ func TestEncodeAttachment(t *testing.T) { name: "simple", val: func() cadence.Value { attachmentType := cadence.NewAttachmentType( - utils.TestLocation, + TestLocation, "FooAttachment", nil, []cadence.Field{ @@ -6906,7 +6906,7 @@ func TestEncodeAttachment(t *testing.T) { name: "struct field", val: func() cadence.Value { structType := cadence.NewStructType( - utils.TestLocation, + TestLocation, "FooStruct", []cadence.Field{ { @@ -6917,7 +6917,7 @@ func TestEncodeAttachment(t *testing.T) { nil, ) attachmentType := cadence.NewAttachmentType( - utils.TestLocation, + TestLocation, "FooAttachment", nil, []cadence.Field{ @@ -7508,7 +7508,7 @@ func TestEncodeValueOfReferenceType(t *testing.T) { newSimpleStructType := func() *cadence.StructType { return cadence.NewStructType( - utils.TestLocation, + TestLocation, "Foo", []cadence.Field{ { @@ -8840,7 +8840,7 @@ func TestEncodeType(t *testing.T) { t, cadence.TypeValue{ StaticType: cadence.NewStructType( - utils.TestLocation, + TestLocation, "S", []cadence.Field{}, [][]cadence.Parameter{}, @@ -8889,7 +8889,7 @@ func TestEncodeType(t *testing.T) { val := cadence.TypeValue{ StaticType: cadence.NewStructType( - utils.TestLocation, + TestLocation, "S", []cadence.Field{ {Identifier: "foo", Type: cadence.IntType}, @@ -8993,7 +8993,7 @@ func TestEncodeType(t *testing.T) { // Encode value without sorting of composite fields. actualCBOR, err := ccf.Encode(val) require.NoError(t, err) - utils.AssertEqualWithDiff(t, expectedCBOR, actualCBOR) + AssertEqualWithDiff(t, expectedCBOR, actualCBOR) // Decode value without enforcing sorting of composite fields. decodedVal, err := ccf.Decode(nil, actualCBOR) @@ -9012,7 +9012,7 @@ func TestEncodeType(t *testing.T) { t, cadence.TypeValue{ StaticType: cadence.NewStructType( - utils.TestLocation, + TestLocation, "S", []cadence.Field{ {Identifier: "foo", Type: cadence.IntType}, @@ -9113,7 +9113,7 @@ func TestEncodeType(t *testing.T) { }, cadence.TypeValue{ StaticType: cadence.NewStructType( - utils.TestLocation, + TestLocation, "S", []cadence.Field{ {Identifier: "bar", Type: cadence.IntType}, @@ -9134,21 +9134,21 @@ func TestEncodeType(t *testing.T) { t.Parallel() fooTy := cadence.NewResourceType( - utils.TestLocation, + TestLocation, "Foo", []cadence.Field{}, [][]cadence.Parameter{}, ) fooTy2 := cadence.NewResourceType( - utils.TestLocation, + TestLocation, "Foo2", []cadence.Field{}, [][]cadence.Parameter{}, ) barTy := cadence.NewResourceType( - utils.TestLocation, + TestLocation, "Bar", []cadence.Field{ { @@ -9274,7 +9274,7 @@ func TestEncodeType(t *testing.T) { t, cadence.TypeValue{ StaticType: cadence.NewResourceType( - utils.TestLocation, + TestLocation, "R", []cadence.Field{ {Identifier: "foo", Type: cadence.IntType}, @@ -9372,7 +9372,7 @@ func TestEncodeType(t *testing.T) { t, cadence.TypeValue{ StaticType: cadence.NewContractType( - utils.TestLocation, + TestLocation, "C", []cadence.Field{ {Identifier: "foo", Type: cadence.IntType}, @@ -9470,7 +9470,7 @@ func TestEncodeType(t *testing.T) { t, cadence.TypeValue{ StaticType: cadence.NewStructInterfaceType( - utils.TestLocation, + TestLocation, "S", []cadence.Field{ {Identifier: "foo", Type: cadence.IntType}, @@ -9568,7 +9568,7 @@ func TestEncodeType(t *testing.T) { t, cadence.TypeValue{ StaticType: cadence.NewResourceInterfaceType( - utils.TestLocation, + TestLocation, "R", []cadence.Field{ {Identifier: "foo", Type: cadence.IntType}, @@ -9666,7 +9666,7 @@ func TestEncodeType(t *testing.T) { t, cadence.TypeValue{ StaticType: cadence.NewContractInterfaceType( - utils.TestLocation, + TestLocation, "C", []cadence.Field{ {Identifier: "foo", Type: cadence.IntType}, @@ -9764,7 +9764,7 @@ func TestEncodeType(t *testing.T) { t, cadence.TypeValue{ StaticType: cadence.NewEventType( - utils.TestLocation, + TestLocation, "E", []cadence.Field{ {Identifier: "foo", Type: cadence.IntType}, @@ -9860,7 +9860,7 @@ func TestEncodeType(t *testing.T) { t, cadence.TypeValue{ StaticType: cadence.NewEnumType( - utils.TestLocation, + TestLocation, "E", cadence.StringType, []cadence.Field{ @@ -9961,7 +9961,7 @@ func TestEncodeType(t *testing.T) { t, cadence.TypeValue{ StaticType: cadence.NewAttachmentType( - utils.TestLocation, + TestLocation, "A", cadence.StringType, []cadence.Field{ @@ -10059,7 +10059,7 @@ func TestEncodeType(t *testing.T) { t.Parallel() baseType := cadence.NewResourceType( - utils.TestLocation, + TestLocation, "FooBase", []cadence.Field{ {Identifier: "bar", Type: cadence.StringType}, @@ -10071,7 +10071,7 @@ func TestEncodeType(t *testing.T) { t, cadence.TypeValue{ StaticType: cadence.NewAttachmentType( - utils.TestLocation, + TestLocation, "A", baseType, []cadence.Field{ @@ -11050,7 +11050,7 @@ func TestEncodeCapability(t *testing.T) { t.Parallel() simpleStructType := cadence.NewStructType( - utils.TestLocation, + TestLocation, "FooStruct", []cadence.Field{ { @@ -11722,7 +11722,7 @@ func TestExportRecursiveType(t *testing.T) { }, } ty := cadence.NewResourceType( - utils.TestLocation, + TestLocation, "Foo", fields, nil, @@ -11815,7 +11815,7 @@ func TestExportTypeValueRecursiveType(t *testing.T) { }, } ty := cadence.NewResourceType( - utils.TestLocation, + TestLocation, "Foo", fields, [][]cadence.Parameter{}, @@ -12061,21 +12061,21 @@ func TestExportTypeValueRecursiveType(t *testing.T) { t.Parallel() fooTy := cadence.NewResourceType( - utils.TestLocation, + TestLocation, "Foo", []cadence.Field{}, [][]cadence.Parameter{}, ) fooTy2 := cadence.NewResourceType( - utils.TestLocation, + TestLocation, "Foo2", []cadence.Field{}, [][]cadence.Parameter{}, ) barTy := cadence.NewResourceType( - utils.TestLocation, + TestLocation, "Bar", []cadence.Field{ { @@ -12729,7 +12729,7 @@ func testEncode(t *testing.T, val cadence.Value, expectedCBOR []byte) (actualCBO actualCBOR, err := deterministicEncMode.Encode(val) require.NoError(t, err) - utils.AssertEqualWithDiff(t, expectedCBOR, actualCBOR) + AssertEqualWithDiff(t, expectedCBOR, actualCBOR) return actualCBOR } @@ -12748,7 +12748,7 @@ func testDecode(t *testing.T, actualCBOR []byte, expectedVal cadence.Value) { // TODO: make resource (illegal nesting) func newResourceStructType() *cadence.StructType { return cadence.NewStructType( - utils.TestLocation, + TestLocation, "FooStruct", []cadence.Field{ { @@ -12766,7 +12766,7 @@ func newResourceStructType() *cadence.StructType { func newFooResourceType() *cadence.ResourceType { return cadence.NewResourceType( - utils.TestLocation, + TestLocation, "Foo", []cadence.Field{ { @@ -12780,7 +12780,7 @@ func newFooResourceType() *cadence.ResourceType { func newFoooResourceTypeWithAbstractField() *cadence.ResourceType { return cadence.NewResourceType( - utils.TestLocation, + TestLocation, "Fooo", []cadence.Field{ { @@ -13187,7 +13187,7 @@ func TestExportFunctionValue(t *testing.T) { }, } ty := cadence.NewResourceType( - utils.TestLocation, + TestLocation, "Foo", fields, nil, @@ -14038,7 +14038,7 @@ func TestDeployedEvents(t *testing.T) { // Encode Cadence value to CCF actualCBOR, err := ccf.EventsEncMode.Encode(tc.event) require.NoError(t, err) - utils.AssertEqualWithDiff(t, tc.expectedCBOR, actualCBOR) + AssertEqualWithDiff(t, tc.expectedCBOR, actualCBOR) // Decode CCF to Cadence value decodedEvent, err := ccf.EventsDecMode.Decode(nil, actualCBOR) @@ -15912,7 +15912,7 @@ func TestSortEntitlementSet(t *testing.T) { // Encode value without sorting. actualCBOR, err := ccf.Encode(val) require.NoError(t, err) - utils.AssertEqualWithDiff(t, expectedCBOR, actualCBOR) + AssertEqualWithDiff(t, expectedCBOR, actualCBOR) // Decode value without enforcing sorting. decodedVal, err := ccf.Decode(nil, actualCBOR) @@ -16010,7 +16010,7 @@ func TestSortEntitlementSet(t *testing.T) { // Encode value with sorted entitlement types. actualCBOR, err := sortEntitlementTypesEncMode.Encode(val) require.NoError(t, err) - utils.AssertEqualWithDiff(t, expectedCBOR, actualCBOR) + AssertEqualWithDiff(t, expectedCBOR, actualCBOR) // Decode value enforcing sorting of composite fields. decodedVal, err := enforceSortedEntitlementTypesDecMode.Decode(nil, actualCBOR) @@ -16079,7 +16079,7 @@ func TestSortEntitlementSet(t *testing.T) { // Encode value without sorting. actualCBOR, err := ccf.Encode(val) require.NoError(t, err) - utils.AssertEqualWithDiff(t, expectedCBOR, actualCBOR) + AssertEqualWithDiff(t, expectedCBOR, actualCBOR) // Decode value without enforcing sorting. decodedVal, err := ccf.Decode(nil, actualCBOR) @@ -16156,7 +16156,7 @@ func TestSortEntitlementSet(t *testing.T) { // Encode value with sorting. actualCBOR, err := sortEntitlementTypesEncMode.Encode(val) require.NoError(t, err) - utils.AssertEqualWithDiff(t, expectedCBOR, actualCBOR) + AssertEqualWithDiff(t, expectedCBOR, actualCBOR) // Decode value without enforcing sorting. decodedVal, err := ccf.Decode(nil, actualCBOR) @@ -16404,7 +16404,7 @@ func TestSortOptions(t *testing.T) { // Encode value without sorting. actualCBOR, err := ccf.Encode(val) require.NoError(t, err) - utils.AssertEqualWithDiff(t, expectedCBOR, actualCBOR) + AssertEqualWithDiff(t, expectedCBOR, actualCBOR) // Decode value without enforcing sorting. decodedVal, err := ccf.Decode(nil, actualCBOR) @@ -16593,7 +16593,7 @@ func TestSortOptions(t *testing.T) { // Encode value with sorted composite fields. actualCBOR, err := sortFieldsEncMode.Encode(val) require.NoError(t, err) - utils.AssertEqualWithDiff(t, expectedCBOR, actualCBOR) + AssertEqualWithDiff(t, expectedCBOR, actualCBOR) // Decode value enforcing sorting of composite fields. decodedVal, err := enforceSortedFieldsDecMode.Decode(nil, actualCBOR) @@ -16782,7 +16782,7 @@ func TestSortOptions(t *testing.T) { // Encode value with sorted Intersection types. actualCBOR, err := sortIntersectionTypesEncMode.Encode(val) require.NoError(t, err) - utils.AssertEqualWithDiff(t, expectedCBOR, actualCBOR) + AssertEqualWithDiff(t, expectedCBOR, actualCBOR) // Decode value enforcing sorting of Intersection types. decodedVal, err := enforceSortedIntersectionTypesDecMode.Decode(nil, actualCBOR) @@ -16971,7 +16971,7 @@ func TestSortOptions(t *testing.T) { // Encode value with sorted composite fields and Intersection types. actualCBOR, err := deterministicEncMode.Encode(val) require.NoError(t, err) - utils.AssertEqualWithDiff(t, expectedCBOR, actualCBOR) + AssertEqualWithDiff(t, expectedCBOR, actualCBOR) // Decode value enforcing sorting of composite fields and Intersection types. decodedVal, err := deterministicDecMode.Decode(nil, actualCBOR) @@ -17111,7 +17111,7 @@ func TestDecodeFunctionTypeBackwardCompatibility(t *testing.T) { testDecode(t, data, val) } -func TestEncodeEventWithAttachement(t *testing.T) { +func TestEncodeEventWithAttachment(t *testing.T) { script := ` access(all) struct S { access(all) let x: Int @@ -17146,11 +17146,11 @@ func TestEncodeEventWithAttachement(t *testing.T) { } func exportEventFromScript(t *testing.T, script string) cadence.Event { - rt := runtime_utils.NewTestInterpreterRuntime() + rt := NewTestInterpreterRuntime() var events []cadence.Event - inter := &runtime_utils.TestRuntimeInterface{ + inter := &TestRuntimeInterface{ OnEmitEvent: func(event cadence.Event) error { events = append(events, event) return nil diff --git a/encoding/ccf/ccf_type_id_test.go b/encoding/ccf/ccf_type_id_test.go index 271623e4e4..2019a2bbfa 100644 --- a/encoding/ccf/ccf_type_id_test.go +++ b/encoding/ccf/ccf_type_id_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestCCFTypeID(t *testing.T) { @@ -117,7 +117,7 @@ func TestCadenceTypeByCCFTypeID(t *testing.T) { func simpleStructType() *cadence.StructType { return cadence.NewStructType( - utils.TestLocation, + TestLocation, "FooStruct", []cadence.Field{ { @@ -131,7 +131,7 @@ func simpleStructType() *cadence.StructType { func simpleStructType2() *cadence.StructType { return cadence.NewStructType( - utils.TestLocation, + TestLocation, "FooStruct2", []cadence.Field{ { diff --git a/encoding/json/encoding_test.go b/encoding/json/encoding_test.go index 5a22360dd0..da52ff3cc8 100644 --- a/encoding/json/encoding_test.go +++ b/encoding/json/encoding_test.go @@ -28,14 +28,13 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/onflow/cadence" "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/runtime" - "github.com/onflow/cadence/tests/checker" - - "github.com/onflow/cadence" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) type encodeTest struct { @@ -1123,7 +1122,7 @@ func TestEncodeDictionary(t *testing.T) { } func exportFromScript(t *testing.T, code string) cadence.Value { - checker, err := checker.ParseAndCheck(t, code) + checker, err := ParseAndCheck(t, code) require.NoError(t, err) var uuid uint64 = 0 @@ -1337,7 +1336,7 @@ func TestEncodeStruct(t *testing.T) { t.Parallel() simpleStructType := cadence.NewStructType( - utils.TestLocation, + TestLocation, "FooStruct", []cadence.Field{ { @@ -1390,7 +1389,7 @@ func TestEncodeStruct(t *testing.T) { fooResourceType := newFooResourceType() resourceStructType := cadence.NewStructType( - utils.TestLocation, + TestLocation, "FooStruct", []cadence.Field{ { @@ -1499,7 +1498,7 @@ func TestEncodeEvent(t *testing.T) { t.Parallel() simpleEventType := cadence.NewEventType( - utils.TestLocation, + TestLocation, "FooEvent", []cadence.Field{ { @@ -1552,7 +1551,7 @@ func TestEncodeEvent(t *testing.T) { fooResourceType := newFooResourceType() resourceEventType := cadence.NewEventType( - utils.TestLocation, + TestLocation, "FooEvent", []cadence.Field{ { @@ -1625,7 +1624,7 @@ func TestEncodeContract(t *testing.T) { t.Parallel() simpleContractType := cadence.NewContractType( - utils.TestLocation, + TestLocation, "FooContract", []cadence.Field{ { @@ -1678,7 +1677,7 @@ func TestEncodeContract(t *testing.T) { fooResourceType := newFooResourceType() resourceContractType := cadence.NewContractType( - utils.TestLocation, + TestLocation, "FooContract", []cadence.Field{ { @@ -1916,7 +1915,7 @@ func TestEncodeType(t *testing.T) { t, cadence.TypeValue{ StaticType: cadence.NewStructType( - utils.TestLocation, + TestLocation, "S", []cadence.Field{ {Identifier: "foo", Type: cadence.IntType}, @@ -1977,7 +1976,7 @@ func TestEncodeType(t *testing.T) { t, cadence.TypeValue{ StaticType: cadence.NewResourceType( - utils.TestLocation, + TestLocation, "R", []cadence.Field{ {Identifier: "foo", Type: cadence.IntType}, @@ -2038,7 +2037,7 @@ func TestEncodeType(t *testing.T) { t, cadence.TypeValue{ StaticType: cadence.NewContractType( - utils.TestLocation, + TestLocation, "C", []cadence.Field{ {Identifier: "foo", Type: cadence.IntType}, @@ -2099,7 +2098,7 @@ func TestEncodeType(t *testing.T) { t, cadence.TypeValue{ StaticType: cadence.NewStructInterfaceType( - utils.TestLocation, + TestLocation, "S", []cadence.Field{ {Identifier: "foo", Type: cadence.IntType}, @@ -2160,7 +2159,7 @@ func TestEncodeType(t *testing.T) { t, cadence.TypeValue{ StaticType: cadence.NewResourceInterfaceType( - utils.TestLocation, + TestLocation, "R", []cadence.Field{ {Identifier: "foo", Type: cadence.IntType}, @@ -2221,7 +2220,7 @@ func TestEncodeType(t *testing.T) { t, cadence.TypeValue{ StaticType: cadence.NewContractInterfaceType( - utils.TestLocation, + TestLocation, "C", []cadence.Field{ {Identifier: "foo", Type: cadence.IntType}, @@ -2282,7 +2281,7 @@ func TestEncodeType(t *testing.T) { t, cadence.TypeValue{ StaticType: cadence.NewEventType( - utils.TestLocation, + TestLocation, "E", []cadence.Field{ {Identifier: "foo", Type: cadence.IntType}, @@ -2341,7 +2340,7 @@ func TestEncodeType(t *testing.T) { t, cadence.TypeValue{ StaticType: cadence.NewEnumType( - utils.TestLocation, + TestLocation, "E", cadence.StringType, []cadence.Field{ @@ -3317,7 +3316,7 @@ func TestExportRecursiveType(t *testing.T) { }, } ty := cadence.NewResourceType( - utils.TestLocation, + TestLocation, "Foo", fields, nil, @@ -3368,7 +3367,7 @@ func TestExportTypeValueRecursiveType(t *testing.T) { }, } ty := cadence.NewResourceType( - utils.TestLocation, + TestLocation, "Foo", fields, [][]cadence.Parameter{}, @@ -3415,14 +3414,14 @@ func TestExportTypeValueRecursiveType(t *testing.T) { t.Parallel() fooTy := cadence.NewResourceType( - utils.TestLocation, + TestLocation, "Foo", []cadence.Field{}, [][]cadence.Parameter{}, ) barTy := cadence.NewResourceType( - utils.TestLocation, + TestLocation, "Bar", []cadence.Field{ { @@ -3638,7 +3637,7 @@ func testDecode(t *testing.T, actualJSON string, expectedVal cadence.Value, opti func newFooResourceType() *cadence.ResourceType { return cadence.NewResourceType( - utils.TestLocation, + TestLocation, "Foo", []cadence.Field{ { diff --git a/fuzz.go b/fuzz.go index 35774a3137..3b98f72655 100644 --- a/fuzz.go +++ b/fuzz.go @@ -23,7 +23,7 @@ import ( "github.com/onflow/cadence/parser" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func Fuzz(data []byte) int { @@ -40,7 +40,7 @@ func Fuzz(data []byte) int { checker, err := sema.NewChecker( program, - utils.TestLocation, + TestLocation, nil, &sema.Config{ AccessCheckMode: sema.AccessCheckModeNotSpecifiedUnrestricted, diff --git a/tests/fuzz/crashers_test.go b/fuzz/crashers_test.go similarity index 96% rename from tests/fuzz/crashers_test.go rename to fuzz/crashers_test.go index b52a889d73..9ac802ac36 100644 --- a/tests/fuzz/crashers_test.go +++ b/fuzz/crashers_test.go @@ -28,7 +28,7 @@ import ( "github.com/onflow/cadence" ) -const crashersDir = "../../../crashers" +const crashersDir = "crashers" func TestCrashers(t *testing.T) { diff --git a/go.mod b/go.mod index 4ee8098b0f..6193bce06e 100644 --- a/go.mod +++ b/go.mod @@ -22,10 +22,10 @@ require ( github.com/turbolent/prettier v0.0.0-20220320183459-661cc755135d go.opentelemetry.io/otel v1.8.0 go.uber.org/goleak v1.1.10 - golang.org/x/crypto v0.1.0 - golang.org/x/mod v0.14.0 - golang.org/x/text v0.4.0 - golang.org/x/tools v0.16.0 + golang.org/x/crypto v0.28.0 + golang.org/x/mod v0.17.0 + golang.org/x/text v0.19.0 + golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 ) @@ -56,8 +56,9 @@ require ( github.com/zeebo/assert v1.3.0 // indirect github.com/zeebo/blake3 v0.2.3 // indirect golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect - golang.org/x/sys v0.15.0 // indirect - golang.org/x/term v0.6.0 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/sys v0.26.0 // indirect + golang.org/x/term v0.25.0 // indirect gonum.org/v1/gonum v0.6.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index c5711d90b7..cc2c3058d0 100644 --- a/go.sum +++ b/go.sum @@ -23,8 +23,8 @@ github.com/fxamacker/cbor/v2 v2.4.1-0.20230228173756-c0c9f774e40c/go.mod h1:TA1x github.com/fxamacker/circlehash v0.3.0 h1:XKdvTtIJV9t7DDUtsf0RIpC1OcxZtPbmgIH7ekx28WA= github.com/fxamacker/circlehash v0.3.0/go.mod h1:3aq3OfVvsWtkWMb6A1owjOQFA+TLsD5FgJflnaQwtMM= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= -github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= -github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/itchyny/gojq v0.12.14 h1:6k8vVtsrhQSYgSGg827AD+PVVaB1NLXEdX+dda2oZCc= github.com/itchyny/gojq v0.12.14/go.mod h1:y1G7oO7XkcR1LPZO59KyoCRy08T3j9vDYRV0GgYSS+s= github.com/itchyny/timefmt-go v0.1.5 h1:G0INE2la8S6ru/ZI5JecgyzbbJNs5lG1RcBqa7Jm6GE= @@ -121,8 +121,8 @@ go.uber.org/goleak v1.1.10 h1:z+mqJhf6ss6BSfSM671tgKyZBFPTTJM+HLxnhPC3wu0= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU= -golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= +golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= +golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -133,8 +133,8 @@ golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= -golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -143,8 +143,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20191109021931-daa7c04131f5/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= -golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -157,20 +157,21 @@ golang.org/x/sys v0.0.0-20200918174421-af09f7315aff/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= +golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24= +golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= -golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= +golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM= -golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= diff --git a/tests/interpreter/account_test.go b/interpreter/account_test.go similarity index 99% rename from tests/interpreter/account_test.go rename to interpreter/account_test.go index 9ef518efb9..a003477a56 100644 --- a/tests/interpreter/account_test.go +++ b/interpreter/account_test.go @@ -34,7 +34,8 @@ import ( "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) type storageKey struct { diff --git a/tests/interpreter/arithmetic_test.go b/interpreter/arithmetic_test.go similarity index 99% rename from tests/interpreter/arithmetic_test.go rename to interpreter/arithmetic_test.go index 4c56b41345..86d966ac92 100644 --- a/tests/interpreter/arithmetic_test.go +++ b/interpreter/arithmetic_test.go @@ -29,7 +29,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) var integerTestValues = map[string]interpreter.NumberValue{ diff --git a/tests/interpreter/array_test.go b/interpreter/array_test.go similarity index 100% rename from tests/interpreter/array_test.go rename to interpreter/array_test.go diff --git a/tests/interpreter/attachments_test.go b/interpreter/attachments_test.go similarity index 99% rename from tests/interpreter/attachments_test.go rename to interpreter/attachments_test.go index 3c61208033..384ee9f647 100644 --- a/tests/interpreter/attachments_test.go +++ b/interpreter/attachments_test.go @@ -26,7 +26,7 @@ import ( "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" "github.com/stretchr/testify/require" ) diff --git a/tests/interpreter/bitwise_test.go b/interpreter/bitwise_test.go similarity index 99% rename from tests/interpreter/bitwise_test.go rename to interpreter/bitwise_test.go index b0e9e9cd74..a288e7e667 100644 --- a/tests/interpreter/bitwise_test.go +++ b/interpreter/bitwise_test.go @@ -24,7 +24,7 @@ import ( "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) var bitwiseTestValueFunctions = map[string]func(int) interpreter.NumberValue{ diff --git a/tests/interpreter/builtinfunctions_test.go b/interpreter/builtinfunctions_test.go similarity index 99% rename from tests/interpreter/builtinfunctions_test.go rename to interpreter/builtinfunctions_test.go index b527af6900..93402c80e5 100644 --- a/tests/interpreter/builtinfunctions_test.go +++ b/interpreter/builtinfunctions_test.go @@ -29,7 +29,8 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) func TestInterpretToString(t *testing.T) { diff --git a/tests/interpreter/character_test.go b/interpreter/character_test.go similarity index 97% rename from tests/interpreter/character_test.go rename to interpreter/character_test.go index 298fb1c604..b079563f09 100644 --- a/tests/interpreter/character_test.go +++ b/interpreter/character_test.go @@ -26,7 +26,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) func TestInterpretCharacterUtf8Field(t *testing.T) { diff --git a/tests/interpreter/composite_value_test.go b/interpreter/composite_value_test.go similarity index 97% rename from tests/interpreter/composite_value_test.go rename to interpreter/composite_value_test.go index cacf0c145d..de85e30b22 100644 --- a/tests/interpreter/composite_value_test.go +++ b/interpreter/composite_value_test.go @@ -29,7 +29,8 @@ import ( "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) func TestInterpretCompositeValue(t *testing.T) { diff --git a/tests/interpreter/condition_test.go b/interpreter/condition_test.go similarity index 99% rename from tests/interpreter/condition_test.go rename to interpreter/condition_test.go index 34d56d2f14..ef1df7b638 100644 --- a/tests/interpreter/condition_test.go +++ b/interpreter/condition_test.go @@ -31,8 +31,9 @@ import ( "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - "github.com/onflow/cadence/tests/checker" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestInterpretFunctionPreTestCondition(t *testing.T) { @@ -855,7 +856,7 @@ func TestInterpretInitializerWithInterfacePreCondition(t *testing.T) { ) } - checker, err := checker.ParseAndCheck(t, + checker, err := ParseAndCheck(t, fmt.Sprintf( ` access(all) diff --git a/interpreter/config.go b/interpreter/config.go index 1d921085f2..d77bd667c3 100644 --- a/interpreter/config.go +++ b/interpreter/config.go @@ -72,8 +72,6 @@ type Config struct { CapabilityBorrowHandler CapabilityBorrowHandlerFunc // LegacyContractUpgradeEnabled specifies whether to fall back to the old parser when attempting a contract upgrade LegacyContractUpgradeEnabled bool - // ContractUpdateTypeRemovalEnabled specifies if type removal is enabled in contract updates - ContractUpdateTypeRemovalEnabled bool // ValidateAccountCapabilitiesGetHandler is used to handle when a capability of an account is got. ValidateAccountCapabilitiesGetHandler ValidateAccountCapabilitiesGetHandlerFunc // ValidateAccountCapabilitiesPublishHandler is used to handle when a capability of an account is got. diff --git a/tests/interpreter/container_mutation_test.go b/interpreter/container_mutation_test.go similarity index 99% rename from tests/interpreter/container_mutation_test.go rename to interpreter/container_mutation_test.go index 10a37e6a30..5f67eab2b1 100644 --- a/tests/interpreter/container_mutation_test.go +++ b/interpreter/container_mutation_test.go @@ -29,10 +29,11 @@ import ( "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) -func TestInterpetArrayMutation(t *testing.T) { +func TestInterpretArrayMutation(t *testing.T) { t.Parallel() diff --git a/tests/interpreter/contract_test.go b/interpreter/contract_test.go similarity index 98% rename from tests/interpreter/contract_test.go rename to interpreter/contract_test.go index e4f9e8b30f..6d437fdec1 100644 --- a/tests/interpreter/contract_test.go +++ b/interpreter/contract_test.go @@ -24,7 +24,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/interpreter" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestInterpretContractUseBeforeInitializationComplete(t *testing.T) { diff --git a/interpreter/conversion_test.go b/interpreter/conversion_test.go index a3eb0122a0..a798b10fb0 100644 --- a/interpreter/conversion_test.go +++ b/interpreter/conversion_test.go @@ -27,7 +27,7 @@ import ( "github.com/onflow/cadence/common" . "github.com/onflow/cadence/interpreter" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestByteArrayValueToByteSlice(t *testing.T) { diff --git a/tests/interpreter/declaration_test.go b/interpreter/declaration_test.go similarity index 100% rename from tests/interpreter/declaration_test.go rename to interpreter/declaration_test.go diff --git a/interpreter/deepcopyremove_test.go b/interpreter/deepcopyremove_test.go index 5521332900..0f12a4b034 100644 --- a/interpreter/deepcopyremove_test.go +++ b/interpreter/deepcopyremove_test.go @@ -26,8 +26,8 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/common" - . "github.com/onflow/cadence/interpreter" - "github.com/onflow/cadence/tests/utils" + "github.com/onflow/cadence/interpreter" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestValueDeepCopyAndDeepRemove(t *testing.T) { @@ -38,49 +38,49 @@ func TestValueDeepCopyAndDeepRemove(t *testing.T) { storage := newUnmeteredInMemoryStorage() - inter, err := NewInterpreter( + inter, err := interpreter.NewInterpreter( nil, - utils.TestLocation, - &Config{ + TestLocation, + &interpreter.Config{ Storage: storage, }, ) require.NoError(t, err) - dictionaryStaticType := &DictionaryStaticType{ - KeyType: PrimitiveStaticTypeString, - ValueType: PrimitiveStaticTypeInt256, + dictionaryStaticType := &interpreter.DictionaryStaticType{ + KeyType: interpreter.PrimitiveStaticTypeString, + ValueType: interpreter.PrimitiveStaticTypeInt256, } - dictValueKey := NewUnmeteredStringValue( + dictValueKey := interpreter.NewUnmeteredStringValue( strings.Repeat("x", int(atree.MaxInlineMapKeySize()+1)), ) - dictValueValue := NewUnmeteredInt256ValueFromInt64(1) - dictValue := NewDictionaryValue( + dictValueValue := interpreter.NewUnmeteredInt256ValueFromInt64(1) + dictValue := interpreter.NewDictionaryValue( inter, - EmptyLocationRange, + interpreter.EmptyLocationRange, dictionaryStaticType, dictValueKey, dictValueValue, ) - arrayValue := NewArrayValue( + arrayValue := interpreter.NewArrayValue( inter, - EmptyLocationRange, - &VariableSizedStaticType{ + interpreter.EmptyLocationRange, + &interpreter.VariableSizedStaticType{ Type: dictionaryStaticType, }, common.ZeroAddress, dictValue, ) - optionalValue := NewUnmeteredSomeValueNonCopying(arrayValue) + optionalValue := interpreter.NewUnmeteredSomeValueNonCopying(arrayValue) compositeValue := newTestCompositeValue(inter, address) compositeValue.SetMember( inter, - EmptyLocationRange, + interpreter.EmptyLocationRange, "value", optionalValue, ) @@ -99,7 +99,3 @@ func TestValueDeepCopyAndDeepRemove(t *testing.T) { require.Equal(t, 1, count) } - -func newUnmeteredInMemoryStorage() InMemoryStorage { - return NewInMemoryStorage(nil) -} diff --git a/tests/interpreter/dictionary_test.go b/interpreter/dictionary_test.go similarity index 100% rename from tests/interpreter/dictionary_test.go rename to interpreter/dictionary_test.go diff --git a/tests/interpreter/dynamic_casting_test.go b/interpreter/dynamic_casting_test.go similarity index 99% rename from tests/interpreter/dynamic_casting_test.go rename to interpreter/dynamic_casting_test.go index 03b532b119..255a7b719e 100644 --- a/tests/interpreter/dynamic_casting_test.go +++ b/interpreter/dynamic_casting_test.go @@ -32,7 +32,8 @@ import ( "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) // dynamic casting operation -> returns optional diff --git a/interpreter/encoding_test.go b/interpreter/encoding_test.go index 5bcc19bc7e..2eb4047209 100644 --- a/interpreter/encoding_test.go +++ b/interpreter/encoding_test.go @@ -30,12 +30,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/onflow/cadence/common" . "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - - "github.com/onflow/cadence/common" - "github.com/onflow/cadence/tests/utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) type encodeDecodeTest struct { @@ -492,7 +491,7 @@ func TestEncodeDecodeComposite(t *testing.T) { expected := NewCompositeValue( inter, EmptyLocationRange, - utils.TestLocation, + TestLocation, "TestStruct", common.CompositeKindStructure, nil, @@ -530,7 +529,7 @@ func TestEncodeDecodeComposite(t *testing.T) { expected := NewCompositeValue( inter, EmptyLocationRange, - utils.TestLocation, + TestLocation, "TestResource", common.CompositeKindResource, fields, @@ -4256,7 +4255,7 @@ func TestEncodeDecodeStorageCapabilityControllerValue(t *testing.T) { BorrowType: &ReferenceStaticType{ ReferencedType: NewCompositeStaticTypeComputeTypeID( nil, - utils.TestLocation, + TestLocation, "SimpleStruct", ), Authorization: UnauthorizedAccess, @@ -4305,7 +4304,7 @@ func TestEncodeDecodeStorageCapabilityControllerValue(t *testing.T) { value := &StorageCapabilityControllerValue{ TargetPath: publicPathValue, BorrowType: &ReferenceStaticType{ - ReferencedType: NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "SimpleInterface"), + ReferencedType: NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "SimpleInterface"), Authorization: UnauthorizedAccess, }, CapabilityID: capabilityID, @@ -4485,8 +4484,8 @@ func TestEncodeDecodeStorageCapabilityControllerValue(t *testing.T) { BorrowType: &ReferenceStaticType{ ReferencedType: &IntersectionStaticType{ Types: []*InterfaceStaticType{ - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "I1"), - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "I2"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "I1"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "I2"), }, }, Authorization: UnauthorizedAccess, @@ -4705,7 +4704,7 @@ func TestEncodeDecodeAccountCapabilityControllerValue(t *testing.T) { BorrowType: &ReferenceStaticType{ ReferencedType: &IntersectionStaticType{ Types: []*InterfaceStaticType{ - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "SimpleInterface"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "SimpleInterface"), }, }, Authorization: UnauthorizedAccess, diff --git a/tests/interpreter/entitlements_test.go b/interpreter/entitlements_test.go similarity index 99% rename from tests/interpreter/entitlements_test.go rename to interpreter/entitlements_test.go index 0475ec1191..79d368de70 100644 --- a/tests/interpreter/entitlements_test.go +++ b/interpreter/entitlements_test.go @@ -28,7 +28,7 @@ import ( "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) func TestInterpretEntitledReferenceRuntimeTypes(t *testing.T) { diff --git a/tests/interpreter/enum_test.go b/interpreter/enum_test.go similarity index 98% rename from tests/interpreter/enum_test.go rename to interpreter/enum_test.go index 54e563c784..fa3e9a0c05 100644 --- a/tests/interpreter/enum_test.go +++ b/interpreter/enum_test.go @@ -24,10 +24,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - . "github.com/onflow/cadence/tests/utils" - "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) func TestInterpretEnum(t *testing.T) { diff --git a/tests/interpreter/equality_test.go b/interpreter/equality_test.go similarity index 98% rename from tests/interpreter/equality_test.go rename to interpreter/equality_test.go index dee8dc54c9..68cfd10f04 100644 --- a/tests/interpreter/equality_test.go +++ b/interpreter/equality_test.go @@ -31,7 +31,8 @@ import ( "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) func TestInterpretEquality(t *testing.T) { diff --git a/interpreter/errors_test.go b/interpreter/errors_test.go index 568158cf58..4c120a0994 100644 --- a/interpreter/errors_test.go +++ b/interpreter/errors_test.go @@ -26,7 +26,7 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/common" . "github.com/onflow/cadence/interpreter" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestOverwriteError_Error(t *testing.T) { @@ -47,11 +47,11 @@ func TestErrorOutputIncludesLocationRage(t *testing.T) { t.Parallel() require.Equal(t, Error{ - Location: utils.TestLocation, + Location: TestLocation, Err: DereferenceError{ Cause: "the value being referenced has been destroyed or moved", LocationRange: LocationRange{ - Location: utils.TestLocation, + Location: TestLocation, HasPosition: ast.Range{ StartPos: ast.Position{Offset: 0, Column: 0, Line: 0}, EndPos: ast.Position{Offset: 0, Column: 0, Line: 0}, diff --git a/tests/interpreter/fixedpoint_test.go b/interpreter/fixedpoint_test.go similarity index 99% rename from tests/interpreter/fixedpoint_test.go rename to interpreter/fixedpoint_test.go index 0fe9d9258b..fa19591104 100644 --- a/tests/interpreter/fixedpoint_test.go +++ b/interpreter/fixedpoint_test.go @@ -29,7 +29,8 @@ import ( "github.com/onflow/cadence/fixedpoint" "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) func TestInterpretNegativeZeroFixedPoint(t *testing.T) { diff --git a/tests/interpreter/for_test.go b/interpreter/for_test.go similarity index 99% rename from tests/interpreter/for_test.go rename to interpreter/for_test.go index 370546ffdf..48246d29b0 100644 --- a/tests/interpreter/for_test.go +++ b/interpreter/for_test.go @@ -30,7 +30,8 @@ import ( "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) func TestInterpretForStatement(t *testing.T) { diff --git a/tests/interpreter/function_test.go b/interpreter/function_test.go similarity index 96% rename from tests/interpreter/function_test.go rename to interpreter/function_test.go index f2e4675e4e..b16b77c642 100644 --- a/tests/interpreter/function_test.go +++ b/interpreter/function_test.go @@ -27,8 +27,8 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/checker" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestInterpretResultVariable(t *testing.T) { @@ -60,7 +60,7 @@ func TestInterpretResultVariable(t *testing.T) { require.IsType(t, &interpreter.CompositeValue{}, result) resource := result.(*interpreter.CompositeValue) assert.Equal(t, common.CompositeKindResource, resource.Kind) - utils.AssertValuesEqual( + AssertValuesEqual( t, inter, interpreter.UInt8Value(1), @@ -98,7 +98,7 @@ func TestInterpretResultVariable(t *testing.T) { resource := innerValue.(*interpreter.CompositeValue) assert.Equal(t, common.CompositeKindResource, resource.Kind) - utils.AssertValuesEqual( + AssertValuesEqual( t, inter, interpreter.UInt8Value(1), @@ -162,7 +162,7 @@ func TestInterpretResultVariable(t *testing.T) { resource := innerValue.(*interpreter.CompositeValue) assert.Equal(t, common.CompositeKindResource, resource.Kind) - utils.AssertValuesEqual( + AssertValuesEqual( t, inter, interpreter.UInt8Value(1), @@ -221,7 +221,7 @@ func TestInterpretResultVariable(t *testing.T) { ) require.NoError(t, err) require.Len(t, checkerErrors, 1) - checkerError := checker.RequireCheckerErrors(t, checkerErrors[0], 1) + checkerError := RequireCheckerErrors(t, checkerErrors[0], 1) require.IsType(t, &sema.PurityError{}, checkerError[0]) _, err = inter.Invoke("main") @@ -280,7 +280,7 @@ func TestInterpretResultVariable(t *testing.T) { ) require.NoError(t, err) require.Len(t, checkerErrors, 1) - checkerError := checker.RequireCheckerErrors(t, checkerErrors[0], 1) + checkerError := RequireCheckerErrors(t, checkerErrors[0], 1) require.IsType(t, &sema.PurityError{}, checkerError[0]) _, err = inter.Invoke("main") @@ -316,7 +316,7 @@ func TestInterpretFunctionSubtyping(t *testing.T) { result, err := inter.Invoke("main") require.NoError(t, err) - utils.AssertValuesEqual( + AssertValuesEqual( t, inter, interpreter.NewUnmeteredSomeValueNonCopying(interpreter.UInt8Value(4)), diff --git a/tests/interpreter/if_test.go b/interpreter/if_test.go similarity index 97% rename from tests/interpreter/if_test.go rename to interpreter/if_test.go index cc7efb83c2..ef92e2a576 100644 --- a/tests/interpreter/if_test.go +++ b/interpreter/if_test.go @@ -24,11 +24,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - . "github.com/onflow/cadence/tests/utils" - "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/checker" + . "github.com/onflow/cadence/test_utils/interpreter_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestInterpretIfStatement(t *testing.T) { @@ -83,7 +82,7 @@ func TestInterpretIfStatement(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 2) + errs := RequireCheckerErrors(t, err, 2) assert.IsType(t, &sema.UnreachableStatementError{}, errs[0]) assert.IsType(t, &sema.UnreachableStatementError{}, errs[1]) diff --git a/tests/interpreter/import_test.go b/interpreter/import_test.go similarity index 93% rename from tests/interpreter/import_test.go rename to interpreter/import_test.go index 45204a23c8..b1599e2a09 100644 --- a/tests/interpreter/import_test.go +++ b/interpreter/import_test.go @@ -29,8 +29,9 @@ import ( "github.com/onflow/cadence/common/orderedmap" "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/checker" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestInterpretVirtualImport(t *testing.T) { @@ -154,7 +155,7 @@ func TestInterpretImportMultipleProgramsFromLocation(t *testing.T) { address := common.MustBytesToAddress([]byte{0x1}) - importedCheckerA, err := checker.ParseAndCheckWithOptions(t, + importedCheckerA, err := ParseAndCheckWithOptions(t, ` // this function *SHOULD* be imported in the importing program access(all) fun a(): Int { @@ -166,7 +167,7 @@ func TestInterpretImportMultipleProgramsFromLocation(t *testing.T) { return 11 } `, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Location: common.AddressLocation{ Address: address, Name: "a", @@ -175,7 +176,7 @@ func TestInterpretImportMultipleProgramsFromLocation(t *testing.T) { ) require.NoError(t, err) - importedCheckerB, err := checker.ParseAndCheckWithOptions(t, + importedCheckerB, err := ParseAndCheckWithOptions(t, ` // this function *SHOULD* be imported in the importing program access(all) fun b(): Int { @@ -187,7 +188,7 @@ func TestInterpretImportMultipleProgramsFromLocation(t *testing.T) { return 22 } `, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Location: common.AddressLocation{ Address: address, Name: "b", @@ -196,7 +197,7 @@ func TestInterpretImportMultipleProgramsFromLocation(t *testing.T) { ) require.NoError(t, err) - importingChecker, err := checker.ParseAndCheckWithOptions(t, + importingChecker, err := ParseAndCheckWithOptions(t, ` import a, b from 0x1 @@ -204,7 +205,7 @@ func TestInterpretImportMultipleProgramsFromLocation(t *testing.T) { return a() + b() } `, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Config: &sema.Config{ LocationHandler: func(identifiers []ast.Identifier, location common.Location) (result []sema.ResolvedLocation, err error) { @@ -316,11 +317,11 @@ func TestInterpretResourceConstructionThroughIndirectImport(t *testing.T) { address := common.MustBytesToAddress([]byte{0x1}) - importedChecker, err := checker.ParseAndCheckWithOptions(t, + importedChecker, err := ParseAndCheckWithOptions(t, ` resource R {} `, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Location: common.AddressLocation{ Address: address, }, @@ -328,7 +329,7 @@ func TestInterpretResourceConstructionThroughIndirectImport(t *testing.T) { ) require.NoError(t, err) - importingChecker, err := checker.ParseAndCheckWithOptions(t, + importingChecker, err := ParseAndCheckWithOptions(t, ` import R from 0x1 @@ -337,7 +338,7 @@ func TestInterpretResourceConstructionThroughIndirectImport(t *testing.T) { destroy r } `, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Config: &sema.Config{ ImportHandler: func(checker *sema.Checker, importedLocation common.Location, _ ast.Range) (sema.Import, error) { require.IsType(t, common.AddressLocation{}, importedLocation) @@ -396,7 +397,7 @@ func TestInterpretResourceConstructionThroughIndirectImport(t *testing.T) { require.ErrorAs(t, err, &resourceConstructionError) assert.Equal(t, - checker.RequireGlobalType(t, importedChecker.Elaboration, "R"), + RequireGlobalType(t, importedChecker.Elaboration, "R"), resourceConstructionError.CompositeType, ) } diff --git a/tests/interpreter/indexing_test.go b/interpreter/indexing_test.go similarity index 100% rename from tests/interpreter/indexing_test.go rename to interpreter/indexing_test.go diff --git a/interpreter/inspect_test.go b/interpreter/inspect_test.go index da6e78537e..e0ea1ff19f 100644 --- a/interpreter/inspect_test.go +++ b/interpreter/inspect_test.go @@ -23,7 +23,7 @@ import ( "github.com/onflow/cadence/common" . "github.com/onflow/cadence/interpreter" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) func TestInspectValue(t *testing.T) { diff --git a/tests/interpreter/integers_test.go b/interpreter/integers_test.go similarity index 99% rename from tests/interpreter/integers_test.go rename to interpreter/integers_test.go index 9da93b1745..86f1eb4f22 100644 --- a/tests/interpreter/integers_test.go +++ b/interpreter/integers_test.go @@ -28,10 +28,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - . "github.com/onflow/cadence/tests/utils" - "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) var testIntegerTypesAndValues = map[string]interpreter.Value{ diff --git a/tests/interpreter/interface_test.go b/interpreter/interface_test.go similarity index 99% rename from tests/interpreter/interface_test.go rename to interpreter/interface_test.go index b61c422ba5..09580c8171 100644 --- a/tests/interpreter/interface_test.go +++ b/interpreter/interface_test.go @@ -29,7 +29,7 @@ import ( "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestInterpretInterfaceDefaultImplementation(t *testing.T) { @@ -456,7 +456,7 @@ func TestInterpretInterfaceFunctionConditionsInheritance(t *testing.T) { // Implementation should satisfy inherited conditions _, err = inter.Invoke("main", interpreter.NewUnmeteredIntValueFromInt64(5)) - utils.RequireError(t, err) + RequireError(t, err) assert.ErrorAs(t, err, &interpreter.ConditionError{}) }) @@ -496,7 +496,7 @@ func TestInterpretInterfaceFunctionConditionsInheritance(t *testing.T) { // Implementation should satisfy inherited conditions _, err = inter.Invoke("main", interpreter.NewUnmeteredIntValueFromInt64(5)) - utils.RequireError(t, err) + RequireError(t, err) assert.ErrorAs(t, err, &interpreter.ConditionError{}) }) @@ -539,11 +539,11 @@ func TestInterpretInterfaceFunctionConditionsInheritance(t *testing.T) { // Implementation should satisfy both inherited conditions _, err = inter.Invoke("main", interpreter.NewUnmeteredIntValueFromInt64(5)) - utils.RequireError(t, err) + RequireError(t, err) assert.ErrorAs(t, err, &interpreter.ConditionError{}) _, err = inter.Invoke("main", interpreter.NewUnmeteredIntValueFromInt64(25)) - utils.RequireError(t, err) + RequireError(t, err) assert.ErrorAs(t, err, &interpreter.ConditionError{}) }) @@ -588,11 +588,11 @@ func TestInterpretInterfaceFunctionConditionsInheritance(t *testing.T) { // Implementation should satisfy both inherited conditions _, err = inter.Invoke("main", interpreter.NewUnmeteredIntValueFromInt64(5)) - utils.RequireError(t, err) + RequireError(t, err) assert.ErrorAs(t, err, &interpreter.ConditionError{}) _, err = inter.Invoke("main", interpreter.NewUnmeteredIntValueFromInt64(25)) - utils.RequireError(t, err) + RequireError(t, err) assert.ErrorAs(t, err, &interpreter.ConditionError{}) }) diff --git a/interpreter/interpreter.go b/interpreter/interpreter.go index 0dba05041e..80def48c42 100644 --- a/interpreter/interpreter.go +++ b/interpreter/interpreter.go @@ -4912,6 +4912,10 @@ func (interpreter *Interpreter) GetInterfaceType( typeID TypeID, ) (*sema.InterfaceType, error) { if location == nil { + var interfaceType = sema.NativeInterfaceTypes[qualifiedIdentifier] + if interfaceType != nil { + return interfaceType, nil + } return nil, InterfaceMissingLocationError{ QualifiedIdentifier: qualifiedIdentifier, } diff --git a/interpreter/interpreter_expression.go b/interpreter/interpreter_expression.go index 60cf329af1..5fecffec0e 100644 --- a/interpreter/interpreter_expression.go +++ b/interpreter/interpreter_expression.go @@ -20,6 +20,7 @@ package interpreter import ( "math/big" + "strings" "time" "github.com/onflow/atree" @@ -969,6 +970,28 @@ func (interpreter *Interpreter) VisitStringExpression(expression *ast.StringExpr return NewUnmeteredStringValue(expression.Value) } +func (interpreter *Interpreter) VisitStringTemplateExpression(expression *ast.StringTemplateExpression) Value { + values := interpreter.visitExpressionsNonCopying(expression.Expressions) + + var builder strings.Builder + for i, str := range expression.Values { + builder.WriteString(str) + if i < len(values) { + // switch on value instead of type + switch value := values[i].(type) { + case *StringValue: + builder.WriteString(value.Str) + case CharacterValue: + builder.WriteString(value.Str) + default: + builder.WriteString(value.String()) + } + } + } + + return NewUnmeteredStringValue(builder.String()) +} + func (interpreter *Interpreter) VisitArrayExpression(expression *ast.ArrayExpression) Value { values := interpreter.visitExpressionsNonCopying(expression.Values) diff --git a/interpreter/interpreter_tracing_test.go b/interpreter/interpreter_tracing_test.go index dfcfc16521..5f2a758fbc 100644 --- a/interpreter/interpreter_tracing_test.go +++ b/interpreter/interpreter_tracing_test.go @@ -28,7 +28,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func setupInterpreterWithTracingCallBack( @@ -38,7 +38,7 @@ func setupInterpreterWithTracingCallBack( storage := newUnmeteredInMemoryStorage() inter, err := interpreter.NewInterpreter( nil, - utils.TestLocation, + TestLocation, &interpreter.Config{ OnRecordTrace: func(inter *interpreter.Interpreter, operationName string, diff --git a/tests/interpreter/invocation_test.go b/interpreter/invocation_test.go similarity index 98% rename from tests/interpreter/invocation_test.go rename to interpreter/invocation_test.go index 4e9164f36f..1d08c47f14 100644 --- a/tests/interpreter/invocation_test.go +++ b/interpreter/invocation_test.go @@ -28,7 +28,7 @@ import ( "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestInterpretFunctionInvocationCheckArgumentTypes(t *testing.T) { diff --git a/tests/interpreter/member_test.go b/interpreter/member_test.go similarity index 98% rename from tests/interpreter/member_test.go rename to interpreter/member_test.go index 29d14e5b82..f73b4e8be6 100644 --- a/tests/interpreter/member_test.go +++ b/interpreter/member_test.go @@ -25,8 +25,8 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/interpreter" - "github.com/onflow/cadence/tests/checker" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestInterpretMemberAccessType(t *testing.T) { @@ -407,7 +407,7 @@ func TestInterpretMemberAccessType(t *testing.T) { value, err := inter.Invoke("S") require.NoError(t, err) - sType := checker.RequireGlobalType(t, inter.Program.Elaboration, "S") + sType := RequireGlobalType(t, inter.Program.Elaboration, "S") ref := interpreter.NewUnmeteredEphemeralReferenceValue(inter, interpreter.UnauthorizedAccess, value, sType, interpreter.EmptyLocationRange) @@ -454,7 +454,7 @@ func TestInterpretMemberAccessType(t *testing.T) { value, err := inter.Invoke("S2") require.NoError(t, err) - sType := checker.RequireGlobalType(t, inter.Program.Elaboration, "S") + sType := RequireGlobalType(t, inter.Program.Elaboration, "S") ref := interpreter.NewUnmeteredEphemeralReferenceValue(inter, interpreter.UnauthorizedAccess, value, sType, interpreter.EmptyLocationRange) @@ -496,7 +496,7 @@ func TestInterpretMemberAccessType(t *testing.T) { value, err := inter.Invoke("S") require.NoError(t, err) - sType := checker.RequireGlobalType(t, inter.Program.Elaboration, "S") + sType := RequireGlobalType(t, inter.Program.Elaboration, "S") ref := interpreter.NewUnmeteredEphemeralReferenceValue(inter, interpreter.UnauthorizedAccess, value, sType, interpreter.EmptyLocationRange) @@ -541,7 +541,7 @@ func TestInterpretMemberAccessType(t *testing.T) { value, err := inter.Invoke("S2") require.NoError(t, err) - sType := checker.RequireGlobalType(t, inter.Program.Elaboration, "S") + sType := RequireGlobalType(t, inter.Program.Elaboration, "S") ref := interpreter.NewUnmeteredEphemeralReferenceValue(inter, interpreter.UnauthorizedAccess, value, sType, interpreter.EmptyLocationRange) diff --git a/tests/interpreter/memory_metering_test.go b/interpreter/memory_metering_test.go similarity index 99% rename from tests/interpreter/memory_metering_test.go rename to interpreter/memory_metering_test.go index 5de97ddfe5..725ea93037 100644 --- a/tests/interpreter/memory_metering_test.go +++ b/interpreter/memory_metering_test.go @@ -23,6 +23,7 @@ import ( "testing" "github.com/onflow/cadence/activations" + . "github.com/onflow/cadence/test_utils/sema_utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -32,8 +33,7 @@ import ( "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - "github.com/onflow/cadence/tests/checker" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) type assumeValidPublicKeyValidator struct{} @@ -8147,12 +8147,12 @@ func TestInterpretASTMetering(t *testing.T) { #pragma ` - importedChecker, err := checker.ParseAndCheckWithOptions(t, + importedChecker, err := ParseAndCheckWithOptions(t, ` let Foo = 1 `, - checker.ParseAndCheckOptions{ - Location: utils.ImportedLocation, + ParseAndCheckOptions{ + Location: ImportedLocation, }, ) require.NoError(t, err) @@ -8444,13 +8444,13 @@ func TestInterpretASTMetering(t *testing.T) { import B from "string-location" ` - importedChecker, err := checker.ParseAndCheckWithOptions(t, + importedChecker, err := ParseAndCheckWithOptions(t, ` let A = 1 let B = 1 `, - checker.ParseAndCheckOptions{ - Location: utils.ImportedLocation, + ParseAndCheckOptions{ + Location: ImportedLocation, }, ) require.NoError(t, err) @@ -8960,7 +8960,7 @@ func TestInterpretValueStringConversion(t *testing.T) { interpreter.NewUnmeteredCapabilityValue( 4, interpreter.AddressValue{1}, - interpreter.NewCompositeStaticTypeComputeTypeID(nil, utils.TestLocation, "Bar"), + interpreter.NewCompositeStaticTypeComputeTypeID(nil, TestLocation, "Bar"), )) }) diff --git a/tests/interpreter/metatype_test.go b/interpreter/metatype_test.go similarity index 99% rename from tests/interpreter/metatype_test.go rename to interpreter/metatype_test.go index ad96c6b1d9..edcd83a901 100644 --- a/tests/interpreter/metatype_test.go +++ b/interpreter/metatype_test.go @@ -30,7 +30,8 @@ import ( "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) func TestInterpretMetaTypeEquality(t *testing.T) { diff --git a/tests/interpreter/metering_test.go b/interpreter/metering_test.go similarity index 94% rename from tests/interpreter/metering_test.go rename to interpreter/metering_test.go index 243afdba05..267b15d985 100644 --- a/tests/interpreter/metering_test.go +++ b/interpreter/metering_test.go @@ -28,28 +28,28 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/checker" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestInterpretStatementHandler(t *testing.T) { t.Parallel() - importedChecker, err := checker.ParseAndCheckWithOptions(t, + importedChecker, err := ParseAndCheckWithOptions(t, ` access(all) fun a() { true true } `, - checker.ParseAndCheckOptions{ - Location: utils.ImportedLocation, + ParseAndCheckOptions{ + Location: ImportedLocation, }, ) require.NoError(t, err) - importingChecker, err := checker.ParseAndCheckWithOptions(t, + importingChecker, err := ParseAndCheckWithOptions(t, ` import a from "imported" @@ -69,11 +69,11 @@ func TestInterpretStatementHandler(t *testing.T) { true } `, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Config: &sema.Config{ ImportHandler: func(_ *sema.Checker, importedLocation common.Location, _ ast.Range) (sema.Import, error) { assert.Equal(t, - utils.ImportedLocation, + ImportedLocation, importedLocation, ) @@ -116,7 +116,7 @@ func TestInterpretStatementHandler(t *testing.T) { }, ImportLocationHandler: func(inter *interpreter.Interpreter, location common.Location) interpreter.Import { assert.Equal(t, - utils.ImportedLocation, + ImportedLocation, location, ) @@ -163,7 +163,7 @@ func TestInterpretLoopIterationHandler(t *testing.T) { t.Parallel() - importedChecker, err := checker.ParseAndCheckWithOptions(t, + importedChecker, err := ParseAndCheckWithOptions(t, ` access(all) fun a() { var i = 1 @@ -174,11 +174,11 @@ func TestInterpretLoopIterationHandler(t *testing.T) { for n in [1, 2, 3, 4, 5] {} } `, - checker.ParseAndCheckOptions{}, + ParseAndCheckOptions{}, ) require.NoError(t, err) - importingChecker, err := checker.ParseAndCheckWithOptions(t, + importingChecker, err := ParseAndCheckWithOptions(t, ` import a from "imported" @@ -193,11 +193,11 @@ func TestInterpretLoopIterationHandler(t *testing.T) { a() } `, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Config: &sema.Config{ ImportHandler: func(_ *sema.Checker, importedLocation common.Location, _ ast.Range) (sema.Import, error) { assert.Equal(t, - utils.ImportedLocation, + ImportedLocation, importedLocation, ) @@ -241,7 +241,7 @@ func TestInterpretLoopIterationHandler(t *testing.T) { }, ImportLocationHandler: func(inter *interpreter.Interpreter, location common.Location) interpreter.Import { assert.Equal(t, - utils.ImportedLocation, + ImportedLocation, location, ) @@ -290,7 +290,7 @@ func TestInterpretFunctionInvocationHandler(t *testing.T) { t.Parallel() - importedChecker, err := checker.ParseAndCheckWithOptions(t, + importedChecker, err := ParseAndCheckWithOptions(t, ` access(all) fun a() {} @@ -302,13 +302,13 @@ func TestInterpretFunctionInvocationHandler(t *testing.T) { true } `, - checker.ParseAndCheckOptions{ - Location: utils.ImportedLocation, + ParseAndCheckOptions{ + Location: ImportedLocation, }, ) require.NoError(t, err) - importingChecker, err := checker.ParseAndCheckWithOptions(t, + importingChecker, err := ParseAndCheckWithOptions(t, ` import b from "imported" @@ -328,11 +328,11 @@ func TestInterpretFunctionInvocationHandler(t *testing.T) { true } `, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Config: &sema.Config{ ImportHandler: func(_ *sema.Checker, importedLocation common.Location, _ ast.Range) (sema.Import, error) { assert.Equal(t, - utils.ImportedLocation, + ImportedLocation, importedLocation, ) @@ -368,7 +368,7 @@ func TestInterpretFunctionInvocationHandler(t *testing.T) { }, ImportLocationHandler: func(inter *interpreter.Interpreter, location common.Location) interpreter.Import { assert.Equal(t, - utils.ImportedLocation, + ImportedLocation, location, ) diff --git a/tests/interpreter/interpreter_test.go b/interpreter/misc_test.go similarity index 98% rename from tests/interpreter/interpreter_test.go rename to interpreter/misc_test.go index 6a697eff69..8ec9d08532 100644 --- a/tests/interpreter/interpreter_test.go +++ b/interpreter/misc_test.go @@ -39,8 +39,9 @@ import ( "github.com/onflow/cadence/runtime" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - "github.com/onflow/cadence/tests/checker" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) type ParseCheckAndInterpretOptions struct { @@ -168,9 +169,9 @@ func parseCheckAndInterpretWithOptionsAndMemoryMetering( err error, ) { - checker, err := checker.ParseAndCheckWithOptionsAndMemoryMetering(t, + checker, err := ParseAndCheckWithOptionsAndMemoryMetering(t, code, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Config: options.CheckerConfig, }, memoryGauge, @@ -1208,7 +1209,7 @@ func TestInterpretReturns(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.UnreachableStatementError{}, errs[0]) }, @@ -4207,19 +4208,19 @@ func TestInterpretImport(t *testing.T) { t.Parallel() - importedChecker, err := checker.ParseAndCheckWithOptions(t, + importedChecker, err := ParseAndCheckWithOptions(t, ` access(all) fun answer(): Int { return 42 } `, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Location: ImportedLocation, }, ) require.NoError(t, err) - importingChecker, err := checker.ParseAndCheckWithOptions(t, + importingChecker, err := ParseAndCheckWithOptions(t, ` import answer from "imported" @@ -4227,7 +4228,7 @@ func TestInterpretImport(t *testing.T) { return answer() } `, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Config: &sema.Config{ ImportHandler: func(_ *sema.Checker, importedLocation common.Location, _ ast.Range) (sema.Import, error) { assert.Equal(t, @@ -4298,9 +4299,9 @@ func TestInterpretImportError(t *testing.T) { baseValueActivation.DeclareValue(stdlib.PanicFunction) parseAndCheck := func(code string, location common.Location) *sema.Checker { - checker, err := checker.ParseAndCheckWithOptions(t, + checker, err := ParseAndCheckWithOptions(t, code, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Location: location, Config: &sema.Config{ BaseValueActivationHandler: func(_ common.Location) *sema.VariableActivation { @@ -5257,7 +5258,7 @@ func TestInterpretReferenceFailableDowncasting(t *testing.T) { func(invocation interpreter.Invocation) interpreter.Value { authorized := bool(invocation.Arguments[0].(interpreter.BoolValue)) - var auth interpreter.Authorization = interpreter.UnauthorizedAccess + var auth = interpreter.UnauthorizedAccess if authorized { auth = interpreter.ConvertSemaAccessToStaticAuthorization( invocation.Interpreter, @@ -6823,7 +6824,7 @@ func TestInterpretCompositeFunctionInvocationFromImportingProgram(t *testing.T) t.Parallel() - importedChecker, err := checker.ParseAndCheckWithOptions(t, + importedChecker, err := ParseAndCheckWithOptions(t, ` // function must have arguments access(all) fun x(x: Int) {} @@ -6836,13 +6837,13 @@ func TestInterpretCompositeFunctionInvocationFromImportingProgram(t *testing.T) } } `, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Location: ImportedLocation, }, ) require.NoError(t, err) - importingChecker, err := checker.ParseAndCheckWithOptions(t, + importingChecker, err := ParseAndCheckWithOptions(t, ` import Y from "imported" @@ -6851,7 +6852,7 @@ func TestInterpretCompositeFunctionInvocationFromImportingProgram(t *testing.T) Y().x() } `, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Config: &sema.Config{ ImportHandler: func(_ *sema.Checker, importedLocation common.Location, _ ast.Range) (sema.Import, error) { assert.Equal(t, @@ -7277,8 +7278,8 @@ func TestInterpretEmitEvent(t *testing.T) { _, err = inter.Invoke("test") require.NoError(t, err) - transferEventType := checker.RequireGlobalType(t, inter.Program.Elaboration, "Transfer") - transferAmountEventType := checker.RequireGlobalType(t, inter.Program.Elaboration, "TransferAmount") + transferEventType := RequireGlobalType(t, inter.Program.Elaboration, "Transfer") + transferAmountEventType := RequireGlobalType(t, inter.Program.Elaboration, "TransferAmount") fields1 := []interpreter.CompositeField{ { @@ -7420,7 +7421,7 @@ func TestInterpretReferenceEventParameter(t *testing.T) { _, err = inter.Invoke("test", ref) require.NoError(t, err) - eventType := checker.RequireGlobalType(t, inter.Program.Elaboration, "TestEvent") + eventType := RequireGlobalType(t, inter.Program.Elaboration, "TestEvent") expectedEvents := []interpreter.Value{ interpreter.NewCompositeValue( @@ -7758,7 +7759,7 @@ func TestInterpretEmitEventParameterTypes(t *testing.T) { _, err = inter.Invoke("test") require.NoError(t, err) - testType := checker.RequireGlobalType(t, inter.Program.Elaboration, "Test") + testType := RequireGlobalType(t, inter.Program.Elaboration, "Test") fields := []interpreter.CompositeField{ { @@ -8613,7 +8614,7 @@ func TestInterpretConformToImportedInterface(t *testing.T) { t.Parallel() - importedChecker, err := checker.ParseAndCheckWithOptions(t, + importedChecker, err := ParseAndCheckWithOptions(t, ` struct interface Foo { fun check(answer: Int) { @@ -8623,13 +8624,13 @@ func TestInterpretConformToImportedInterface(t *testing.T) { } } `, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Location: ImportedLocation, }, ) require.NoError(t, err) - importingChecker, err := checker.ParseAndCheckWithOptions(t, + importingChecker, err := ParseAndCheckWithOptions(t, ` import Foo from "imported" @@ -8642,7 +8643,7 @@ func TestInterpretConformToImportedInterface(t *testing.T) { bar.check(answer: 1) } `, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Config: &sema.Config{ ImportHandler: func(_ *sema.Checker, importedLocation common.Location, _ ast.Range) (sema.Import, error) { assert.Equal(t, @@ -10686,7 +10687,7 @@ func TestInterpretArrayFilter(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.PurityError{}, errs[0]) }, }, @@ -12379,3 +12380,133 @@ func TestInterpretOptionalAddressInConditional(t *testing.T) { value, ) } + +func TestInterpretStringTemplates(t *testing.T) { + + t.Parallel() + + t.Run("int", func(t *testing.T) { + t.Parallel() + + inter := parseCheckAndInterpret(t, ` + let x = 123 + let y = "x = \(x)" + `) + + AssertValuesEqual( + t, + inter, + interpreter.NewUnmeteredIntValueFromInt64(123), + inter.Globals.Get("x").GetValue(inter), + ) + AssertValuesEqual( + t, + inter, + interpreter.NewUnmeteredStringValue("x = 123"), + inter.Globals.Get("y").GetValue(inter), + ) + }) + + t.Run("multiple", func(t *testing.T) { + t.Parallel() + + inter := parseCheckAndInterpret(t, ` + let x = 123.321 + let y = "abc" + let z = "\(y) and \(x)" + `) + + AssertValuesEqual( + t, + inter, + interpreter.NewUnmeteredStringValue("abc and 123.32100000"), + inter.Globals.Get("z").GetValue(inter), + ) + }) + + t.Run("nested template", func(t *testing.T) { + t.Parallel() + + inter := parseCheckAndInterpret(t, ` + let x = "{}" + let y = "[\(x)]" + let z = "(\(y))" + `) + + AssertValuesEqual( + t, + inter, + interpreter.NewUnmeteredStringValue("([{}])"), + inter.Globals.Get("z").GetValue(inter), + ) + }) + + t.Run("boolean", func(t *testing.T) { + t.Parallel() + + inter := parseCheckAndInterpret(t, ` + let x = false + let y = "\(x)" + `) + + AssertValuesEqual( + t, + inter, + interpreter.NewUnmeteredStringValue("false"), + inter.Globals.Get("y").GetValue(inter), + ) + }) + + t.Run("func extracted", func(t *testing.T) { + t.Parallel() + + inter := parseCheckAndInterpret(t, ` + let add = fun(): Int { + return 2+2 + } + let y = add() + let x: String = "\(y)" + `) + + AssertValuesEqual( + t, + inter, + interpreter.NewUnmeteredStringValue("4"), + inter.Globals.Get("x").GetValue(inter), + ) + }) + + t.Run("path expr", func(t *testing.T) { + t.Parallel() + + inter := parseCheckAndInterpret(t, ` + let a = /public/foo + let x = "file at \(a)" + `) + + AssertValuesEqual( + t, + inter, + interpreter.NewUnmeteredStringValue("file at /public/foo"), + inter.Globals.Get("x").GetValue(inter), + ) + }) + + t.Run("consecutive", func(t *testing.T) { + t.Parallel() + + inter := parseCheckAndInterpret(t, ` + let c = "C" + let a: Character = "A" + let n = "N" + let x = "\(c)\(a)\(n)" + `) + + AssertValuesEqual( + t, + inter, + interpreter.NewUnmeteredStringValue("CAN"), + inter.Globals.Get("x").GetValue(inter), + ) + }) +} diff --git a/tests/interpreter/nesting_test.go b/interpreter/nesting_test.go similarity index 100% rename from tests/interpreter/nesting_test.go rename to interpreter/nesting_test.go diff --git a/tests/interpreter/path_test.go b/interpreter/path_test.go similarity index 98% rename from tests/interpreter/path_test.go rename to interpreter/path_test.go index 015ef66643..10ff7f32f9 100644 --- a/tests/interpreter/path_test.go +++ b/interpreter/path_test.go @@ -27,7 +27,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) func TestInterpretPath(t *testing.T) { diff --git a/tests/interpreter/pathcapability_test.go b/interpreter/pathcapability_test.go similarity index 100% rename from tests/interpreter/pathcapability_test.go rename to interpreter/pathcapability_test.go diff --git a/tests/interpreter/range_value_test.go b/interpreter/range_value_test.go similarity index 98% rename from tests/interpreter/range_value_test.go rename to interpreter/range_value_test.go index ba3b714129..eb88cb4b50 100644 --- a/tests/interpreter/range_value_test.go +++ b/interpreter/range_value_test.go @@ -30,8 +30,8 @@ import ( "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - "github.com/onflow/cadence/tests/utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) type containsTestCase struct { @@ -440,7 +440,7 @@ func TestInclusiveRange(t *testing.T) { ) } - utils.AssertValuesEqual( + AssertValuesEqual( t, inter, expectedRangeValue, @@ -456,7 +456,7 @@ func TestInclusiveRange(t *testing.T) { expectedValue = interpreter.AsBoolValue(tc.expectedWithoutStep) } - utils.AssertValuesEqual( + AssertValuesEqual( t, inter, expectedValue, diff --git a/tests/interpreter/reference_test.go b/interpreter/reference_test.go similarity index 98% rename from tests/interpreter/reference_test.go rename to interpreter/reference_test.go index 808ff46c83..273f49d74d 100644 --- a/tests/interpreter/reference_test.go +++ b/interpreter/reference_test.go @@ -28,8 +28,9 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/checker" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestInterpretResourceReferenceInstanceOf(t *testing.T) { @@ -530,7 +531,7 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { errorHandler := func(tt *testing.T) func(err error) { return func(err error) { - errors := checker.RequireCheckerErrors(tt, err, 1) + errors := RequireCheckerErrors(tt, err, 1) invalidatedRefError := &sema.InvalidatedResourceReferenceError{} assert.ErrorAs(tt, errors[0], &invalidatedRefError) } @@ -637,7 +638,7 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { address := common.Address{0x1} - rType := checker.RequireGlobalType(t, inter.Program.Elaboration, "R").(*sema.CompositeType) + rType := RequireGlobalType(t, inter.Program.Elaboration, "R").(*sema.CompositeType) array := interpreter.NewArrayValue( inter, @@ -742,7 +743,7 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { } `) - rType := checker.RequireGlobalType(t, inter.Program.Elaboration, "R").(*sema.CompositeType) + rType := RequireGlobalType(t, inter.Program.Elaboration, "R").(*sema.CompositeType) // Resource array in account 0x01 @@ -843,7 +844,7 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { address := common.Address{0x1} - rType := checker.RequireGlobalType(t, inter.Program.Elaboration, "R").(*sema.CompositeType) + rType := RequireGlobalType(t, inter.Program.Elaboration, "R").(*sema.CompositeType) array := interpreter.NewArrayValue( inter, @@ -969,7 +970,7 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { address := common.Address{0x1} - rType := checker.RequireGlobalType(t, inter.Program.Elaboration, "R").(*sema.CompositeType) + rType := RequireGlobalType(t, inter.Program.Elaboration, "R").(*sema.CompositeType) array := interpreter.NewArrayValue( inter, @@ -1524,7 +1525,7 @@ func TestInterpretResourceReferenceInvalidationOnDestroy(t *testing.T) { errorHandler := func(tt *testing.T) func(err error) { return func(err error) { - errors := checker.RequireCheckerErrors(tt, err, 1) + errors := RequireCheckerErrors(tt, err, 1) invalidatedRefError := &sema.InvalidatedResourceReferenceError{} assert.ErrorAs(tt, errors[0], &invalidatedRefError) } @@ -1747,7 +1748,7 @@ func TestInterpretReferenceToReference(t *testing.T) { } `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.NestedReferenceError{}, errs[0]) }, }) @@ -1787,7 +1788,7 @@ func TestInterpretReferenceToReference(t *testing.T) { } `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.NestedReferenceError{}, errs[0]) }, }) @@ -3040,7 +3041,7 @@ func TestInterpretDereference(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.InvalidUnaryOperandError{}, errs[0]) }, @@ -3071,7 +3072,7 @@ func TestInterpretDereference(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.InvalidUnaryOperandError{}, errs[0]) }, @@ -3208,7 +3209,7 @@ func TestInterpretHostFunctionReferenceInvalidation(t *testing.T) { result, err := inter.Invoke("main") require.NoError(t, err) - sType := checker.RequireGlobalType(t, inter.Program.Elaboration, "S").(*sema.CompositeType) + sType := RequireGlobalType(t, inter.Program.Elaboration, "S").(*sema.CompositeType) expectedResult := interpreter.NewArrayValue( inter, @@ -3281,7 +3282,7 @@ func TestInterpretHostFunctionReferenceInvalidation(t *testing.T) { result, err := inter.Invoke("main") require.NoError(t, err) - sType := checker.RequireGlobalType(t, inter.Program.Elaboration, "S").(*sema.CompositeType) + sType := RequireGlobalType(t, inter.Program.Elaboration, "S").(*sema.CompositeType) expectedResult := interpreter.NewTypeValue( inter, diff --git a/tests/interpreter/resources_test.go b/interpreter/resources_test.go similarity index 97% rename from tests/interpreter/resources_test.go rename to interpreter/resources_test.go index f6d1b11283..564c745258 100644 --- a/tests/interpreter/resources_test.go +++ b/interpreter/resources_test.go @@ -24,11 +24,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/checker" - . "github.com/onflow/cadence/tests/utils" - "github.com/onflow/cadence/interpreter" + "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestInterpretOptionalResourceBindingWithSecondValue(t *testing.T) { @@ -321,7 +321,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -367,7 +367,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -413,7 +413,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -459,7 +459,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -502,7 +502,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -542,7 +542,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -582,7 +582,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -622,7 +622,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -664,7 +664,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -705,7 +705,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -743,7 +743,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -776,7 +776,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -809,7 +809,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -840,7 +840,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -891,7 +891,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -936,7 +936,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -981,7 +981,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -1026,7 +1026,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -1067,7 +1067,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -1105,7 +1105,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -1143,7 +1143,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -1181,7 +1181,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -1222,7 +1222,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -1262,7 +1262,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -1300,7 +1300,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -1332,7 +1332,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -1364,7 +1364,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -1396,7 +1396,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -1430,7 +1430,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { }`, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -1458,7 +1458,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { }`, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 2) + errs := RequireCheckerErrors(t, err, 2) require.IsType(t, &sema.ResourceLossError{}, errs[0]) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[1]) }, @@ -1491,7 +1491,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { }`, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 6) + errs := RequireCheckerErrors(t, err, 6) require.IsType(t, &sema.InvalidConditionalResourceOperandError{}, errs[0]) require.IsType(t, &sema.InvalidConditionalResourceOperandError{}, errs[1]) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[2]) @@ -1525,7 +1525,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { }`, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -1553,7 +1553,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { }`, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -1585,7 +1585,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { }`, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -1614,7 +1614,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { }`, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -1643,7 +1643,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { }`, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -1675,7 +1675,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { }`, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 2) + errs := RequireCheckerErrors(t, err, 2) require.IsType(t, &sema.InvalidConditionalResourceOperandError{}, errs[0]) require.IsType(t, &sema.InvalidConditionalResourceOperandError{}, errs[1]) }, @@ -1708,7 +1708,7 @@ func TestInterpretInvalidatedResourceValidation(t *testing.T) { }`, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 2) + errs := RequireCheckerErrors(t, err, 2) require.IsType(t, &sema.InvalidConditionalResourceOperandError{}, errs[0]) require.IsType(t, &sema.InvalidConditionalResourceOperandError{}, errs[1]) }, @@ -1740,7 +1740,7 @@ func TestInterpretResourceInvalidationWithConditionalExprInDestroy(t *testing.T) }`, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 2) + errs := RequireCheckerErrors(t, err, 2) require.IsType(t, &sema.InvalidConditionalResourceOperandError{}, errs[0]) require.IsType(t, &sema.InvalidConditionalResourceOperandError{}, errs[0]) }, @@ -1782,7 +1782,7 @@ func TestInterpretResourceUseAfterInvalidation(t *testing.T) { }`, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 2) + errs := RequireCheckerErrors(t, err, 2) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[1]) }, @@ -1820,7 +1820,7 @@ func TestInterpretResourceUseAfterInvalidation(t *testing.T) { }`, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }, @@ -2158,7 +2158,7 @@ func TestInterpretResourceDestroyedInPreCondition(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 2) + errs := RequireCheckerErrors(t, err, 2) require.IsType(t, &sema.PurityError{}, errs[0]) require.IsType(t, &sema.InvalidInterfaceConditionResourceInvalidationError{}, errs[1]) }, @@ -2633,7 +2633,7 @@ func TestInterpretDefaultDestroyEventArgumentScoping(t *testing.T) { }, }, HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.DefaultDestroyInvalidArgumentError{}, errs[0]) assert.Equal(t, errs[0].(*sema.DefaultDestroyInvalidArgumentError).Kind, sema.InvalidIdentifier) // ... @@ -2857,7 +2857,7 @@ func TestInterpretMovedResourceInOptionalBinding(t *testing.T) { } `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }) @@ -2900,7 +2900,7 @@ func TestInterpretMovedResourceInSecondValue(t *testing.T) { } `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.ResourceUseAfterInvalidationError{}, errs[0]) }, }) @@ -3032,7 +3032,7 @@ func TestInterpretPreConditionResourceMove(t *testing.T) { }`, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - checkerErrors := checker.RequireCheckerErrors(t, err, 3) + checkerErrors := RequireCheckerErrors(t, err, 3) require.IsType(t, &sema.PurityError{}, checkerErrors[0]) require.IsType(t, &sema.InvalidInterfaceConditionResourceInvalidationError{}, checkerErrors[1]) require.IsType(t, &sema.PurityError{}, checkerErrors[2]) @@ -3566,7 +3566,7 @@ func TestInterpretInvalidNilCoalescingResourceDuplication(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.InvalidNilCoalescingRightResourceOperandError{}, errs[0]) }, }, diff --git a/tests/interpreter/runtimetype_test.go b/interpreter/runtimetype_test.go similarity index 93% rename from tests/interpreter/runtimetype_test.go rename to interpreter/runtimetype_test.go index c1ea4ea109..526d28856d 100644 --- a/tests/interpreter/runtimetype_test.go +++ b/interpreter/runtimetype_test.go @@ -24,7 +24,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" "github.com/stretchr/testify/assert" ) @@ -65,7 +65,7 @@ func TestInterpretOptionalType(t *testing.T) { assert.Equal(t, interpreter.TypeValue{ Type: &interpreter.OptionalStaticType{ - Type: interpreter.NewCompositeStaticTypeComputeTypeID(nil, utils.TestLocation, "R"), + Type: interpreter.NewCompositeStaticTypeComputeTypeID(nil, TestLocation, "R"), }, }, inter.Globals.Get("c").GetValue(inter), @@ -124,7 +124,7 @@ func TestInterpretVariableSizedArrayType(t *testing.T) { assert.Equal(t, interpreter.TypeValue{ Type: &interpreter.VariableSizedStaticType{ - Type: interpreter.NewCompositeStaticTypeComputeTypeID(nil, utils.TestLocation, "R"), + Type: interpreter.NewCompositeStaticTypeComputeTypeID(nil, TestLocation, "R"), }, }, inter.Globals.Get("c").GetValue(inter), @@ -184,7 +184,7 @@ func TestInterpretConstantSizedArrayType(t *testing.T) { assert.Equal(t, interpreter.TypeValue{ Type: &interpreter.ConstantSizedStaticType{ - Type: interpreter.NewCompositeStaticTypeComputeTypeID(nil, utils.TestLocation, "R"), + Type: interpreter.NewCompositeStaticTypeComputeTypeID(nil, TestLocation, "R"), Size: int64(400), }, }, @@ -250,7 +250,7 @@ func TestInterpretDictionaryType(t *testing.T) { assert.Equal(t, interpreter.TypeValue{ Type: &interpreter.DictionaryStaticType{ - ValueType: interpreter.NewCompositeStaticTypeComputeTypeID(nil, utils.TestLocation, "R"), + ValueType: interpreter.NewCompositeStaticTypeComputeTypeID(nil, TestLocation, "R"), KeyType: interpreter.PrimitiveStaticTypeInt, }, }, @@ -305,14 +305,14 @@ func TestInterpretCompositeType(t *testing.T) { assert.Equal(t, interpreter.TypeValue{ - Type: interpreter.NewCompositeStaticTypeComputeTypeID(nil, utils.TestLocation, "R"), + Type: interpreter.NewCompositeStaticTypeComputeTypeID(nil, TestLocation, "R"), }, inter.Globals.Get("a").GetValue(inter), ) assert.Equal(t, interpreter.TypeValue{ - Type: interpreter.NewCompositeStaticTypeComputeTypeID(nil, utils.TestLocation, "S"), + Type: interpreter.NewCompositeStaticTypeComputeTypeID(nil, TestLocation, "S"), }, inter.Globals.Get("b").GetValue(inter), ) @@ -334,7 +334,7 @@ func TestInterpretCompositeType(t *testing.T) { assert.Equal(t, interpreter.TypeValue{ - Type: interpreter.NewCompositeStaticTypeComputeTypeID(nil, utils.TestLocation, "F"), + Type: interpreter.NewCompositeStaticTypeComputeTypeID(nil, TestLocation, "F"), }, inter.Globals.Get("f").GetValue(inter), ) @@ -433,7 +433,7 @@ func TestInterpretReferenceType(t *testing.T) { assert.Equal(t, interpreter.TypeValue{ Type: &interpreter.ReferenceStaticType{ - ReferencedType: interpreter.NewCompositeStaticTypeComputeTypeID(nil, utils.TestLocation, "R"), + ReferencedType: interpreter.NewCompositeStaticTypeComputeTypeID(nil, TestLocation, "R"), Authorization: interpreter.NewEntitlementSetAuthorization( nil, func() []common.TypeID { return []common.TypeID{"S.test.X"} }, @@ -458,7 +458,7 @@ func TestInterpretReferenceType(t *testing.T) { assert.Equal(t, interpreter.TypeValue{ Type: &interpreter.ReferenceStaticType{ - ReferencedType: interpreter.NewCompositeStaticTypeComputeTypeID(nil, utils.TestLocation, "S"), + ReferencedType: interpreter.NewCompositeStaticTypeComputeTypeID(nil, TestLocation, "S"), Authorization: interpreter.NewEntitlementSetAuthorization( nil, func() []common.TypeID { return []common.TypeID{"S.test.X"} }, @@ -513,7 +513,7 @@ func TestInterpretIntersectionType(t *testing.T) { interpreter.TypeValue{ Type: &interpreter.IntersectionStaticType{ Types: []*interpreter.InterfaceStaticType{ - interpreter.NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "R"), + interpreter.NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "R"), }, }, }, @@ -529,7 +529,7 @@ func TestInterpretIntersectionType(t *testing.T) { interpreter.TypeValue{ Type: &interpreter.IntersectionStaticType{ Types: []*interpreter.InterfaceStaticType{ - interpreter.NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "S"), + interpreter.NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "S"), }, }, }, @@ -545,8 +545,8 @@ func TestInterpretIntersectionType(t *testing.T) { interpreter.TypeValue{ Type: &interpreter.IntersectionStaticType{ Types: []*interpreter.InterfaceStaticType{ - interpreter.NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "S"), - interpreter.NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "S2"), + interpreter.NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "S"), + interpreter.NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "S2"), }, }, }, @@ -612,7 +612,7 @@ func TestInterpretCapabilityType(t *testing.T) { interpreter.TypeValue{ Type: &interpreter.CapabilityStaticType{ BorrowType: &interpreter.ReferenceStaticType{ - ReferencedType: interpreter.NewCompositeStaticTypeComputeTypeID(nil, utils.TestLocation, "R"), + ReferencedType: interpreter.NewCompositeStaticTypeComputeTypeID(nil, TestLocation, "R"), Authorization: interpreter.UnauthorizedAccess, }, }, diff --git a/interpreter/statictype_test.go b/interpreter/statictype_test.go index 76f3570deb..145296ad56 100644 --- a/interpreter/statictype_test.go +++ b/interpreter/statictype_test.go @@ -27,7 +27,7 @@ import ( "github.com/onflow/cadence/common" . "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestCapabilityStaticType_Equal(t *testing.T) { @@ -182,12 +182,12 @@ func TestCompositeStaticType_Equal(t *testing.T) { require.True(t, NewCompositeStaticTypeComputeTypeID( nil, - utils.TestLocation, + TestLocation, "X", ).Equal( NewCompositeStaticTypeComputeTypeID( nil, - utils.TestLocation, + TestLocation, "X", ), ), @@ -201,12 +201,12 @@ func TestCompositeStaticType_Equal(t *testing.T) { require.False(t, NewCompositeStaticTypeComputeTypeID( nil, - utils.TestLocation, + TestLocation, "X", ).Equal( NewCompositeStaticTypeComputeTypeID( nil, - utils.TestLocation, + TestLocation, "Y", ), ), @@ -333,8 +333,8 @@ func TestInterfaceStaticType_Equal(t *testing.T) { t.Parallel() require.True(t, - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "X"). - Equal(NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "X")), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "X"). + Equal(NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "X")), ) }) @@ -343,8 +343,8 @@ func TestInterfaceStaticType_Equal(t *testing.T) { t.Parallel() require.False(t, - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "X"). - Equal(NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "Y")), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "X"). + Equal(NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "Y")), ) }) @@ -749,14 +749,14 @@ func TestIntersectionStaticType_Equal(t *testing.T) { require.True(t, (&IntersectionStaticType{ Types: []*InterfaceStaticType{ - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "X"), - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "Y"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "X"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "Y"), }, }).Equal( &IntersectionStaticType{ Types: []*InterfaceStaticType{ - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "Y"), - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "X"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "Y"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "X"), }, }, ), @@ -785,13 +785,13 @@ func TestIntersectionStaticType_Equal(t *testing.T) { require.False(t, (&IntersectionStaticType{ Types: []*InterfaceStaticType{ - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "X"), - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "Y"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "X"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "Y"), }, }).Equal( &IntersectionStaticType{ Types: []*InterfaceStaticType{ - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "X"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "X"), }, }, ), @@ -805,14 +805,14 @@ func TestIntersectionStaticType_Equal(t *testing.T) { require.True(t, (&IntersectionStaticType{ Types: []*InterfaceStaticType{ - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "X"), - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "Y"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "X"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "Y"), }, }).Equal( &IntersectionStaticType{ Types: []*InterfaceStaticType{ - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "Y"), - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "X"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "Y"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "X"), }, }, ), @@ -826,14 +826,14 @@ func TestIntersectionStaticType_Equal(t *testing.T) { require.True(t, (&IntersectionStaticType{ Types: []*InterfaceStaticType{ - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "X"), - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "Y"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "X"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "Y"), }, }).Equal( &IntersectionStaticType{ Types: []*InterfaceStaticType{ - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "X"), - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "Y"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "X"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "Y"), }, }, ), @@ -847,14 +847,14 @@ func TestIntersectionStaticType_Equal(t *testing.T) { require.False(t, (&IntersectionStaticType{ Types: []*InterfaceStaticType{ - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "X"), - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "Y"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "X"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "Y"), }, }).Equal( &IntersectionStaticType{ Types: []*InterfaceStaticType{ - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "X"), - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "Z"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "X"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "Z"), }, }, ), @@ -868,13 +868,13 @@ func TestIntersectionStaticType_Equal(t *testing.T) { require.False(t, (&IntersectionStaticType{ Types: []*InterfaceStaticType{ - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "X"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "X"), }, }).Equal( &IntersectionStaticType{ Types: []*InterfaceStaticType{ - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "X"), - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "Y"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "X"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "Y"), }, }, ), @@ -888,14 +888,14 @@ func TestIntersectionStaticType_Equal(t *testing.T) { require.False(t, (&IntersectionStaticType{ Types: []*InterfaceStaticType{ - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "X"), - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "Y"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "X"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "Y"), }, }).Equal( &IntersectionStaticType{ Types: []*InterfaceStaticType{ - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "X"), - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "Z"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "X"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "Z"), }, }, ), @@ -909,8 +909,8 @@ func TestIntersectionStaticType_Equal(t *testing.T) { require.False(t, (&IntersectionStaticType{ Types: []*InterfaceStaticType{ - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "X"), - NewInterfaceStaticTypeComputeTypeID(nil, utils.TestLocation, "Y"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "X"), + NewInterfaceStaticTypeComputeTypeID(nil, TestLocation, "Y"), }, }).Equal( &ReferenceStaticType{ diff --git a/interpreter/storage_test.go b/interpreter/storage_test.go index 01e9299c38..0693df2d9b 100644 --- a/interpreter/storage_test.go +++ b/interpreter/storage_test.go @@ -29,7 +29,8 @@ import ( "github.com/onflow/cadence/common" . "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) func TestCompositeStorage(t *testing.T) { diff --git a/tests/interpreter/string_test.go b/interpreter/string_test.go similarity index 99% rename from tests/interpreter/string_test.go rename to interpreter/string_test.go index 410d2f478c..580608e26e 100644 --- a/tests/interpreter/string_test.go +++ b/interpreter/string_test.go @@ -26,7 +26,8 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) func TestInterpretRecursiveValueString(t *testing.T) { diff --git a/interpreter/struct_stringer_test.go b/interpreter/struct_stringer_test.go new file mode 100644 index 0000000000..d81ea4e7a4 --- /dev/null +++ b/interpreter/struct_stringer_test.go @@ -0,0 +1,125 @@ +/* + * Cadence - The resource-oriented smart contract programming language + * + * Copyright Flow Foundation + * + * 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 interpreter_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/onflow/cadence/interpreter" + . "github.com/onflow/cadence/test_utils/interpreter_utils" +) + +func TestStringerBasic(t *testing.T) { + + t.Parallel() + + inter := parseCheckAndInterpret(t, ` + access(all) + struct Example: StructStringer { + view fun toString(): String { + return "example" + } + } + fun test(): String { + return Example().toString() + } + `) + + result, err := inter.Invoke("test") + require.NoError(t, err) + + RequireValuesEqual( + t, + inter, + interpreter.NewUnmeteredStringValue("example"), + result, + ) +} + +func TestStringerBuiltIn(t *testing.T) { + + t.Parallel() + + inter := parseCheckAndInterpret(t, ` + access(all) + fun test(): String { + let v = 1 + return v.toString() + } + `) + + result, err := inter.Invoke("test") + require.NoError(t, err) + + RequireValuesEqual( + t, + inter, + interpreter.NewUnmeteredStringValue("1"), + result, + ) +} + +func TestStringerCast(t *testing.T) { + + t.Parallel() + + inter := parseCheckAndInterpret(t, ` + access(all) + fun test(): String { + var s = 1 + var somevalue = s as {StructStringer} + return somevalue.toString() + } + `) + + result, err := inter.Invoke("test") + require.NoError(t, err) + + RequireValuesEqual( + t, + inter, + interpreter.NewUnmeteredStringValue("1"), + result, + ) +} + +func TestStringerAsValue(t *testing.T) { + + t.Parallel() + + inter := parseCheckAndInterpret(t, ` + access(all) + fun test(): String { + var v = Type<{StructStringer}>() + return v.identifier + } + `) + + result, err := inter.Invoke("test") + require.NoError(t, err) + + RequireValuesEqual( + t, + inter, + interpreter.NewUnmeteredStringValue("{StructStringer}"), + result, + ) +} diff --git a/tests/interpreter/switch_test.go b/interpreter/switch_test.go similarity index 96% rename from tests/interpreter/switch_test.go rename to interpreter/switch_test.go index 3d0dda4b90..2a30c6cbdb 100644 --- a/tests/interpreter/switch_test.go +++ b/interpreter/switch_test.go @@ -24,11 +24,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - . "github.com/onflow/cadence/tests/utils" - "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/checker" + . "github.com/onflow/cadence/test_utils/interpreter_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestInterpretSwitchStatement(t *testing.T) { @@ -53,7 +52,7 @@ func TestInterpretSwitchStatement(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.UnreachableStatementError{}, errs[0]) }, @@ -91,7 +90,7 @@ func TestInterpretSwitchStatement(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.UnreachableStatementError{}, errs[0]) }, @@ -132,7 +131,7 @@ func TestInterpretSwitchStatement(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.UnreachableStatementError{}, errs[0]) }, @@ -219,7 +218,7 @@ func TestInterpretSwitchStatement(t *testing.T) { `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.UnreachableStatementError{}, errs[0]) }, diff --git a/tests/interpreter/transactions_test.go b/interpreter/transactions_test.go similarity index 98% rename from tests/interpreter/transactions_test.go rename to interpreter/transactions_test.go index 71680a184d..21a1642f99 100644 --- a/tests/interpreter/transactions_test.go +++ b/interpreter/transactions_test.go @@ -29,8 +29,9 @@ import ( "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - "github.com/onflow/cadence/tests/checker" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestInterpretTransactions(t *testing.T) { @@ -420,7 +421,7 @@ func TestRuntimeInvalidTransferInExecute(t *testing.T) { } `, ParseCheckAndInterpretOptions{ HandleCheckerError: func(err error) { - errs := checker.RequireCheckerErrors(t, err, 3) + errs := RequireCheckerErrors(t, err, 3) require.IsType(t, &sema.ResourceCapturingError{}, errs[0]) require.IsType(t, &sema.ResourceCapturingError{}, errs[1]) require.IsType(t, &sema.ResourceCapturingError{}, errs[2]) diff --git a/tests/interpreter/transfer_test.go b/interpreter/transfer_test.go similarity index 98% rename from tests/interpreter/transfer_test.go rename to interpreter/transfer_test.go index c40a4f0ee3..72447e2dd9 100644 --- a/tests/interpreter/transfer_test.go +++ b/interpreter/transfer_test.go @@ -28,7 +28,7 @@ import ( "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestInterpretTransferCheck(t *testing.T) { diff --git a/tests/interpreter/uuid_test.go b/interpreter/uuid_test.go similarity index 91% rename from tests/interpreter/uuid_test.go rename to interpreter/uuid_test.go index 3e56037a5c..efdc8d1010 100644 --- a/tests/interpreter/uuid_test.go +++ b/interpreter/uuid_test.go @@ -28,15 +28,16 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/checker" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestInterpretResourceUUID(t *testing.T) { t.Parallel() - importedChecker, err := checker.ParseAndCheckWithOptions(t, + importedChecker, err := ParseAndCheckWithOptions(t, ` access(all) resource R {} @@ -44,13 +45,13 @@ func TestInterpretResourceUUID(t *testing.T) { return <- create R() } `, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Location: ImportedLocation, }, ) require.NoError(t, err) - importingChecker, err := checker.ParseAndCheckWithOptions(t, + importingChecker, err := ParseAndCheckWithOptions(t, ` import createR from "imported" @@ -63,7 +64,7 @@ func TestInterpretResourceUUID(t *testing.T) { ] } `, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Config: &sema.Config{ ImportHandler: func(_ *sema.Checker, importedLocation common.Location, _ ast.Range) (sema.Import, error) { assert.Equal(t, diff --git a/interpreter/value_function_test.go b/interpreter/value_function_test.go index 0cf1fd6464..2d25e8bc1b 100644 --- a/interpreter/value_function_test.go +++ b/interpreter/value_function_test.go @@ -24,10 +24,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/onflow/cadence/common" - "github.com/onflow/cadence/tests/utils" - . "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestFunctionStaticType(t *testing.T) { @@ -67,7 +66,7 @@ func TestFunctionStaticType(t *testing.T) { inter.SharedState.Config.CompositeTypeHandler = func(location common.Location, typeID TypeID) *sema.CompositeType { return &sema.CompositeType{ - Location: utils.TestLocation, + Location: TestLocation, Identifier: "foo", Kind: common.CompositeKindStructure, } @@ -92,7 +91,7 @@ func TestFunctionStaticType(t *testing.T) { var compositeValue Value = NewCompositeValue( inter, EmptyLocationRange, - utils.TestLocation, + TestLocation, "foo", common.CompositeKindStructure, []CompositeField{}, diff --git a/interpreter/value_test.go b/interpreter/value_test.go index 1bfc7d3cc5..295f5a4346 100644 --- a/interpreter/value_test.go +++ b/interpreter/value_test.go @@ -36,15 +36,15 @@ import ( . "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - checkerUtils "github.com/onflow/cadence/tests/checker" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func newTestCompositeValue(inter *Interpreter, owner common.Address) *CompositeValue { return NewCompositeValue( inter, EmptyLocationRange, - utils.TestLocation, + TestLocation, "Test", common.CompositeKindStructure, nil, @@ -53,7 +53,7 @@ func newTestCompositeValue(inter *Interpreter, owner common.Address) *CompositeV } var testCompositeValueType = &sema.CompositeType{ - Location: utils.TestLocation, + Location: TestLocation, Identifier: "Test", Kind: common.CompositeKindStructure, Members: &sema.StringMemberOrderedMap{}, @@ -94,7 +94,7 @@ func TestOwnerNewArray(t *testing.T) { &Program{ Elaboration: elaboration, }, - utils.TestLocation, + TestLocation, &Config{Storage: storage}, ) require.NoError(t, err) @@ -137,7 +137,7 @@ func TestOwnerArrayDeepCopy(t *testing.T) { &Program{ Elaboration: elaboration, }, - utils.TestLocation, + TestLocation, &Config{ Storage: storage, OnMeterComputation: getMeterCompFuncWithExpectedKinds(t, @@ -206,7 +206,7 @@ func TestOwnerArrayElement(t *testing.T) { &Program{ Elaboration: elaboration, }, - utils.TestLocation, + TestLocation, &Config{Storage: storage}, ) require.NoError(t, err) @@ -248,7 +248,7 @@ func TestOwnerArraySetIndex(t *testing.T) { &Program{ Elaboration: elaboration, }, - utils.TestLocation, + TestLocation, &Config{Storage: storage}, ) require.NoError(t, err) @@ -300,7 +300,7 @@ func TestOwnerArrayAppend(t *testing.T) { &Program{ Elaboration: elaboration, }, - utils.TestLocation, + TestLocation, &Config{Storage: storage}, ) require.NoError(t, err) @@ -346,7 +346,7 @@ func TestOwnerArrayInsert(t *testing.T) { &Program{ Elaboration: elaboration, }, - utils.TestLocation, + TestLocation, &Config{Storage: storage}, ) require.NoError(t, err) @@ -392,7 +392,7 @@ func TestOwnerArrayRemove(t *testing.T) { &Program{ Elaboration: elaboration, }, - utils.TestLocation, + TestLocation, &Config{Storage: storage}, ) require.NoError(t, err) @@ -436,7 +436,7 @@ func TestOwnerNewDictionary(t *testing.T) { &Program{ Elaboration: elaboration, }, - utils.TestLocation, + TestLocation, &Config{Storage: storage}, ) require.NoError(t, err) @@ -483,7 +483,7 @@ func TestOwnerDictionary(t *testing.T) { &Program{ Elaboration: elaboration, }, - utils.TestLocation, + TestLocation, &Config{Storage: storage}, ) require.NoError(t, err) @@ -530,7 +530,7 @@ func TestOwnerDictionaryCopy(t *testing.T) { &Program{ Elaboration: elaboration, }, - utils.TestLocation, + TestLocation, &Config{ Storage: storage, OnMeterComputation: getMeterCompFuncWithExpectedKinds(t, @@ -603,7 +603,7 @@ func TestOwnerDictionarySetSome(t *testing.T) { &Program{ Elaboration: elaboration, }, - utils.TestLocation, + TestLocation, &Config{Storage: storage}, ) require.NoError(t, err) @@ -657,7 +657,7 @@ func TestOwnerDictionaryInsertNonExisting(t *testing.T) { &Program{ Elaboration: elaboration, }, - utils.TestLocation, + TestLocation, &Config{Storage: storage}, ) require.NoError(t, err) @@ -712,7 +712,7 @@ func TestOwnerDictionaryRemove(t *testing.T) { &Program{ Elaboration: elaboration, }, - utils.TestLocation, + TestLocation, &Config{Storage: storage}, ) require.NoError(t, err) @@ -773,7 +773,7 @@ func TestOwnerDictionaryInsertExisting(t *testing.T) { &Program{ Elaboration: elaboration, }, - utils.TestLocation, + TestLocation, &Config{Storage: storage}, ) require.NoError(t, err) @@ -1115,7 +1115,7 @@ func TestStringer(t *testing.T) { return NewCompositeValue( inter, EmptyLocationRange, - utils.TestLocation, + TestLocation, "Foo", common.CompositeKindResource, fields, @@ -1137,7 +1137,7 @@ func TestStringer(t *testing.T) { compositeValue := NewCompositeValue( inter, EmptyLocationRange, - utils.TestLocation, + TestLocation, "Foo", common.CompositeKindResource, fields, @@ -1410,7 +1410,7 @@ func TestVisitor(t *testing.T) { value = NewCompositeValue( inter, EmptyLocationRange, - utils.TestLocation, + TestLocation, "Foo", common.CompositeKindStructure, fields, @@ -1742,7 +1742,7 @@ func TestGetHashInput(t *testing.T) { return NewCompositeValue( inter, EmptyLocationRange, - utils.TestLocation, + TestLocation, "Foo", common.CompositeKindEnum, fields, @@ -1770,7 +1770,7 @@ func TestGetHashInput(t *testing.T) { return NewCompositeValue( inter, EmptyLocationRange, - utils.TestLocation, + TestLocation, strings.Repeat("a", 32), common.CompositeKindEnum, fields, @@ -1898,9 +1898,9 @@ func TestEphemeralReferenceTypeConformance(t *testing.T) { } }` - checker, err := checkerUtils.ParseAndCheckWithOptions(t, + checker, err := ParseAndCheckWithOptions(t, code, - checkerUtils.ParseAndCheckOptions{}, + ParseAndCheckOptions{}, ) require.NoError(t, err) @@ -2959,7 +2959,7 @@ func TestCompositeValue_Equal(t *testing.T) { NewCompositeValue( inter, EmptyLocationRange, - utils.TestLocation, + TestLocation, "X", common.CompositeKindStructure, fields1, @@ -2970,7 +2970,7 @@ func TestCompositeValue_Equal(t *testing.T) { NewCompositeValue( inter, EmptyLocationRange, - utils.TestLocation, + TestLocation, "X", common.CompositeKindStructure, fields2, @@ -3384,7 +3384,7 @@ func TestPublicKeyValue(t *testing.T) { inter, err := NewInterpreter( nil, - utils.TestLocation, + TestLocation, &Config{ Storage: storage, }, @@ -3433,7 +3433,7 @@ func TestPublicKeyValue(t *testing.T) { inter, err := NewInterpreter( nil, - utils.TestLocation, + TestLocation, &Config{ Storage: storage, }, @@ -3589,7 +3589,7 @@ func newTestInterpreter(tb testing.TB) *Interpreter { inter, err := NewInterpreter( nil, - utils.TestLocation, + TestLocation, &Config{ Storage: storage, AtreeValueValidationEnabled: true, @@ -3622,9 +3622,9 @@ func TestNonStorable(t *testing.T) { } ` - checker, err := checkerUtils.ParseAndCheckWithOptions(t, + checker, err := ParseAndCheckWithOptions(t, code, - checkerUtils.ParseAndCheckOptions{}, + ParseAndCheckOptions{}, ) require.NoError(t, err) @@ -3756,7 +3756,7 @@ func TestValue_ConformsToStaticType(t *testing.T) { return NewCompositeValue( inter, EmptyLocationRange, - utils.TestLocation, + TestLocation, "Test", common.CompositeKindStructure, fields, @@ -3775,7 +3775,7 @@ func TestValue_ConformsToStaticType(t *testing.T) { members := &sema.StringMemberOrderedMap{} compositeType := &sema.CompositeType{ - Location: utils.TestLocation, + Location: TestLocation, Identifier: "Test", Kind: common.CompositeKindStructure, Members: members, @@ -3801,7 +3801,7 @@ func TestValue_ConformsToStaticType(t *testing.T) { &Program{ Elaboration: elaboration, }, - utils.TestLocation, + TestLocation, &Config{Storage: storage}, ) require.NoError(t, err) @@ -4493,7 +4493,7 @@ func TestOverwriteDictionaryValueWhereKeyIsStoredInSeparateAtreeSlab(t *testing. return NewCompositeValue( inter, EmptyLocationRange, - utils.TestLocation, + TestLocation, "Test", common.CompositeKindEnum, []CompositeField{ @@ -4518,7 +4518,7 @@ func TestOverwriteDictionaryValueWhereKeyIsStoredInSeparateAtreeSlab(t *testing. &Program{ Elaboration: elaboration, }, - utils.TestLocation, + TestLocation, &Config{ Storage: storage, AtreeValueValidationEnabled: true, @@ -4594,7 +4594,7 @@ func TestOverwriteDictionaryValueWhereKeyIsStoredInSeparateAtreeSlab(t *testing. &Program{ Elaboration: elaboration, }, - utils.TestLocation, + TestLocation, &Config{ Storage: storage, AtreeValueValidationEnabled: true, diff --git a/interpreter/value_uint64.go b/interpreter/value_uint64.go index 5c11cca04b..f8b3cdb2ce 100644 --- a/interpreter/value_uint64.go +++ b/interpreter/value_uint64.go @@ -19,12 +19,11 @@ package interpreter import ( + "encoding/binary" "math" "math/big" "unsafe" - "encoding/binary" - "github.com/onflow/atree" "github.com/onflow/cadence/ast" diff --git a/tests/interpreter/values_test.go b/interpreter/values_test.go similarity index 96% rename from tests/interpreter/values_test.go rename to interpreter/values_test.go index e725b5a30c..b874aa4213 100644 --- a/tests/interpreter/values_test.go +++ b/interpreter/values_test.go @@ -36,7 +36,8 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) // TODO: make these program args? @@ -64,7 +65,7 @@ func TestInterpretRandomMapOperations(t *testing.T) { Program: ast.NewProgram(nil, []ast.Declaration{}), Elaboration: sema.NewElaboration(nil), }, - utils.TestLocation, + TestLocation, &interpreter.Config{ Storage: storage, ImportLocationHandler: func(inter *interpreter.Interpreter, location common.Location) interpreter.Import { @@ -119,7 +120,7 @@ func TestInterpretRandomMapOperations(t *testing.T) { value, found := testMap.Get(inter, interpreter.EmptyLocationRange, orgKey) require.True(t, found) - utils.AssertValuesEqual(t, inter, orgValue, value) + AssertValuesEqual(t, inter, orgValue, value) return false }) @@ -138,7 +139,7 @@ func TestInterpretRandomMapOperations(t *testing.T) { orgValue, ok := entries.get(inter, key) require.True(t, ok, "cannot find key: %v", key) - utils.AssertValuesEqual(t, inter, orgValue, value) + AssertValuesEqual(t, inter, orgValue, value) return true }, ) @@ -164,7 +165,7 @@ func TestInterpretRandomMapOperations(t *testing.T) { value, found := copyOfTestMap.Get(inter, interpreter.EmptyLocationRange, orgKey) require.True(t, found) - utils.AssertValuesEqual(t, inter, orgValue, value) + AssertValuesEqual(t, inter, orgValue, value) return false }) @@ -192,7 +193,7 @@ func TestInterpretRandomMapOperations(t *testing.T) { value, found := testMap.Get(inter, interpreter.EmptyLocationRange, orgKey) require.True(t, found) - utils.AssertValuesEqual(t, inter, orgValue, value) + AssertValuesEqual(t, inter, orgValue, value) return false }) @@ -233,7 +234,7 @@ func TestInterpretRandomMapOperations(t *testing.T) { value, found := dictionary.Get(inter, interpreter.EmptyLocationRange, orgKey) require.True(t, found) - utils.AssertValuesEqual(t, inter, orgValue, value) + AssertValuesEqual(t, inter, orgValue, value) return false }) @@ -284,7 +285,7 @@ func TestInterpretRandomMapOperations(t *testing.T) { // Removed value must be same as the original value innerValue := someValue.InnerValue(inter, interpreter.EmptyLocationRange) - utils.AssertValuesEqual(t, inter, orgValue, innerValue) + AssertValuesEqual(t, inter, orgValue, innerValue) return false }) @@ -344,7 +345,7 @@ func TestInterpretRandomMapOperations(t *testing.T) { // Removed value must be same as the original value innerValue := someValue.InnerValue(inter, interpreter.EmptyLocationRange) - utils.AssertValuesEqual(t, inter, orgValue, innerValue) + AssertValuesEqual(t, inter, orgValue, innerValue) return false }) @@ -412,7 +413,7 @@ func TestInterpretRandomMapOperations(t *testing.T) { // Removed value must be same as the original value innerValue := someValue.InnerValue(inter, interpreter.EmptyLocationRange) - utils.AssertValuesEqual(t, inter, value1, innerValue) + AssertValuesEqual(t, inter, value1, innerValue) } // Check the values @@ -428,7 +429,7 @@ func TestInterpretRandomMapOperations(t *testing.T) { // Read value must be updated value innerValue := someValue.InnerValue(inter, interpreter.EmptyLocationRange) - utils.AssertValuesEqual(t, inter, value2, innerValue) + AssertValuesEqual(t, inter, value2, innerValue) } }) @@ -515,7 +516,7 @@ func TestInterpretRandomMapOperations(t *testing.T) { // Removed value must be same as the original value innerValue := someValue.InnerValue(inter, interpreter.EmptyLocationRange) - utils.AssertValuesEqual(t, inter, orgValue, innerValue) + AssertValuesEqual(t, inter, orgValue, innerValue) deleteCount++ } @@ -583,7 +584,7 @@ func TestInterpretRandomMapOperations(t *testing.T) { value, found := movedDictionary.Get(inter, interpreter.EmptyLocationRange, orgKey) require.True(t, found) - utils.AssertValuesEqual(t, inter, orgValue, value) + AssertValuesEqual(t, inter, orgValue, value) return false }) @@ -607,7 +608,7 @@ func TestInterpretRandomArrayOperations(t *testing.T) { Program: ast.NewProgram(nil, []ast.Declaration{}), Elaboration: sema.NewElaboration(nil), }, - utils.TestLocation, + TestLocation, &interpreter.Config{ Storage: storage, ImportLocationHandler: func(inter *interpreter.Interpreter, location common.Location) interpreter.Import { @@ -651,7 +652,7 @@ func TestInterpretRandomArrayOperations(t *testing.T) { for index, orgElement := range elements { element := testArray.Get(inter, interpreter.EmptyLocationRange, index) - utils.AssertValuesEqual(t, inter, orgElement, element) + AssertValuesEqual(t, inter, orgElement, element) } owner := testArray.GetOwner() @@ -666,10 +667,10 @@ func TestInterpretRandomArrayOperations(t *testing.T) { inter, func(element interpreter.Value) (resume bool) { orgElement := elements[index] - utils.AssertValuesEqual(t, inter, orgElement, element) + AssertValuesEqual(t, inter, orgElement, element) elementByIndex := testArray.Get(inter, interpreter.EmptyLocationRange, index) - utils.AssertValuesEqual(t, inter, element, elementByIndex) + AssertValuesEqual(t, inter, element, elementByIndex) index++ return true @@ -695,7 +696,7 @@ func TestInterpretRandomArrayOperations(t *testing.T) { for index, orgElement := range elements { element := copyOfTestArray.Get(inter, interpreter.EmptyLocationRange, index) - utils.AssertValuesEqual(t, inter, orgElement, element) + AssertValuesEqual(t, inter, orgElement, element) } owner := copyOfTestArray.GetOwner() @@ -717,7 +718,7 @@ func TestInterpretRandomArrayOperations(t *testing.T) { // go over original elements again and check no missing data (no side effect should be found) for index, orgElement := range elements { element := testArray.Get(inter, interpreter.EmptyLocationRange, index) - utils.AssertValuesEqual(t, inter, orgElement, element) + AssertValuesEqual(t, inter, orgElement, element) } owner := testArray.GetOwner() @@ -755,7 +756,7 @@ func TestInterpretRandomArrayOperations(t *testing.T) { // Go over original values again and check no missing data (no side effect should be found) for index, element := range newElements { value := testArray.Get(inter, interpreter.EmptyLocationRange, index) - utils.AssertValuesEqual(t, inter, element, value) + AssertValuesEqual(t, inter, element, value) } }) @@ -789,7 +790,7 @@ func TestInterpretRandomArrayOperations(t *testing.T) { // Go over original values again and check no missing data (no side effect should be found) for index, element := range newElements { value := testArray.Get(inter, interpreter.EmptyLocationRange, index) - utils.AssertValuesEqual(t, inter, element, value) + AssertValuesEqual(t, inter, element, value) } }) @@ -831,7 +832,7 @@ func TestInterpretRandomArrayOperations(t *testing.T) { removedValue := testArray.Remove(inter, interpreter.EmptyLocationRange, 0) // Removed value must be same as the original value - utils.AssertValuesEqual(t, inter, element, removedValue) + AssertValuesEqual(t, inter, element, removedValue) } // Array must be empty @@ -896,7 +897,7 @@ func TestInterpretRandomArrayOperations(t *testing.T) { removedValue := testArray.RemoveFirst(inter, interpreter.EmptyLocationRange) // Removed value must be same as the original value - utils.AssertValuesEqual(t, inter, orgValue, removedValue) + AssertValuesEqual(t, inter, orgValue, removedValue) deleteCount++ } @@ -957,7 +958,7 @@ func TestInterpretRandomArrayOperations(t *testing.T) { // Check the elements for index, orgElement := range elements { element := movedArray.Get(inter, interpreter.EmptyLocationRange, index) - utils.AssertValuesEqual(t, inter, orgElement, element) + AssertValuesEqual(t, inter, orgElement, element) } owner = movedArray.GetOwner() @@ -979,7 +980,7 @@ func TestInterpretRandomCompositeValueOperations(t *testing.T) { Program: ast.NewProgram(nil, []ast.Declaration{}), Elaboration: sema.NewElaboration(nil), }, - utils.TestLocation, + TestLocation, &interpreter.Config{ Storage: storage, ImportLocationHandler: func(inter *interpreter.Interpreter, location common.Location) interpreter.Import { @@ -1005,7 +1006,7 @@ func TestInterpretRandomCompositeValueOperations(t *testing.T) { for fieldName, orgFieldValue := range orgFields { fieldValue := testComposite.GetField(inter, interpreter.EmptyLocationRange, fieldName) - utils.AssertValuesEqual(t, inter, orgFieldValue, fieldValue) + AssertValuesEqual(t, inter, orgFieldValue, fieldValue) } owner := testComposite.GetOwner() @@ -1017,7 +1018,7 @@ func TestInterpretRandomCompositeValueOperations(t *testing.T) { testComposite.ForEachField(inter, func(name string, value interpreter.Value) (resume bool) { orgValue, ok := orgFields[name] require.True(t, ok) - utils.AssertValuesEqual(t, inter, orgValue, value) + AssertValuesEqual(t, inter, orgValue, value) fieldCount++ // continue iteration @@ -1042,7 +1043,7 @@ func TestInterpretRandomCompositeValueOperations(t *testing.T) { for name, orgValue := range orgFields { value := copyOfTestComposite.GetField(inter, interpreter.EmptyLocationRange, name) - utils.AssertValuesEqual(t, inter, orgValue, value) + AssertValuesEqual(t, inter, orgValue, value) } owner := copyOfTestComposite.GetOwner() @@ -1062,7 +1063,7 @@ func TestInterpretRandomCompositeValueOperations(t *testing.T) { // go over original values again and check no missing data (no side effect should be found) for name, orgValue := range orgFields { value := testComposite.GetField(inter, interpreter.EmptyLocationRange, name) - utils.AssertValuesEqual(t, inter, orgValue, value) + AssertValuesEqual(t, inter, orgValue, value) } owner := testComposite.GetOwner() @@ -1115,7 +1116,7 @@ func TestInterpretRandomCompositeValueOperations(t *testing.T) { // Check the elements for fieldName, orgFieldValue := range fields { fieldValue := movedComposite.GetField(inter, interpreter.EmptyLocationRange, fieldName) - utils.AssertValuesEqual(t, inter, orgFieldValue, fieldValue) + AssertValuesEqual(t, inter, orgFieldValue, fieldValue) } owner = composite.GetOwner() @@ -1714,7 +1715,7 @@ func TestCheckStorageHealthInMiddleOfDeepRemove(t *testing.T) { Program: ast.NewProgram(nil, []ast.Declaration{}), Elaboration: sema.NewElaboration(nil), }, - utils.TestLocation, + TestLocation, &interpreter.Config{ Storage: storage, ImportLocationHandler: func(inter *interpreter.Interpreter, location common.Location) interpreter.Import { @@ -1792,7 +1793,7 @@ func TestCheckStorageHealthInMiddleOfTransferAndRemove(t *testing.T) { Program: ast.NewProgram(nil, []ast.Declaration{}), Elaboration: sema.NewElaboration(nil), }, - utils.TestLocation, + TestLocation, &interpreter.Config{ Storage: storage, ImportLocationHandler: func(inter *interpreter.Interpreter, location common.Location) interpreter.Import { diff --git a/tests/interpreter/while_test.go b/interpreter/while_test.go similarity index 97% rename from tests/interpreter/while_test.go rename to interpreter/while_test.go index 10bcf69db6..c341dfdf57 100644 --- a/tests/interpreter/while_test.go +++ b/interpreter/while_test.go @@ -23,9 +23,8 @@ import ( "github.com/stretchr/testify/require" - . "github.com/onflow/cadence/tests/utils" - "github.com/onflow/cadence/interpreter" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) func TestInterpretWhileStatement(t *testing.T) { diff --git a/npm-packages/cadence-parser/package.json b/npm-packages/cadence-parser/package.json index a3c6ba8a53..b82eeda922 100644 --- a/npm-packages/cadence-parser/package.json +++ b/npm-packages/cadence-parser/package.json @@ -1,6 +1,6 @@ { "name": "@onflow/cadence-parser", - "version": "1.2.1-preview.52", + "version": "1.2.2", "description": "The Cadence parser", "homepage": "https://github.com/onflow/cadence", "repository": { diff --git a/old_parser/declaration_test.go b/old_parser/declaration_test.go index f41fd0c978..23463f9479 100644 --- a/old_parser/declaration_test.go +++ b/old_parser/declaration_test.go @@ -27,7 +27,7 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/common" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestParseVariableDeclaration(t *testing.T) { @@ -41,7 +41,7 @@ func TestParseVariableDeclaration(t *testing.T) { result, errs := testParseDeclarations("var x = 1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -77,7 +77,7 @@ func TestParseVariableDeclaration(t *testing.T) { result, errs := testParseDeclarations(" pub var x = 1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessAll, @@ -113,7 +113,7 @@ func TestParseVariableDeclaration(t *testing.T) { result, errs := testParseDeclarations("let x = 1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -149,7 +149,7 @@ func TestParseVariableDeclaration(t *testing.T) { result, errs := testParseDeclarations("let x <- 1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -185,7 +185,7 @@ func TestParseVariableDeclaration(t *testing.T) { result, errs := testParseDeclarations("let r2: @R <- r") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -228,7 +228,7 @@ func TestParseVariableDeclaration(t *testing.T) { result, errs := testParseStatements("var x <- y <- z") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -275,7 +275,7 @@ func TestParseVariableDeclaration(t *testing.T) { StaticModifierEnabled: true, }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier for variable", @@ -291,7 +291,7 @@ func TestParseVariableDeclaration(t *testing.T) { t.Parallel() _, errs := testParseDeclarations("static var x = 1") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -313,7 +313,7 @@ func TestParseVariableDeclaration(t *testing.T) { NativeModifierEnabled: true, }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid native modifier for variable", @@ -329,7 +329,7 @@ func TestParseVariableDeclaration(t *testing.T) { t.Parallel() _, errs := testParseDeclarations("native var x = 1") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -361,7 +361,7 @@ func TestParseParameterList(t *testing.T) { result, errs := parse("()") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ParameterList{ Range: ast.Range{ StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, @@ -379,7 +379,7 @@ func TestParseParameterList(t *testing.T) { result, errs := parse(" ( )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ParameterList{ Range: ast.Range{ StartPos: ast.Position{Line: 1, Column: 1, Offset: 1}, @@ -397,7 +397,7 @@ func TestParseParameterList(t *testing.T) { result, errs := parse("( a : Int )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ParameterList{ Parameters: []*ast.Parameter{ { @@ -435,7 +435,7 @@ func TestParseParameterList(t *testing.T) { result, errs := parse("( a b : Int )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ParameterList{ Parameters: []*ast.Parameter{ { @@ -473,7 +473,7 @@ func TestParseParameterList(t *testing.T) { result, errs := parse("( a b : Int , c : Int )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ParameterList{ Parameters: []*ast.Parameter{ { @@ -527,7 +527,7 @@ func TestParseParameterList(t *testing.T) { t.Parallel() _, errs := parse("( a b : Int c : Int )") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &MissingCommaInParameterListError{ Pos: ast.Position{Offset: 14, Line: 1, Column: 14}, @@ -549,7 +549,7 @@ func TestParseFunctionDeclaration(t *testing.T) { result, errs := testParseDeclarations("fun foo () { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -586,7 +586,7 @@ func TestParseFunctionDeclaration(t *testing.T) { result, errs := testParseDeclarations("pub fun foo () { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessAll, @@ -623,7 +623,7 @@ func TestParseFunctionDeclaration(t *testing.T) { result, errs := testParseDeclarations("fun foo (): X { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -682,7 +682,7 @@ func TestParseFunctionDeclaration(t *testing.T) { `) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -797,7 +797,7 @@ func TestParseFunctionDeclaration(t *testing.T) { result, errs := testParseDeclarations("/// Test\nfun foo() {}") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -835,7 +835,7 @@ func TestParseFunctionDeclaration(t *testing.T) { result, errs := testParseDeclarations("\n /// First line\n \n/// Second line\n\n\nfun foo() {}") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -873,7 +873,7 @@ func TestParseFunctionDeclaration(t *testing.T) { result, errs := testParseDeclarations("\n /** Cool dogs.\n\n Cool cats!! */\n\n\nfun foo() {}") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -916,7 +916,7 @@ func TestParseFunctionDeclaration(t *testing.T) { result, errs := testParseDeclarations("fun main(): Int{ return 1 }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -985,7 +985,7 @@ func TestParseFunctionDeclaration(t *testing.T) { ) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1022,7 +1022,7 @@ func TestParseFunctionDeclaration(t *testing.T) { _, errs := testParseDeclarations("native fun foo() {}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -1046,7 +1046,7 @@ func TestParseFunctionDeclaration(t *testing.T) { ) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1083,7 +1083,7 @@ func TestParseFunctionDeclaration(t *testing.T) { _, errs := testParseDeclarations("static fun foo() {}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -1108,7 +1108,7 @@ func TestParseFunctionDeclaration(t *testing.T) { ) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1145,7 +1145,7 @@ func TestParseFunctionDeclaration(t *testing.T) { _, errs := testParseDeclarations("static native fun foo() {}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -1168,7 +1168,7 @@ func TestParseFunctionDeclaration(t *testing.T) { NativeModifierEnabled: true, }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier after native modifier", @@ -1185,7 +1185,7 @@ func TestParseFunctionDeclaration(t *testing.T) { _, errs := testParseDeclarations("native static fun foo() {}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -1210,7 +1210,7 @@ func TestParseFunctionDeclaration(t *testing.T) { ) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessAll, @@ -1247,7 +1247,7 @@ func TestParseFunctionDeclaration(t *testing.T) { _, errs := testParseDeclarations("pub static native fun foo() {}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -1271,7 +1271,7 @@ func TestParseFunctionDeclaration(t *testing.T) { ) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1321,7 +1321,7 @@ func TestParseFunctionDeclaration(t *testing.T) { ) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1378,7 +1378,7 @@ func TestParseFunctionDeclaration(t *testing.T) { ) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1443,7 +1443,7 @@ func TestParseFunctionDeclaration(t *testing.T) { _, errs := testParseDeclarations("fun foo() {}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected '(' as start of parameter list, got '<'", @@ -1466,7 +1466,7 @@ func TestParseFunctionDeclaration(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "missing '>' at end of type parameter list", @@ -1489,7 +1489,7 @@ func TestParseFunctionDeclaration(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &MissingCommaInParameterListError{ Pos: ast.Position{Offset: 13, Line: 1, Column: 13}, @@ -1521,7 +1521,7 @@ func TestParseAccess(t *testing.T) { result, errs := parse("pub") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessAll, result, ) @@ -1534,7 +1534,7 @@ func TestParseAccess(t *testing.T) { result, errs := parse("pub ( set )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessPubSettableLegacy, result, ) @@ -1545,7 +1545,7 @@ func TestParseAccess(t *testing.T) { t.Parallel() result, errs := parse("pub ( ") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected keyword \"set\", got EOF", @@ -1555,7 +1555,7 @@ func TestParseAccess(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessNotSpecified, result, ) @@ -1566,7 +1566,7 @@ func TestParseAccess(t *testing.T) { t.Parallel() result, errs := parse("pub ( set ") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token ')'", @@ -1576,7 +1576,7 @@ func TestParseAccess(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessNotSpecified, result, ) @@ -1587,7 +1587,7 @@ func TestParseAccess(t *testing.T) { t.Parallel() result, errs := parse("pub ( foo )") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected keyword \"set\", got \"foo\"", @@ -1597,7 +1597,7 @@ func TestParseAccess(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessNotSpecified, result, ) @@ -1610,7 +1610,7 @@ func TestParseAccess(t *testing.T) { result, errs := parse("priv") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessSelf, result, ) @@ -1623,7 +1623,7 @@ func TestParseAccess(t *testing.T) { result, errs := parse("access ( all )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessAll, result, ) @@ -1636,7 +1636,7 @@ func TestParseAccess(t *testing.T) { result, errs := parse("access ( account )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessAccount, result, ) @@ -1649,7 +1649,7 @@ func TestParseAccess(t *testing.T) { result, errs := parse("access ( contract )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessContract, result, ) @@ -1662,7 +1662,7 @@ func TestParseAccess(t *testing.T) { result, errs := parse("access ( self )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessSelf, result, ) @@ -1673,7 +1673,7 @@ func TestParseAccess(t *testing.T) { t.Parallel() result, errs := parse("access ( ") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected keyword \"all\", \"account\", \"contract\", or \"self\", got EOF", @@ -1683,7 +1683,7 @@ func TestParseAccess(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessNotSpecified, result, ) @@ -1694,7 +1694,7 @@ func TestParseAccess(t *testing.T) { t.Parallel() result, errs := parse("access ( self ") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token ')'", @@ -1704,7 +1704,7 @@ func TestParseAccess(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessNotSpecified, result, ) @@ -1715,7 +1715,7 @@ func TestParseAccess(t *testing.T) { t.Parallel() result, errs := parse("access ( foo )") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected keyword \"all\", \"account\", \"contract\", or \"self\", got \"foo\"", @@ -1725,7 +1725,7 @@ func TestParseAccess(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessNotSpecified, result, ) @@ -1741,7 +1741,7 @@ func TestParseImportDeclaration(t *testing.T) { t.Parallel() result, errs := testParseDeclarations(` import`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected end in import declaration: expected string, address, or identifier", @@ -1753,7 +1753,7 @@ func TestParseImportDeclaration(t *testing.T) { var expected []ast.Declaration - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, expected, result, ) @@ -1766,7 +1766,7 @@ func TestParseImportDeclaration(t *testing.T) { result, errs := testParseDeclarations(` import "foo"`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.ImportDeclaration{ Identifiers: nil, @@ -1789,7 +1789,7 @@ func TestParseImportDeclaration(t *testing.T) { result, errs := testParseDeclarations(` import 0x42`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.ImportDeclaration{ Identifiers: nil, @@ -1812,7 +1812,7 @@ func TestParseImportDeclaration(t *testing.T) { t.Parallel() result, errs := testParseDeclarations(` import 0x10000000000000001`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "address too large", @@ -1836,7 +1836,7 @@ func TestParseImportDeclaration(t *testing.T) { }, } - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, expected, result, ) @@ -1847,7 +1847,7 @@ func TestParseImportDeclaration(t *testing.T) { t.Parallel() result, errs := testParseDeclarations(` import 1`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token in import declaration: " + @@ -1860,7 +1860,7 @@ func TestParseImportDeclaration(t *testing.T) { var expected []ast.Declaration - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, expected, result, ) @@ -1874,7 +1874,7 @@ func TestParseImportDeclaration(t *testing.T) { result, errs := testParseDeclarations(` import foo from "bar"`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.ImportDeclaration{ Identifiers: []ast.Identifier{ @@ -1900,7 +1900,7 @@ func TestParseImportDeclaration(t *testing.T) { t.Parallel() result, errs := testParseDeclarations(` import foo "bar"`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token in import declaration: " + @@ -1913,7 +1913,7 @@ func TestParseImportDeclaration(t *testing.T) { var expected []ast.Declaration - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, expected, result, ) @@ -1926,7 +1926,7 @@ func TestParseImportDeclaration(t *testing.T) { result, errs := testParseDeclarations(` import foo , bar , baz from 0x42`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.ImportDeclaration{ Identifiers: []ast.Identifier{ @@ -1962,7 +1962,7 @@ func TestParseImportDeclaration(t *testing.T) { t.Parallel() result, errs := testParseDeclarations(` import foo , bar , from 0x42`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: `expected identifier, got keyword "from"`, @@ -1974,7 +1974,7 @@ func TestParseImportDeclaration(t *testing.T) { var expected []ast.Declaration - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, expected, result, ) @@ -1987,7 +1987,7 @@ func TestParseImportDeclaration(t *testing.T) { result, errs := testParseDeclarations(` import foo`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.ImportDeclaration{ Identifiers: nil, @@ -2013,7 +2013,7 @@ func TestParseImportDeclaration(t *testing.T) { `) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.ImportDeclaration{ Identifiers: []ast.Identifier{ @@ -2076,7 +2076,7 @@ func TestParseEvent(t *testing.T) { result, errs := testParseDeclarations("event E()") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -2119,7 +2119,7 @@ func TestParseEvent(t *testing.T) { result, errs := testParseDeclarations(" priv event E2 ( a : Int , b : String )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ @@ -2224,7 +2224,7 @@ func TestParseFieldWithVariableKind(t *testing.T) { result, errs := parse("var x : Int") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FieldDeclaration{ Access: ast.AccessNotSpecified, VariableKind: ast.VariableKindVariable, @@ -2258,7 +2258,7 @@ func TestParseFieldWithVariableKind(t *testing.T) { result, errs := parse("let x : Int") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FieldDeclaration{ Access: ast.AccessNotSpecified, VariableKind: ast.VariableKindConstant, @@ -2316,7 +2316,7 @@ func TestParseField(t *testing.T) { ) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FieldDeclaration{ Access: ast.AccessNotSpecified, Flags: ast.FieldDeclarationFlagsIsNative, @@ -2367,7 +2367,7 @@ func TestParseField(t *testing.T) { ) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FieldDeclaration{ Access: ast.AccessNotSpecified, Flags: ast.FieldDeclarationFlagsIsStatic, @@ -2422,7 +2422,7 @@ func TestParseField(t *testing.T) { ) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FieldDeclaration{ Access: ast.AccessNotSpecified, Flags: ast.FieldDeclarationFlagsIsStatic | ast.FieldDeclarationFlagsIsNative, @@ -2458,7 +2458,7 @@ func TestParseField(t *testing.T) { // For now, leading unknown identifiers are valid. // This will be rejected in Stable Cadence. - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected identifier", @@ -2481,7 +2481,7 @@ func TestParseField(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier after native modifier", @@ -2505,7 +2505,7 @@ func TestParseField(t *testing.T) { ) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FieldDeclaration{ Access: ast.AccessAll, Flags: ast.FieldDeclarationFlagsIsStatic | ast.FieldDeclarationFlagsIsNative, @@ -2541,7 +2541,7 @@ func TestParseField(t *testing.T) { // For now, leading unknown identifiers are valid. // This will be rejected in Stable Cadence. - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected identifier", @@ -2565,7 +2565,7 @@ func TestParseCompositeDeclaration(t *testing.T) { result, errs := testParseDeclarations(" pub struct S { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessAll, @@ -2592,7 +2592,7 @@ func TestParseCompositeDeclaration(t *testing.T) { result, errs := testParseDeclarations(" pub resource R : RI { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessAll, @@ -2640,7 +2640,7 @@ func TestParseCompositeDeclaration(t *testing.T) { require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -2822,7 +2822,7 @@ func TestParseAttachmentDeclaration(t *testing.T) { result, errs := testParseDeclarations("pub attachment E for S {} ") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.AttachmentDeclaration{ Access: ast.AccessAll, @@ -2857,7 +2857,7 @@ func TestParseAttachmentDeclaration(t *testing.T) { }`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -2903,7 +2903,7 @@ func TestParseAttachmentDeclaration(t *testing.T) { t.Parallel() _, errs := testParseDeclarations("attachment E {} ") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected 'for', got '{'", @@ -2921,7 +2921,7 @@ func TestParseAttachmentDeclaration(t *testing.T) { result, errs := testParseDeclarations("pub attachment E for S: I {} ") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.AttachmentDeclaration{ Access: ast.AccessAll, @@ -2963,7 +2963,7 @@ func TestParseAttachmentDeclaration(t *testing.T) { result, errs := testParseDeclarations("pub attachment E for S: I1, I2 {} ") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.AttachmentDeclaration{ Access: ast.AccessAll, @@ -3018,7 +3018,7 @@ func TestParseAttachmentDeclaration(t *testing.T) { }`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.AttachmentDeclaration{ Access: ast.AccessAll, @@ -3162,7 +3162,7 @@ func TestParseInterfaceDeclaration(t *testing.T) { result, errs := testParseDeclarations(" pub struct interface S { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.InterfaceDeclaration{ Access: ast.AccessAll, @@ -3187,7 +3187,7 @@ func TestParseInterfaceDeclaration(t *testing.T) { t.Parallel() result, errs := testParseDeclarations(" pub struct interface interface { }") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected interface name, got keyword \"interface\"", @@ -3199,7 +3199,7 @@ func TestParseInterfaceDeclaration(t *testing.T) { var expected []ast.Declaration - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, expected, result, ) @@ -3225,7 +3225,7 @@ func TestParseInterfaceDeclaration(t *testing.T) { require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.InterfaceDeclaration{ Access: ast.AccessNotSpecified, @@ -3400,7 +3400,7 @@ func TestParseEnumDeclaration(t *testing.T) { result, errs := testParseDeclarations(" pub enum E { case c ; pub case d }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessAll, @@ -3450,7 +3450,7 @@ func TestParseEnumDeclaration(t *testing.T) { StaticModifierEnabled: true, }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier for enum case", @@ -3484,7 +3484,7 @@ func TestParseEnumDeclaration(t *testing.T) { NativeModifierEnabled: true, }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid native modifier for enum case", @@ -3519,7 +3519,7 @@ func TestParseTransactionDeclaration(t *testing.T) { result, errs := testParseDeclarations("transaction { execute {} }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.TransactionDeclaration{ Execute: &ast.SpecialFunctionDeclaration{ @@ -3559,7 +3559,7 @@ func TestParseTransactionDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.TransactionDeclaration{ Fields: nil, @@ -3595,7 +3595,7 @@ func TestParseTransactionDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.TransactionDeclaration{ Fields: []*ast.FieldDeclaration{ @@ -3788,7 +3788,7 @@ func TestParseTransactionDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.TransactionDeclaration{ Fields: []*ast.FieldDeclaration{ @@ -4027,7 +4027,7 @@ func TestParseTransactionDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.TransactionDeclaration{ Fields: []*ast.FieldDeclaration{ @@ -4250,7 +4250,7 @@ func TestParseFunctionAndBlock(t *testing.T) { `) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -4296,7 +4296,7 @@ func TestParseFunctionParameterWithoutLabel(t *testing.T) { `) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -4354,7 +4354,7 @@ func TestParseFunctionParameterWithLabel(t *testing.T) { `) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -4423,7 +4423,7 @@ func TestParseStructure(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -4603,7 +4603,7 @@ func TestParseStructureWithConformances(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -4674,7 +4674,7 @@ func TestParsePreAndPostConditions(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -4824,7 +4824,7 @@ func TestParseConditionMessage(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -5045,7 +5045,7 @@ func TestParseInterface(t *testing.T) { }, } - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{test}, actual.Declarations(), ) @@ -5063,7 +5063,7 @@ func TestParsePragmaNoArguments(t *testing.T) { result, errs := testParseDeclarations(`#pedantic`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.PragmaDeclaration{ Expression: &ast.IdentifierExpression{ @@ -5093,7 +5093,7 @@ func TestParsePragmaNoArguments(t *testing.T) { StaticModifierEnabled: true, }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier for pragma", @@ -5109,7 +5109,7 @@ func TestParsePragmaNoArguments(t *testing.T) { t.Parallel() _, errs := testParseDeclarations("static #foo") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -5131,7 +5131,7 @@ func TestParsePragmaNoArguments(t *testing.T) { NativeModifierEnabled: true, }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid native modifier for pragma", @@ -5147,7 +5147,7 @@ func TestParsePragmaNoArguments(t *testing.T) { t.Parallel() _, errs := testParseDeclarations("native #foo") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -5167,7 +5167,7 @@ func TestParsePragmaArguments(t *testing.T) { actual, err := testParseProgram(code) require.NoError(t, err) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.PragmaDeclaration{ Expression: &ast.InvocationExpression{ @@ -5212,7 +5212,7 @@ func TestParseImportWithString(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.ImportDeclaration{ Identifiers: nil, @@ -5238,7 +5238,7 @@ func TestParseImportWithAddress(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.ImportDeclaration{ Identifiers: nil, @@ -5266,7 +5266,7 @@ func TestParseImportWithIdentifiers(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.ImportDeclaration{ Identifiers: []ast.Identifier{ @@ -5305,7 +5305,7 @@ func TestParseFieldWithFromIdentifier(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -5370,7 +5370,7 @@ func TestParseImportWithFromIdentifier(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.ImportDeclaration{ Identifiers: []ast.Identifier{ @@ -5415,7 +5415,7 @@ func TestParseResource(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -5445,7 +5445,7 @@ func TestParseEventDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -5531,7 +5531,7 @@ func TestParseEventEmitStatement(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -5617,7 +5617,7 @@ func TestParseResourceReturnType(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -5666,7 +5666,7 @@ func TestParseMovingVariableDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5702,7 +5702,7 @@ func TestParseResourceParameterType(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -5761,7 +5761,7 @@ func TestParseMovingVariableDeclarationWithTypeAnnotation(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5807,7 +5807,7 @@ func TestParseFieldDeclarationWithMoveTypeAnnotation(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -5864,7 +5864,7 @@ func TestParseDestructor(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -5922,7 +5922,7 @@ func TestParseCompositeDeclarationWithSemicolonSeparatedMembers(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -6136,7 +6136,7 @@ func TestParsePreconditionWithUnaryNegation(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -6215,7 +6215,7 @@ func TestParseInvalidAccessModifiers(t *testing.T) { t.Parallel() _, errs := testParseDeclarations("pub #test") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid access modifier for pragma", @@ -6231,7 +6231,7 @@ func TestParseInvalidAccessModifiers(t *testing.T) { t.Parallel() _, errs := testParseDeclarations("pub transaction {}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid access modifier for transaction", @@ -6247,7 +6247,7 @@ func TestParseInvalidAccessModifiers(t *testing.T) { t.Parallel() _, errs := testParseDeclarations("pub priv let x = 1") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid second access modifier", @@ -6277,7 +6277,7 @@ func TestParseInvalidImportWithModifier(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier for import", @@ -6296,7 +6296,7 @@ func TestParseInvalidImportWithModifier(t *testing.T) { static import x from 0x1 `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -6321,7 +6321,7 @@ func TestParseInvalidImportWithModifier(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid native modifier for import", @@ -6340,7 +6340,7 @@ func TestParseInvalidImportWithModifier(t *testing.T) { native import x from 0x1 `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -6370,7 +6370,7 @@ func TestParseInvalidEventWithModifier(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier for event", @@ -6389,7 +6389,7 @@ func TestParseInvalidEventWithModifier(t *testing.T) { static event Foo() `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -6414,7 +6414,7 @@ func TestParseInvalidEventWithModifier(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid native modifier for event", @@ -6433,7 +6433,7 @@ func TestParseInvalidEventWithModifier(t *testing.T) { native event Foo() `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -6464,7 +6464,7 @@ func TestParseCompositeWithModifier(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier for structure", @@ -6483,7 +6483,7 @@ func TestParseCompositeWithModifier(t *testing.T) { static struct Foo() `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -6508,7 +6508,7 @@ func TestParseCompositeWithModifier(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid native modifier for structure", @@ -6527,7 +6527,7 @@ func TestParseCompositeWithModifier(t *testing.T) { native struct Foo() `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -6557,7 +6557,7 @@ func TestParseTransactionWithModifier(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier for transaction", @@ -6576,7 +6576,7 @@ func TestParseTransactionWithModifier(t *testing.T) { static transaction {} `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -6601,7 +6601,7 @@ func TestParseTransactionWithModifier(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid native modifier for transaction", @@ -6620,7 +6620,7 @@ func TestParseTransactionWithModifier(t *testing.T) { native transaction {} `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -6661,7 +6661,7 @@ func TestParseNestedPragma(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid native modifier for pragma", @@ -6678,7 +6678,7 @@ func TestParseNestedPragma(t *testing.T) { _, errs := parse("native #pragma", Config{}) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -6699,7 +6699,7 @@ func TestParseNestedPragma(t *testing.T) { StaticModifierEnabled: true, }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier for pragma", @@ -6719,7 +6719,7 @@ func TestParseNestedPragma(t *testing.T) { Config{}, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -6741,7 +6741,7 @@ func TestParseNestedPragma(t *testing.T) { NativeModifierEnabled: true, }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier for pragma", @@ -6761,7 +6761,7 @@ func TestParseNestedPragma(t *testing.T) { // For now, leading unknown identifiers are valid. // This will be rejected in Stable Cadence. - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected identifier", @@ -6784,7 +6784,7 @@ func TestParseNestedPragma(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier after native modifier", @@ -6801,7 +6801,7 @@ func TestParseNestedPragma(t *testing.T) { _, errs := parse("pub #pragma", Config{}) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid access modifier for pragma", @@ -6823,7 +6823,7 @@ func TestParseNestedPragma(t *testing.T) { NativeModifierEnabled: true, }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid access modifier for pragma", @@ -6843,7 +6843,7 @@ func TestParseNestedPragma(t *testing.T) { // For now, leading unknown identifiers are valid. // This will be rejected in Stable Cadence. - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected identifier", @@ -6880,7 +6880,7 @@ func TestParseMemberDocStrings(t *testing.T) { require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -6996,7 +6996,7 @@ func TestParseMemberDocStrings(t *testing.T) { require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -7093,7 +7093,7 @@ func TestParseInvalidSpecialFunctionReturnTypeAnnotation(t *testing.T) { init(): Int } `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid return type for initializer", diff --git a/old_parser/expression_test.go b/old_parser/expression_test.go index c90f4702cf..a91ad7d4dc 100644 --- a/old_parser/expression_test.go +++ b/old_parser/expression_test.go @@ -34,7 +34,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/errors" "github.com/onflow/cadence/parser/lexer" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestParseSimpleInfixExpression(t *testing.T) { @@ -48,7 +48,7 @@ func TestParseSimpleInfixExpression(t *testing.T) { result, errs := testParseExpression("1+2*3") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationPlus, Left: &ast.IntegerExpression{ @@ -93,7 +93,7 @@ func TestParseSimpleInfixExpression(t *testing.T) { result, errs := testParseExpression(" 1 + 2 * 3 ") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationPlus, Left: &ast.IntegerExpression{ @@ -138,7 +138,7 @@ func TestParseSimpleInfixExpression(t *testing.T) { result, errs := testParseExpression("1 + 2 + 3") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationPlus, Left: &ast.BinaryExpression{ @@ -183,7 +183,7 @@ func TestParseSimpleInfixExpression(t *testing.T) { result, errs := testParseExpression("1 ?? 2 ?? 3") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationNilCoalesce, Left: &ast.IntegerExpression{ @@ -233,7 +233,7 @@ func TestParseAdvancedExpression(t *testing.T) { result, errs := testParseExpression("1 +- 2 -- 3") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationMinus, Left: &ast.BinaryExpression{ @@ -278,7 +278,7 @@ func TestParseAdvancedExpression(t *testing.T) { result, errs := testParseExpression("(1 + 2) * 3") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationMul, Left: &ast.BinaryExpression{ @@ -369,7 +369,7 @@ func TestParseAdvancedExpression(t *testing.T) { result, errs := testParseExpression("1 < 2 > 3") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationGreater, Left: &ast.BinaryExpression{ @@ -414,7 +414,7 @@ func TestParseAdvancedExpression(t *testing.T) { result, errs := testParseExpression("a ? b : c ? d : e") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ConditionalExpression{ Test: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -460,7 +460,7 @@ func TestParseAdvancedExpression(t *testing.T) { result, errs := testParseExpression("true + false") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationPlus, Left: &ast.BoolExpression{ @@ -489,7 +489,7 @@ func TestParseAdvancedExpression(t *testing.T) { result, errs := testParseExpression("(<-x)") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.UnaryExpression{ Operation: ast.OperationMove, Expression: &ast.IdentifierExpression{ @@ -517,7 +517,7 @@ func TestParseArrayExpression(t *testing.T) { result, errs := testParseExpression("[ 1,2 + 3, 4 , 5 ]") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ArrayExpression{ Values: []ast.Expression{ &ast.IntegerExpression{ @@ -585,7 +585,7 @@ func TestParseArrayExpression(t *testing.T) { result, errs := testParseExpression("[ 1 , \n 2 \n , \n\n 3 \n\n\n]") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ArrayExpression{ Values: []ast.Expression{ &ast.IntegerExpression{ @@ -632,7 +632,7 @@ func TestParseArrayExpression(t *testing.T) { result, errs := testParseExpression("[\n]") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ArrayExpression{ Range: ast.Range{ StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, @@ -656,7 +656,7 @@ func TestParseDictionaryExpression(t *testing.T) { result, errs := testParseExpression("{ 1:2 + 3, 4 : 5 }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.DictionaryExpression{ Entries: []ast.DictionaryEntry{ { @@ -728,7 +728,7 @@ func TestParseDictionaryExpression(t *testing.T) { result, errs := testParseExpression("{ 1 : 2 , \n 3 \n : \n 4 \n , \n\n 5 \n\n : \n\n 6 \n\n }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.DictionaryExpression{ Entries: []ast.DictionaryEntry{ { @@ -808,7 +808,7 @@ func TestParseDictionaryExpression(t *testing.T) { result, errs := testParseExpression("{\n}") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.DictionaryExpression{ Range: ast.Range{ StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, @@ -829,7 +829,7 @@ func TestParseIndexExpression(t *testing.T) { result, errs := testParseExpression("a[0]") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IndexExpression{ TargetExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -861,7 +861,7 @@ func TestParseIndexExpression(t *testing.T) { result, errs := testParseExpression("a [ 0 ]") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IndexExpression{ TargetExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -893,7 +893,7 @@ func TestParseIndexExpression(t *testing.T) { result, errs := testParseExpression("a [foo]") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IndexExpression{ TargetExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -928,7 +928,7 @@ func TestParseIdentifier(t *testing.T) { result, errs := testParseExpression("a + 3") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationPlus, Left: &ast.IdentifierExpression{ @@ -959,7 +959,7 @@ func TestParsePath(t *testing.T) { result, errs := testParseExpression("/foo/bar") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.PathExpression{ Domain: ast.Identifier{ Identifier: "foo", @@ -986,7 +986,7 @@ func TestParseString(t *testing.T) { result, errs := testParseExpression("\"\"") assert.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "", Range: ast.Range{ @@ -1003,7 +1003,7 @@ func TestParseString(t *testing.T) { t.Parallel() result, errs := testParseExpression("\"") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid end of string literal: missing '\"'", @@ -1013,7 +1013,7 @@ func TestParseString(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "", Range: ast.Range{ @@ -1030,7 +1030,7 @@ func TestParseString(t *testing.T) { t.Parallel() result, errs := testParseExpression("\"\n") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid end of string literal: missing '\"'", @@ -1040,7 +1040,7 @@ func TestParseString(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "", Range: ast.Range{ @@ -1056,7 +1056,7 @@ func TestParseString(t *testing.T) { t.Parallel() result, errs := testParseExpression("\"t") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid end of string literal: missing '\"'", @@ -1066,7 +1066,7 @@ func TestParseString(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "t", Range: ast.Range{ @@ -1083,7 +1083,7 @@ func TestParseString(t *testing.T) { t.Parallel() result, errs := testParseExpression("\"t\n") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid end of string literal: missing '\"'", @@ -1093,7 +1093,7 @@ func TestParseString(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "t", Range: ast.Range{ @@ -1110,7 +1110,7 @@ func TestParseString(t *testing.T) { t.Parallel() result, errs := testParseExpression("\"\\") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "incomplete escape sequence: missing character after escape character", @@ -1124,7 +1124,7 @@ func TestParseString(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "", Range: ast.Range{ @@ -1143,7 +1143,7 @@ func TestParseString(t *testing.T) { result, errs := testParseExpression(`"te\tst\"te\u{1F3CE}\u{FE0F}xt"`) assert.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "te\tst\"te\U0001F3CE\uFE0Fxt", Range: ast.Range{ @@ -1160,7 +1160,7 @@ func TestParseString(t *testing.T) { t.Parallel() result, errs := testParseExpression(`"te\Xst"`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid escape character: 'X'", @@ -1170,7 +1170,7 @@ func TestParseString(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "test", Range: ast.Range{ @@ -1187,7 +1187,7 @@ func TestParseString(t *testing.T) { t.Parallel() result, errs := testParseExpression(`"te\u`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "incomplete Unicode escape sequence: missing character '{' after escape character", @@ -1201,7 +1201,7 @@ func TestParseString(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "te", Range: ast.Range{ @@ -1218,7 +1218,7 @@ func TestParseString(t *testing.T) { t.Parallel() result, errs := testParseExpression(`"te\us`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid Unicode escape sequence: expected '{', got 's'", @@ -1232,7 +1232,7 @@ func TestParseString(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "te", Range: ast.Range{ @@ -1249,7 +1249,7 @@ func TestParseString(t *testing.T) { t.Parallel() result, errs := testParseExpression(`"te\u{`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "incomplete Unicode escape sequence: missing character '}' after escape character", @@ -1263,7 +1263,7 @@ func TestParseString(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "te", Range: ast.Range{ @@ -1282,7 +1282,7 @@ func TestParseString(t *testing.T) { result, errs := testParseExpression(`"te\u{}"`) assert.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "te", Range: ast.Range{ @@ -1309,7 +1309,7 @@ func TestParseString(t *testing.T) { ) assert.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "test JJJJ KKKK LLLL MMMM NNNN OOOO", Range: ast.Range{ @@ -1326,7 +1326,7 @@ func TestParseString(t *testing.T) { t.Parallel() result, errs := testParseExpression(`"te\u{X}st"`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid Unicode escape sequence: expected hex digit, got 'X'", @@ -1336,7 +1336,7 @@ func TestParseString(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "test", Range: ast.Range{ @@ -1360,7 +1360,7 @@ func TestParseInvocation(t *testing.T) { result, errs := testParseExpression("f()") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1383,7 +1383,7 @@ func TestParseInvocation(t *testing.T) { result, errs := testParseExpression("f ()") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1406,7 +1406,7 @@ func TestParseInvocation(t *testing.T) { result, errs := testParseExpression("f ( )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1429,7 +1429,7 @@ func TestParseInvocation(t *testing.T) { result, errs := testParseExpression("f(1)") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1466,7 +1466,7 @@ func TestParseInvocation(t *testing.T) { result, errs := testParseExpression("f(label:1)") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1505,7 +1505,7 @@ func TestParseInvocation(t *testing.T) { result, errs := testParseExpression("f(1,2)") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1555,7 +1555,7 @@ func TestParseInvocation(t *testing.T) { result, errs := testParseExpression("f(a:1,b:2)") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1607,7 +1607,7 @@ func TestParseInvocation(t *testing.T) { t.Parallel() _, errs := testParseExpression("f(,,)") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected argument or end of argument list, got ','", @@ -1623,7 +1623,7 @@ func TestParseInvocation(t *testing.T) { t.Parallel() _, errs := testParseExpression("f(1,,)") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected argument or end of argument list, got ','", @@ -1639,7 +1639,7 @@ func TestParseInvocation(t *testing.T) { t.Parallel() _, errs := testParseExpression("f(1 2)") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected argument in argument list (expecting delimiter or end of argument list)," + @@ -1658,7 +1658,7 @@ func TestParseInvocation(t *testing.T) { result, errs := testParseExpression("f(1,g(2))") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1724,7 +1724,7 @@ func TestParseInvocation(t *testing.T) { result, errs := testParseExpression("f(1,g(\"test\"))") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1793,7 +1793,7 @@ func TestParseMemberExpression(t *testing.T) { result, errs := testParseExpression("f.n") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.MemberExpression{ Expression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1818,7 +1818,7 @@ func TestParseMemberExpression(t *testing.T) { result, errs := testParseExpression("f .n") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.MemberExpression{ Expression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1841,7 +1841,7 @@ func TestParseMemberExpression(t *testing.T) { t.Parallel() result, errs := testParseExpression("f.") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected member name, got EOF", @@ -1851,7 +1851,7 @@ func TestParseMemberExpression(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.MemberExpression{ Expression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1872,7 +1872,7 @@ func TestParseMemberExpression(t *testing.T) { result, errs := testParseExpression("f.n * 3") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationMul, Left: &ast.MemberExpression{ @@ -1909,7 +1909,7 @@ func TestParseMemberExpression(t *testing.T) { result, errs := testParseExpression("3 * f.n") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationMul, Left: &ast.IntegerExpression{ @@ -1946,7 +1946,7 @@ func TestParseMemberExpression(t *testing.T) { result, errs := testParseExpression("f?.n") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.MemberExpression{ Optional: true, Expression: &ast.IdentifierExpression{ @@ -1975,7 +1975,7 @@ func TestParseMemberExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2020,7 +2020,7 @@ func TestParseBlockComment(t *testing.T) { result, errs := testParseExpression(" /* test foo/* bar */ asd*/ true") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BoolExpression{ Value: true, Range: ast.Range{ @@ -2039,7 +2039,7 @@ func TestParseBlockComment(t *testing.T) { result, errs := testParseExpression(" /*test foo*/ /* bar */ true") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BoolExpression{ Value: true, Range: ast.Range{ @@ -2058,7 +2058,7 @@ func TestParseBlockComment(t *testing.T) { result, errs := testParseExpression(" 1/*test foo*/+/* bar */ 2 ") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationPlus, Left: &ast.IntegerExpression{ @@ -2089,7 +2089,7 @@ func TestParseBlockComment(t *testing.T) { t.Parallel() _, errs := testParseExpression(" /* test foo/* bar */ asd*/ true */ bar") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ // `true */ bar` is parsed as infix operation of path &SyntaxError{ @@ -2110,7 +2110,7 @@ func TestParseBlockComment(t *testing.T) { t.Parallel() _, errs := testParseExpression(" /* test foo/* bar */ asd true ") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ // `true */ bar` is parsed as infix operation of path &SyntaxError{ @@ -2185,7 +2185,7 @@ func TestParseBlockComment(t *testing.T) { }, Config{}, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token identifier in block comment", @@ -2244,7 +2244,7 @@ func TestParseReference(t *testing.T) { result, errs := testParseExpression("& t as T") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ReferenceExpression{ Expression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -2265,7 +2265,7 @@ func TestParseReference(t *testing.T) { const code = `&y[z]` _, errs := testParseExpression(code) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected casting expression", @@ -2287,7 +2287,7 @@ func TestParseReference(t *testing.T) { const code = `&x[y]? as &Z?` _, errs := testParseExpression(code) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected casting expression", @@ -2312,7 +2312,7 @@ func TestParseNilCoelesceReference(t *testing.T) { `) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationNilCoalesce, Left: &ast.ReferenceExpression{ @@ -2394,7 +2394,7 @@ func TestParseCasts(t *testing.T) { result, errs := testParseExpression(" t as T") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.CastingExpression{ Operation: ast.OperationCast, Expression: &ast.IdentifierExpression{ @@ -2424,7 +2424,7 @@ func TestParseCasts(t *testing.T) { result, errs := testParseExpression(" t as? T") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.CastingExpression{ Operation: ast.OperationFailableCast, Expression: &ast.IdentifierExpression{ @@ -2455,7 +2455,7 @@ func TestParseCasts(t *testing.T) { result, errs := testParseExpression(" t as! T") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.CastingExpression{ Operation: ast.OperationForceCast, Expression: &ast.IdentifierExpression{ @@ -2490,7 +2490,7 @@ func TestParseForceExpression(t *testing.T) { result, errs := testParseExpression("t!") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ForceExpression{ Expression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -2511,7 +2511,7 @@ func TestParseForceExpression(t *testing.T) { result, errs := testParseExpression(" t ! ") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ForceExpression{ Expression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -2532,7 +2532,7 @@ func TestParseForceExpression(t *testing.T) { result, errs := testParseExpression("<-t!") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.UnaryExpression{ Operation: ast.OperationMove, Expression: &ast.ForceExpression{ @@ -2557,7 +2557,7 @@ func TestParseForceExpression(t *testing.T) { result, errs := testParseExpression("10 * t!") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationMul, Left: &ast.IntegerExpression{ @@ -2589,7 +2589,7 @@ func TestParseForceExpression(t *testing.T) { result, errs := testParseStatements("x\n!y") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ExpressionStatement{ Expression: &ast.IdentifierExpression{ @@ -2623,7 +2623,7 @@ func TestParseForceExpression(t *testing.T) { result, errs := testParseStatements("x\n.y!") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ExpressionStatement{ Expression: &ast.ForceExpression{ @@ -2653,7 +2653,7 @@ func TestParseForceExpression(t *testing.T) { t.Parallel() result, errs := testParseStatements("x. y") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid whitespace after '.'", @@ -2663,7 +2663,7 @@ func TestParseForceExpression(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ExpressionStatement{ Expression: &ast.MemberExpression{ @@ -2697,7 +2697,7 @@ func TestParseCreate(t *testing.T) { result, errs := testParseExpression("create T()") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.CreateExpression{ InvocationExpression: &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ @@ -2723,7 +2723,7 @@ func TestParseNil(t *testing.T) { result, errs := testParseExpression(" nil") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.NilExpression{ Pos: ast.Position{Line: 1, Column: 1, Offset: 1}, }, @@ -2742,7 +2742,7 @@ func TestParseDestroy(t *testing.T) { result, errs := testParseExpression("destroy t") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.DestroyExpression{ Expression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -2768,7 +2768,7 @@ func TestParseAttach(t *testing.T) { result, errs := testParseExpression("attach E() to r") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.AttachExpression{ Base: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -2797,7 +2797,7 @@ func TestParseAttach(t *testing.T) { t.Parallel() _, errs := testParseExpression("attach A to E") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token '('", @@ -2815,7 +2815,7 @@ func TestParseAttach(t *testing.T) { result, errs := testParseExpression("attach A() to attach B() to r") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.AttachExpression{ Base: &ast.AttachExpression{ Base: &ast.IdentifierExpression{ @@ -2857,7 +2857,7 @@ func TestParseAttach(t *testing.T) { t.Parallel() _, errs := testParseExpression("attach A()") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected 'to', got EOF", @@ -2873,7 +2873,7 @@ func TestParseAttach(t *testing.T) { t.Parallel() _, errs := testParseExpression("attach E() to") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected end of program", @@ -2892,7 +2892,7 @@ func TestParseLineComment(t *testing.T) { result, errs := testParseExpression(" //// // this is a comment\n 1 / 2") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationDiv, Left: &ast.IntegerExpression{ @@ -2929,7 +2929,7 @@ func TestParseFunctionExpression(t *testing.T) { result, errs := testParseExpression("fun () { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FunctionExpression{ ParameterList: &ast.ParameterList{ Parameters: nil, @@ -2959,7 +2959,7 @@ func TestParseFunctionExpression(t *testing.T) { result, errs := testParseExpression("fun (): X { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FunctionExpression{ ParameterList: &ast.ParameterList{ Parameters: nil, @@ -3001,7 +3001,7 @@ func TestParseIntegerLiterals(t *testing.T) { t.Parallel() result, errs := testParseExpression(`0b`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "missing digits", @@ -3020,7 +3020,7 @@ func TestParseIntegerLiterals(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0b"), Value: new(big.Int), @@ -3041,7 +3041,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`0b101010`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0b101010"), Value: big.NewInt(42), @@ -3060,7 +3060,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`0b001000`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0b001000"), Value: big.NewInt(8), @@ -3081,7 +3081,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`0b101010_101010`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0b101010_101010"), Value: big.NewInt(2730), @@ -3100,7 +3100,7 @@ func TestParseIntegerLiterals(t *testing.T) { t.Parallel() result, errs := testParseExpression(`0b_101010_101010`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &InvalidIntegerLiteralError{ Literal: "0b_101010_101010", @@ -3115,7 +3115,7 @@ func TestParseIntegerLiterals(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0b_101010_101010"), Value: big.NewInt(2730), @@ -3134,7 +3134,7 @@ func TestParseIntegerLiterals(t *testing.T) { t.Parallel() result, errs := testParseExpression(`0b101010_101010_`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &InvalidIntegerLiteralError{ Literal: "0b101010_101010_", @@ -3149,7 +3149,7 @@ func TestParseIntegerLiterals(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0b101010_101010_"), Value: big.NewInt(2730), @@ -3168,7 +3168,7 @@ func TestParseIntegerLiterals(t *testing.T) { t.Parallel() result, errs := testParseExpression(`0o`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "missing digits", @@ -3187,7 +3187,7 @@ func TestParseIntegerLiterals(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0o"), Value: new(big.Int), @@ -3208,7 +3208,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`0o32`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0o32"), Value: big.NewInt(26), @@ -3229,7 +3229,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`0o32_45`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0o32_45"), Value: big.NewInt(1701), @@ -3248,7 +3248,7 @@ func TestParseIntegerLiterals(t *testing.T) { t.Parallel() result, errs := testParseExpression(`0o_32_45`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &InvalidIntegerLiteralError{ Literal: "0o_32_45", @@ -3263,7 +3263,7 @@ func TestParseIntegerLiterals(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0o_32_45"), Value: big.NewInt(1701), @@ -3282,7 +3282,7 @@ func TestParseIntegerLiterals(t *testing.T) { t.Parallel() result, errs := testParseExpression(`0o32_45_`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &InvalidIntegerLiteralError{ Literal: "0o32_45_", @@ -3297,7 +3297,7 @@ func TestParseIntegerLiterals(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0o32_45_"), Value: big.NewInt(1701), @@ -3318,7 +3318,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`1234567890`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("1234567890"), Value: big.NewInt(1234567890), @@ -3339,7 +3339,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`1_234_567_890`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("1_234_567_890"), Value: big.NewInt(1234567890), @@ -3358,7 +3358,7 @@ func TestParseIntegerLiterals(t *testing.T) { t.Parallel() result, errs := testParseExpression(`1_234_567_890_`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &InvalidIntegerLiteralError{ Literal: "1_234_567_890_", @@ -3373,7 +3373,7 @@ func TestParseIntegerLiterals(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("1_234_567_890_"), Value: big.NewInt(1234567890), @@ -3392,7 +3392,7 @@ func TestParseIntegerLiterals(t *testing.T) { t.Parallel() result, errs := testParseExpression(`0x`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "missing digits", @@ -3411,7 +3411,7 @@ func TestParseIntegerLiterals(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0x"), Value: new(big.Int), @@ -3432,7 +3432,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`0xf2`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0xf2"), Value: big.NewInt(242), @@ -3453,7 +3453,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`0xf2_09`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0xf2_09"), Value: big.NewInt(61961), @@ -3472,7 +3472,7 @@ func TestParseIntegerLiterals(t *testing.T) { t.Parallel() result, errs := testParseExpression(`0x_f2_09`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &InvalidIntegerLiteralError{ Literal: "0x_f2_09", @@ -3487,7 +3487,7 @@ func TestParseIntegerLiterals(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0x_f2_09"), Value: big.NewInt(61961), @@ -3506,7 +3506,7 @@ func TestParseIntegerLiterals(t *testing.T) { t.Parallel() result, errs := testParseExpression(`0xf2_09_`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &InvalidIntegerLiteralError{ Literal: `0xf2_09_`, @@ -3521,7 +3521,7 @@ func TestParseIntegerLiterals(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0xf2_09_"), Value: big.NewInt(61961), @@ -3542,7 +3542,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`0`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0"), Value: big.NewInt(0), @@ -3563,7 +3563,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`01`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("01"), Value: big.NewInt(1), @@ -3584,7 +3584,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`09`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("09"), Value: big.NewInt(9), @@ -3605,7 +3605,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression("00123") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("00123"), Value: big.NewInt(123), @@ -3624,7 +3624,7 @@ func TestParseIntegerLiterals(t *testing.T) { t.Parallel() result, errs := testParseExpression(`0z123`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid number literal prefix: 'z'", @@ -3643,7 +3643,7 @@ func TestParseIntegerLiterals(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0z123"), Value: new(big.Int), @@ -3664,7 +3664,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`0_100`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0_100"), Value: big.NewInt(100), @@ -3685,7 +3685,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`1_100`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("1_100"), Value: big.NewInt(1100), @@ -3708,7 +3708,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`_100`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IdentifierExpression{ Identifier: ast.Identifier{ Identifier: "_100", @@ -3731,7 +3731,7 @@ func TestParseFixedPoint(t *testing.T) { result, errs := testParseExpression("1234_5678_90.0009_8765_4321") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FixedPointExpression{ PositiveLiteral: []byte("1234_5678_90.0009_8765_4321"), Negative: false, @@ -3754,7 +3754,7 @@ func TestParseFixedPoint(t *testing.T) { result, errs := testParseExpression("0.1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FixedPointExpression{ PositiveLiteral: []byte("0.1"), Negative: false, @@ -3775,7 +3775,7 @@ func TestParseFixedPoint(t *testing.T) { t.Parallel() result, errs := testParseExpression("0.") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "missing fractional digits", @@ -3785,7 +3785,7 @@ func TestParseFixedPoint(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FixedPointExpression{ PositiveLiteral: []byte("0."), Negative: false, @@ -3813,7 +3813,7 @@ func TestParseLessThanOrTypeArguments(t *testing.T) { result, errs := testParseExpression("1 < 2") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationLess, Left: &ast.IntegerExpression{ @@ -3846,7 +3846,7 @@ func TestParseLessThanOrTypeArguments(t *testing.T) { result, errs := testParseExpression("a < > ()") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -3870,7 +3870,7 @@ func TestParseLessThanOrTypeArguments(t *testing.T) { result, errs := testParseExpression("a < { K : V } > ( 1 )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -3930,7 +3930,7 @@ func TestParseLessThanOrTypeArguments(t *testing.T) { result, errs := testParseExpression("a < { K : V } , @R , [ S ] > ( 1 , 2 )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -4028,7 +4028,7 @@ func TestParseLessThanOrTypeArguments(t *testing.T) { result, errs := testParseExpression("1 + a<>()") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationPlus, Left: &ast.IntegerExpression{ @@ -4064,7 +4064,7 @@ func TestParseLessThanOrTypeArguments(t *testing.T) { result, errs := testParseExpression("a>()") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -4114,7 +4114,7 @@ func TestParseLessThanOrTypeArguments(t *testing.T) { result, errs := testParseExpression("a >()") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -4164,7 +4164,7 @@ func TestParseLessThanOrTypeArguments(t *testing.T) { result, errs := testParseExpression("0 + 1 < 2") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationLess, Left: &ast.BinaryExpression{ @@ -4209,7 +4209,7 @@ func TestParseLessThanOrTypeArguments(t *testing.T) { result, errs := testParseExpression("0 + 1 << 2") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationBitwiseLeftShift, Left: &ast.BinaryExpression{ @@ -4254,7 +4254,7 @@ func TestParseLessThanOrTypeArguments(t *testing.T) { result, errs := testParseExpression("0 + 1 > 2") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationGreater, Left: &ast.BinaryExpression{ @@ -4299,7 +4299,7 @@ func TestParseLessThanOrTypeArguments(t *testing.T) { result, errs := testParseExpression("0 + 1 >> 2") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationBitwiseRightShift, Left: &ast.BinaryExpression{ @@ -4348,7 +4348,7 @@ func TestParseBoolExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -4385,7 +4385,7 @@ func TestParseIdentifierExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -4421,7 +4421,7 @@ func TestParseArrayExpressionInVariableDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -4476,7 +4476,7 @@ func TestParseDictionaryExpressionInVariableDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -4549,7 +4549,7 @@ func TestParseInvocationExpressionWithoutLabels(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -4617,7 +4617,7 @@ func TestParseInvocationExpressionWithLabels(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -4704,7 +4704,7 @@ func TestParseOptionalMemberExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -4748,7 +4748,7 @@ func TestParseIndexExpressionInVariableDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -4799,7 +4799,7 @@ func TestParseUnaryExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -4839,7 +4839,7 @@ func TestParseOrExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -4886,7 +4886,7 @@ func TestParseAndExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -4933,7 +4933,7 @@ func TestParseEqualityExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -4980,7 +4980,7 @@ func TestParseRelationalExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5031,7 +5031,7 @@ func TestParseAdditiveExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5082,7 +5082,7 @@ func TestParseMultiplicativeExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5133,7 +5133,7 @@ func TestParseFunctionExpressionAndReturn(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5207,7 +5207,7 @@ func TestParseLeftAssociativity(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5270,7 +5270,7 @@ func TestParseNegativeInteger(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5309,7 +5309,7 @@ func TestParseNegativeFixedPoint(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5352,7 +5352,7 @@ func TestParseTernaryRightAssociativity(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5455,7 +5455,7 @@ func TestParseVoidLiteral(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5501,7 +5501,7 @@ func TestParseMissingReturnType(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5643,7 +5643,7 @@ func TestParseExpression(t *testing.T) { }, } - utils.AssertEqualWithDiff(t, expected, actual) + AssertEqualWithDiff(t, expected, actual) } func TestParseStringEscapes(t *testing.T) { @@ -5671,7 +5671,7 @@ func TestParseStringEscapes(t *testing.T) { }, } - utils.AssertEqualWithDiff(t, expected, actual) + AssertEqualWithDiff(t, expected, actual) } func TestParseStringWithUnicode(t *testing.T) { @@ -5699,7 +5699,7 @@ func TestParseStringWithUnicode(t *testing.T) { }, } - utils.AssertEqualWithDiff(t, expected, actual) + AssertEqualWithDiff(t, expected, actual) } func TestParseNilCoalescing(t *testing.T) { @@ -5712,7 +5712,7 @@ func TestParseNilCoalescing(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5758,7 +5758,7 @@ func TestParseNilCoalescingRightAssociativity(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5861,7 +5861,7 @@ func TestParseFailableCasting(t *testing.T) { failableDowncast.ParentVariableDeclaration = variableDeclaration - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ variableDeclaration, }, @@ -5879,7 +5879,7 @@ func TestParseMoveOperator(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5937,7 +5937,7 @@ func TestParseFunctionExpressionWithResourceTypeAnnotation(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ @@ -6046,7 +6046,7 @@ func TestParseFailableCastingResourceTypeAnnotation(t *testing.T) { failableDowncast.ParentVariableDeclaration = variableDeclaration - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ variableDeclaration, }, @@ -6100,7 +6100,7 @@ func TestParseCasting(t *testing.T) { cast.ParentVariableDeclaration = variableDeclaration - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ variableDeclaration, }, @@ -6131,7 +6131,7 @@ func TestParseReferenceInVariableDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -6189,7 +6189,7 @@ func TestParseFixedPointExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -6229,7 +6229,7 @@ func TestParseFixedPointExpressionZeroInteger(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -6269,7 +6269,7 @@ func TestParsePathLiteral(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -6309,7 +6309,7 @@ func TestParseBitwiseExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, diff --git a/old_parser/lexer/lexer_test.go b/old_parser/lexer/lexer_test.go index 1e48fed700..be9ee63f08 100644 --- a/old_parser/lexer/lexer_test.go +++ b/old_parser/lexer/lexer_test.go @@ -28,7 +28,7 @@ import ( "go.uber.org/goleak" "github.com/onflow/cadence/ast" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestMain(m *testing.M) { @@ -64,7 +64,7 @@ func testLex(t *testing.T, input string, expected []token) { bytes := []byte(input) withTokens(Lex(bytes, nil), func(actualTokens []Token) { - utils.AssertEqualWithDiff(t, expectedTokens, actualTokens) + AssertEqualWithDiff(t, expectedTokens, actualTokens) require.Len(t, actualTokens, len(expectedTokens)) for i, expectedToken := range expected { diff --git a/old_parser/parser_test.go b/old_parser/parser_test.go index 156ae7c286..ecff29407f 100644 --- a/old_parser/parser_test.go +++ b/old_parser/parser_test.go @@ -33,7 +33,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/errors" "github.com/onflow/cadence/parser/lexer" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestMain(m *testing.M) { @@ -240,7 +240,7 @@ func TestParseBuffering(t *testing.T) { Config{}, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token identifier with string value c", @@ -483,7 +483,7 @@ func TestParseBuffering(t *testing.T) { Config{}, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token identifier with string value d", @@ -511,7 +511,7 @@ func TestParseBuffering(t *testing.T) { } ` _, err := testParseProgram(code) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token identifier", @@ -536,7 +536,7 @@ func TestParseBuffering(t *testing.T) { ` _, err := testParseProgram(code) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token identifier", @@ -703,7 +703,7 @@ func TestParseArgumentList(t *testing.T) { t.Parallel() _, errs := testParseArgumentList(`xyz`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token '('", @@ -722,7 +722,7 @@ func TestParseArgumentList(t *testing.T) { var expected ast.Arguments - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, expected, result, ) @@ -747,7 +747,7 @@ func TestParseArgumentList(t *testing.T) { result, errs := testParseArgumentList(`(1, b: true)`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.Arguments{ { Label: "", @@ -832,7 +832,7 @@ func TestParseBufferedErrors(t *testing.T) { // there is another error (missing closing parenthesis after). _, errs := testParseExpression("a(") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "missing type annotation after comma", @@ -871,7 +871,7 @@ func TestParseExpressionDepthLimit(t *testing.T) { _, err := testParseProgram(code) require.Error(t, err) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ ExpressionDepthLimitReachedError{ Pos: ast.Position{ @@ -907,7 +907,7 @@ func TestParseTypeDepthLimit(t *testing.T) { _, err := testParseProgram(code) require.Error(t, err) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ TypeDepthLimitReachedError{ Pos: ast.Position{ @@ -933,7 +933,7 @@ func TestParseLocalReplayLimit(t *testing.T) { code := []byte(builder.String()) _, err := ParseProgram(nil, code, Config{}) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, Error{ Code: code, Errors: []error{ @@ -968,7 +968,7 @@ func TestParseGlobalReplayLimit(t *testing.T) { code := []byte(builder.String()) _, err := ParseProgram(nil, code, Config{}) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, Error{ Code: code, Errors: []error{ diff --git a/old_parser/statement_test.go b/old_parser/statement_test.go index e22d1c2b94..ce5d17d25d 100644 --- a/old_parser/statement_test.go +++ b/old_parser/statement_test.go @@ -26,7 +26,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/ast" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestParseReplInput(t *testing.T) { @@ -63,7 +63,7 @@ func TestParseReturnStatement(t *testing.T) { result, errs := testParseStatements("return") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ReturnStatement{ Range: ast.Range{ @@ -83,7 +83,7 @@ func TestParseReturnStatement(t *testing.T) { result, errs := testParseStatements("return 1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ReturnStatement{ Expression: &ast.IntegerExpression{ @@ -112,7 +112,7 @@ func TestParseReturnStatement(t *testing.T) { result, errs := testParseStatements("return \n1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ReturnStatement{ Range: ast.Range{ @@ -143,7 +143,7 @@ func TestParseReturnStatement(t *testing.T) { result, errs := testParseStatements("return ;\n1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ReturnStatement{ Range: ast.Range{ @@ -179,7 +179,7 @@ func TestParseIfStatement(t *testing.T) { result, errs := testParseStatements("if true { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.IfStatement{ Test: &ast.BoolExpression{ @@ -210,7 +210,7 @@ func TestParseIfStatement(t *testing.T) { result, errs := testParseStatements("if true { 1 ; 2 }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.IfStatement{ Test: &ast.BoolExpression{ @@ -264,7 +264,7 @@ func TestParseIfStatement(t *testing.T) { result, errs := testParseStatements("if true { 1 \n 2 }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.IfStatement{ Test: &ast.BoolExpression{ @@ -318,7 +318,7 @@ func TestParseIfStatement(t *testing.T) { result, errs := testParseStatements("if true { 1 } else { 2 }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.IfStatement{ Test: &ast.BoolExpression{ @@ -380,7 +380,7 @@ func TestParseIfStatement(t *testing.T) { result, errs := testParseStatements("if true{1}else if true {2} else{3}") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.IfStatement{ Test: &ast.BoolExpression{ @@ -514,7 +514,7 @@ func TestParseIfStatement(t *testing.T) { expected.Test.(*ast.VariableDeclaration).ParentIfStatement = expected - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ expected, }, @@ -564,7 +564,7 @@ func TestParseIfStatement(t *testing.T) { expected.Test.(*ast.VariableDeclaration).ParentIfStatement = expected - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ expected, }, @@ -585,7 +585,7 @@ func TestParseWhileStatement(t *testing.T) { result, errs := testParseStatements("while true { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.WhileStatement{ Test: &ast.BoolExpression{ @@ -621,7 +621,7 @@ func TestParseAssignmentStatement(t *testing.T) { result, errs := testParseStatements("x=1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.AssignmentStatement{ Target: &ast.IdentifierExpression{ @@ -656,7 +656,7 @@ func TestParseAssignmentStatement(t *testing.T) { result, errs := testParseStatements(" x = 1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.AssignmentStatement{ Target: &ast.IdentifierExpression{ @@ -691,7 +691,7 @@ func TestParseAssignmentStatement(t *testing.T) { result, errs := testParseStatements(" x <- 1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.AssignmentStatement{ Target: &ast.IdentifierExpression{ @@ -726,7 +726,7 @@ func TestParseAssignmentStatement(t *testing.T) { result, errs := testParseStatements(" x <-! 1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.AssignmentStatement{ Target: &ast.IdentifierExpression{ @@ -766,7 +766,7 @@ func TestParseSwapStatement(t *testing.T) { result, errs := testParseStatements(" x <-> y") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.SwapStatement{ Left: &ast.IdentifierExpression{ @@ -799,7 +799,7 @@ func TestParseForStatement(t *testing.T) { result, errs := testParseStatements("for x in y { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ForStatement{ Identifier: ast.Identifier{ @@ -838,7 +838,7 @@ func TestParseForStatementIndexBinding(t *testing.T) { result, errs := testParseStatements("for i, x in y { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ForStatement{ Identifier: ast.Identifier{ @@ -874,7 +874,7 @@ func TestParseForStatementIndexBinding(t *testing.T) { t.Parallel() _, errs := testParseStatements("for i x in y { }") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected keyword \"in\", got identifier", @@ -894,7 +894,7 @@ func TestParseForStatementIndexBinding(t *testing.T) { t.Parallel() _, errs := testParseStatements("for in y { }") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected identifier, got keyword \"in\"", @@ -921,7 +921,7 @@ func TestParseEmit(t *testing.T) { result, errs := testParseStatements("emit T()") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.EmitStatement{ InvocationExpression: &ast.InvocationExpression{ @@ -953,7 +953,7 @@ func TestParseFunctionStatementOrExpression(t *testing.T) { result, errs := testParseStatements("fun foo() {}") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -989,7 +989,7 @@ func TestParseFunctionStatementOrExpression(t *testing.T) { result, errs := testParseStatements("fun () {}") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ExpressionStatement{ Expression: &ast.FunctionExpression{ @@ -1027,7 +1027,7 @@ func TestParseStatements(t *testing.T) { result, errs := testParseStatements("a + b < c\nd") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ExpressionStatement{ Expression: &ast.BinaryExpression{ @@ -1073,7 +1073,7 @@ func TestParseStatements(t *testing.T) { t.Parallel() result, errs := testParseStatements(`assert true`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "statements on the same line must be separated with a semicolon", @@ -1083,7 +1083,7 @@ func TestParseStatements(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ExpressionStatement{ Expression: &ast.IdentifierExpression{ @@ -1119,7 +1119,7 @@ func TestParseRemoveAttachmentStatement(t *testing.T) { result, errs := testParseStatements("remove A from b") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.RemoveStatement{ Attachment: &ast.NominalType{ @@ -1148,7 +1148,7 @@ func TestParseRemoveAttachmentStatement(t *testing.T) { result, errs := testParseStatements("remove Foo.E from b") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.RemoveStatement{ Attachment: &ast.NominalType{ @@ -1182,7 +1182,7 @@ func TestParseRemoveAttachmentStatement(t *testing.T) { _, errs := testParseStatements("remove A") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected from keyword, got EOF", @@ -1203,7 +1203,7 @@ func TestParseRemoveAttachmentStatement(t *testing.T) { _, errs := testParseStatements("remove A from") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected end of program", @@ -1220,7 +1220,7 @@ func TestParseRemoveAttachmentStatement(t *testing.T) { _, errs := testParseStatements("remove [A] from e") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected attachment nominal type, got [A]", @@ -1238,7 +1238,7 @@ func TestParseRemoveAttachmentStatement(t *testing.T) { result, errs := testParseStatements("remove A from foo()") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.RemoveStatement{ Attachment: &ast.NominalType{ @@ -1276,7 +1276,7 @@ func TestParseSwitchStatement(t *testing.T) { result, errs := testParseStatements("switch true { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.SwitchStatement{ Expression: &ast.BoolExpression{ @@ -1304,7 +1304,7 @@ func TestParseSwitchStatement(t *testing.T) { result, errs := testParseStatements("switch x { case 1 :\n a\nb default : c\nd }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.SwitchStatement{ Expression: &ast.IdentifierExpression{ @@ -1402,7 +1402,7 @@ func TestParseIfStatementInFunctionDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1604,7 +1604,7 @@ func TestParseIfStatementWithVariableDeclaration(t *testing.T) { ifStatement.Test = ifTestVariableDeclaration - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1650,7 +1650,7 @@ func TestParseIfStatementNoElse(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1722,7 +1722,7 @@ func TestParseWhileStatementInFunctionDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1802,7 +1802,7 @@ func TestParseForStatementInFunctionDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1864,7 +1864,7 @@ func TestParseAssignment(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1928,7 +1928,7 @@ func TestParseAccessAssignment(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -2041,7 +2041,7 @@ func TestParseExpressionStatementWithAccess(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -2143,7 +2143,7 @@ func TestParseMoveStatement(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -2205,7 +2205,7 @@ func TestParseFunctionExpressionStatementAfterVariableDeclarationWithCreateExpre result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -2308,7 +2308,7 @@ func TestParseExpressionStatementAfterReturnStatement(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -2369,7 +2369,7 @@ func TestParseSwapStatementInFunctionDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, diff --git a/old_parser/type_test.go b/old_parser/type_test.go index 814a51b813..7e9bcdf1dc 100644 --- a/old_parser/type_test.go +++ b/old_parser/type_test.go @@ -27,7 +27,7 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/common" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestParseNominalType(t *testing.T) { @@ -41,7 +41,7 @@ func TestParseNominalType(t *testing.T) { result, errs := testParseType("Int") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "Int", @@ -59,7 +59,7 @@ func TestParseNominalType(t *testing.T) { result, errs := testParseType("Foo.Bar") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "Foo", @@ -88,7 +88,7 @@ func TestParseArrayType(t *testing.T) { result, errs := testParseType("[Int]") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.VariableSizedType{ Type: &ast.NominalType{ Identifier: ast.Identifier{ @@ -112,7 +112,7 @@ func TestParseArrayType(t *testing.T) { result, errs := testParseType("[Int ; 2 ]") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ConstantSizedType{ Type: &ast.NominalType{ Identifier: ast.Identifier{ @@ -143,7 +143,7 @@ func TestParseArrayType(t *testing.T) { t.Parallel() result, errs := testParseType("[Int ; -2 ]") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: `expected positive integer size for constant sized type`, @@ -166,7 +166,7 @@ func TestParseArrayType(t *testing.T) { t.Parallel() result, errs := testParseType("[Int ; X ]") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: `expected positive integer size for constant sized type`, @@ -176,7 +176,7 @@ func TestParseArrayType(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.VariableSizedType{ Type: &ast.NominalType{ Identifier: ast.Identifier{ @@ -206,7 +206,7 @@ func TestParseOptionalType(t *testing.T) { result, errs := testParseType("Int?") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.OptionalType{ Type: &ast.NominalType{ Identifier: ast.Identifier{ @@ -227,7 +227,7 @@ func TestParseOptionalType(t *testing.T) { result, errs := testParseType("Int??") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.OptionalType{ Type: &ast.OptionalType{ Type: &ast.NominalType{ @@ -251,7 +251,7 @@ func TestParseOptionalType(t *testing.T) { result, errs := testParseType("Int???") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.OptionalType{ Type: &ast.OptionalType{ Type: &ast.OptionalType{ @@ -283,7 +283,7 @@ func TestParseReferenceType(t *testing.T) { result, errs := testParseType("&Int") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ReferenceType{ Authorization: nil, Type: &ast.NominalType{ @@ -305,7 +305,7 @@ func TestParseReferenceType(t *testing.T) { result, errs := testParseType("auth &Int") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ReferenceType{ Authorization: nil, LegacyAuthorized: true, @@ -333,7 +333,7 @@ func TestParseOptionalReferenceType(t *testing.T) { result, errs := testParseType("&Int?") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.OptionalType{ Type: &ast.ReferenceType{ Authorization: nil, @@ -363,7 +363,7 @@ func TestParseRestrictedType(t *testing.T) { result, errs := testParseType("T{}") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntersectionType{ LegacyRestrictedType: &ast.NominalType{ NestedIdentifiers: nil, @@ -388,7 +388,7 @@ func TestParseRestrictedType(t *testing.T) { result, errs := testParseType("T{U}") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntersectionType{ LegacyRestrictedType: &ast.NominalType{ NestedIdentifiers: nil, @@ -421,7 +421,7 @@ func TestParseRestrictedType(t *testing.T) { result, errs := testParseType("T{U , V }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntersectionType{ LegacyRestrictedType: &ast.NominalType{ NestedIdentifiers: nil, @@ -460,7 +460,7 @@ func TestParseRestrictedType(t *testing.T) { result, errs := testParseType("{}") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntersectionType{ Range: ast.Range{ StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, @@ -478,7 +478,7 @@ func TestParseRestrictedType(t *testing.T) { result, errs := testParseType("{ T }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntersectionType{ Types: []*ast.NominalType{ { @@ -502,7 +502,7 @@ func TestParseRestrictedType(t *testing.T) { t.Parallel() result, errs := testParseType("{ T , }") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "missing type after comma", @@ -512,7 +512,7 @@ func TestParseRestrictedType(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntersectionType{ Types: []*ast.NominalType{ { @@ -536,7 +536,7 @@ func TestParseRestrictedType(t *testing.T) { t.Parallel() result, errs := testParseType("{ T U }") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected type", @@ -555,7 +555,7 @@ func TestParseRestrictedType(t *testing.T) { t.Parallel() result, errs := testParseType("{ T , U : V }") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected colon in restricted type", @@ -574,7 +574,7 @@ func TestParseRestrictedType(t *testing.T) { t.Parallel() result, errs := testParseType("T{U , V : W }") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: `unexpected token: got ':', expected ',' or '}'`, @@ -593,7 +593,7 @@ func TestParseRestrictedType(t *testing.T) { t.Parallel() result, errs := testParseType("{[T]}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "non-nominal type in restriction list: [T]", @@ -612,7 +612,7 @@ func TestParseRestrictedType(t *testing.T) { t.Parallel() result, errs := testParseType("T{[U]}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected non-nominal type: [U]", @@ -631,7 +631,7 @@ func TestParseRestrictedType(t *testing.T) { t.Parallel() result, errs := testParseType("{T, [U]}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "non-nominal type in restriction list: [U]", @@ -650,7 +650,7 @@ func TestParseRestrictedType(t *testing.T) { t.Parallel() result, errs := testParseType("T{U, [V]}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected non-nominal type: [V]", @@ -669,7 +669,7 @@ func TestParseRestrictedType(t *testing.T) { t.Parallel() result, errs := testParseType("{") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid end of input, expected type", @@ -687,7 +687,7 @@ func TestParseRestrictedType(t *testing.T) { t.Parallel() result, errs := testParseType("T{") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid end of input, expected type", @@ -705,7 +705,7 @@ func TestParseRestrictedType(t *testing.T) { t.Parallel() result, errs := testParseType("{U") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid end of input, expected '}'", @@ -723,7 +723,7 @@ func TestParseRestrictedType(t *testing.T) { t.Parallel() result, errs := testParseType("T{U") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid end of input, expected '}'", @@ -741,7 +741,7 @@ func TestParseRestrictedType(t *testing.T) { t.Parallel() result, errs := testParseType("{U,") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid end of input, expected type", @@ -759,7 +759,7 @@ func TestParseRestrictedType(t *testing.T) { t.Parallel() result, errs := testParseType("T{U,") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid end of input, expected type", @@ -777,7 +777,7 @@ func TestParseRestrictedType(t *testing.T) { t.Parallel() result, errs := testParseType("{,}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected comma in restricted type", @@ -795,7 +795,7 @@ func TestParseRestrictedType(t *testing.T) { t.Parallel() result, errs := testParseType("T{,}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected comma", @@ -820,7 +820,7 @@ func TestParseDictionaryType(t *testing.T) { result, errs := testParseType("{T: U}") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.DictionaryType{ KeyType: &ast.NominalType{ Identifier: ast.Identifier{ @@ -848,7 +848,7 @@ func TestParseDictionaryType(t *testing.T) { t.Parallel() result, errs := testParseType("{T:}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "missing dictionary value type", @@ -858,7 +858,7 @@ func TestParseDictionaryType(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.DictionaryType{ KeyType: &ast.NominalType{ Identifier: ast.Identifier{ @@ -881,7 +881,7 @@ func TestParseDictionaryType(t *testing.T) { t.Parallel() result, errs := testParseType("{:}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected colon in dictionary type", @@ -899,7 +899,7 @@ func TestParseDictionaryType(t *testing.T) { t.Parallel() result, errs := testParseType("{:U}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected colon in dictionary type", @@ -918,7 +918,7 @@ func TestParseDictionaryType(t *testing.T) { t.Parallel() result, errs := testParseType("{T:U,}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected comma in dictionary type", @@ -937,7 +937,7 @@ func TestParseDictionaryType(t *testing.T) { t.Parallel() result, errs := testParseType("{T:U:}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected colon in dictionary type", @@ -956,7 +956,7 @@ func TestParseDictionaryType(t *testing.T) { t.Parallel() result, errs := testParseType("{T::U}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected colon in dictionary type", @@ -975,7 +975,7 @@ func TestParseDictionaryType(t *testing.T) { t.Parallel() result, errs := testParseType("{T:") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid end of input, expected type", @@ -993,7 +993,7 @@ func TestParseDictionaryType(t *testing.T) { t.Parallel() result, errs := testParseType("{T:U") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid end of input, expected '}'", @@ -1018,7 +1018,7 @@ func TestParseFunctionType(t *testing.T) { result, errs := testParseType("(():Void)") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FunctionType{ ParameterTypeAnnotations: nil, ReturnTypeAnnotation: &ast.TypeAnnotation{ @@ -1047,7 +1047,7 @@ func TestParseFunctionType(t *testing.T) { result, errs := testParseType("( ( String , Bool , @R ) : Int)") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FunctionType{ ParameterTypeAnnotations: []*ast.TypeAnnotation{ { @@ -1112,7 +1112,7 @@ func TestParseInstantiationType(t *testing.T) { result, errs := testParseType("T<>") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InstantiationType{ Type: &ast.NominalType{ Identifier: ast.Identifier{ @@ -1134,7 +1134,7 @@ func TestParseInstantiationType(t *testing.T) { result, errs := testParseType("T") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InstantiationType{ Type: &ast.NominalType{ Identifier: ast.Identifier{ @@ -1168,7 +1168,7 @@ func TestParseInstantiationType(t *testing.T) { result, errs := testParseType("T< U >") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InstantiationType{ Type: &ast.NominalType{ Identifier: ast.Identifier{ @@ -1202,7 +1202,7 @@ func TestParseInstantiationType(t *testing.T) { result, errs := testParseType("T< U , @V >") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InstantiationType{ Type: &ast.NominalType{ Identifier: ast.Identifier{ @@ -1246,7 +1246,7 @@ func TestParseInstantiationType(t *testing.T) { result, errs := testParseType("T") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InstantiationType{ Type: &ast.NominalType{ Identifier: ast.Identifier{ @@ -1280,7 +1280,7 @@ func TestParseInstantiationType(t *testing.T) { result, errs := testParseType("T< U< V > >") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InstantiationType{ Type: &ast.NominalType{ Identifier: ast.Identifier{ @@ -1334,7 +1334,7 @@ func TestParseParametersAndArrayTypes(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessAll, @@ -1483,7 +1483,7 @@ func TestParseDictionaryTypeInVariableDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -1805,7 +1805,7 @@ func TestParseIntegerTypes(t *testing.T) { StartPos: ast.Position{Offset: 137, Line: 9, Column: 2}, } - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{a, b, c, d, e, f, g, h}, result.Declarations(), ) @@ -1821,7 +1821,7 @@ func TestParseFunctionTypeInVariableDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -1899,7 +1899,7 @@ func TestParseFunctionArrayType(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -1983,7 +1983,7 @@ func TestParseFunctionTypeWithArrayReturnType(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2066,7 +2066,7 @@ func TestParseFunctionTypeWithFunctionReturnTypeInParentheses(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2156,7 +2156,7 @@ func TestParseFunctionTypeWithFunctionReturnType(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2246,7 +2246,7 @@ func TestParseOptionalTypeDouble(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2301,7 +2301,7 @@ func TestParseFunctionTypeWithResourceTypeAnnotation(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2358,7 +2358,7 @@ func TestParseReferenceTypeInVariableDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2419,7 +2419,7 @@ func TestParseOptionalReference(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2474,7 +2474,7 @@ func TestParseRestrictedReferenceTypeWithBaseType(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2541,7 +2541,7 @@ func TestParseRestrictedReferenceTypeWithoutBaseType(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2601,7 +2601,7 @@ func TestParseOptionalRestrictedType(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2668,7 +2668,7 @@ func TestParseOptionalRestrictedTypeOnlyRestrictions(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2728,7 +2728,7 @@ func TestParseAuthorizedReferenceType(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2783,7 +2783,7 @@ func TestParseInstantiationTypeInVariableDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2859,7 +2859,7 @@ func TestParseConstantSizedSizedArrayWithTrailingUnderscoreSize(t *testing.T) { let T:[d;0_]=0 `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &InvalidIntegerLiteralError{ Literal: "0_", diff --git a/parser/declaration_test.go b/parser/declaration_test.go index 2f27396cbd..681d5cb593 100644 --- a/parser/declaration_test.go +++ b/parser/declaration_test.go @@ -29,7 +29,7 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/common" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestParseVariableDeclaration(t *testing.T) { @@ -43,7 +43,7 @@ func TestParseVariableDeclaration(t *testing.T) { result, errs := testParseDeclarations("var x = 1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -79,7 +79,7 @@ func TestParseVariableDeclaration(t *testing.T) { result, errs := testParseDeclarations(" access(all) var x = 1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Value: &ast.IntegerExpression{ @@ -136,7 +136,7 @@ func TestParseVariableDeclaration(t *testing.T) { result, errs := testParseDeclarations("let x = 1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -172,7 +172,7 @@ func TestParseVariableDeclaration(t *testing.T) { result, errs := testParseDeclarations("let x <- 1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -208,7 +208,7 @@ func TestParseVariableDeclaration(t *testing.T) { result, errs := testParseDeclarations("let r2: @R <- r") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -251,7 +251,7 @@ func TestParseVariableDeclaration(t *testing.T) { result, errs := testParseStatements("var x <- y <- z") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -292,7 +292,7 @@ func TestParseVariableDeclaration(t *testing.T) { t.Parallel() _, errs := testParseDeclarations("view var x = 1") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid view modifier for variable", @@ -314,7 +314,7 @@ func TestParseVariableDeclaration(t *testing.T) { StaticModifierEnabled: true, }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier for variable", @@ -330,7 +330,7 @@ func TestParseVariableDeclaration(t *testing.T) { t.Parallel() _, errs := testParseDeclarations("static var x = 1") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -352,7 +352,7 @@ func TestParseVariableDeclaration(t *testing.T) { NativeModifierEnabled: true, }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid native modifier for variable", @@ -368,7 +368,7 @@ func TestParseVariableDeclaration(t *testing.T) { t.Parallel() _, errs := testParseDeclarations("native var x = 1") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -402,7 +402,7 @@ func TestParseParameterList(t *testing.T) { result, errs := parse("()") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ParameterList{ Range: ast.Range{ StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, @@ -420,7 +420,7 @@ func TestParseParameterList(t *testing.T) { result, errs := parse(" ( )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ParameterList{ Range: ast.Range{ StartPos: ast.Position{Line: 1, Column: 1, Offset: 1}, @@ -438,7 +438,7 @@ func TestParseParameterList(t *testing.T) { result, errs := parse("( a : Int )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ParameterList{ Parameters: []*ast.Parameter{ { @@ -476,7 +476,7 @@ func TestParseParameterList(t *testing.T) { result, errs := parse("( a b : Int )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ParameterList{ Parameters: []*ast.Parameter{ { @@ -514,7 +514,7 @@ func TestParseParameterList(t *testing.T) { result, errs := parse("( a b : Int , c : Int )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ParameterList{ Parameters: []*ast.Parameter{ { @@ -568,7 +568,7 @@ func TestParseParameterList(t *testing.T) { t.Parallel() _, errs := parse("( a b : Int c : Int )") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &MissingCommaInParameterListError{ Pos: ast.Position{Offset: 14, Line: 1, Column: 14}, @@ -590,7 +590,7 @@ func TestParseFunctionDeclaration(t *testing.T) { result, errs := testParseDeclarations("fun foo () { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -628,7 +628,7 @@ func TestParseFunctionDeclaration(t *testing.T) { result, errs := testParseDeclarations("access(all) fun foo () { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ ParameterList: &ast.ParameterList{ @@ -688,7 +688,7 @@ func TestParseFunctionDeclaration(t *testing.T) { result, errs := testParseDeclarations("fun foo (): X { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -747,7 +747,7 @@ func TestParseFunctionDeclaration(t *testing.T) { `) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -870,7 +870,7 @@ func TestParseFunctionDeclaration(t *testing.T) { result, errs := testParseDeclarations("/// Test\nfun foo() {}") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -908,7 +908,7 @@ func TestParseFunctionDeclaration(t *testing.T) { result, errs := testParseDeclarations("\n /// First line\n \n/// Second line\n\n\nfun foo() {}") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -946,7 +946,7 @@ func TestParseFunctionDeclaration(t *testing.T) { result, errs := testParseDeclarations("\n /** Cool dogs.\n\n Cool cats!! */\n\n\nfun foo() {}") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -989,7 +989,7 @@ func TestParseFunctionDeclaration(t *testing.T) { result, errs := testParseDeclarations("fun main(): Int{ return 1 }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1052,7 +1052,7 @@ func TestParseFunctionDeclaration(t *testing.T) { result, errs := testParseDeclarations("view fun foo (): X { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1105,7 +1105,7 @@ func TestParseFunctionDeclaration(t *testing.T) { ) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1154,7 +1154,7 @@ func TestParseFunctionDeclaration(t *testing.T) { _, errs := testParseDeclarations("native fun foo() {}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -1178,7 +1178,7 @@ func TestParseFunctionDeclaration(t *testing.T) { ) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1215,7 +1215,7 @@ func TestParseFunctionDeclaration(t *testing.T) { _, errs := testParseDeclarations("static fun foo() {}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -1240,7 +1240,7 @@ func TestParseFunctionDeclaration(t *testing.T) { ) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1277,7 +1277,7 @@ func TestParseFunctionDeclaration(t *testing.T) { _, errs := testParseDeclarations("static native fun foo() {}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -1300,7 +1300,7 @@ func TestParseFunctionDeclaration(t *testing.T) { NativeModifierEnabled: true, }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier after native modifier", @@ -1317,7 +1317,7 @@ func TestParseFunctionDeclaration(t *testing.T) { _, errs := testParseDeclarations("native static fun foo() {}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -1342,7 +1342,7 @@ func TestParseFunctionDeclaration(t *testing.T) { ) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Purity: 0, @@ -1408,7 +1408,7 @@ func TestParseFunctionDeclaration(t *testing.T) { _, errs := testParseDeclarations("access(all) static native fun foo() {}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -1436,7 +1436,7 @@ func TestParseFunctionDeclaration(t *testing.T) { ) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1486,7 +1486,7 @@ func TestParseFunctionDeclaration(t *testing.T) { ) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1543,7 +1543,7 @@ func TestParseFunctionDeclaration(t *testing.T) { ) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1608,7 +1608,7 @@ func TestParseFunctionDeclaration(t *testing.T) { _, errs := testParseDeclarations("fun foo() {}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected '(' as start of parameter list, got '<'", @@ -1631,7 +1631,7 @@ func TestParseFunctionDeclaration(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "missing '>' at end of type parameter list", @@ -1654,7 +1654,7 @@ func TestParseFunctionDeclaration(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &MissingCommaInParameterListError{ Pos: ast.Position{Offset: 13, Line: 1, Column: 13}, @@ -1686,7 +1686,7 @@ func TestParseAccess(t *testing.T) { result, errs := parse("access ( all )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessAll, result, ) @@ -1699,7 +1699,7 @@ func TestParseAccess(t *testing.T) { result, errs := parse("access ( account )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessAccount, result, ) @@ -1712,7 +1712,7 @@ func TestParseAccess(t *testing.T) { result, errs := parse("access ( contract )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessContract, result, ) @@ -1725,7 +1725,7 @@ func TestParseAccess(t *testing.T) { result, errs := parse("access ( self )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessSelf, result, ) @@ -1736,7 +1736,7 @@ func TestParseAccess(t *testing.T) { t.Parallel() result, errs := parse("access ( ") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected keyword \"all\", \"account\", \"contract\", or \"self\", got EOF", @@ -1746,7 +1746,7 @@ func TestParseAccess(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessNotSpecified, result, ) @@ -1757,7 +1757,7 @@ func TestParseAccess(t *testing.T) { t.Parallel() result, errs := parse("access ( self ") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token ')'", @@ -1767,7 +1767,7 @@ func TestParseAccess(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessNotSpecified, result, ) @@ -1780,7 +1780,7 @@ func TestParseAccess(t *testing.T) { result, errs := parse("access ( foo )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.EntitlementAccess{ EntitlementSet: &ast.ConjunctiveEntitlementSet{ Elements: []*ast.NominalType{ @@ -1804,7 +1804,7 @@ func TestParseAccess(t *testing.T) { result, errs := parse("access ( foo , bar )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.EntitlementAccess{ EntitlementSet: &ast.ConjunctiveEntitlementSet{ Elements: []*ast.NominalType{ @@ -1834,7 +1834,7 @@ func TestParseAccess(t *testing.T) { result, errs := parse("access ( foo | bar )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.EntitlementAccess{ EntitlementSet: &ast.DisjunctiveEntitlementSet{ Elements: []*ast.NominalType{ @@ -1862,7 +1862,7 @@ func TestParseAccess(t *testing.T) { t.Parallel() result, errs := parse("access ( foo | bar , baz )") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: got ',', expected '|' or ')'", @@ -1872,7 +1872,7 @@ func TestParseAccess(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessNotSpecified, result, ) @@ -1883,7 +1883,7 @@ func TestParseAccess(t *testing.T) { t.Parallel() result, errs := parse("access ( foo , bar | baz )") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: got '|', expected ',' or ')'", @@ -1893,7 +1893,7 @@ func TestParseAccess(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessNotSpecified, result, ) @@ -1904,7 +1904,7 @@ func TestParseAccess(t *testing.T) { t.Parallel() result, errs := parse("access ( self , bar )") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token ')'", @@ -1914,7 +1914,7 @@ func TestParseAccess(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessNotSpecified, result, ) @@ -1925,7 +1925,7 @@ func TestParseAccess(t *testing.T) { t.Parallel() result, errs := parse("access ( self | bar )") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token ')'", @@ -1935,7 +1935,7 @@ func TestParseAccess(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessNotSpecified, result, ) @@ -1946,7 +1946,7 @@ func TestParseAccess(t *testing.T) { t.Parallel() result, errs := parse("access ( foo , self )") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected non-nominal type: self", @@ -1956,7 +1956,7 @@ func TestParseAccess(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessNotSpecified, result, ) @@ -1967,7 +1967,7 @@ func TestParseAccess(t *testing.T) { t.Parallel() result, errs := parse("access ( foo | self )") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected non-nominal type: self", @@ -1977,7 +1977,7 @@ func TestParseAccess(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessNotSpecified, result, ) @@ -1988,7 +1988,7 @@ func TestParseAccess(t *testing.T) { t.Parallel() result, errs := parse("access ( foo bar )") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected entitlement separator identifier", @@ -1998,7 +1998,7 @@ func TestParseAccess(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessNotSpecified, result, ) @@ -2009,7 +2009,7 @@ func TestParseAccess(t *testing.T) { t.Parallel() result, errs := parse("access ( foo & bar )") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected entitlement separator '&'", @@ -2019,7 +2019,7 @@ func TestParseAccess(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessNotSpecified, result, ) @@ -2032,7 +2032,7 @@ func TestParseAccess(t *testing.T) { result, errs := parse("access ( mapping foo )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.MappedAccess{ EntitlementMap: &ast.NominalType{ Identifier: ast.Identifier{ @@ -2051,7 +2051,7 @@ func TestParseAccess(t *testing.T) { t.Parallel() result, errs := parse("access ( mapping )") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token in type: ')'", @@ -2061,7 +2061,7 @@ func TestParseAccess(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.AccessNotSpecified, result, ) @@ -2078,7 +2078,7 @@ func TestParseImportDeclaration(t *testing.T) { t.Parallel() result, errs := testParseDeclarations(` import`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected end in import declaration: expected string, address, or identifier", @@ -2090,7 +2090,7 @@ func TestParseImportDeclaration(t *testing.T) { var expected []ast.Declaration - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, expected, result, ) @@ -2103,7 +2103,7 @@ func TestParseImportDeclaration(t *testing.T) { result, errs := testParseDeclarations(` import "foo"`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.ImportDeclaration{ Identifiers: nil, @@ -2126,7 +2126,7 @@ func TestParseImportDeclaration(t *testing.T) { result, errs := testParseDeclarations(` import 0x42`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.ImportDeclaration{ Identifiers: nil, @@ -2149,7 +2149,7 @@ func TestParseImportDeclaration(t *testing.T) { t.Parallel() result, errs := testParseDeclarations(` import 0x10000000000000001`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "address too large", @@ -2173,7 +2173,7 @@ func TestParseImportDeclaration(t *testing.T) { }, } - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, expected, result, ) @@ -2184,7 +2184,7 @@ func TestParseImportDeclaration(t *testing.T) { t.Parallel() result, errs := testParseDeclarations(` import 1`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token in import declaration: " + @@ -2197,7 +2197,7 @@ func TestParseImportDeclaration(t *testing.T) { var expected []ast.Declaration - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, expected, result, ) @@ -2211,7 +2211,7 @@ func TestParseImportDeclaration(t *testing.T) { result, errs := testParseDeclarations(` import foo from "bar"`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.ImportDeclaration{ Identifiers: []ast.Identifier{ @@ -2237,7 +2237,7 @@ func TestParseImportDeclaration(t *testing.T) { t.Parallel() result, errs := testParseDeclarations(` import foo "bar"`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token in import declaration: " + @@ -2250,7 +2250,7 @@ func TestParseImportDeclaration(t *testing.T) { var expected []ast.Declaration - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, expected, result, ) @@ -2263,7 +2263,7 @@ func TestParseImportDeclaration(t *testing.T) { result, errs := testParseDeclarations(` import foo , bar , baz from 0x42`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.ImportDeclaration{ Identifiers: []ast.Identifier{ @@ -2299,7 +2299,7 @@ func TestParseImportDeclaration(t *testing.T) { t.Parallel() result, errs := testParseDeclarations(` import foo , bar , from 0x42`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: `expected identifier, got keyword "from"`, @@ -2311,7 +2311,7 @@ func TestParseImportDeclaration(t *testing.T) { var expected []ast.Declaration - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, expected, result, ) @@ -2321,7 +2321,7 @@ func TestParseImportDeclaration(t *testing.T) { t.Parallel() result, errs := testParseDeclarations(`import foo, , bar from 0xaaaa`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Pos: ast.Position{Line: 1, Column: 12, Offset: 12}, @@ -2332,7 +2332,7 @@ func TestParseImportDeclaration(t *testing.T) { ) var expected []ast.Declaration - utils.AssertEqualWithDiff(t, expected, result) + AssertEqualWithDiff(t, expected, result) }) t.Run("no identifiers, identifier location", func(t *testing.T) { @@ -2342,7 +2342,7 @@ func TestParseImportDeclaration(t *testing.T) { result, errs := testParseDeclarations(` import foo`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.ImportDeclaration{ Identifiers: nil, @@ -2363,7 +2363,7 @@ func TestParseImportDeclaration(t *testing.T) { _, errs := testParseDeclarations(`import foo, bar, baz, @ from 0x42`) - utils.AssertEqualWithDiff(t, []error{ + AssertEqualWithDiff(t, []error{ &SyntaxError{ Pos: ast.Position{Line: 1, Column: 22, Offset: 22}, Message: `unexpected token in import declaration: got '@', expected keyword "from" or ','`, @@ -2381,7 +2381,7 @@ func TestParseImportDeclaration(t *testing.T) { `) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.ImportDeclaration{ Identifiers: []ast.Identifier{ @@ -2444,7 +2444,7 @@ func TestParseEvent(t *testing.T) { result, errs := testParseDeclarations("event E()") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -2487,7 +2487,7 @@ func TestParseEvent(t *testing.T) { result, errs := testParseDeclarations(" access(self) event E2 ( a : Int , b : String )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Members: ast.NewUnmeteredMembers( @@ -2620,7 +2620,7 @@ func TestParseEvent(t *testing.T) { result, errs := testParseDeclarations(` access(all) event ResourceDestroyed ( a : String = "foo")`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Members: ast.NewUnmeteredMembers( @@ -2735,7 +2735,7 @@ func TestParseEvent(t *testing.T) { _, errs := testParseDeclarations(" access(all) event ResourceDestroyed ( a : Int )") - utils.AssertEqualWithDiff(t, []error{ + AssertEqualWithDiff(t, []error{ &SyntaxError{ Pos: ast.Position{Line: 1, Column: 47, Offset: 47}, Message: "expected a default argument after type annotation, got ')'", @@ -2749,7 +2749,7 @@ func TestParseEvent(t *testing.T) { _, errs := testParseDeclarations(" access(all) event Foo ( a : Int = 3)") - utils.AssertEqualWithDiff(t, []error{ + AssertEqualWithDiff(t, []error{ &SyntaxError{ Pos: ast.Position{Line: 1, Column: 33, Offset: 33}, Message: "cannot use a default argument for this function", @@ -2760,7 +2760,7 @@ func TestParseEvent(t *testing.T) { t.Run("invalid event name", func(t *testing.T) { _, errs := testParseDeclarations(`event continue {}`) - utils.AssertEqualWithDiff(t, []error{ + AssertEqualWithDiff(t, []error{ &SyntaxError{ Pos: ast.Position{Line: 1, Column: 6, Offset: 6}, Message: "expected identifier after start of event declaration, got keyword continue", @@ -2798,7 +2798,7 @@ func TestParseFieldWithVariableKind(t *testing.T) { result, errs := parse("var x : Int") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FieldDeclaration{ Access: ast.AccessNotSpecified, VariableKind: ast.VariableKindVariable, @@ -2832,7 +2832,7 @@ func TestParseFieldWithVariableKind(t *testing.T) { result, errs := parse("let x : Int") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FieldDeclaration{ Access: ast.AccessNotSpecified, VariableKind: ast.VariableKindConstant, @@ -2890,7 +2890,7 @@ func TestParseField(t *testing.T) { ) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FieldDeclaration{ Access: ast.AccessNotSpecified, Flags: ast.FieldDeclarationFlagsIsNative, @@ -2923,7 +2923,7 @@ func TestParseField(t *testing.T) { _, errs := parse("native let foo: Int", Config{}) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected identifier", @@ -2946,7 +2946,7 @@ func TestParseField(t *testing.T) { ) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FieldDeclaration{ Access: ast.AccessNotSpecified, Flags: ast.FieldDeclarationFlagsIsStatic, @@ -2982,7 +2982,7 @@ func TestParseField(t *testing.T) { Config{}, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected identifier", @@ -3006,7 +3006,7 @@ func TestParseField(t *testing.T) { ) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FieldDeclaration{ Access: ast.AccessNotSpecified, Flags: ast.FieldDeclarationFlagsIsStatic | ast.FieldDeclarationFlagsIsNative, @@ -3039,7 +3039,7 @@ func TestParseField(t *testing.T) { _, errs := parse("static native let foo: Int", Config{}) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected identifier", @@ -3062,7 +3062,7 @@ func TestParseField(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier after native modifier", @@ -3086,7 +3086,7 @@ func TestParseField(t *testing.T) { ) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FieldDeclaration{ TypeAnnotation: &ast.TypeAnnotation{ Type: &ast.NominalType{ @@ -3140,7 +3140,7 @@ func TestParseField(t *testing.T) { _, errs := parse("access(all) static native let foo: Int", Config{}) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected identifier", @@ -3164,7 +3164,7 @@ func TestParseCompositeDeclaration(t *testing.T) { result, errs := testParseDeclarations(" access(all) struct S { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Members: ast.NewUnmeteredMembers(nil), @@ -3203,7 +3203,7 @@ func TestParseCompositeDeclaration(t *testing.T) { result, errs := testParseDeclarations(" access(all) resource R : RI { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessAll, @@ -3251,7 +3251,7 @@ func TestParseCompositeDeclaration(t *testing.T) { require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Members: ast.NewUnmeteredMembers( @@ -3579,7 +3579,7 @@ func TestParseCompositeDeclaration(t *testing.T) { }`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -3632,7 +3632,7 @@ func TestParseCompositeDeclaration(t *testing.T) { }`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -3687,7 +3687,7 @@ func TestParseCompositeDeclaration(t *testing.T) { view foo: Int }`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid view modifier for variable", @@ -3720,7 +3720,7 @@ func TestParseInvalidCompositeFunctionWithSelfParameter(t *testing.T) { _, err := testParseDeclarations(code) - utils.AssertEqualWithDiff( + AssertEqualWithDiff( t, []error{ &SyntaxError{ @@ -3739,7 +3739,7 @@ func TestParseInvalidParameterWithoutLabel(t *testing.T) { _, errs := testParseDeclarations(`access(all) fun foo(continue: Int) {}`) - utils.AssertEqualWithDiff(t, []error{ + AssertEqualWithDiff(t, []error{ &SyntaxError{ Pos: ast.Position{Line: 1, Column: 20, Offset: 20}, Message: "expected identifier for argument label or parameter name, got keyword continue", @@ -3752,7 +3752,7 @@ func TestParseParametersWithExtraLabels(t *testing.T) { _, errs := testParseDeclarations(`access(all) fun foo(_ foo: String, label fable table: Int) {}`) - utils.AssertEqualWithDiff(t, []error{ + AssertEqualWithDiff(t, []error{ &SyntaxError{ Pos: ast.Position{Line: 1, Column: 47, Offset: 47}, Message: "expected ':' after parameter name, got identifier", @@ -3771,7 +3771,7 @@ func TestParseAttachmentDeclaration(t *testing.T) { result, errs := testParseDeclarations("access(all) attachment E for S {} ") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.AttachmentDeclaration{ Access: ast.AccessAll, @@ -3806,7 +3806,7 @@ func TestParseAttachmentDeclaration(t *testing.T) { }`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -3852,7 +3852,7 @@ func TestParseAttachmentDeclaration(t *testing.T) { t.Parallel() _, errs := testParseDeclarations("attachment E {} ") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected 'for', got '{'", @@ -3870,7 +3870,7 @@ func TestParseAttachmentDeclaration(t *testing.T) { result, errs := testParseDeclarations("access(all) attachment E for S: I {} ") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.AttachmentDeclaration{ Access: ast.AccessAll, @@ -3912,7 +3912,7 @@ func TestParseAttachmentDeclaration(t *testing.T) { result, errs := testParseDeclarations("access(all) attachment E for S: I1, I2 {} ") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.AttachmentDeclaration{ Access: ast.AccessAll, @@ -3986,7 +3986,7 @@ func TestParseAttachmentDeclaration(t *testing.T) { }`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.AttachmentDeclaration{ Access: ast.AccessAll, @@ -4193,7 +4193,7 @@ func TestParseAttachmentDeclaration(t *testing.T) { _, errs := testParseDeclarations(`access(all) attachment E for S { require entitlement X }`) - utils.AssertEqualWithDiff(t, []error{ + AssertEqualWithDiff(t, []error{ &SyntaxError{ Pos: ast.Position{Line: 2, Column: 3, Offset: 36}, Message: "unexpected identifier", @@ -4210,7 +4210,7 @@ func TestParseAttachmentDeclaration(t *testing.T) { }`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.AttachmentDeclaration{ Access: ast.AccessAll, @@ -4323,7 +4323,7 @@ func TestParseInterfaceDeclaration(t *testing.T) { result, errs := testParseDeclarations(" access(all) struct interface S { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.InterfaceDeclaration{ Access: ast.AccessAll, @@ -4348,7 +4348,7 @@ func TestParseInterfaceDeclaration(t *testing.T) { t.Parallel() result, errs := testParseDeclarations(" access(all) struct interface interface { }") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected interface name, got keyword \"interface\"", @@ -4360,7 +4360,7 @@ func TestParseInterfaceDeclaration(t *testing.T) { var expected []ast.Declaration - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, expected, result, ) @@ -4384,7 +4384,7 @@ func TestParseInterfaceDeclaration(t *testing.T) { require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.InterfaceDeclaration{ Members: ast.NewUnmeteredMembers( @@ -4647,7 +4647,7 @@ func TestParseInterfaceDeclaration(t *testing.T) { t.Run("invalid interface name", func(t *testing.T) { _, errs := testParseDeclarations(`access(all) struct interface continue {}`) - utils.AssertEqualWithDiff(t, []error{ + AssertEqualWithDiff(t, []error{ &SyntaxError{ Pos: ast.Position{Line: 1, Column: 29, Offset: 29}, Message: "expected identifier following struct declaration, got keyword continue", @@ -4664,7 +4664,7 @@ func TestParseInterfaceDeclaration(t *testing.T) { }`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.InterfaceDeclaration{ Access: ast.AccessNotSpecified, @@ -4720,7 +4720,7 @@ func TestParseEnumDeclaration(t *testing.T) { result, errs := testParseDeclarations(" access(all) enum E { case c ; access(all) case d }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessAll, @@ -4764,7 +4764,7 @@ func TestParseEnumDeclaration(t *testing.T) { t.Parallel() _, errs := testParseDeclarations(" enum E { view case e }") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid view modifier for enum case", @@ -4786,7 +4786,7 @@ func TestParseEnumDeclaration(t *testing.T) { StaticModifierEnabled: true, }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier for enum case", @@ -4803,7 +4803,7 @@ func TestParseEnumDeclaration(t *testing.T) { _, errs := testParseDeclarations(" enum E { static case e }") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected identifier", @@ -4825,7 +4825,7 @@ func TestParseEnumDeclaration(t *testing.T) { NativeModifierEnabled: true, }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid native modifier for enum case", @@ -4842,7 +4842,7 @@ func TestParseEnumDeclaration(t *testing.T) { _, errs := testParseDeclarations(" enum E { native case e }") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected identifier", @@ -4865,7 +4865,7 @@ func TestParseTransactionDeclaration(t *testing.T) { result, errs := testParseDeclarations("transaction { execute {} }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.TransactionDeclaration{ Execute: &ast.SpecialFunctionDeclaration{ @@ -4905,7 +4905,7 @@ func TestParseTransactionDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.TransactionDeclaration{ Fields: nil, @@ -4941,7 +4941,7 @@ func TestParseTransactionDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.TransactionDeclaration{ Fields: []*ast.FieldDeclaration{ @@ -5141,7 +5141,7 @@ func TestParseTransactionDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.TransactionDeclaration{ Fields: []*ast.FieldDeclaration{ @@ -5388,7 +5388,7 @@ func TestParseTransactionDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.TransactionDeclaration{ Fields: []*ast.FieldDeclaration{ @@ -5628,7 +5628,7 @@ func TestParseTransactionDeclaration(t *testing.T) { _, errs := testParseDeclarations(code) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, `unexpected identifier, expected keyword "prepare" or "execute", got "uwu"`, errs[0].Error(), ) @@ -5644,7 +5644,7 @@ func TestParseFunctionAndBlock(t *testing.T) { `) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -5690,7 +5690,7 @@ func TestParseFunctionParameterWithoutLabel(t *testing.T) { `) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -5748,7 +5748,7 @@ func TestParseFunctionParameterWithLabel(t *testing.T) { `) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -5817,7 +5817,7 @@ func TestParseStructure(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Members: ast.NewUnmeteredMembers( @@ -6144,7 +6144,7 @@ func TestParseStructureWithConformances(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -6205,7 +6205,7 @@ func TestParseInvalidMember(t *testing.T) { IgnoreLeadingIdentifierEnabled: false, }) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected identifier", @@ -6236,7 +6236,7 @@ func TestParsePreAndPostConditions(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -6393,7 +6393,7 @@ func TestParseConditionMessage(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -6507,7 +6507,7 @@ func TestParseInvalidEmitConditionNonInvocation(t *testing.T) { } `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token '('", @@ -6530,7 +6530,7 @@ func TestParseInvalidEmitConditionNonInvocation(t *testing.T) { } `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token '('", @@ -6562,7 +6562,7 @@ func TestParseEmitAndTestCondition(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -6833,7 +6833,7 @@ func TestParseInterface(t *testing.T) { }, } - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{test}, actual.Declarations(), ) @@ -6851,7 +6851,7 @@ func TestParsePragmaNoArguments(t *testing.T) { result, errs := testParseDeclarations(`#pedantic`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.PragmaDeclaration{ Expression: &ast.IdentifierExpression{ @@ -6875,7 +6875,7 @@ func TestParsePragmaNoArguments(t *testing.T) { t.Parallel() _, errs := testParseDeclarations("view #foo") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid view modifier for pragma", @@ -6897,7 +6897,7 @@ func TestParsePragmaNoArguments(t *testing.T) { StaticModifierEnabled: true, }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier for pragma", @@ -6913,7 +6913,7 @@ func TestParsePragmaNoArguments(t *testing.T) { t.Parallel() _, errs := testParseDeclarations("static #foo") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -6935,7 +6935,7 @@ func TestParsePragmaNoArguments(t *testing.T) { NativeModifierEnabled: true, }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid native modifier for pragma", @@ -6951,7 +6951,7 @@ func TestParsePragmaNoArguments(t *testing.T) { t.Parallel() _, errs := testParseDeclarations("native #foo") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -6971,7 +6971,7 @@ func TestParsePragmaArguments(t *testing.T) { actual, err := testParseProgram(code) require.NoError(t, err) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.PragmaDeclaration{ Expression: &ast.InvocationExpression{ @@ -7016,7 +7016,7 @@ func TestParseImportWithString(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.ImportDeclaration{ Identifiers: nil, @@ -7042,7 +7042,7 @@ func TestParseImportWithAddress(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.ImportDeclaration{ Identifiers: nil, @@ -7070,7 +7070,7 @@ func TestParseImportWithIdentifiers(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.ImportDeclaration{ Identifiers: []ast.Identifier{ @@ -7109,7 +7109,7 @@ func TestParseFieldWithFromIdentifier(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -7174,7 +7174,7 @@ func TestParseImportWithFromIdentifier(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.ImportDeclaration{ Identifiers: []ast.Identifier{ @@ -7206,7 +7206,7 @@ func TestParseInvalidImportWithPurity(t *testing.T) { ` _, errs := testParseDeclarations(code) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid view modifier for import", @@ -7227,7 +7227,7 @@ func TestParseInvalidDefaultArgument(t *testing.T) { _, errs := testParseDeclarations(" access(all) fun foo ( a : Int = 3) { } ") - utils.AssertEqualWithDiff(t, []error{ + AssertEqualWithDiff(t, []error{ &SyntaxError{ Pos: ast.Position{Line: 1, Column: 31, Offset: 31}, Message: "cannot use a default argument for this function", @@ -7241,7 +7241,7 @@ func TestParseInvalidDefaultArgument(t *testing.T) { _, errs := testParseDeclarations(" let foo = fun ( a : Int = 3) { } ") - utils.AssertEqualWithDiff(t, []error{ + AssertEqualWithDiff(t, []error{ &SyntaxError{ Pos: ast.Position{Line: 1, Column: 25, Offset: 25}, Message: "cannot use a default argument for this function", @@ -7259,7 +7259,7 @@ func TestParseInvalidEventWithPurity(t *testing.T) { ` _, errs := testParseDeclarations(code) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid view modifier for event", @@ -7279,7 +7279,7 @@ func TestParseInvalidCompositeWithPurity(t *testing.T) { ` _, errs := testParseDeclarations(code) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid view modifier for struct", @@ -7299,7 +7299,7 @@ func TestParseInvalidTransactionWithPurity(t *testing.T) { ` _, errs := testParseDeclarations(code) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid view modifier for transaction", @@ -7332,7 +7332,7 @@ func TestParseResource(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -7362,7 +7362,7 @@ func TestParseEventDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -7448,7 +7448,7 @@ func TestParseEventEmitStatement(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -7534,7 +7534,7 @@ func TestParseResourceReturnType(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -7583,7 +7583,7 @@ func TestParseMovingVariableDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -7619,7 +7619,7 @@ func TestParseResourceParameterType(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -7678,7 +7678,7 @@ func TestParseMovingVariableDeclarationWithTypeAnnotation(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -7724,7 +7724,7 @@ func TestParseFieldDeclarationWithMoveTypeAnnotation(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -7779,7 +7779,7 @@ func TestParseDestructor(t *testing.T) { } ` _, errs := testParseDeclarations(code) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &CustomDestructorError{ Pos: ast.Position{Offset: 37, Line: 3, Column: 12}, @@ -7799,7 +7799,7 @@ func TestParseCompositeDeclarationWithSemicolonSeparatedMembers(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -7965,7 +7965,7 @@ func TestParseInvalidCompositeFunctionNames(t *testing.T) { assert.True(t, ok, "Parser error does not conform to parser.Error") syntaxErr := errs.Errors[0].(*SyntaxError) - utils.AssertEqualWithDiff( + AssertEqualWithDiff( t, "expected identifier after start of function declaration, got keyword init", syntaxErr.Message, @@ -8075,7 +8075,7 @@ func TestParsePreconditionWithUnaryNegation(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -8157,7 +8157,7 @@ func TestParseInvalidAccessModifiers(t *testing.T) { t.Parallel() _, errs := testParseDeclarations("access(all) #test") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid access modifier for pragma", @@ -8173,7 +8173,7 @@ func TestParseInvalidAccessModifiers(t *testing.T) { t.Parallel() _, errs := testParseDeclarations("access(all) transaction {}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid access modifier for transaction", @@ -8189,7 +8189,7 @@ func TestParseInvalidAccessModifiers(t *testing.T) { t.Parallel() _, errs := testParseDeclarations("access(all) access(self) let x = 1") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid second access modifier", @@ -8219,7 +8219,7 @@ func TestParseInvalidImportWithModifier(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier for import", @@ -8238,7 +8238,7 @@ func TestParseInvalidImportWithModifier(t *testing.T) { static import x from 0x1 `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -8263,7 +8263,7 @@ func TestParseInvalidImportWithModifier(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid native modifier for import", @@ -8282,7 +8282,7 @@ func TestParseInvalidImportWithModifier(t *testing.T) { native import x from 0x1 `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -8312,7 +8312,7 @@ func TestParseInvalidEventWithModifier(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier for event", @@ -8331,7 +8331,7 @@ func TestParseInvalidEventWithModifier(t *testing.T) { static event Foo() `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -8356,7 +8356,7 @@ func TestParseInvalidEventWithModifier(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid native modifier for event", @@ -8375,7 +8375,7 @@ func TestParseInvalidEventWithModifier(t *testing.T) { native event Foo() `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -8406,7 +8406,7 @@ func TestParseCompositeWithModifier(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier for structure", @@ -8425,7 +8425,7 @@ func TestParseCompositeWithModifier(t *testing.T) { static struct Foo() `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -8450,7 +8450,7 @@ func TestParseCompositeWithModifier(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid native modifier for structure", @@ -8469,7 +8469,7 @@ func TestParseCompositeWithModifier(t *testing.T) { native struct Foo() `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -8499,7 +8499,7 @@ func TestParseTransactionWithModifier(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier for transaction", @@ -8518,7 +8518,7 @@ func TestParseTransactionWithModifier(t *testing.T) { static transaction {} `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -8543,7 +8543,7 @@ func TestParseTransactionWithModifier(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid native modifier for transaction", @@ -8562,7 +8562,7 @@ func TestParseTransactionWithModifier(t *testing.T) { native transaction {} `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -8603,7 +8603,7 @@ func TestParseNestedPragma(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid native modifier for pragma", @@ -8620,7 +8620,7 @@ func TestParseNestedPragma(t *testing.T) { _, errs := parse("native #pragma", Config{}) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -8641,7 +8641,7 @@ func TestParseNestedPragma(t *testing.T) { StaticModifierEnabled: true, }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier for pragma", @@ -8661,7 +8661,7 @@ func TestParseNestedPragma(t *testing.T) { Config{}, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -8683,7 +8683,7 @@ func TestParseNestedPragma(t *testing.T) { NativeModifierEnabled: true, }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier for pragma", @@ -8700,7 +8700,7 @@ func TestParseNestedPragma(t *testing.T) { _, errs := parse("static native #pragma", Config{}) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected identifier", @@ -8723,7 +8723,7 @@ func TestParseNestedPragma(t *testing.T) { }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid static modifier after native modifier", @@ -8740,7 +8740,7 @@ func TestParseNestedPragma(t *testing.T) { _, errs := parse("access(all) #pragma", Config{}) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid access modifier for pragma", @@ -8762,7 +8762,7 @@ func TestParseNestedPragma(t *testing.T) { NativeModifierEnabled: true, }, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid access modifier for pragma", @@ -8779,7 +8779,7 @@ func TestParseNestedPragma(t *testing.T) { _, errs := parse("access(all) static native #pragma", Config{}) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected identifier", @@ -8803,7 +8803,7 @@ func TestParseEntitlementDeclaration(t *testing.T) { result, errs := testParseDeclarations(" access(all) entitlement ABC ") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.EntitlementDeclaration{ Access: ast.AccessAll, @@ -8834,7 +8834,7 @@ func TestParseEntitlementDeclaration(t *testing.T) { `) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Members: ast.NewUnmeteredMembers( @@ -8897,7 +8897,7 @@ func TestParseEntitlementDeclaration(t *testing.T) { t.Parallel() _, errs := testParseDeclarations(" access(all) entitlement") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected identifier, got EOF", @@ -8913,7 +8913,7 @@ func TestParseEntitlementDeclaration(t *testing.T) { t.Parallel() _, errs := testParseDeclarations(" access(all) view entitlement E") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid view modifier for entitlement", @@ -8949,7 +8949,7 @@ func TestParseMemberDocStrings(t *testing.T) { require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -9062,7 +9062,7 @@ func TestParseMemberDocStrings(t *testing.T) { require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ Access: ast.AccessNotSpecified, @@ -9134,7 +9134,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { result, errs := testParseDeclarations(" access(all) entitlement mapping M { } ") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.EntitlementMappingDeclaration{ Access: ast.AccessAll, @@ -9162,7 +9162,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { } `) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.EntitlementMappingDeclaration{ Access: ast.AccessAll, @@ -9251,7 +9251,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { } `) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.EntitlementMappingDeclaration{ Access: ast.AccessAll, @@ -9356,7 +9356,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { } `) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.EntitlementMappingDeclaration{ Access: ast.AccessAll, @@ -9437,7 +9437,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { t.Parallel() _, errs := testParseDeclarations(" access(all) mapping M {} ") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -9453,7 +9453,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { t.Parallel() _, errs := testParseDeclarations(" access(all) entitlement M {} ") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: '{'", @@ -9469,7 +9469,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { t.Parallel() _, errs := testParseDeclarations(" access(all) entitlement mapping M ") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token '{'", @@ -9485,7 +9485,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { t.Parallel() _, errs := testParseDeclarations(" access(all) entitlement mapping M {") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token '}'", @@ -9501,7 +9501,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { t.Parallel() _, errs := testParseDeclarations(" access(all) entitlement mapping M }") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token '{'", @@ -9517,7 +9517,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { t.Parallel() _, errs := testParseDeclarations(" access(all) entitlement mapping {}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected identifier following entitlement mapping declaration, got '{'", @@ -9536,7 +9536,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { &A -> B } `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected nominal type, got &A", @@ -9555,7 +9555,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { A -> [B] } `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected nominal type, got [B]", @@ -9574,7 +9574,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { A B } `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token '->'", @@ -9593,7 +9593,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { A - B } `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token '->'", @@ -9612,7 +9612,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { include &A } `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected nominal type, got &A", @@ -9631,7 +9631,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { include -> B } `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token in type: '->'", @@ -9653,7 +9653,7 @@ func TestParseInvalidSpecialFunctionReturnTypeAnnotation(t *testing.T) { init(): Int } `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid return type for initializer", @@ -9709,7 +9709,7 @@ func TestSoftKeywordsInFunctionDeclaration(t *testing.T) { }, }, } - utils.AssertEqualWithDiff(t, expected, result) + AssertEqualWithDiff(t, expected, result) }) } @@ -9728,7 +9728,7 @@ func TestParseDeprecatedAccessModifiers(t *testing.T) { t.Parallel() _, errs := testParseDeclarations(" pub fun foo ( ) { }") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxErrorWithSuggestedReplacement{ Message: "`pub` is no longer a valid access keyword", @@ -9749,7 +9749,7 @@ func TestParseDeprecatedAccessModifiers(t *testing.T) { t.Parallel() _, errs := testParseDeclarations(" priv fun foo ( ) { }") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxErrorWithSuggestedReplacement{ Message: "`priv` is no longer a valid access keyword", @@ -9770,7 +9770,7 @@ func TestParseDeprecatedAccessModifiers(t *testing.T) { t.Parallel() _, errs := testParseDeclarations(" pub(set) fun foo ( ) { }") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "`pub(set)` is no longer a valid access keyword", diff --git a/parser/expression.go b/parser/expression.go index fef98c5f68..8499f95e60 100644 --- a/parser/expression.go +++ b/parser/expression.go @@ -433,19 +433,6 @@ func init() { }, }) - defineExpr(literalExpr{ - tokenType: lexer.TokenString, - nullDenotation: func(p *parser, token lexer.Token) (ast.Expression, error) { - literal := p.tokenSource(token) - parsedString := parseStringLiteral(p, literal) - return ast.NewStringExpression( - p.memoryGauge, - parsedString, - token.Range, - ), nil - }, - }) - defineExpr(prefixExpr{ tokenType: lexer.TokenMinus, bindingPower: exprLeftBindingPowerUnaryPrefix, @@ -510,6 +497,7 @@ func init() { defineNestedExpression() defineInvocationExpression() defineArrayExpression() + defineStringExpression() defineDictionaryExpression() defineIndexExpression() definePathExpression() @@ -1144,6 +1132,107 @@ func defineNestedExpression() { ) } +func defineStringExpression() { + setExprNullDenotation( + lexer.TokenString, + func(p *parser, startToken lexer.Token) (ast.Expression, error) { + var literals []string + var values []ast.Expression + curToken := startToken + endToken := startToken + + // check for start " of string literal + literal := p.tokenSource(curToken) + length := len(literal) + if length == 0 { + p.reportSyntaxError("invalid end of string literal: missing '\"'") + return ast.NewStringExpression( + p.memoryGauge, + "", + startToken.Range, + ), nil + } + + if length >= 1 { + first := literal[0] + if first != '"' { + p.reportSyntaxError("invalid start of string literal: expected '\"', got %q", first) + } + } + + // flag for ending " check + missingEnd := true + + for curToken.Is(lexer.TokenString) { + literal = p.tokenSource(curToken) + + // remove quotation marks if they exist + if curToken == startToken { + literal = literal[1:] + } + + length = len(literal) + if length >= 1 && literal[length-1] == '"' { + literal = literal[:length-1] + missingEnd = false + } + + parsedString := parseStringLiteralContent(p, literal) + literals = append(literals, parsedString) + endToken = curToken + + // parser already points to next token + curToken = p.current + if curToken.Is(lexer.TokenStringTemplate) { + // advance to the expression + p.next() + value, err := parseExpression(p, lowestBindingPower) + // consider invalid expression first + if err != nil { + return nil, err + } + // limit string templates to identifiers only + if _, ok := value.(*ast.IdentifierExpression); !ok { + return nil, p.syntaxError("expected identifier got: %s", value.String()) + } + _, err = p.mustOne(lexer.TokenParenClose) + if err != nil { + return nil, err + } + values = append(values, value) + // parser already points to next token + curToken = p.current + // safely call next because this should always be a string + p.next() + missingEnd = true + } + } + + // check for end " of string literal + if missingEnd { + p.reportSyntaxError("invalid end of string literal: missing '\"'") + } + + if len(values) == 0 { + return ast.NewStringExpression( + p.memoryGauge, + literals[0], // must exist + startToken.Range, + ), nil + } else { + return ast.NewStringTemplateExpression( + p.memoryGauge, + literals, values, + ast.NewRange(p.memoryGauge, + startToken.StartPos, + endToken.EndPos), + ), nil + } + + }, + ) +} + func defineArrayExpression() { setExprNullDenotation( lexer.TokenBracketOpen, diff --git a/parser/expression_test.go b/parser/expression_test.go index 7acb0ac4eb..172884de18 100644 --- a/parser/expression_test.go +++ b/parser/expression_test.go @@ -34,7 +34,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/errors" "github.com/onflow/cadence/parser/lexer" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestParseSimpleInfixExpression(t *testing.T) { @@ -48,7 +48,7 @@ func TestParseSimpleInfixExpression(t *testing.T) { result, errs := testParseExpression("1+2*3") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationPlus, Left: &ast.IntegerExpression{ @@ -93,7 +93,7 @@ func TestParseSimpleInfixExpression(t *testing.T) { result, errs := testParseExpression(" 1 + 2 * 3 ") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationPlus, Left: &ast.IntegerExpression{ @@ -138,7 +138,7 @@ func TestParseSimpleInfixExpression(t *testing.T) { result, errs := testParseExpression("1 + 2 + 3") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationPlus, Left: &ast.BinaryExpression{ @@ -183,7 +183,7 @@ func TestParseSimpleInfixExpression(t *testing.T) { result, errs := testParseExpression("1 ?? 2 ?? 3") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationNilCoalesce, Left: &ast.IntegerExpression{ @@ -233,7 +233,7 @@ func TestParseAdvancedExpression(t *testing.T) { result, errs := testParseExpression("1 +- 2 -- 3") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationMinus, Left: &ast.BinaryExpression{ @@ -278,7 +278,7 @@ func TestParseAdvancedExpression(t *testing.T) { result, errs := testParseExpression("(1 + 2) * 3") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationMul, Left: &ast.BinaryExpression{ @@ -356,7 +356,7 @@ func TestParseAdvancedExpression(t *testing.T) { result, errs := testParseExpression("1 < 2 > 3") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationGreater, Left: &ast.BinaryExpression{ @@ -401,7 +401,7 @@ func TestParseAdvancedExpression(t *testing.T) { result, errs := testParseExpression("a ? b : c ? d : e") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ConditionalExpression{ Test: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -447,7 +447,7 @@ func TestParseAdvancedExpression(t *testing.T) { result, errs := testParseExpression("true + false") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationPlus, Left: &ast.BoolExpression{ @@ -476,7 +476,7 @@ func TestParseAdvancedExpression(t *testing.T) { result, errs := testParseExpression("(<-x)") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.UnaryExpression{ Operation: ast.OperationMove, Expression: &ast.IdentifierExpression{ @@ -498,7 +498,7 @@ func TestParseAdvancedExpression(t *testing.T) { result, errs := testParseExpression("<-x as! @T") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.UnaryExpression{ Operation: ast.OperationMove, Expression: &ast.CastingExpression{ @@ -533,7 +533,7 @@ func TestParseAdvancedExpression(t *testing.T) { result, errs := testParseExpression("<-x as? @T") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.UnaryExpression{ Operation: ast.OperationMove, Expression: &ast.CastingExpression{ @@ -568,7 +568,7 @@ func TestParseAdvancedExpression(t *testing.T) { result, errs := testParseExpression("<-x as @T") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.UnaryExpression{ Operation: ast.OperationMove, Expression: &ast.CastingExpression{ @@ -609,7 +609,7 @@ func TestParseArrayExpression(t *testing.T) { result, errs := testParseExpression("[ 1,2 + 3, 4 , 5 ]") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ArrayExpression{ Values: []ast.Expression{ &ast.IntegerExpression{ @@ -677,7 +677,7 @@ func TestParseArrayExpression(t *testing.T) { result, errs := testParseExpression("[ 1 , \n 2 \n , \n\n 3 \n\n\n]") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ArrayExpression{ Values: []ast.Expression{ &ast.IntegerExpression{ @@ -724,7 +724,7 @@ func TestParseArrayExpression(t *testing.T) { result, errs := testParseExpression("[\n]") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ArrayExpression{ Range: ast.Range{ StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, @@ -748,7 +748,7 @@ func TestParseDictionaryExpression(t *testing.T) { result, errs := testParseExpression("{ 1:2 + 3, 4 : 5 }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.DictionaryExpression{ Entries: []ast.DictionaryEntry{ { @@ -820,7 +820,7 @@ func TestParseDictionaryExpression(t *testing.T) { result, errs := testParseExpression("{ 1 : 2 , \n 3 \n : \n 4 \n , \n\n 5 \n\n : \n\n 6 \n\n }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.DictionaryExpression{ Entries: []ast.DictionaryEntry{ { @@ -900,7 +900,7 @@ func TestParseDictionaryExpression(t *testing.T) { result, errs := testParseExpression("{\n}") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.DictionaryExpression{ Range: ast.Range{ StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, @@ -921,7 +921,7 @@ func TestParseIndexExpression(t *testing.T) { result, errs := testParseExpression("a[0]") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IndexExpression{ TargetExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -953,7 +953,7 @@ func TestParseIndexExpression(t *testing.T) { result, errs := testParseExpression("a [ 0 ]") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IndexExpression{ TargetExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -985,7 +985,7 @@ func TestParseIndexExpression(t *testing.T) { result, errs := testParseExpression("a [foo]") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IndexExpression{ TargetExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1020,7 +1020,7 @@ func TestParseIdentifier(t *testing.T) { result, errs := testParseExpression("a + 3") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationPlus, Left: &ast.IdentifierExpression{ @@ -1051,7 +1051,7 @@ func TestParsePath(t *testing.T) { result, errs := testParseExpression("/foo/bar") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.PathExpression{ Domain: ast.Identifier{ Identifier: "foo", @@ -1078,7 +1078,7 @@ func TestParseString(t *testing.T) { result, errs := testParseExpression("\"\"") assert.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "", Range: ast.Range{ @@ -1095,7 +1095,7 @@ func TestParseString(t *testing.T) { t.Parallel() result, errs := testParseExpression("\"") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid end of string literal: missing '\"'", @@ -1105,7 +1105,7 @@ func TestParseString(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "", Range: ast.Range{ @@ -1122,7 +1122,7 @@ func TestParseString(t *testing.T) { t.Parallel() result, errs := testParseExpression("\"\n") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid end of string literal: missing '\"'", @@ -1132,7 +1132,7 @@ func TestParseString(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "", Range: ast.Range{ @@ -1148,7 +1148,7 @@ func TestParseString(t *testing.T) { t.Parallel() result, errs := testParseExpression("\"t") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid end of string literal: missing '\"'", @@ -1158,7 +1158,7 @@ func TestParseString(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "t", Range: ast.Range{ @@ -1175,7 +1175,7 @@ func TestParseString(t *testing.T) { t.Parallel() result, errs := testParseExpression("\"t\n") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid end of string literal: missing '\"'", @@ -1185,7 +1185,7 @@ func TestParseString(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "t", Range: ast.Range{ @@ -1202,7 +1202,7 @@ func TestParseString(t *testing.T) { t.Parallel() result, errs := testParseExpression("\"\\") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "incomplete escape sequence: missing character after escape character", @@ -1216,7 +1216,7 @@ func TestParseString(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "", Range: ast.Range{ @@ -1235,7 +1235,7 @@ func TestParseString(t *testing.T) { result, errs := testParseExpression(`"te\tst\"te\u{1F3CE}\u{FE0F}xt"`) assert.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "te\tst\"te\U0001F3CE\uFE0Fxt", Range: ast.Range{ @@ -1252,7 +1252,7 @@ func TestParseString(t *testing.T) { t.Parallel() result, errs := testParseExpression(`"te\Xst"`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid escape character: 'X'", @@ -1262,7 +1262,7 @@ func TestParseString(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "test", Range: ast.Range{ @@ -1279,7 +1279,7 @@ func TestParseString(t *testing.T) { t.Parallel() result, errs := testParseExpression(`"te\u`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "incomplete Unicode escape sequence: missing character '{' after escape character", @@ -1293,7 +1293,7 @@ func TestParseString(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "te", Range: ast.Range{ @@ -1310,7 +1310,7 @@ func TestParseString(t *testing.T) { t.Parallel() result, errs := testParseExpression(`"te\us`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid Unicode escape sequence: expected '{', got 's'", @@ -1324,7 +1324,7 @@ func TestParseString(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "te", Range: ast.Range{ @@ -1341,7 +1341,7 @@ func TestParseString(t *testing.T) { t.Parallel() result, errs := testParseExpression(`"te\u{`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "incomplete Unicode escape sequence: missing character '}' after escape character", @@ -1355,7 +1355,7 @@ func TestParseString(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "te", Range: ast.Range{ @@ -1374,7 +1374,7 @@ func TestParseString(t *testing.T) { result, errs := testParseExpression(`"te\u{}"`) assert.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "te", Range: ast.Range{ @@ -1401,7 +1401,7 @@ func TestParseString(t *testing.T) { ) assert.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "test JJJJ KKKK LLLL MMMM NNNN OOOO", Range: ast.Range{ @@ -1418,7 +1418,7 @@ func TestParseString(t *testing.T) { t.Parallel() result, errs := testParseExpression(`"te\u{X}st"`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid Unicode escape sequence: expected hex digit, got 'X'", @@ -1428,7 +1428,7 @@ func TestParseString(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.StringExpression{ Value: "test", Range: ast.Range{ @@ -1452,7 +1452,7 @@ func TestParseInvocation(t *testing.T) { result, errs := testParseExpression("f()") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1475,7 +1475,7 @@ func TestParseInvocation(t *testing.T) { result, errs := testParseExpression("f ()") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1498,7 +1498,7 @@ func TestParseInvocation(t *testing.T) { result, errs := testParseExpression("f ( )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1521,7 +1521,7 @@ func TestParseInvocation(t *testing.T) { result, errs := testParseExpression("f(1)") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1558,7 +1558,7 @@ func TestParseInvocation(t *testing.T) { result, errs := testParseExpression("f(label:1)") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1597,7 +1597,7 @@ func TestParseInvocation(t *testing.T) { result, errs := testParseExpression("f(1,2)") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1647,7 +1647,7 @@ func TestParseInvocation(t *testing.T) { result, errs := testParseExpression("f(a:1,b:2)") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1699,7 +1699,7 @@ func TestParseInvocation(t *testing.T) { t.Parallel() _, errs := testParseExpression("f(,,)") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected argument or end of argument list, got ','", @@ -1715,7 +1715,7 @@ func TestParseInvocation(t *testing.T) { t.Parallel() _, errs := testParseExpression("f(1,,)") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected argument or end of argument list, got ','", @@ -1731,7 +1731,7 @@ func TestParseInvocation(t *testing.T) { t.Parallel() _, errs := testParseExpression("f(1 2)") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected argument in argument list (expecting delimiter or end of argument list)," + @@ -1750,7 +1750,7 @@ func TestParseInvocation(t *testing.T) { result, errs := testParseExpression("f(1,g(2))") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1816,7 +1816,7 @@ func TestParseInvocation(t *testing.T) { result, errs := testParseExpression("f(1,g(\"test\"))") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1885,7 +1885,7 @@ func TestParseMemberExpression(t *testing.T) { result, errs := testParseExpression("f.n") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.MemberExpression{ Expression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1910,7 +1910,7 @@ func TestParseMemberExpression(t *testing.T) { result, errs := testParseExpression("f .n") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.MemberExpression{ Expression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1933,7 +1933,7 @@ func TestParseMemberExpression(t *testing.T) { t.Parallel() result, errs := testParseExpression("f.") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected member name, got EOF", @@ -1943,7 +1943,7 @@ func TestParseMemberExpression(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.MemberExpression{ Expression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -1964,7 +1964,7 @@ func TestParseMemberExpression(t *testing.T) { result, errs := testParseExpression("f.n * 3") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationMul, Left: &ast.MemberExpression{ @@ -2001,7 +2001,7 @@ func TestParseMemberExpression(t *testing.T) { result, errs := testParseExpression("3 * f.n") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationMul, Left: &ast.IntegerExpression{ @@ -2038,7 +2038,7 @@ func TestParseMemberExpression(t *testing.T) { result, errs := testParseExpression("f?.n") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.MemberExpression{ Optional: true, Expression: &ast.IdentifierExpression{ @@ -2067,7 +2067,7 @@ func TestParseMemberExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2112,7 +2112,7 @@ func TestParseBlockComment(t *testing.T) { result, errs := testParseExpression(" /* test foo/* bar */ asd*/ true") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BoolExpression{ Value: true, Range: ast.Range{ @@ -2131,7 +2131,7 @@ func TestParseBlockComment(t *testing.T) { result, errs := testParseExpression(" /*test foo*/ /* bar */ true") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BoolExpression{ Value: true, Range: ast.Range{ @@ -2150,7 +2150,7 @@ func TestParseBlockComment(t *testing.T) { result, errs := testParseExpression(" 1/*test foo*/+/* bar */ 2 ") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationPlus, Left: &ast.IntegerExpression{ @@ -2181,7 +2181,7 @@ func TestParseBlockComment(t *testing.T) { t.Parallel() _, errs := testParseExpression(" /* test foo/* bar */ asd*/ true */ bar") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ // `true */ bar` is parsed as infix operation of path &SyntaxError{ @@ -2202,7 +2202,7 @@ func TestParseBlockComment(t *testing.T) { t.Parallel() _, errs := testParseExpression(" /* test foo/* bar */ asd true ") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ // `true */ bar` is parsed as infix operation of path &SyntaxError{ @@ -2277,7 +2277,7 @@ func TestParseBlockComment(t *testing.T) { }, Config{}, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token identifier in block comment", @@ -2300,7 +2300,7 @@ func TestParseMulInfixExpression(t *testing.T) { result, errs := testParseExpression(" 1 ** 2") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationMul, Left: &ast.IntegerExpression{ @@ -2373,7 +2373,7 @@ func TestParseReference(t *testing.T) { result, errs := testParseExpression("& t") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ReferenceExpression{ Expression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -2396,7 +2396,7 @@ func TestParseReference(t *testing.T) { result, errs := testParseExpression(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ReferenceExpression{ Expression: &ast.IndexExpression{ TargetExpression: &ast.IdentifierExpression{ @@ -2429,7 +2429,7 @@ func TestParseReference(t *testing.T) { const code = `&x[y]? as &Z?` _, errs := testParseExpression(code) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected end of program", @@ -2454,7 +2454,7 @@ func TestParseNilCoelesceReference(t *testing.T) { `) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationNilCoalesce, Left: &ast.CastingExpression{ @@ -2570,7 +2570,7 @@ func TestParseCasts(t *testing.T) { result, errs := testParseExpression(" t as T") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.CastingExpression{ Operation: ast.OperationCast, Expression: &ast.IdentifierExpression{ @@ -2600,7 +2600,7 @@ func TestParseCasts(t *testing.T) { result, errs := testParseExpression(" t as? T") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.CastingExpression{ Operation: ast.OperationFailableCast, Expression: &ast.IdentifierExpression{ @@ -2631,7 +2631,7 @@ func TestParseCasts(t *testing.T) { result, errs := testParseExpression(" t as! T") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.CastingExpression{ Operation: ast.OperationForceCast, Expression: &ast.IdentifierExpression{ @@ -2666,7 +2666,7 @@ func TestParseForceExpression(t *testing.T) { result, errs := testParseExpression("t!") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ForceExpression{ Expression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -2687,7 +2687,7 @@ func TestParseForceExpression(t *testing.T) { result, errs := testParseExpression(" t ! ") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ForceExpression{ Expression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -2708,7 +2708,7 @@ func TestParseForceExpression(t *testing.T) { result, errs := testParseExpression("<-t!") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.UnaryExpression{ Operation: ast.OperationMove, Expression: &ast.ForceExpression{ @@ -2733,7 +2733,7 @@ func TestParseForceExpression(t *testing.T) { result, errs := testParseExpression("10 * t!") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationMul, Left: &ast.IntegerExpression{ @@ -2765,7 +2765,7 @@ func TestParseForceExpression(t *testing.T) { result, errs := testParseStatements("x\n!y") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ExpressionStatement{ Expression: &ast.IdentifierExpression{ @@ -2799,7 +2799,7 @@ func TestParseForceExpression(t *testing.T) { result, errs := testParseStatements("x\n.y!") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ExpressionStatement{ Expression: &ast.ForceExpression{ @@ -2829,7 +2829,7 @@ func TestParseForceExpression(t *testing.T) { t.Parallel() result, errs := testParseStatements("x. y") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid whitespace after '.'", @@ -2839,7 +2839,7 @@ func TestParseForceExpression(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ExpressionStatement{ Expression: &ast.MemberExpression{ @@ -2873,7 +2873,7 @@ func TestParseCreate(t *testing.T) { result, errs := testParseExpression("create T()") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.CreateExpression{ InvocationExpression: &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ @@ -2899,7 +2899,7 @@ func TestParseNil(t *testing.T) { result, errs := testParseExpression(" nil") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.NilExpression{ Pos: ast.Position{Line: 1, Column: 1, Offset: 1}, }, @@ -2918,7 +2918,7 @@ func TestParseDestroy(t *testing.T) { result, errs := testParseExpression("destroy t") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.DestroyExpression{ Expression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -2944,7 +2944,7 @@ func TestParseAttach(t *testing.T) { result, errs := testParseExpression("attach E() to r") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.AttachExpression{ Base: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -2973,7 +2973,7 @@ func TestParseAttach(t *testing.T) { t.Parallel() _, errs := testParseExpression("attach E() to r with (X)") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -2991,7 +2991,7 @@ func TestParseAttach(t *testing.T) { result, errs := testParseExpression("attach A() to attach B() to r") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.AttachExpression{ Base: &ast.AttachExpression{ Base: &ast.IdentifierExpression{ @@ -3033,7 +3033,7 @@ func TestParseAttach(t *testing.T) { t.Parallel() _, errs := testParseExpression("attach A()") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected 'to', got EOF", @@ -3049,7 +3049,7 @@ func TestParseAttach(t *testing.T) { t.Parallel() _, errs := testParseExpression("attach E() to") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected end of program", @@ -3068,7 +3068,7 @@ func TestParseLineComment(t *testing.T) { result, errs := testParseExpression(" //// // this is a comment\n 1 / 2") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationDiv, Left: &ast.IntegerExpression{ @@ -3105,7 +3105,7 @@ func TestParseFunctionExpression(t *testing.T) { result, errs := testParseExpression("fun () { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FunctionExpression{ ParameterList: &ast.ParameterList{ Parameters: nil, @@ -3135,7 +3135,7 @@ func TestParseFunctionExpression(t *testing.T) { result, errs := testParseExpression("fun (): X { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FunctionExpression{ ParameterList: &ast.ParameterList{ Parameters: nil, @@ -3174,7 +3174,7 @@ func TestParseFunctionExpression(t *testing.T) { result, errs := testParseExpression("view fun (): X { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FunctionExpression{ Purity: 1, ParameterList: &ast.ParameterList{ @@ -3212,7 +3212,7 @@ func TestParseFunctionExpression(t *testing.T) { t.Parallel() _, errs := testParseExpression("view for (): X { }") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", @@ -3255,7 +3255,7 @@ func TestParseAdjacentViewKeyword(t *testing.T) { }, StartPos: ast.Position{Line: 2, Column: 2, Offset: 3}, } - utils.AssertEqualWithDiff(t, expected, result) + AssertEqualWithDiff(t, expected, result) } @@ -3268,7 +3268,7 @@ func TestParseIntegerLiterals(t *testing.T) { t.Parallel() result, errs := testParseExpression(`0b`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "missing digits", @@ -3287,7 +3287,7 @@ func TestParseIntegerLiterals(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0b"), Value: new(big.Int), @@ -3308,7 +3308,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`0b101010`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0b101010"), Value: big.NewInt(42), @@ -3327,7 +3327,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`0b001000`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0b001000"), Value: big.NewInt(8), @@ -3348,7 +3348,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`0b101010_101010`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0b101010_101010"), Value: big.NewInt(2730), @@ -3367,7 +3367,7 @@ func TestParseIntegerLiterals(t *testing.T) { t.Parallel() result, errs := testParseExpression(`0b_101010_101010`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &InvalidIntegerLiteralError{ Literal: "0b_101010_101010", @@ -3382,7 +3382,7 @@ func TestParseIntegerLiterals(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0b_101010_101010"), Value: big.NewInt(2730), @@ -3401,7 +3401,7 @@ func TestParseIntegerLiterals(t *testing.T) { t.Parallel() result, errs := testParseExpression(`0b101010_101010_`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &InvalidIntegerLiteralError{ Literal: "0b101010_101010_", @@ -3416,7 +3416,7 @@ func TestParseIntegerLiterals(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0b101010_101010_"), Value: big.NewInt(2730), @@ -3435,7 +3435,7 @@ func TestParseIntegerLiterals(t *testing.T) { t.Parallel() result, errs := testParseExpression(`0o`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "missing digits", @@ -3454,7 +3454,7 @@ func TestParseIntegerLiterals(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0o"), Value: new(big.Int), @@ -3475,7 +3475,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`0o32`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0o32"), Value: big.NewInt(26), @@ -3496,7 +3496,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`0o32_45`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0o32_45"), Value: big.NewInt(1701), @@ -3515,7 +3515,7 @@ func TestParseIntegerLiterals(t *testing.T) { t.Parallel() result, errs := testParseExpression(`0o_32_45`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &InvalidIntegerLiteralError{ Literal: "0o_32_45", @@ -3530,7 +3530,7 @@ func TestParseIntegerLiterals(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0o_32_45"), Value: big.NewInt(1701), @@ -3549,7 +3549,7 @@ func TestParseIntegerLiterals(t *testing.T) { t.Parallel() result, errs := testParseExpression(`0o32_45_`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &InvalidIntegerLiteralError{ Literal: "0o32_45_", @@ -3564,7 +3564,7 @@ func TestParseIntegerLiterals(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0o32_45_"), Value: big.NewInt(1701), @@ -3585,7 +3585,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`1234567890`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("1234567890"), Value: big.NewInt(1234567890), @@ -3606,7 +3606,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`1_234_567_890`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("1_234_567_890"), Value: big.NewInt(1234567890), @@ -3625,7 +3625,7 @@ func TestParseIntegerLiterals(t *testing.T) { t.Parallel() result, errs := testParseExpression(`1_234_567_890_`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &InvalidIntegerLiteralError{ Literal: "1_234_567_890_", @@ -3640,7 +3640,7 @@ func TestParseIntegerLiterals(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("1_234_567_890_"), Value: big.NewInt(1234567890), @@ -3659,7 +3659,7 @@ func TestParseIntegerLiterals(t *testing.T) { t.Parallel() result, errs := testParseExpression(`0x`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "missing digits", @@ -3678,7 +3678,7 @@ func TestParseIntegerLiterals(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0x"), Value: new(big.Int), @@ -3699,7 +3699,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`0xf2`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0xf2"), Value: big.NewInt(242), @@ -3720,7 +3720,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`0xf2_09`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0xf2_09"), Value: big.NewInt(61961), @@ -3739,7 +3739,7 @@ func TestParseIntegerLiterals(t *testing.T) { t.Parallel() result, errs := testParseExpression(`0x_f2_09`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &InvalidIntegerLiteralError{ Literal: "0x_f2_09", @@ -3754,7 +3754,7 @@ func TestParseIntegerLiterals(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0x_f2_09"), Value: big.NewInt(61961), @@ -3773,7 +3773,7 @@ func TestParseIntegerLiterals(t *testing.T) { t.Parallel() result, errs := testParseExpression(`0xf2_09_`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &InvalidIntegerLiteralError{ Literal: `0xf2_09_`, @@ -3788,7 +3788,7 @@ func TestParseIntegerLiterals(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0xf2_09_"), Value: big.NewInt(61961), @@ -3809,7 +3809,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`0`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0"), Value: big.NewInt(0), @@ -3830,7 +3830,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`01`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("01"), Value: big.NewInt(1), @@ -3851,7 +3851,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`09`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("09"), Value: big.NewInt(9), @@ -3872,7 +3872,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression("00123") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("00123"), Value: big.NewInt(123), @@ -3891,7 +3891,7 @@ func TestParseIntegerLiterals(t *testing.T) { t.Parallel() result, errs := testParseExpression(`0z123`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid number literal prefix: 'z'", @@ -3910,7 +3910,7 @@ func TestParseIntegerLiterals(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0z123"), Value: new(big.Int), @@ -3931,7 +3931,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`0_100`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("0_100"), Value: big.NewInt(100), @@ -3952,7 +3952,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`1_100`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntegerExpression{ PositiveLiteral: []byte("1_100"), Value: big.NewInt(1100), @@ -3975,7 +3975,7 @@ func TestParseIntegerLiterals(t *testing.T) { result, errs := testParseExpression(`_100`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IdentifierExpression{ Identifier: ast.Identifier{ Identifier: "_100", @@ -3998,7 +3998,7 @@ func TestParseFixedPoint(t *testing.T) { result, errs := testParseExpression("1234_5678_90.0009_8765_4321") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FixedPointExpression{ PositiveLiteral: []byte("1234_5678_90.0009_8765_4321"), Negative: false, @@ -4021,7 +4021,7 @@ func TestParseFixedPoint(t *testing.T) { result, errs := testParseExpression("0.1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FixedPointExpression{ PositiveLiteral: []byte("0.1"), Negative: false, @@ -4042,7 +4042,7 @@ func TestParseFixedPoint(t *testing.T) { t.Parallel() result, errs := testParseExpression("0.") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "missing fractional digits", @@ -4052,7 +4052,7 @@ func TestParseFixedPoint(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FixedPointExpression{ PositiveLiteral: []byte("0."), Negative: false, @@ -4080,7 +4080,7 @@ func TestParseLessThanOrTypeArguments(t *testing.T) { result, errs := testParseExpression("1 < 2") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationLess, Left: &ast.IntegerExpression{ @@ -4113,7 +4113,7 @@ func TestParseLessThanOrTypeArguments(t *testing.T) { result, errs := testParseExpression("a < > ()") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -4137,7 +4137,7 @@ func TestParseLessThanOrTypeArguments(t *testing.T) { result, errs := testParseExpression("a < { K : V } > ( 1 )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -4197,7 +4197,7 @@ func TestParseLessThanOrTypeArguments(t *testing.T) { result, errs := testParseExpression("a < { K : V } , @R , [ S ] > ( 1 , 2 )") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -4295,7 +4295,7 @@ func TestParseLessThanOrTypeArguments(t *testing.T) { result, errs := testParseExpression("1 + a<>()") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationPlus, Left: &ast.IntegerExpression{ @@ -4331,7 +4331,7 @@ func TestParseLessThanOrTypeArguments(t *testing.T) { result, errs := testParseExpression("a>()") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -4381,7 +4381,7 @@ func TestParseLessThanOrTypeArguments(t *testing.T) { result, errs := testParseExpression("a >()") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InvocationExpression{ InvokedExpression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ @@ -4431,7 +4431,7 @@ func TestParseLessThanOrTypeArguments(t *testing.T) { result, errs := testParseExpression("0 + 1 < 2") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationLess, Left: &ast.BinaryExpression{ @@ -4476,7 +4476,7 @@ func TestParseLessThanOrTypeArguments(t *testing.T) { result, errs := testParseExpression("0 + 1 << 2") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationBitwiseLeftShift, Left: &ast.BinaryExpression{ @@ -4521,7 +4521,7 @@ func TestParseLessThanOrTypeArguments(t *testing.T) { result, errs := testParseExpression("0 + 1 > 2") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationGreater, Left: &ast.BinaryExpression{ @@ -4566,7 +4566,7 @@ func TestParseLessThanOrTypeArguments(t *testing.T) { result, errs := testParseExpression("0 + 1 >> 2") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.BinaryExpression{ Operation: ast.OperationBitwiseRightShift, Left: &ast.BinaryExpression{ @@ -4609,7 +4609,7 @@ func TestParseLessThanOrTypeArguments(t *testing.T) { t.Parallel() _, errs := testParseExpression("foo") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &RestrictedTypeError{ Range: ast.Range{ @@ -4633,7 +4633,7 @@ func TestParseBoolExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -4670,7 +4670,7 @@ func TestParseIdentifierExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -4706,7 +4706,7 @@ func TestParseArrayExpressionInVariableDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -4761,7 +4761,7 @@ func TestParseDictionaryExpressionInVariableDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -4834,7 +4834,7 @@ func TestParseInvocationExpressionWithoutLabels(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -4902,7 +4902,7 @@ func TestParseInvocationExpressionWithLabels(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -4989,7 +4989,7 @@ func TestParseOptionalMemberExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5033,7 +5033,7 @@ func TestParseIndexExpressionInVariableDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5087,7 +5087,7 @@ func TestParseUnaryExpression(t *testing.T) { result, errs := testParseExpression(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.UnaryExpression{ Operation: ast.OperationMinus, Expression: &ast.IdentifierExpression{ @@ -5111,7 +5111,7 @@ func TestParseUnaryExpression(t *testing.T) { result, errs := testParseExpression(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.UnaryExpression{ Operation: ast.OperationNegate, Expression: &ast.IdentifierExpression{ @@ -5135,7 +5135,7 @@ func TestParseUnaryExpression(t *testing.T) { result, errs := testParseExpression(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.UnaryExpression{ Operation: ast.OperationMul, Expression: &ast.IdentifierExpression{ @@ -5157,7 +5157,7 @@ func TestParseUnaryExpression(t *testing.T) { const code = ` % boo` _, errs := testParseExpression(code) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token in expression: '%'", @@ -5179,7 +5179,7 @@ func TestParseOrExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5226,7 +5226,7 @@ func TestParseAndExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5273,7 +5273,7 @@ func TestParseEqualityExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5320,7 +5320,7 @@ func TestParseRelationalExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5371,7 +5371,7 @@ func TestParseAdditiveExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5422,7 +5422,7 @@ func TestParseMultiplicativeExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5473,7 +5473,7 @@ func TestParseFunctionExpressionAndReturn(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5547,7 +5547,7 @@ func TestParseLeftAssociativity(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5610,7 +5610,7 @@ func TestParseNegativeInteger(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5649,7 +5649,7 @@ func TestParseNegativeFixedPoint(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5692,7 +5692,7 @@ func TestParseTernaryRightAssociativity(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5795,7 +5795,7 @@ func TestParseVoidLiteral(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5841,7 +5841,7 @@ func TestParseMissingReturnType(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -5983,7 +5983,7 @@ func TestParseExpression(t *testing.T) { }, } - utils.AssertEqualWithDiff(t, expected, actual) + AssertEqualWithDiff(t, expected, actual) } func TestParseStringEscapes(t *testing.T) { @@ -6011,7 +6011,7 @@ func TestParseStringEscapes(t *testing.T) { }, } - utils.AssertEqualWithDiff(t, expected, actual) + AssertEqualWithDiff(t, expected, actual) } func TestParseStringWithUnicode(t *testing.T) { @@ -6039,7 +6039,463 @@ func TestParseStringWithUnicode(t *testing.T) { }, } - utils.AssertEqualWithDiff(t, expected, actual) + AssertEqualWithDiff(t, expected, actual) +} + +func TestParseStringTemplate(t *testing.T) { + + t.Parallel() + + t.Run("simple", func(t *testing.T) { + + t.Parallel() + + actual, errs := testParseExpression(` + "\(test)" + `) + + var err error + if len(errs) > 0 { + err = Error{ + Errors: errs, + } + } + + require.NoError(t, err) + + expected := &ast.StringTemplateExpression{ + Values: []string{ + "", + "", + }, + Expressions: []ast.Expression{ + &ast.IdentifierExpression{ + Identifier: ast.Identifier{ + Identifier: "test", + Pos: ast.Position{Offset: 6, Line: 2, Column: 5}, + }, + }, + }, + Range: ast.Range{ + StartPos: ast.Position{Offset: 3, Line: 2, Column: 2}, + EndPos: ast.Position{Offset: 11, Line: 2, Column: 10}, + }, + } + + AssertEqualWithDiff(t, expected, actual) + }) + + t.Run("multi", func(t *testing.T) { + + t.Parallel() + + actual, errs := testParseExpression(` + "this is a test \(abc)\(def) test" + `) + + var err error + if len(errs) > 0 { + err = Error{ + Errors: errs, + } + } + + require.NoError(t, err) + + expected := &ast.StringTemplateExpression{ + Values: []string{ + "this is a test ", + "", + " test", + }, + Expressions: []ast.Expression{ + &ast.IdentifierExpression{ + Identifier: ast.Identifier{ + Identifier: "abc", + Pos: ast.Position{Offset: 21, Line: 2, Column: 20}, + }, + }, + &ast.IdentifierExpression{ + Identifier: ast.Identifier{ + Identifier: "def", + Pos: ast.Position{Offset: 27, Line: 2, Column: 27}, + }, + }, + }, + Range: ast.Range{ + StartPos: ast.Position{Offset: 3, Line: 2, Column: 2}, + EndPos: ast.Position{Offset: 36, Line: 2, Column: 36}, + }, + } + + AssertEqualWithDiff(t, expected, actual) + }) + + t.Run("missing end", func(t *testing.T) { + + t.Parallel() + + _, errs := testParseExpression(` + "this is a test \(FOO) + `) + + var err error + if len(errs) > 0 { + err = Error{ + Errors: errs, + } + } + + require.Error(t, err) + AssertEqualWithDiff(t, + []error{ + &SyntaxError{ + Message: "invalid end of string literal: missing '\"'", + Pos: ast.Position{Offset: 27, Line: 2, Column: 27}, + }, + }, + errs, + ) + }) + + t.Run("invalid identifier", func(t *testing.T) { + + t.Parallel() + + _, errs := testParseExpression(` + "\(.)" + `) + + var err error + if len(errs) > 0 { + err = Error{ + Errors: errs, + } + } + + require.Error(t, err) + AssertEqualWithDiff(t, + []error{ + &SyntaxError{ + Message: "unexpected token in expression: '.'", + Pos: ast.Position{Offset: 9, Line: 2, Column: 8}, + }, + }, + errs, + ) + }) + + t.Run("invalid, num", func(t *testing.T) { + + t.Parallel() + + _, errs := testParseExpression(` + "\(2 + 2) is a" + `) + + var err error + if len(errs) > 0 { + err = Error{ + Errors: errs, + } + } + + require.Error(t, err) + AssertEqualWithDiff(t, + []error{ + &SyntaxError{ + Message: "expected identifier got: 2 + 2", + Pos: ast.Position{Offset: 13, Line: 2, Column: 12}, + }, + }, + errs, + ) + }) + + t.Run("valid, nested identifier", func(t *testing.T) { + + t.Parallel() + + actual, errs := testParseExpression(` + "\((a))" + `) + + var err error + if len(errs) > 0 { + err = Error{ + Errors: errs, + } + } + + require.NoError(t, err) + + expected := &ast.StringTemplateExpression{ + Values: []string{ + "", + "", + }, + Expressions: []ast.Expression{ + &ast.IdentifierExpression{ + Identifier: ast.Identifier{ + Identifier: "a", + Pos: ast.Position{Offset: 9, Line: 2, Column: 8}, + }, + }, + }, + Range: ast.Range{ + StartPos: ast.Position{Offset: 5, Line: 2, Column: 4}, + EndPos: ast.Position{Offset: 12, Line: 2, Column: 11}, + }, + } + + AssertEqualWithDiff(t, expected, actual) + + }) + t.Run("invalid, empty", func(t *testing.T) { + + t.Parallel() + + _, errs := testParseExpression(` + "\()" + `) + + var err error + if len(errs) > 0 { + err = Error{ + Errors: errs, + } + } + + require.Error(t, err) + AssertEqualWithDiff(t, + []error{ + &SyntaxError{ + Message: "unexpected token in expression: ')'", + Pos: ast.Position{Offset: 9, Line: 2, Column: 8}, + }, + }, + errs, + ) + }) + + t.Run("invalid, function identifier", func(t *testing.T) { + + t.Parallel() + + _, errs := testParseExpression(` + "\(add())" + `) + + var err error + if len(errs) > 0 { + err = Error{ + Errors: errs, + } + } + + require.Error(t, err) + AssertEqualWithDiff(t, + []error{ + &SyntaxError{ + Message: "expected identifier got: add()", + Pos: ast.Position{Offset: 12, Line: 2, Column: 11}, + }, + }, + errs, + ) + }) + + t.Run("invalid, unbalanced paren", func(t *testing.T) { + + t.Parallel() + + _, errs := testParseExpression(` + "\(add" + `) + + var err error + if len(errs) > 0 { + err = Error{ + Errors: errs, + } + } + + require.Error(t, err) + AssertEqualWithDiff(t, + []error{ + &SyntaxError{ + Message: "expected token ')'", + Pos: ast.Position{Offset: 10, Line: 2, Column: 9}, + }, + }, + errs, + ) + }) + + t.Run("invalid, nested templates", func(t *testing.T) { + + t.Parallel() + + _, errs := testParseExpression(` + "outer string \( "\(inner template)" )" + `) + + var err error + if len(errs) > 0 { + err = Error{ + Errors: errs, + } + } + + require.Error(t, err) + AssertEqualWithDiff(t, + []error{ + &SyntaxError{ + Message: "expected token ')'", + Pos: ast.Position{Offset: 30, Line: 2, Column: 29}, + }, + }, + errs, + ) + }) + + t.Run("valid, alternating", func(t *testing.T) { + + t.Parallel() + + actual, errs := testParseExpression(` + "a\(b)c" + `) + + var err error + if len(errs) > 0 { + err = Error{ + Errors: errs, + } + } + + require.NoError(t, err) + + expected := &ast.StringTemplateExpression{ + Values: []string{ + "a", + "c", + }, + Expressions: []ast.Expression{ + &ast.IdentifierExpression{ + Identifier: ast.Identifier{ + Identifier: "b", + Pos: ast.Position{Offset: 8, Line: 2, Column: 7}, + }, + }, + }, + Range: ast.Range{ + StartPos: ast.Position{Offset: 4, Line: 2, Column: 3}, + EndPos: ast.Position{Offset: 11, Line: 2, Column: 10}, + }, + } + + AssertEqualWithDiff(t, expected, actual) + }) + + t.Run("valid, surrounded", func(t *testing.T) { + + t.Parallel() + + actual, errs := testParseExpression(` + "\(a)b\(c)" + `) + + var err error + if len(errs) > 0 { + err = Error{ + Errors: errs, + } + } + + require.NoError(t, err) + + expected := &ast.StringTemplateExpression{ + Values: []string{ + "", + "b", + "", + }, + Expressions: []ast.Expression{ + &ast.IdentifierExpression{ + Identifier: ast.Identifier{ + Identifier: "a", + Pos: ast.Position{Offset: 7, Line: 2, Column: 6}, + }, + }, + &ast.IdentifierExpression{ + Identifier: ast.Identifier{ + Identifier: "c", + Pos: ast.Position{Offset: 12, Line: 2, Column: 11}, + }, + }, + }, + Range: ast.Range{ + StartPos: ast.Position{Offset: 4, Line: 2, Column: 3}, + EndPos: ast.Position{Offset: 14, Line: 2, Column: 13}, + }, + } + + AssertEqualWithDiff(t, expected, actual) + }) + + t.Run("valid, adjacent", func(t *testing.T) { + + t.Parallel() + + actual, errs := testParseExpression(` + "\(a)\(b)\(c)" + `) + + var err error + if len(errs) > 0 { + err = Error{ + Errors: errs, + } + } + + require.NoError(t, err) + + expected := &ast.StringTemplateExpression{ + Values: []string{ + "", + "", + "", + "", + }, + Expressions: []ast.Expression{ + &ast.IdentifierExpression{ + Identifier: ast.Identifier{ + Identifier: "a", + Pos: ast.Position{Offset: 7, Line: 2, Column: 6}, + }, + }, + &ast.IdentifierExpression{ + Identifier: ast.Identifier{ + Identifier: "b", + Pos: ast.Position{Offset: 11, Line: 2, Column: 11}, + }, + }, + &ast.IdentifierExpression{ + Identifier: ast.Identifier{ + Identifier: "c", + Pos: ast.Position{Offset: 15, Line: 2, Column: 16}, + }, + }, + }, + Range: ast.Range{ + StartPos: ast.Position{Offset: 4, Line: 2, Column: 3}, + EndPos: ast.Position{Offset: 17, Line: 2, Column: 18}, + }, + } + + AssertEqualWithDiff(t, expected, actual) + }) } func TestParseNilCoalescing(t *testing.T) { @@ -6052,7 +6508,7 @@ func TestParseNilCoalescing(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -6098,7 +6554,7 @@ func TestParseNilCoalescingRightAssociativity(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -6201,7 +6657,7 @@ func TestParseFailableCasting(t *testing.T) { failableDowncast.ParentVariableDeclaration = variableDeclaration - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ variableDeclaration, }, @@ -6219,7 +6675,7 @@ func TestParseMoveOperator(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -6277,7 +6733,7 @@ func TestParseFunctionExpressionWithResourceTypeAnnotation(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ @@ -6386,7 +6842,7 @@ func TestParseFailableCastingResourceTypeAnnotation(t *testing.T) { failableDowncast.ParentVariableDeclaration = variableDeclaration - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ variableDeclaration, }, @@ -6440,7 +6896,7 @@ func TestParseCasting(t *testing.T) { cast.ParentVariableDeclaration = variableDeclaration - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ variableDeclaration, }, @@ -6484,7 +6940,7 @@ func TestParseHardKeywords(t *testing.T) { t.Parallel() testParseIdentifiersWith(t, HardKeywords, func(t *testing.T, keyword string, err error) { - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Pos: ast.Position{Line: 1, Column: 4, Offset: 4}, @@ -6573,7 +7029,7 @@ func TestParseReferenceInVariableDeclaration(t *testing.T) { expected.Value.(*ast.CastingExpression).ParentVariableDeclaration = expected - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ expected, }, @@ -6591,7 +7047,7 @@ func TestParseFixedPointExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -6631,7 +7087,7 @@ func TestParseFixedPointExpressionZeroInteger(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -6671,7 +7127,7 @@ func TestParsePathLiteral(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -6711,7 +7167,7 @@ func TestParseBitwiseExpression(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, diff --git a/parser/lexer/lexer.go b/parser/lexer/lexer.go index 2a59bc9b52..8501b69240 100644 --- a/parser/lexer/lexer.go +++ b/parser/lexer/lexer.go @@ -49,6 +49,13 @@ type position struct { column int } +type lexerMode uint8 + +const ( + lexerModeNormal lexerMode = iota + lexerModeStringInterpolation +) + type lexer struct { // memoryGauge is used for metering memory usage memoryGauge common.MemoryGauge @@ -74,6 +81,10 @@ type lexer struct { prev rune // canBackup indicates whether stepping back is allowed canBackup bool + // lexer mode is used for string templates + mode lexerMode + // counts the number of unclosed brackets for string templates \((())) + openBrackets int } var _ TokenStream = &lexer{} @@ -130,6 +141,8 @@ func (l *lexer) clear() { l.cursor = 0 l.tokens = l.tokens[:0] l.tokenCount = 0 + l.mode = lexerModeNormal + l.openBrackets = 0 } func (l *lexer) Reclaim() { @@ -404,8 +417,19 @@ func (l *lexer) scanString(quote rune) { l.backupOne() return case '\\': + // might have to backup twice due to string template + tmpBackupOffset := l.prevEndOffset + tmpBackup := l.prev r = l.next() switch r { + case '(': + // string template, stop and set mode + l.mode = lexerModeStringInterpolation + // no need to update prev values because these next tokens will not backup + l.endOffset = tmpBackupOffset + l.current = tmpBackup + l.canBackup = false + return case '\n', EOF: // NOTE: invalid end of string handled by parser l.backupOne() diff --git a/parser/lexer/lexer_test.go b/parser/lexer/lexer_test.go index d6562fdebd..3a30d729e4 100644 --- a/parser/lexer/lexer_test.go +++ b/parser/lexer/lexer_test.go @@ -28,7 +28,7 @@ import ( "go.uber.org/goleak" "github.com/onflow/cadence/ast" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestMain(m *testing.M) { @@ -67,7 +67,7 @@ func testLex(t *testing.T, input string, expected []token) { require.NoError(t, err) withTokens(tokenStream, func(actualTokens []Token) { - utils.AssertEqualWithDiff(t, expectedTokens, actualTokens) + AssertEqualWithDiff(t, expectedTokens, actualTokens) require.Len(t, actualTokens, len(expectedTokens)) for i, expectedToken := range expected { @@ -1017,6 +1017,448 @@ func TestLexString(t *testing.T) { ) }) + t.Run("valid, string template", func(t *testing.T) { + testLex(t, + `"\(abc).length"`, + []token{ + { + Token: Token{ + Type: TokenString, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, + EndPos: ast.Position{Line: 1, Column: 0, Offset: 0}, + }, + }, + Source: `"`, + }, + { + Token: Token{ + Type: TokenStringTemplate, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 1, Offset: 1}, + EndPos: ast.Position{Line: 1, Column: 2, Offset: 2}, + }, + }, + Source: `\(`, + }, + { + Token: Token{ + Type: TokenIdentifier, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 3, Offset: 3}, + EndPos: ast.Position{Line: 1, Column: 5, Offset: 5}, + }, + }, + Source: `abc`, + }, + { + Token: Token{ + Type: TokenParenClose, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 6, Offset: 6}, + EndPos: ast.Position{Line: 1, Column: 6, Offset: 6}, + }, + }, + Source: `)`, + }, + { + Token: Token{ + Type: TokenString, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 7, Offset: 7}, + EndPos: ast.Position{Line: 1, Column: 14, Offset: 14}, + }, + }, + Source: `.length"`, + }, + { + Token: Token{ + Type: TokenEOF, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 15, Offset: 15}, + EndPos: ast.Position{Line: 1, Column: 15, Offset: 15}, + }, + }, + }, + }, + ) + }) + + t.Run("valid, not a string template", func(t *testing.T) { + testLex(t, + `"(1.00)"`, + []token{ + { + Token: Token{ + Type: TokenString, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, + EndPos: ast.Position{Line: 1, Column: 7, Offset: 7}, + }, + }, + Source: `"(1.00)"`, + }, + { + Token: Token{ + Type: TokenEOF, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 8, Offset: 8}, + EndPos: ast.Position{Line: 1, Column: 8, Offset: 8}, + }, + }, + }, + }, + ) + }) + + t.Run("invalid, number string template", func(t *testing.T) { + testLex(t, + `"\(7)"`, + []token{ + { + Token: Token{ + Type: TokenString, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, + EndPos: ast.Position{Line: 1, Column: 0, Offset: 0}, + }, + }, + Source: `"`, + }, + { + Token: Token{ + Type: TokenStringTemplate, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 1, Offset: 1}, + EndPos: ast.Position{Line: 1, Column: 2, Offset: 2}, + }, + }, + Source: `\(`, + }, + { + Token: Token{ + Type: TokenDecimalIntegerLiteral, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 3, Offset: 3}, + EndPos: ast.Position{Line: 1, Column: 3, Offset: 3}, + }, + }, + Source: `7`, + }, + { + Token: Token{ + Type: TokenParenClose, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 4, Offset: 4}, + EndPos: ast.Position{Line: 1, Column: 4, Offset: 4}, + }, + }, + Source: `)`, + }, + { + Token: Token{ + Type: TokenString, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 5, Offset: 5}, + EndPos: ast.Position{Line: 1, Column: 5, Offset: 5}, + }, + }, + Source: `"`, + }, + { + Token: Token{ + Type: TokenEOF, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 6, Offset: 6}, + EndPos: ast.Position{Line: 1, Column: 6, Offset: 6}, + }, + }, + }, + }, + ) + }) + + t.Run("invalid identifier string template", func(t *testing.T) { + testLex(t, + `"\(a+2)"`, + []token{ + { + Token: Token{ + Type: TokenString, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, + EndPos: ast.Position{Line: 1, Column: 0, Offset: 0}, + }, + }, + Source: `"`, + }, + { + Token: Token{ + Type: TokenStringTemplate, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 1, Offset: 1}, + EndPos: ast.Position{Line: 1, Column: 2, Offset: 2}, + }, + }, + Source: `\(`, + }, + { + Token: Token{ + Type: TokenIdentifier, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 3, Offset: 3}, + EndPos: ast.Position{Line: 1, Column: 3, Offset: 3}, + }, + }, + Source: `a`, + }, + { + Token: Token{ + Type: TokenPlus, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 4, Offset: 4}, + EndPos: ast.Position{Line: 1, Column: 4, Offset: 4}, + }, + }, + Source: `+`, + }, + { + Token: Token{ + Type: TokenDecimalIntegerLiteral, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 5, Offset: 5}, + EndPos: ast.Position{Line: 1, Column: 5, Offset: 5}, + }, + }, + Source: `2`, + }, + { + Token: Token{ + Type: TokenParenClose, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 6, Offset: 6}, + EndPos: ast.Position{Line: 1, Column: 6, Offset: 6}, + }, + }, + Source: `)`, + }, + { + Token: Token{ + Type: TokenString, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 7, Offset: 7}, + EndPos: ast.Position{Line: 1, Column: 7, Offset: 7}, + }, + }, + Source: `"`, + }, + { + Token: Token{ + Type: TokenEOF, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 8, Offset: 8}, + EndPos: ast.Position{Line: 1, Column: 8, Offset: 8}, + }, + }, + }, + }, + ) + }) + + t.Run("valid, multi string template", func(t *testing.T) { + testLex(t, + `"\(a)\(b)"`, + []token{ + { + Token: Token{ + Type: TokenString, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, + EndPos: ast.Position{Line: 1, Column: 0, Offset: 0}, + }, + }, + Source: `"`, + }, + { + Token: Token{ + Type: TokenStringTemplate, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 1, Offset: 1}, + EndPos: ast.Position{Line: 1, Column: 2, Offset: 2}, + }, + }, + Source: `\(`, + }, + { + Token: Token{ + Type: TokenIdentifier, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 3, Offset: 3}, + EndPos: ast.Position{Line: 1, Column: 3, Offset: 3}, + }, + }, + Source: `a`, + }, + { + Token: Token{ + Type: TokenParenClose, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 4, Offset: 4}, + EndPos: ast.Position{Line: 1, Column: 4, Offset: 4}, + }, + }, + Source: `)`, + }, + { + Token: Token{ + Type: TokenString, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 5, Offset: 5}, + EndPos: ast.Position{Line: 1, Column: 5, Offset: 4}, + }, + }, + Source: ``, + }, + { + Token: Token{ + Type: TokenStringTemplate, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 6, Offset: 5}, + EndPos: ast.Position{Line: 1, Column: 7, Offset: 6}, + }, + }, + Source: `\(`, + }, + { + Token: Token{ + Type: TokenIdentifier, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 8, Offset: 7}, + EndPos: ast.Position{Line: 1, Column: 8, Offset: 7}, + }, + }, + Source: `b`, + }, + { + Token: Token{ + Type: TokenParenClose, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 9, Offset: 8}, + EndPos: ast.Position{Line: 1, Column: 9, Offset: 8}, + }, + }, + Source: `)`, + }, + { + Token: Token{ + Type: TokenString, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 10, Offset: 9}, + EndPos: ast.Position{Line: 1, Column: 10, Offset: 9}, + }, + }, + Source: `"`, + }, + { + Token: Token{ + Type: TokenEOF, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 11, Offset: 10}, + EndPos: ast.Position{Line: 1, Column: 11, Offset: 10}, + }, + }, + }, + }, + ) + }) + + t.Run("valid, nested brackets", func(t *testing.T) { + testLex(t, + `"\((a))"`, + []token{ + { + Token: Token{ + Type: TokenString, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, + EndPos: ast.Position{Line: 1, Column: 0, Offset: 0}, + }, + }, + Source: `"`, + }, + { + Token: Token{ + Type: TokenStringTemplate, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 1, Offset: 1}, + EndPos: ast.Position{Line: 1, Column: 2, Offset: 2}, + }, + }, + Source: `\(`, + }, + { + Token: Token{ + Type: TokenParenOpen, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 3, Offset: 3}, + EndPos: ast.Position{Line: 1, Column: 3, Offset: 3}, + }, + }, + Source: `(`, + }, + { + Token: Token{ + Type: TokenIdentifier, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 4, Offset: 4}, + EndPos: ast.Position{Line: 1, Column: 4, Offset: 4}, + }, + }, + Source: `a`, + }, + { + Token: Token{ + Type: TokenParenClose, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 5, Offset: 5}, + EndPos: ast.Position{Line: 1, Column: 5, Offset: 5}, + }, + }, + Source: `)`, + }, + { + Token: Token{ + Type: TokenParenClose, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 6, Offset: 6}, + EndPos: ast.Position{Line: 1, Column: 6, Offset: 6}, + }, + }, + Source: `)`, + }, + { + Token: Token{ + Type: TokenString, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 7, Offset: 7}, + EndPos: ast.Position{Line: 1, Column: 7, Offset: 7}, + }, + }, + Source: `"`, + }, + { + Token: Token{ + Type: TokenEOF, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 8, Offset: 8}, + EndPos: ast.Position{Line: 1, Column: 8, Offset: 8}, + }, + }, + }, + }, + ) + }) + t.Run("invalid, empty, not terminated at line end", func(t *testing.T) { testLex(t, "\"\n", diff --git a/parser/lexer/state.go b/parser/lexer/state.go index 8bafc0e476..2dde3e1fd9 100644 --- a/parser/lexer/state.go +++ b/parser/lexer/state.go @@ -56,9 +56,20 @@ func rootState(l *lexer) stateFn { case '%': l.emitType(TokenPercent) case '(': + if l.mode == lexerModeStringInterpolation { + // it is necessary to balance brackets when generating tokens for string templates to know when to change modes + l.openBrackets++ + } l.emitType(TokenParenOpen) case ')': l.emitType(TokenParenClose) + if l.mode == lexerModeStringInterpolation { + l.openBrackets-- + if l.openBrackets == 0 { + l.mode = lexerModeNormal + return stringState + } + } case '{': l.emitType(TokenBraceOpen) case '}': @@ -118,6 +129,17 @@ func rootState(l *lexer) stateFn { return numberState case '"': return stringState + case '\\': + if l.mode == lexerModeStringInterpolation { + r = l.next() + switch r { + case '(': + l.emitType(TokenStringTemplate) + l.openBrackets++ + } + } else { + return l.error(fmt.Errorf("unrecognized character: %#U", r)) + } case '/': r = l.next() switch r { diff --git a/parser/lexer/tokentype.go b/parser/lexer/tokentype.go index 4310f312de..627c47055e 100644 --- a/parser/lexer/tokentype.go +++ b/parser/lexer/tokentype.go @@ -82,6 +82,7 @@ const ( TokenAsExclamationMark TokenAsQuestionMark TokenPragma + TokenStringTemplate // NOTE: not an actual token, must be last item TokenMax ) @@ -205,6 +206,8 @@ func (t TokenType) String() string { return `'as?'` case TokenPragma: return `'#'` + case TokenStringTemplate: + return `'\('` default: panic(errors.NewUnreachableError()) } diff --git a/parser/parser_test.go b/parser/parser_test.go index 93bc5f4918..3629ac6b43 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -33,7 +33,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/errors" "github.com/onflow/cadence/parser/lexer" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestMain(m *testing.M) { @@ -240,7 +240,7 @@ func TestParseBuffering(t *testing.T) { Config{}, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token identifier with string value c", @@ -483,7 +483,7 @@ func TestParseBuffering(t *testing.T) { Config{}, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token identifier with string value d", @@ -511,7 +511,7 @@ func TestParseBuffering(t *testing.T) { } ` _, err := testParseProgram(code) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token identifier", @@ -536,7 +536,7 @@ func TestParseBuffering(t *testing.T) { ` _, err := testParseProgram(code) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &RestrictedTypeError{ Range: ast.Range{ @@ -705,7 +705,7 @@ func TestParseArgumentList(t *testing.T) { t.Parallel() _, errs := testParseArgumentList(`xyz`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token '('", @@ -724,7 +724,7 @@ func TestParseArgumentList(t *testing.T) { var expected ast.Arguments - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, expected, result, ) @@ -750,7 +750,7 @@ func TestParseArgumentList(t *testing.T) { result, errs := testParseArgumentList(`(1, b: true)`) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, ast.Arguments{ { Label: "", @@ -835,7 +835,7 @@ func TestParseBufferedErrors(t *testing.T) { // there is another error (missing closing parenthesis after). _, errs := testParseExpression("a(") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "missing type annotation after comma", @@ -874,7 +874,7 @@ func TestParseExpressionDepthLimit(t *testing.T) { _, err := testParseProgram(code) require.Error(t, err) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ ExpressionDepthLimitReachedError{ Pos: ast.Position{ @@ -910,7 +910,7 @@ func TestParseTypeDepthLimit(t *testing.T) { _, err := testParseProgram(code) require.Error(t, err) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ TypeDepthLimitReachedError{ Pos: ast.Position{ @@ -936,7 +936,7 @@ func TestParseLocalReplayLimit(t *testing.T) { code := []byte(builder.String()) _, err := ParseProgram(nil, code, Config{}) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, Error{ Code: code, Errors: []error{ @@ -971,7 +971,7 @@ func TestParseGlobalReplayLimit(t *testing.T) { code := []byte(builder.String()) _, err := ParseProgram(nil, code, Config{}) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, Error{ Code: code, Errors: []error{ diff --git a/parser/statement_test.go b/parser/statement_test.go index 8e3b6762cb..397fd3c19d 100644 --- a/parser/statement_test.go +++ b/parser/statement_test.go @@ -27,7 +27,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/ast" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestParseReplInput(t *testing.T) { @@ -65,7 +65,7 @@ func TestParseReturnStatement(t *testing.T) { result, errs := testParseStatements("return") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ReturnStatement{ Range: ast.Range{ @@ -85,7 +85,7 @@ func TestParseReturnStatement(t *testing.T) { result, errs := testParseStatements("return 1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ReturnStatement{ Expression: &ast.IntegerExpression{ @@ -114,7 +114,7 @@ func TestParseReturnStatement(t *testing.T) { result, errs := testParseStatements("return \n1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ReturnStatement{ Range: ast.Range{ @@ -145,7 +145,7 @@ func TestParseReturnStatement(t *testing.T) { result, errs := testParseStatements("return ;\n1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ReturnStatement{ Range: ast.Range{ @@ -181,7 +181,7 @@ func TestParseIfStatement(t *testing.T) { result, errs := testParseStatements("if true { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.IfStatement{ Test: &ast.BoolExpression{ @@ -212,7 +212,7 @@ func TestParseIfStatement(t *testing.T) { result, errs := testParseStatements("if true { 1 ; 2 }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.IfStatement{ Test: &ast.BoolExpression{ @@ -266,7 +266,7 @@ func TestParseIfStatement(t *testing.T) { result, errs := testParseStatements("if true { 1 \n 2 }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.IfStatement{ Test: &ast.BoolExpression{ @@ -320,7 +320,7 @@ func TestParseIfStatement(t *testing.T) { result, errs := testParseStatements("if true { 1 } else { 2 }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.IfStatement{ Test: &ast.BoolExpression{ @@ -382,7 +382,7 @@ func TestParseIfStatement(t *testing.T) { result, errs := testParseStatements("if true{1}else if true {2} else{3}") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.IfStatement{ Test: &ast.BoolExpression{ @@ -516,7 +516,7 @@ func TestParseIfStatement(t *testing.T) { expected.Test.(*ast.VariableDeclaration).ParentIfStatement = expected - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ expected, }, @@ -566,7 +566,7 @@ func TestParseIfStatement(t *testing.T) { expected.Test.(*ast.VariableDeclaration).ParentIfStatement = expected - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ expected, }, @@ -587,7 +587,7 @@ func TestParseWhileStatement(t *testing.T) { result, errs := testParseStatements("while true { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.WhileStatement{ Test: &ast.BoolExpression{ @@ -623,7 +623,7 @@ func TestParseAssignmentStatement(t *testing.T) { result, errs := testParseStatements("x=1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.AssignmentStatement{ Target: &ast.IdentifierExpression{ @@ -658,7 +658,7 @@ func TestParseAssignmentStatement(t *testing.T) { result, errs := testParseStatements(" x = 1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.AssignmentStatement{ Target: &ast.IdentifierExpression{ @@ -693,7 +693,7 @@ func TestParseAssignmentStatement(t *testing.T) { result, errs := testParseStatements(" x <- 1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.AssignmentStatement{ Target: &ast.IdentifierExpression{ @@ -728,7 +728,7 @@ func TestParseAssignmentStatement(t *testing.T) { result, errs := testParseStatements(" x <-! 1") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.AssignmentStatement{ Target: &ast.IdentifierExpression{ @@ -768,7 +768,7 @@ func TestParseSwapStatement(t *testing.T) { result, errs := testParseStatements(" x <-> y") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.SwapStatement{ Left: &ast.IdentifierExpression{ @@ -801,7 +801,7 @@ func TestParseForStatement(t *testing.T) { result, errs := testParseStatements("for x in y { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ForStatement{ Identifier: ast.Identifier{ @@ -840,7 +840,7 @@ func TestParseForStatementIndexBinding(t *testing.T) { result, errs := testParseStatements("for i, x in y { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ForStatement{ Identifier: ast.Identifier{ @@ -876,7 +876,7 @@ func TestParseForStatementIndexBinding(t *testing.T) { t.Parallel() _, errs := testParseStatements("for i x in y { }") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected keyword \"in\", got identifier", @@ -896,7 +896,7 @@ func TestParseForStatementIndexBinding(t *testing.T) { t.Parallel() _, errs := testParseStatements("for in y { }") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected identifier, got keyword \"in\"", @@ -923,7 +923,7 @@ func TestParseEmit(t *testing.T) { result, errs := testParseStatements("emit T()") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.EmitStatement{ InvocationExpression: &ast.InvocationExpression{ @@ -955,7 +955,7 @@ func TestParseFunctionStatementOrExpression(t *testing.T) { result, errs := testParseStatements("fun foo() {}") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -991,7 +991,7 @@ func TestParseFunctionStatementOrExpression(t *testing.T) { result, errs := testParseStatements("view fun () {}") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ExpressionStatement{ Expression: &ast.FunctionExpression{ @@ -1025,7 +1025,7 @@ func TestParseFunctionStatementOrExpression(t *testing.T) { result, errs := testParseStatements("view fun foo() {}") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.FunctionDeclaration{ Purity: ast.FunctionPurityView, @@ -1062,7 +1062,7 @@ func TestParseFunctionStatementOrExpression(t *testing.T) { result, errs := testParseStatements("fun () {}") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ExpressionStatement{ Expression: &ast.FunctionExpression{ @@ -1095,7 +1095,7 @@ func TestParseFunctionStatementOrExpression(t *testing.T) { require.Empty(t, result) - utils.AssertEqualWithDiff(t, []error{ + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected identifier after start of function declaration, got keyword continue", Pos: ast.Position{Line: 1, Column: 4, Offset: 4}, @@ -1110,7 +1110,7 @@ func TestParseFunctionStatementOrExpression(t *testing.T) { require.Empty(t, result) - utils.AssertEqualWithDiff(t, []error{ + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected identifier after start of function declaration, got keyword break", Pos: ast.Position{Line: 1, Column: 9, Offset: 9}, @@ -1123,7 +1123,7 @@ func TestParseViewNonFunction(t *testing.T) { t.Parallel() _, errs := testParseStatements("view return 3") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "statements on the same line must be separated with a semicolon", @@ -1145,7 +1145,7 @@ func TestParseStatements(t *testing.T) { result, errs := testParseStatements("a + b < c\nd") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ExpressionStatement{ Expression: &ast.BinaryExpression{ @@ -1191,7 +1191,7 @@ func TestParseStatements(t *testing.T) { t.Parallel() result, errs := testParseStatements(`assert true`) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "statements on the same line must be separated with a semicolon", @@ -1201,7 +1201,7 @@ func TestParseStatements(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.ExpressionStatement{ Expression: &ast.IdentifierExpression{ @@ -1237,7 +1237,7 @@ func TestParseRemoveAttachmentStatement(t *testing.T) { result, errs := testParseStatements("remove A from b") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.RemoveStatement{ Attachment: &ast.NominalType{ @@ -1266,7 +1266,7 @@ func TestParseRemoveAttachmentStatement(t *testing.T) { result, errs := testParseStatements("remove Foo.E from b") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.RemoveStatement{ Attachment: &ast.NominalType{ @@ -1300,7 +1300,7 @@ func TestParseRemoveAttachmentStatement(t *testing.T) { _, errs := testParseStatements("remove A") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected from keyword, got EOF", @@ -1321,7 +1321,7 @@ func TestParseRemoveAttachmentStatement(t *testing.T) { _, errs := testParseStatements("remove A from") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected end of program", @@ -1338,7 +1338,7 @@ func TestParseRemoveAttachmentStatement(t *testing.T) { _, errs := testParseStatements("remove [A] from e") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected attachment nominal type, got [A]", @@ -1356,7 +1356,7 @@ func TestParseRemoveAttachmentStatement(t *testing.T) { result, errs := testParseStatements("remove A from foo()") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.RemoveStatement{ Attachment: &ast.NominalType{ @@ -1394,7 +1394,7 @@ func TestParseSwitchStatement(t *testing.T) { result, errs := testParseStatements("switch true { }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.SwitchStatement{ Expression: &ast.BoolExpression{ @@ -1422,7 +1422,7 @@ func TestParseSwitchStatement(t *testing.T) { result, errs := testParseStatements("switch x { case 1 :\n a\nb default : c\nd }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ &ast.SwitchStatement{ Expression: &ast.IdentifierExpression{ @@ -1503,7 +1503,7 @@ func TestParseSwitchStatement(t *testing.T) { t.Run("Invalid identifiers in switch cases", func(t *testing.T) { code := "switch 1 {AAAAA: break; case 3: break; default: break}" _, errs := testParseStatements(code) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, `unexpected token: got identifier, expected "case" or "default"`, errs[0].Error(), ) @@ -1529,7 +1529,7 @@ func TestParseIfStatementInFunctionDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1731,7 +1731,7 @@ func TestParseIfStatementWithVariableDeclaration(t *testing.T) { ifStatement.Test = ifTestVariableDeclaration - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1777,7 +1777,7 @@ func TestParseIfStatementNoElse(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1849,7 +1849,7 @@ func TestParseWhileStatementInFunctionDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1929,7 +1929,7 @@ func TestParseForStatementInFunctionDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -1991,7 +1991,7 @@ func TestParseAssignment(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -2055,7 +2055,7 @@ func TestParseAccessAssignment(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -2168,7 +2168,7 @@ func TestParseExpressionStatementWithAccess(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -2270,7 +2270,7 @@ func TestParseMoveStatement(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -2332,7 +2332,7 @@ func TestParseFunctionExpressionStatementAfterVariableDeclarationWithCreateExpre result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -2435,7 +2435,7 @@ func TestParseExpressionStatementAfterReturnStatement(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -2496,7 +2496,7 @@ func TestParseSwapStatementInFunctionDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ Access: ast.AccessNotSpecified, @@ -2622,7 +2622,7 @@ func TestParseReferenceExpressionStatement(t *testing.T) { castingExpression.ParentVariableDeclaration = expectedVariableDeclaration - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Statement{ expectedVariableDeclaration, &ast.ExpressionStatement{ @@ -2685,7 +2685,7 @@ func TestSoftKeywordsInStatement(t *testing.T) { }, }, } - utils.AssertEqualWithDiff(t, expected, result) + AssertEqualWithDiff(t, expected, result) }) } diff --git a/parser/type_test.go b/parser/type_test.go index 5a741dc03d..e5efe9d92d 100644 --- a/parser/type_test.go +++ b/parser/type_test.go @@ -27,7 +27,7 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/common" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestParseNominalType(t *testing.T) { @@ -41,7 +41,7 @@ func TestParseNominalType(t *testing.T) { result, errs := testParseType("Int") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "Int", @@ -59,7 +59,7 @@ func TestParseNominalType(t *testing.T) { result, errs := testParseType("Foo.Bar") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "Foo", @@ -88,7 +88,7 @@ func TestParseArrayType(t *testing.T) { result, errs := testParseType("[Int]") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.VariableSizedType{ Type: &ast.NominalType{ Identifier: ast.Identifier{ @@ -112,7 +112,7 @@ func TestParseArrayType(t *testing.T) { result, errs := testParseType("[Int ; 2 ]") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ConstantSizedType{ Type: &ast.NominalType{ Identifier: ast.Identifier{ @@ -143,7 +143,7 @@ func TestParseArrayType(t *testing.T) { t.Parallel() result, errs := testParseType("[Int ; -2 ]") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: `expected positive integer size for constant sized type`, @@ -166,7 +166,7 @@ func TestParseArrayType(t *testing.T) { t.Parallel() result, errs := testParseType("[Int ; X ]") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: `expected positive integer size for constant sized type`, @@ -176,7 +176,7 @@ func TestParseArrayType(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.VariableSizedType{ Type: &ast.NominalType{ Identifier: ast.Identifier{ @@ -206,7 +206,7 @@ func TestParseOptionalType(t *testing.T) { result, errs := testParseType("Int?") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.OptionalType{ Type: &ast.NominalType{ Identifier: ast.Identifier{ @@ -227,7 +227,7 @@ func TestParseOptionalType(t *testing.T) { result, errs := testParseType("Int??") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.OptionalType{ Type: &ast.OptionalType{ Type: &ast.NominalType{ @@ -251,7 +251,7 @@ func TestParseOptionalType(t *testing.T) { result, errs := testParseType("Int???") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.OptionalType{ Type: &ast.OptionalType{ Type: &ast.OptionalType{ @@ -283,7 +283,7 @@ func TestParseReferenceType(t *testing.T) { result, errs := testParseType("&Int") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ReferenceType{ Type: &ast.NominalType{ Identifier: ast.Identifier{ @@ -302,7 +302,7 @@ func TestParseReferenceType(t *testing.T) { t.Parallel() _, errs := testParseType("auth &Int") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected authorization (entitlement list)", @@ -320,7 +320,7 @@ func TestParseReferenceType(t *testing.T) { result, errs := testParseType("auth(X) &Int") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ReferenceType{ Authorization: &ast.ConjunctiveEntitlementSet{ Elements: []*ast.NominalType{ @@ -351,7 +351,7 @@ func TestParseReferenceType(t *testing.T) { result, errs := testParseType("auth(X, Y) &Int") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ReferenceType{ Authorization: &ast.ConjunctiveEntitlementSet{ Elements: []*ast.NominalType{ @@ -388,7 +388,7 @@ func TestParseReferenceType(t *testing.T) { result, errs := testParseType("auth(X| Y) &Int") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ReferenceType{ Authorization: &ast.DisjunctiveEntitlementSet{ Elements: []*ast.NominalType{ @@ -424,7 +424,7 @@ func TestParseReferenceType(t *testing.T) { _, errs := testParseType("auth() &Int") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token in type: ')'", @@ -440,7 +440,7 @@ func TestParseReferenceType(t *testing.T) { t.Parallel() _, errs := testParseType("auth(X, Y | Z) &Int") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: got '|', expected ',' or ')'", @@ -456,7 +456,7 @@ func TestParseReferenceType(t *testing.T) { t.Parallel() _, errs := testParseType("auth(X | Y, Z) &Int") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: got ',', expected '|' or ')'", @@ -474,7 +474,7 @@ func TestParseReferenceType(t *testing.T) { result, errs := testParseType("auth ( mapping X ) & Int") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.ReferenceType{ Authorization: &ast.MappedAccess{ EntitlementMap: &ast.NominalType{ @@ -502,7 +502,7 @@ func TestParseReferenceType(t *testing.T) { t.Parallel() _, errs := testParseType("auth( mapping ) &Int") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token in type: ')'", @@ -525,7 +525,7 @@ func TestParseOptionalReferenceType(t *testing.T) { result, errs := testParseType("&Int?") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.OptionalType{ Type: &ast.ReferenceType{ Type: &ast.NominalType{ @@ -553,7 +553,7 @@ func TestParseIntersectionType(t *testing.T) { _, errs := testParseType("T{}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &RestrictedTypeError{ Range: ast.Range{ @@ -571,7 +571,7 @@ func TestParseIntersectionType(t *testing.T) { t.Parallel() _, errs := testParseType("T{U}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &RestrictedTypeError{ Range: ast.Range{ @@ -589,7 +589,7 @@ func TestParseIntersectionType(t *testing.T) { t.Parallel() _, errs := testParseType("T{U , V }") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &RestrictedTypeError{ Range: ast.Range{ @@ -609,7 +609,7 @@ func TestParseIntersectionType(t *testing.T) { result, errs := testParseType("{}") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntersectionType{ Range: ast.Range{ StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, @@ -627,7 +627,7 @@ func TestParseIntersectionType(t *testing.T) { result, errs := testParseType("{ T }") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntersectionType{ Types: []*ast.NominalType{ { @@ -651,7 +651,7 @@ func TestParseIntersectionType(t *testing.T) { t.Parallel() result, errs := testParseType("{ T , }") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "missing type after comma", @@ -661,7 +661,7 @@ func TestParseIntersectionType(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.IntersectionType{ Types: []*ast.NominalType{ { @@ -685,7 +685,7 @@ func TestParseIntersectionType(t *testing.T) { t.Parallel() result, errs := testParseType("{ T U }") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected type", @@ -704,7 +704,7 @@ func TestParseIntersectionType(t *testing.T) { t.Parallel() result, errs := testParseType("{ T , U : V }") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected colon in intersection type", @@ -723,7 +723,7 @@ func TestParseIntersectionType(t *testing.T) { t.Parallel() result, errs := testParseType("{U , V : W }") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: `unexpected colon in intersection type`, @@ -742,7 +742,7 @@ func TestParseIntersectionType(t *testing.T) { t.Parallel() result, errs := testParseType("{[T]}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "non-nominal type in intersection list: [T]", @@ -761,7 +761,7 @@ func TestParseIntersectionType(t *testing.T) { t.Parallel() result, errs := testParseType("{T, [U]}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "non-nominal type in intersection list: [U]", @@ -780,7 +780,7 @@ func TestParseIntersectionType(t *testing.T) { t.Parallel() result, errs := testParseType("{") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid end of input, expected type", @@ -798,7 +798,7 @@ func TestParseIntersectionType(t *testing.T) { t.Parallel() result, errs := testParseType("{U") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid end of input, expected '}'", @@ -816,7 +816,7 @@ func TestParseIntersectionType(t *testing.T) { t.Parallel() result, errs := testParseType("{U,") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid end of input, expected type", @@ -834,7 +834,7 @@ func TestParseIntersectionType(t *testing.T) { t.Parallel() result, errs := testParseType("{,}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected comma in intersection type", @@ -859,7 +859,7 @@ func TestParseDictionaryType(t *testing.T) { result, errs := testParseType("{T: U}") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.DictionaryType{ KeyType: &ast.NominalType{ Identifier: ast.Identifier{ @@ -887,7 +887,7 @@ func TestParseDictionaryType(t *testing.T) { t.Parallel() result, errs := testParseType("{T:}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "missing dictionary value type", @@ -897,7 +897,7 @@ func TestParseDictionaryType(t *testing.T) { errs, ) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.DictionaryType{ KeyType: &ast.NominalType{ Identifier: ast.Identifier{ @@ -920,7 +920,7 @@ func TestParseDictionaryType(t *testing.T) { t.Parallel() result, errs := testParseType("{:}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected colon in dictionary type", @@ -938,7 +938,7 @@ func TestParseDictionaryType(t *testing.T) { t.Parallel() result, errs := testParseType("{:U}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected colon in dictionary type", @@ -957,7 +957,7 @@ func TestParseDictionaryType(t *testing.T) { t.Parallel() result, errs := testParseType("{T:U,}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected comma in dictionary type", @@ -976,7 +976,7 @@ func TestParseDictionaryType(t *testing.T) { t.Parallel() result, errs := testParseType("{T:U:}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected colon in dictionary type", @@ -995,7 +995,7 @@ func TestParseDictionaryType(t *testing.T) { t.Parallel() result, errs := testParseType("{T::U}") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected colon in dictionary type", @@ -1014,7 +1014,7 @@ func TestParseDictionaryType(t *testing.T) { t.Parallel() result, errs := testParseType("{T:") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid end of input, expected type", @@ -1032,7 +1032,7 @@ func TestParseDictionaryType(t *testing.T) { t.Parallel() result, errs := testParseType("{T:U") - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid end of input, expected '}'", @@ -1057,7 +1057,7 @@ func TestParseFunctionType(t *testing.T) { result, errs := testParseType("fun():Void") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FunctionType{ PurityAnnotation: ast.FunctionPurityUnspecified, ParameterTypeAnnotations: nil, @@ -1087,7 +1087,7 @@ func TestParseFunctionType(t *testing.T) { result, errs := testParseType("view fun ():Void") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FunctionType{ PurityAnnotation: ast.FunctionPurityView, ParameterTypeAnnotations: nil, @@ -1117,7 +1117,7 @@ func TestParseFunctionType(t *testing.T) { result, errs := testParseType("fun( String , Bool , @R ) : Int") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.FunctionType{ ParameterTypeAnnotations: []*ast.TypeAnnotation{ { @@ -1182,7 +1182,7 @@ func TestParseInstantiationType(t *testing.T) { result, errs := testParseType("T<>") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InstantiationType{ Type: &ast.NominalType{ Identifier: ast.Identifier{ @@ -1204,7 +1204,7 @@ func TestParseInstantiationType(t *testing.T) { result, errs := testParseType("T") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InstantiationType{ Type: &ast.NominalType{ Identifier: ast.Identifier{ @@ -1238,7 +1238,7 @@ func TestParseInstantiationType(t *testing.T) { result, errs := testParseType("T< U >") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InstantiationType{ Type: &ast.NominalType{ Identifier: ast.Identifier{ @@ -1272,7 +1272,7 @@ func TestParseInstantiationType(t *testing.T) { result, errs := testParseType("T< U , @V >") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InstantiationType{ Type: &ast.NominalType{ Identifier: ast.Identifier{ @@ -1316,7 +1316,7 @@ func TestParseInstantiationType(t *testing.T) { result, errs := testParseType("T") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InstantiationType{ Type: &ast.NominalType{ Identifier: ast.Identifier{ @@ -1350,7 +1350,7 @@ func TestParseInstantiationType(t *testing.T) { result, errs := testParseType("T< U< V > >") require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, &ast.InstantiationType{ Type: &ast.NominalType{ Identifier: ast.Identifier{ @@ -1404,7 +1404,7 @@ func TestParseParametersAndArrayTypes(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ ParameterList: &ast.ParameterList{ @@ -1696,7 +1696,7 @@ func TestParseDictionaryTypeInVariableDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2018,7 +2018,7 @@ func TestParseIntegerTypes(t *testing.T) { StartPos: ast.Position{Offset: 137, Line: 9, Column: 2}, } - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{a, b, c, d, e, f, g, h}, result.Declarations(), ) @@ -2034,7 +2034,7 @@ func TestParseFunctionTypeInVariableDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2112,7 +2112,7 @@ func TestParseFunctionArrayType(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2196,7 +2196,7 @@ func TestParseFunctionTypeWithArrayReturnType(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2291,7 +2291,7 @@ func TestParseFunctionTypeWithFunctionReturnType(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2451,7 +2451,7 @@ func TestParseViewFunctionTypeWithNewSyntax(t *testing.T) { StartPos: ast.Position{Offset: 3, Line: 2, Column: 2}, }, } - utils.AssertEqualWithDiff(t, expected, result.Declarations()) + AssertEqualWithDiff(t, expected, result.Declarations()) } func TestParseNewSyntaxFunctionType(t *testing.T) { @@ -2534,7 +2534,7 @@ func TestParseNewSyntaxFunctionType(t *testing.T) { StartPos: ast.Position{Offset: 3, Line: 2, Column: 2}, }, } - utils.AssertEqualWithDiff(t, expected, result.Declarations()) + AssertEqualWithDiff(t, expected, result.Declarations()) } func TestParseOptionalTypeDouble(t *testing.T) { @@ -2547,7 +2547,7 @@ func TestParseOptionalTypeDouble(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2602,7 +2602,7 @@ func TestParseFunctionTypeWithResourceTypeAnnotation(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2659,7 +2659,7 @@ func TestParseReferenceTypeInVariableDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2720,7 +2720,7 @@ func TestParseOptionalReference(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2775,7 +2775,7 @@ func TestParseIntersectionReferenceType(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2835,7 +2835,7 @@ func TestParseOptionalIntersectionType(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2894,7 +2894,7 @@ func TestParseAuthorizedReferenceTypeWithNoEntitlements(t *testing.T) { ` _, errs := testParseProgram(code) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected authorization (entitlement list)", @@ -2915,7 +2915,7 @@ func TestParseInstantiationTypeInVariableDeclaration(t *testing.T) { result, errs := testParseProgram(code) require.Empty(t, errs) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ Access: ast.AccessNotSpecified, @@ -2991,7 +2991,7 @@ func TestParseConstantSizedSizedArrayWithTrailingUnderscoreSize(t *testing.T) { let T:[d;0_]=0 `) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &InvalidIntegerLiteralError{ Literal: "0_", @@ -3044,7 +3044,7 @@ func TestParseParenthesizedTypes(t *testing.T) { }, } - utils.AssertEqualWithDiff(t, expected, prog.Declarations()) + AssertEqualWithDiff(t, expected, prog.Declarations()) } func TestParseNestedParenthesizedTypes(t *testing.T) { @@ -3084,5 +3084,5 @@ func TestParseNestedParenthesizedTypes(t *testing.T) { }, } - utils.AssertEqualWithDiff(t, expected, prog.Declarations()) + AssertEqualWithDiff(t, expected, prog.Declarations()) } diff --git a/runtime/.gitattributes b/runtime/.gitattributes deleted file mode 100644 index 7a38edbb9a..0000000000 --- a/runtime/.gitattributes +++ /dev/null @@ -1,9 +0,0 @@ -*.interp linguist-generated=true -*.tokens linguist-generated=true -parser/cadence_parser.go linguist-generated=true -parser/cadence_lexer.go linguist-generated=true -parser/cadence_base_listener.go linguist-generated=true -parser/cadence_base_visitor.go linguist-generated=true -parser/cadence_visitor.go linguist-generated=true -parser/cadence_listener.go linguist-generated=true - diff --git a/tests/account_test.go b/runtime/account_test.go similarity index 99% rename from tests/account_test.go rename to runtime/account_test.go index 3182684d35..0d65fa3ecd 100644 --- a/tests/account_test.go +++ b/runtime/account_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "fmt" @@ -35,10 +35,10 @@ import ( . "github.com/onflow/cadence/runtime" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - "github.com/onflow/cadence/tests/checker" - . "github.com/onflow/cadence/tests/runtime_utils" - "github.com/onflow/cadence/tests/utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestRuntimeAccountKeyConstructor(t *testing.T) { @@ -998,7 +998,7 @@ func TestRuntimePublicAccountKeys(t *testing.T) { value, err := test.executeScript(testEnv.runtime, testEnv.runtimeInterface) require.NoError(t, err) - utils.AssertEqualWithDiff(t, cadence.Void{}, value) + AssertEqualWithDiff(t, cadence.Void{}, value) keys := make(map[int]*AccountKey, len(testEnv.storage.keys)) for _, key := range testEnv.storage.keys { @@ -1043,7 +1043,7 @@ func TestRuntimePublicAccountKeys(t *testing.T) { value, err := test.executeScript(testEnv.runtime, testEnv.runtimeInterface) require.NoError(t, err) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, cadence.NewOptional(cadence.String("Optional.map")), value, ) @@ -1717,7 +1717,7 @@ func TestRuntimePublicKey(t *testing.T) { } _, err := executeScript(script, runtimeInterface) - errs := checker.RequireCheckerErrors(t, err, 4) + errs := RequireCheckerErrors(t, err, 4) assert.IsType(t, &sema.InvalidAssignmentAccessError{}, errs[0]) assert.IsType(t, &sema.AssignmentToConstantMemberError{}, errs[1]) @@ -2360,7 +2360,7 @@ func TestRuntimeAuthAccountContracts(t *testing.T) { }, ) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.UnauthorizedReferenceAssignmentError{}, errs[0]) }) @@ -2402,7 +2402,7 @@ func TestRuntimeAuthAccountContracts(t *testing.T) { }, ) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.UnauthorizedReferenceAssignmentError{}, errs[0]) }) @@ -2614,7 +2614,7 @@ func TestRuntimeGetAuthAccount(t *testing.T) { }, ) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.TypeMismatchError{}, errs[0]) }) @@ -2642,7 +2642,7 @@ func TestRuntimeGetAuthAccount(t *testing.T) { }, ) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.InsufficientArgumentsError{}, errs[0]) }) @@ -2669,7 +2669,7 @@ func TestRuntimeGetAuthAccount(t *testing.T) { Location: common.ScriptLocation{0x1}, }, ) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.ExcessiveArgumentsError{}, errs[0]) }) @@ -2704,7 +2704,7 @@ func TestRuntimeGetAuthAccount(t *testing.T) { }, ) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.NotDeclaredError{}, errs[0]) }) diff --git a/tests/attachments_test.go b/runtime/attachments_test.go similarity index 99% rename from tests/attachments_test.go rename to runtime/attachments_test.go index cf3de8047c..4d3d400d1b 100644 --- a/tests/attachments_test.go +++ b/runtime/attachments_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "testing" @@ -28,8 +28,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" . "github.com/onflow/cadence/runtime" - . "github.com/onflow/cadence/tests/runtime_utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) func TestRuntimeAccountAttachmentSaveAndLoad(t *testing.T) { diff --git a/tests/capabilities_test.go b/runtime/capabilities_test.go similarity index 99% rename from tests/capabilities_test.go rename to runtime/capabilities_test.go index f02f81c079..3e76980213 100644 --- a/tests/capabilities_test.go +++ b/runtime/capabilities_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "testing" @@ -27,8 +27,8 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" . "github.com/onflow/cadence/runtime" - . "github.com/onflow/cadence/tests/runtime_utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) func TestRuntimeCapability_borrowAndCheck(t *testing.T) { diff --git a/tests/capabilitycontrollers_test.go b/runtime/capabilitycontrollers_test.go similarity index 99% rename from tests/capabilitycontrollers_test.go rename to runtime/capabilitycontrollers_test.go index 2a9881d312..fc6f692fe4 100644 --- a/tests/capabilitycontrollers_test.go +++ b/runtime/capabilitycontrollers_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "encoding/binary" @@ -32,8 +32,8 @@ import ( . "github.com/onflow/cadence/runtime" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/runtime_utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) func TestRuntimeCapabilityControllers(t *testing.T) { diff --git a/runtime/config.go b/runtime/config.go index c3be0083d5..d6882cb353 100644 --- a/runtime/config.go +++ b/runtime/config.go @@ -37,6 +37,4 @@ type Config struct { CoverageReport *CoverageReport // LegacyContractUpgradeEnabled enabled specifies whether to use the old parser when parsing an old contract LegacyContractUpgradeEnabled bool - // ContractUpdateTypeRemovalEnabled specifies if type removal is enabled in contract updates - ContractUpdateTypeRemovalEnabled bool } diff --git a/tests/contract_test.go b/runtime/contract_test.go similarity index 99% rename from tests/contract_test.go rename to runtime/contract_test.go index 288424ea5c..2bb89a2cb5 100644 --- a/tests/contract_test.go +++ b/runtime/contract_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "encoding/hex" @@ -33,9 +33,10 @@ import ( . "github.com/onflow/cadence/runtime" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - "github.com/onflow/cadence/tests/checker" - . "github.com/onflow/cadence/tests/runtime_utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestRuntimeContract(t *testing.T) { @@ -1234,7 +1235,7 @@ func TestRuntimeContractTryUpdate(t *testing.T) { ) RequireError(t, err) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) var notExportedError *sema.NotExportedError require.ErrorAs(t, errs[0], ¬ExportedError) }) diff --git a/tests/contract_update_test.go b/runtime/contract_update_test.go similarity index 99% rename from tests/contract_update_test.go rename to runtime/contract_update_test.go index 7cee60bf24..48a0ec8e48 100644 --- a/tests/contract_update_test.go +++ b/runtime/contract_update_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "testing" @@ -29,8 +29,8 @@ import ( "github.com/onflow/cadence/interpreter" . "github.com/onflow/cadence/runtime" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/runtime_utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) func TestRuntimeContractUpdateWithDependencies(t *testing.T) { diff --git a/tests/contract_update_validation_test.go b/runtime/contract_update_validation_test.go similarity index 96% rename from tests/contract_update_validation_test.go rename to runtime/contract_update_validation_test.go index 0bebbb99a0..360387dc33 100644 --- a/tests/contract_update_validation_test.go +++ b/runtime/contract_update_validation_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "encoding/hex" @@ -33,8 +33,8 @@ import ( . "github.com/onflow/cadence/runtime" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/runtime_utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) func newContractDeployTransaction(function, name, code string) string { @@ -83,6 +83,10 @@ func newContractRemovalTransaction(contractName string) string { } func newContractDeploymentTransactor(t *testing.T, config Config) func(code string) error { + return newContractDeploymentTransactorWithVersion(t, config, "") +} + +func newContractDeploymentTransactorWithVersion(t *testing.T, config Config, version string) func(code string) error { rt := NewTestInterpreterRuntimeWithConfig(config) @@ -112,6 +116,9 @@ func newContractDeploymentTransactor(t *testing.T, config Config) func(code stri events = append(events, event) return nil }, + OnMinimumRequiredVersion: func() (string, error) { + return version, nil + }, } nextTransactionLocation := NewTransactionLocationGenerator() @@ -132,7 +139,18 @@ func newContractDeploymentTransactor(t *testing.T, config Config) func(code stri // testDeployAndUpdate deploys a contract in one transaction, // then updates the contract in another transaction func testDeployAndUpdate(t *testing.T, name string, oldCode string, newCode string, config Config) error { - executeTransaction := newContractDeploymentTransactor(t, config) + return testDeployAndUpdateWithVersion(t, name, oldCode, newCode, config, "") +} + +func testDeployAndUpdateWithVersion( + t *testing.T, + name string, + oldCode string, + newCode string, + config Config, + version string, +) error { + executeTransaction := newContractDeploymentTransactorWithVersion(t, config, version) err := executeTransaction(newContractAddTransaction(name, oldCode)) require.NoError(t, err) @@ -177,31 +195,14 @@ func testWithValidatorsAndTypeRemovalEnabled( withC1Upgrade := withC1Upgrade name := name - for _, withTypeRemovalEnabled := range []bool{true, false} { - withTypeRemovalEnabled := withTypeRemovalEnabled - name := name - - switch { - case withC1Upgrade && withTypeRemovalEnabled: - name = fmt.Sprintf("%s (with C1 validator and type removal enabled)", name) - - case withC1Upgrade: - name = fmt.Sprintf("%s (with C1 validator)", name) - - case withTypeRemovalEnabled: - name = fmt.Sprintf("%s (with type removal enabled)", name) - } - - t.Run(name, func(t *testing.T) { - t.Parallel() + t.Run(name, func(t *testing.T) { + t.Parallel() - config := DefaultTestInterpreterConfig - config.LegacyContractUpgradeEnabled = withC1Upgrade - config.ContractUpdateTypeRemovalEnabled = withTypeRemovalEnabled + config := DefaultTestInterpreterConfig + config.LegacyContractUpgradeEnabled = withC1Upgrade - testFunc(t, config) - }) - } + testFunc(t, config) + }) } } @@ -3230,13 +3231,8 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) { ` err := testDeployAndUpdate(t, "Test", oldCode, newCode, config) - - if config.ContractUpdateTypeRemovalEnabled { - var expectedErr *stdlib.TypeRemovalPragmaRemovalError - require.ErrorAs(t, err, &expectedErr) - } else { - require.NoError(t, err) - } + var expectedErr *stdlib.TypeRemovalPragmaRemovalError + require.ErrorAs(t, err, &expectedErr) }, ) @@ -3262,13 +3258,8 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) { ` err := testDeployAndUpdate(t, "Test", oldCode, newCode, config) - - if config.ContractUpdateTypeRemovalEnabled { - var expectedErr *stdlib.TypeRemovalPragmaRemovalError - require.ErrorAs(t, err, &expectedErr) - } else { - require.NoError(t, err) - } + var expectedErr *stdlib.TypeRemovalPragmaRemovalError + require.ErrorAs(t, err, &expectedErr) }, ) @@ -3313,13 +3304,8 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) { ` err := testDeployAndUpdate(t, "Test", oldCode, newCode, config) - - if config.ContractUpdateTypeRemovalEnabled { - var expectedErr *stdlib.InvalidTypeRemovalPragmaError - require.ErrorAs(t, err, &expectedErr) - } else { - require.NoError(t, err) - } + var expectedErr *stdlib.InvalidTypeRemovalPragmaError + require.ErrorAs(t, err, &expectedErr) }, ) @@ -3342,13 +3328,8 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) { ` err := testDeployAndUpdate(t, "Test", oldCode, newCode, config) - - if config.ContractUpdateTypeRemovalEnabled { - var expectedErr *stdlib.InvalidTypeRemovalPragmaError - require.ErrorAs(t, err, &expectedErr) - } else { - require.NoError(t, err) - } + var expectedErr *stdlib.InvalidTypeRemovalPragmaError + require.ErrorAs(t, err, &expectedErr) }, ) @@ -3368,14 +3349,8 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) { ` err := testDeployAndUpdate(t, "Test", oldCode, newCode, config) - - if config.ContractUpdateTypeRemovalEnabled { - - var expectedErr *stdlib.InvalidTypeRemovalPragmaError - require.ErrorAs(t, err, &expectedErr) - } else { - require.NoError(t, err) - } + var expectedErr *stdlib.InvalidTypeRemovalPragmaError + require.ErrorAs(t, err, &expectedErr) }, ) @@ -3395,13 +3370,8 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) { ` err := testDeployAndUpdate(t, "Test", oldCode, newCode, config) - - if config.ContractUpdateTypeRemovalEnabled { - var expectedErr *stdlib.InvalidTypeRemovalPragmaError - require.ErrorAs(t, err, &expectedErr) - } else { - require.NoError(t, err) - } + var expectedErr *stdlib.InvalidTypeRemovalPragmaError + require.ErrorAs(t, err, &expectedErr) }, ) @@ -3422,13 +3392,7 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) { ` err := testDeployAndUpdate(t, "Test", oldCode, newCode, config) - - if config.ContractUpdateTypeRemovalEnabled { - require.NoError(t, err) - } else { - var expectedErr *stdlib.MissingDeclarationError - require.ErrorAs(t, err, &expectedErr) - } + require.NoError(t, err) }, ) @@ -3451,13 +3415,7 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) { ` err := testDeployAndUpdate(t, "Test", oldCode, newCode, config) - - if config.ContractUpdateTypeRemovalEnabled { - require.NoError(t, err) - } else { - var expectedErr *stdlib.MissingDeclarationError - require.ErrorAs(t, err, &expectedErr) - } + require.NoError(t, err) }, ) @@ -3526,13 +3484,7 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) { ` err := testDeployAndUpdate(t, "Test", oldCode, newCode, config) - - if config.ContractUpdateTypeRemovalEnabled { - require.NoError(t, err) - } else { - var expectedErr *stdlib.MissingDeclarationError - require.ErrorAs(t, err, &expectedErr) - } + require.NoError(t, err) }, ) @@ -3574,13 +3526,8 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) { ` err := testDeployAndUpdate(t, "Test", oldCode, newCode, config) - - if config.ContractUpdateTypeRemovalEnabled { - var expectedErr *stdlib.UseOfRemovedTypeError - require.ErrorAs(t, err, &expectedErr) - } else { - require.NoError(t, err) - } + var expectedErr *stdlib.UseOfRemovedTypeError + require.ErrorAs(t, err, &expectedErr) }, ) @@ -3602,13 +3549,8 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) { ` err := testDeployAndUpdate(t, "Test", oldCode, newCode, config) - - if config.ContractUpdateTypeRemovalEnabled { - var expectedErr *stdlib.UseOfRemovedTypeError - require.ErrorAs(t, err, &expectedErr) - } else { - require.NoError(t, err) - } + var expectedErr *stdlib.UseOfRemovedTypeError + require.ErrorAs(t, err, &expectedErr) }, ) @@ -3630,13 +3572,8 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) { ` err := testDeployAndUpdate(t, "Test", oldCode, newCode, config) - - if config.ContractUpdateTypeRemovalEnabled { - var expectedErr *stdlib.UseOfRemovedTypeError - require.ErrorAs(t, err, &expectedErr) - } else { - require.NoError(t, err) - } + var expectedErr *stdlib.UseOfRemovedTypeError + require.ErrorAs(t, err, &expectedErr) }, ) @@ -3764,3 +3701,51 @@ func TestRuntimeContractUpdateErrorsInOldProgram(t *testing.T) { require.ErrorAs(t, err, &oldProgramError) }) } + +func TestAttachmentsUpdates(t *testing.T) { + t.Parallel() + + testWithValidators(t, + "Keep base type", + func(t *testing.T, config Config) { + + const oldCode = ` + access(all) contract Test { + access(all) attachment A for AnyResource {} + } + ` + + const newCode = ` + access(all) contract Test { + access(all) attachment A for AnyResource {} + } + ` + + err := testDeployAndUpdate(t, "Test", oldCode, newCode, config) + require.NoError(t, err) + }, + ) + + testWithValidators(t, + "Change base type", + func(t *testing.T, config Config) { + + const oldCode = ` + access(all) contract Test { + access(all) attachment A for AnyResource {} + } + ` + + const newCode = ` + access(all) contract Test { + access(all) attachment A for AnyStruct {} + } + ` + + err := testDeployAndUpdate(t, "Test", oldCode, newCode, config) + + var expectedErr *stdlib.TypeMismatchError + require.ErrorAs(t, err, &expectedErr) + }, + ) +} diff --git a/tests/convertTypes_test.go b/runtime/convertTypes_test.go similarity index 94% rename from tests/convertTypes_test.go rename to runtime/convertTypes_test.go index 5d5ea6b2a9..3e50371edd 100644 --- a/tests/convertTypes_test.go +++ b/runtime/convertTypes_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "testing" @@ -28,7 +28,7 @@ import ( "github.com/onflow/cadence/common" . "github.com/onflow/cadence/runtime" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestRuntimeExportRecursiveType(t *testing.T) { @@ -36,7 +36,7 @@ func TestRuntimeExportRecursiveType(t *testing.T) { t.Parallel() ty := &sema.CompositeType{ - Location: utils.TestLocation, + Location: TestLocation, Identifier: "Foo", Kind: common.CompositeKindResource, Members: &sema.StringMemberOrderedMap{}, @@ -60,7 +60,7 @@ func TestRuntimeExportRecursiveType(t *testing.T) { } expected := cadence.NewResourceType( - utils.TestLocation, + TestLocation, "Foo", fields, nil, @@ -94,7 +94,7 @@ func BenchmarkExportType(b *testing.B) { b.Run("composite type", func(b *testing.B) { ty := &sema.CompositeType{ - Location: utils.TestLocation, + Location: TestLocation, Identifier: "Foo", Kind: common.CompositeKindResource, Members: &sema.StringMemberOrderedMap{}, @@ -118,7 +118,7 @@ func BenchmarkExportType(b *testing.B) { } expected := cadence.NewResourceType( - utils.TestLocation, + TestLocation, "Foo", fields, nil, diff --git a/tests/convertValues_test.go b/runtime/convertValues_test.go similarity index 99% rename from tests/convertValues_test.go rename to runtime/convertValues_test.go index 9637b6fb0e..f6cf51fcb2 100644 --- a/tests/convertValues_test.go +++ b/runtime/convertValues_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( _ "embed" @@ -37,8 +37,9 @@ import ( . "github.com/onflow/cadence/runtime" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/runtime_utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) func TestRuntimeExportValue(t *testing.T) { @@ -2322,7 +2323,7 @@ func TestRuntimeExportCompositeValueWithFunctionValueField(t *testing.T) { assert.Equal(t, expected, actual) } -//go:embed test-export-json-deterministic.txt +//go:embed test-export-json-deterministic.json var exportJsonDeterministicExpected string func TestRuntimeExportJsonDeterministic(t *testing.T) { diff --git a/tests/coverage_test.go b/runtime/coverage_test.go similarity index 99% rename from tests/coverage_test.go rename to runtime/coverage_test.go index 8877be16eb..5f5f746113 100644 --- a/tests/coverage_test.go +++ b/runtime/coverage_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "encoding/json" @@ -31,8 +31,7 @@ import ( "github.com/onflow/cadence/parser" . "github.com/onflow/cadence/runtime" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/runtime_utils" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) func TestRuntimeNewLocationCoverage(t *testing.T) { @@ -1816,7 +1815,7 @@ func TestRuntimeCoverageWithNoStatements(t *testing.T) { } coverageReport.ExcludeLocation(txLocation) - deploy := utils.DeploymentTransaction("FooContract", contract) + deploy := DeploymentTransaction("FooContract", contract) err := runtime.ExecuteTransaction( Script{ Source: deploy, diff --git a/tests/crypto_test.go b/runtime/crypto_test.go similarity index 99% rename from tests/crypto_test.go rename to runtime/crypto_test.go index 636cece7e9..fcce37cf8b 100644 --- a/tests/crypto_test.go +++ b/runtime/crypto_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "encoding/hex" @@ -33,7 +33,7 @@ import ( . "github.com/onflow/cadence/runtime" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/runtime_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) func TestRuntimeHashAlgorithm_hash(t *testing.T) { diff --git a/tests/debugger_test.go b/runtime/debugger_test.go similarity index 98% rename from tests/debugger_test.go rename to runtime/debugger_test.go index 3289668907..b9d060775e 100644 --- a/tests/debugger_test.go +++ b/runtime/debugger_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "sync" @@ -28,7 +28,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" . "github.com/onflow/cadence/runtime" - . "github.com/onflow/cadence/tests/runtime_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) func TestRuntimeDebugger(t *testing.T) { diff --git a/tests/deployedcontract_test.go b/runtime/deployedcontract_test.go similarity index 94% rename from tests/deployedcontract_test.go rename to runtime/deployedcontract_test.go index 7090f7ad77..bae773da2e 100644 --- a/tests/deployedcontract_test.go +++ b/runtime/deployedcontract_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "testing" @@ -26,8 +26,7 @@ import ( "github.com/onflow/cadence" "github.com/onflow/cadence/common" . "github.com/onflow/cadence/runtime" - . "github.com/onflow/cadence/tests/runtime_utils" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) func TestRuntimeDeployedContracts(t *testing.T) { @@ -104,7 +103,7 @@ func TestRuntimeDeployedContracts(t *testing.T) { // deploy the contract err := rt.ExecuteTransaction( Script{ - Source: utils.DeploymentTransaction("Test", []byte(contractCode)), + Source: DeploymentTransaction("Test", []byte(contractCode)), }, newContext(), ) diff --git a/tests/deployment_test.go b/runtime/deployment_test.go similarity index 98% rename from tests/deployment_test.go rename to runtime/deployment_test.go index 475cceb86f..4d1ab95280 100644 --- a/tests/deployment_test.go +++ b/runtime/deployment_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "encoding/hex" @@ -34,8 +34,9 @@ import ( . "github.com/onflow/cadence/runtime" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/runtime_utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) func TestRuntimeTransactionWithContractDeployment(t *testing.T) { diff --git a/runtime/empty.go b/runtime/empty.go index da93644534..0d2902be38 100644 --- a/runtime/empty.go +++ b/runtime/empty.go @@ -260,3 +260,7 @@ func (EmptyRuntimeInterface) ValidateAccountCapabilitiesPublish( ) (bool, error) { panic("unexpected call to ValidateAccountCapabilitiesPublish") } + +func (EmptyRuntimeInterface) MinimumRequiredVersion() (string, error) { + return "0.0.0", nil +} diff --git a/tests/entitlements_test.go b/runtime/entitlements_test.go similarity index 99% rename from tests/entitlements_test.go rename to runtime/entitlements_test.go index f0f5f7ea5f..428e56615d 100644 --- a/tests/entitlements_test.go +++ b/runtime/entitlements_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "testing" @@ -28,9 +28,8 @@ import ( "github.com/onflow/cadence/interpreter" . "github.com/onflow/cadence/runtime" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/checker" - . "github.com/onflow/cadence/tests/runtime_utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestRuntimeAccountEntitlementSaveAndLoadSuccess(t *testing.T) { @@ -497,7 +496,7 @@ func TestRuntimeAccountEntitlementNamingConflict(t *testing.T) { var checkerErr *sema.CheckerError require.ErrorAs(t, err, &checkerErr) - errs := checker.RequireCheckerErrors(t, checkerErr, 1) + errs := RequireCheckerErrors(t, checkerErr, 1) var accessError *sema.InvalidAccessError require.ErrorAs(t, errs[0], &accessError) diff --git a/runtime/environment.go b/runtime/environment.go index ef3d0130d6..7873d4e990 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -196,7 +196,6 @@ func (e *interpreterEnvironment) newInterpreterConfig() *interpreter.Config { CapabilityBorrowHandler: e.newCapabilityBorrowHandler(), CapabilityCheckHandler: e.newCapabilityCheckHandler(), LegacyContractUpgradeEnabled: e.config.LegacyContractUpgradeEnabled, - ContractUpdateTypeRemovalEnabled: e.config.ContractUpdateTypeRemovalEnabled, ValidateAccountCapabilitiesGetHandler: e.newValidateAccountCapabilitiesGetHandler(), ValidateAccountCapabilitiesPublishHandler: e.newValidateAccountCapabilitiesPublishHandler(), } @@ -242,6 +241,8 @@ func (e *interpreterEnvironment) Configure( e.InterpreterConfig.Storage = storage e.coverageReport = coverageReport e.stackDepthLimiter.depth = 0 + + e.configureVersionedFeatures() } func (e *interpreterEnvironment) DeclareValue(valueDeclaration stdlib.StandardLibraryValue, location common.Location) { @@ -1425,3 +1426,19 @@ func (e *interpreterEnvironment) newValidateAccountCapabilitiesPublishHandler() return ok, err } } + +func (e *interpreterEnvironment) configureVersionedFeatures() { + var ( + minimumRequiredVersion string + err error + ) + errors.WrapPanic(func() { + minimumRequiredVersion, err = e.runtimeInterface.MinimumRequiredVersion() + }) + if err != nil { + panic(err) + } + + // No feature flags yet + _ = minimumRequiredVersion +} diff --git a/tests/error_test.go b/runtime/error_test.go similarity index 99% rename from tests/error_test.go rename to runtime/error_test.go index 2a99de14ad..4d74c390c1 100644 --- a/tests/error_test.go +++ b/runtime/error_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "encoding/hex" @@ -31,7 +31,7 @@ import ( . "github.com/onflow/cadence/runtime" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/runtime_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) func TestRuntimeError(t *testing.T) { diff --git a/tests/errors_test.go b/runtime/errors_test.go similarity index 99% rename from tests/errors_test.go rename to runtime/errors_test.go index 9fafcbf8fc..979a7c366e 100644 --- a/tests/errors_test.go +++ b/runtime/errors_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "fmt" diff --git a/tests/ft_test.go b/runtime/ft_test.go similarity index 99% rename from tests/ft_test.go rename to runtime/ft_test.go index 2efce854de..b9374d986e 100644 --- a/tests/ft_test.go +++ b/runtime/ft_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "fmt" @@ -31,8 +31,9 @@ import ( "github.com/onflow/cadence/interpreter" . "github.com/onflow/cadence/runtime" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/runtime_utils" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) const modifiedFungibleTokenContractInterface = ` @@ -627,7 +628,7 @@ func BenchmarkRuntimeFungibleTokenTransfer(b *testing.B) { err := runtime.ExecuteTransaction( Script{ - Source: utils.DeploymentTransaction( + Source: DeploymentTransaction( "FungibleToken", []byte(modifiedFungibleTokenContractInterface), ), @@ -644,7 +645,7 @@ func BenchmarkRuntimeFungibleTokenTransfer(b *testing.B) { err = runtime.ExecuteTransaction( Script{ - Source: utils.DeploymentTransaction("FlowToken", []byte(modifiedFlowContract)), + Source: DeploymentTransaction("FlowToken", []byte(modifiedFlowContract)), }, Context{ Interface: runtimeInterface, @@ -767,7 +768,7 @@ func BenchmarkRuntimeFungibleTokenTransfer(b *testing.B) { sum = sum.Plus(inter, value, interpreter.EmptyLocationRange).(interpreter.UFix64Value) } - utils.RequireValuesEqual(b, nil, mintAmountValue, sum) + RequireValuesEqual(b, nil, mintAmountValue, sum) } const oldExampleToken = ` @@ -1043,7 +1044,7 @@ func TestRuntimeBrokenFungibleTokenRecovery(t *testing.T) { err := runtime.ExecuteTransaction( Script{ - Source: utils.DeploymentTransaction( + Source: DeploymentTransaction( "FungibleToken", []byte(modifiedFungibleTokenContractInterface), ), @@ -1222,7 +1223,7 @@ func TestRuntimeBrokenFungibleTokenRecovery(t *testing.T) { Environment: environment, }, ) - utils.RequireError(t, err) + RequireError(t, err) require.ErrorContains(t, err, "Vault.withdraw is not available in recovered program") t.Log(err.Error()) diff --git a/tests/import_test.go b/runtime/import_test.go similarity index 95% rename from tests/import_test.go rename to runtime/import_test.go index 2e75215a84..cbc92d7401 100644 --- a/tests/import_test.go +++ b/runtime/import_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "fmt" @@ -30,9 +30,9 @@ import ( "github.com/onflow/cadence/encoding/json" . "github.com/onflow/cadence/runtime" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/checker" - . "github.com/onflow/cadence/tests/runtime_utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestRuntimeCyclicImport(t *testing.T) { @@ -91,7 +91,7 @@ func TestRuntimeCyclicImport(t *testing.T) { var checkerErr *sema.CheckerError require.ErrorAs(t, err, &checkerErr) - errs := checker.RequireCheckerErrors(t, checkerErr, 1) + errs := RequireCheckerErrors(t, checkerErr, 1) var importedProgramErr *sema.ImportedProgramError require.ErrorAs(t, errs[0], &importedProgramErr) @@ -101,7 +101,7 @@ func TestRuntimeCyclicImport(t *testing.T) { var checkerErr2 *sema.CheckerError require.ErrorAs(t, importedProgramErr.Err, &checkerErr2) - errs = checker.RequireCheckerErrors(t, checkerErr2, 1) + errs = RequireCheckerErrors(t, checkerErr2, 1) var importedProgramErr2 *sema.ImportedProgramError require.ErrorAs(t, errs[0], &importedProgramErr2) @@ -111,7 +111,7 @@ func TestRuntimeCyclicImport(t *testing.T) { var checkerErr3 *sema.CheckerError require.ErrorAs(t, importedProgramErr2.Err, &checkerErr3) - errs = checker.RequireCheckerErrors(t, checkerErr3, 1) + errs = RequireCheckerErrors(t, checkerErr3, 1) require.IsType(t, &sema.CyclicImportsError{}, errs[0]) } @@ -201,7 +201,7 @@ func TestRuntimeCheckCyclicImportsAfterUpdate(t *testing.T) { var checkerErr *sema.CheckerError require.ErrorAs(t, err, &checkerErr) - errs := checker.RequireCheckerErrors(t, checkerErr, 1) + errs := RequireCheckerErrors(t, checkerErr, 1) var importedProgramErr *sema.ImportedProgramError require.ErrorAs(t, errs[0], &importedProgramErr) @@ -209,7 +209,7 @@ func TestRuntimeCheckCyclicImportsAfterUpdate(t *testing.T) { var nestedCheckerErr *sema.CheckerError require.ErrorAs(t, importedProgramErr.Err, &nestedCheckerErr) - errs = checker.RequireCheckerErrors(t, nestedCheckerErr, 1) + errs = RequireCheckerErrors(t, nestedCheckerErr, 1) require.IsType(t, &sema.CyclicImportsError{}, errs[0]) } @@ -318,7 +318,7 @@ func TestRuntimeCheckCyclicImportAddress(t *testing.T) { var checkerErr *sema.CheckerError require.ErrorAs(t, err, &checkerErr) - errs := checker.RequireCheckerErrors(t, checkerErr, 1) + errs := RequireCheckerErrors(t, checkerErr, 1) // Direct cycle, by importing `Foo` in `Foo` require.IsType(t, &sema.CyclicImportsError{}, errs[0]) @@ -403,7 +403,7 @@ func TestRuntimeCheckCyclicImportToSelfDuringDeploy(t *testing.T) { var checkerErr *sema.CheckerError require.ErrorAs(t, err, &checkerErr) - errs := checker.RequireCheckerErrors(t, checkerErr, 1) + errs := RequireCheckerErrors(t, checkerErr, 1) require.IsType(t, &sema.CyclicImportsError{}, errs[0]) } diff --git a/tests/imported_values_memory_metering_test.go b/runtime/imported_values_memory_metering_test.go similarity index 99% rename from tests/imported_values_memory_metering_test.go rename to runtime/imported_values_memory_metering_test.go index 8b24d84ae1..d7620f27e9 100644 --- a/tests/imported_values_memory_metering_test.go +++ b/runtime/imported_values_memory_metering_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "fmt" @@ -29,8 +29,8 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/encoding/json" . "github.com/onflow/cadence/runtime" - . "github.com/onflow/cadence/tests/runtime_utils" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) func testUseMemory(meter map[common.MemoryKind]uint64) func(common.MemoryUsage) error { @@ -628,7 +628,7 @@ func TestRuntimeScriptDecodedLocationMetering(t *testing.T) { }, ) - utils.RequireError(t, err) + RequireError(t, err) var entryPointErr *InvalidEntryPointArgumentError require.ErrorAs(t, err, &entryPointErr) diff --git a/tests/inbox_test.go b/runtime/inbox_test.go similarity index 99% rename from tests/inbox_test.go rename to runtime/inbox_test.go index c2330bc954..7017e4a5d9 100644 --- a/tests/inbox_test.go +++ b/runtime/inbox_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "fmt" @@ -30,7 +30,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/encoding/json" . "github.com/onflow/cadence/runtime" - . "github.com/onflow/cadence/tests/runtime_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) func TestRuntimeAccountInboxPublishUnpublish(t *testing.T) { diff --git a/runtime/interface.go b/runtime/interface.go index 410ee057d2..e5d9a22c8e 100644 --- a/runtime/interface.go +++ b/runtime/interface.go @@ -161,6 +161,8 @@ type Interface interface { path interpreter.PathValue, capabilityBorrowType *interpreter.ReferenceStaticType, ) (bool, error) + + MinimumRequiredVersion() (string, error) } type MeterInterface interface { diff --git a/tests/literal_test.go b/runtime/literal_test.go similarity index 99% rename from tests/literal_test.go rename to runtime/literal_test.go index 296488776f..6109662007 100644 --- a/tests/literal_test.go +++ b/runtime/literal_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "fmt" @@ -29,8 +29,8 @@ import ( "github.com/onflow/cadence/common" . "github.com/onflow/cadence/runtime" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/runtime_utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" ) func TestRuntimeParseLiteral(t *testing.T) { diff --git a/tests/nft_test.go b/runtime/nft_test.go similarity index 99% rename from tests/nft_test.go rename to runtime/nft_test.go index dd0f70db3d..fcaebdc473 100644 --- a/tests/nft_test.go +++ b/runtime/nft_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test const modifiedNonFungibleTokenInterface = ` diff --git a/tests/predeclaredvalues_test.go b/runtime/predeclaredvalues_test.go similarity index 98% rename from tests/predeclaredvalues_test.go rename to runtime/predeclaredvalues_test.go index acefd56e08..9b916a3c0f 100644 --- a/tests/predeclaredvalues_test.go +++ b/runtime/predeclaredvalues_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "math/big" @@ -33,9 +33,9 @@ import ( . "github.com/onflow/cadence/runtime" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - "github.com/onflow/cadence/tests/checker" - . "github.com/onflow/cadence/tests/runtime_utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestRuntimePredeclaredValues(t *testing.T) { @@ -245,7 +245,7 @@ func TestRuntimePredeclaredValues(t *testing.T) { require.ErrorAs(t, err, &checkerErr) assert.Equal(t, common.ScriptLocation{}, checkerErr.Location) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) var notDeclaredErr *sema.NotDeclaredError require.ErrorAs(t, errs[0], ¬DeclaredErr) diff --git a/tests/program_params_validation_test.go b/runtime/program_params_validation_test.go similarity index 97% rename from tests/program_params_validation_test.go rename to runtime/program_params_validation_test.go index 827de1ebe5..5cc5485f9d 100644 --- a/tests/program_params_validation_test.go +++ b/runtime/program_params_validation_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "fmt" @@ -30,9 +30,9 @@ import ( "github.com/onflow/cadence/encoding/json" . "github.com/onflow/cadence/runtime" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/checker" - . "github.com/onflow/cadence/tests/runtime_utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestRuntimeScriptParameterTypeValidation(t *testing.T) { @@ -346,7 +346,7 @@ func TestRuntimeScriptParameterTypeValidation(t *testing.T) { var checkerError *sema.CheckerError require.ErrorAs(t, err, &checkerError) - errs := checker.RequireCheckerErrors(t, checkerError, 1) + errs := RequireCheckerErrors(t, checkerError, 1) assert.IsType(t, &sema.InvalidTypeArgumentError{}, errs[0]) }) @@ -385,7 +385,7 @@ func TestRuntimeScriptParameterTypeValidation(t *testing.T) { var checkerError *sema.CheckerError require.ErrorAs(t, err, &checkerError) - errs := checker.RequireCheckerErrors(t, checkerError, 1) + errs := RequireCheckerErrors(t, checkerError, 1) assert.IsType(t, &sema.InvalidTypeArgumentError{}, errs[0]) }) @@ -811,7 +811,7 @@ func TestRuntimeTransactionParameterTypeValidation(t *testing.T) { err := executeTransaction(t, script, contracts, cadence.NewOptional(nil)) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.InvalidNonImportableTransactionParameterTypeError{}, errs[0]) }) @@ -876,7 +876,7 @@ func TestRuntimeTransactionParameterTypeValidation(t *testing.T) { err := executeTransaction(t, script, contracts, cadence.NewOptional(nil)) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.InvalidNonImportableTransactionParameterTypeError{}, errs[0]) }) @@ -903,7 +903,7 @@ func TestRuntimeTransactionParameterTypeValidation(t *testing.T) { err := executeTransaction(t, script, contracts, cadence.NewOptional(nil)) - errs := checker.RequireCheckerErrors(t, err, 2) + errs := RequireCheckerErrors(t, err, 2) require.IsType(t, &sema.InvalidNonImportableTransactionParameterTypeError{}, errs[0]) require.IsType(t, &sema.ResourceLossError{}, errs[1]) @@ -918,7 +918,7 @@ func TestRuntimeTransactionParameterTypeValidation(t *testing.T) { err := executeTransaction(t, script, nil, cadence.NewOptional(nil)) - errs := checker.RequireCheckerErrors(t, err, 2) + errs := RequireCheckerErrors(t, err, 2) require.IsType(t, &sema.InvalidNonImportableTransactionParameterTypeError{}, errs[0]) require.IsType(t, &sema.ResourceLossError{}, errs[1]) @@ -943,7 +943,7 @@ func TestRuntimeTransactionParameterTypeValidation(t *testing.T) { err := executeTransaction(t, script, contracts, cadence.NewOptional(nil)) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.InvalidNonImportableTransactionParameterTypeError{}, errs[0]) }) @@ -968,7 +968,7 @@ func TestRuntimeTransactionParameterTypeValidation(t *testing.T) { err := executeTransaction(t, script, nil, cadence.NewArray([]cadence.Value{})) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.InvalidNonImportableTransactionParameterTypeError{}, errs[0]) }) @@ -1004,7 +1004,7 @@ func TestRuntimeTransactionParameterTypeValidation(t *testing.T) { err := executeTransaction(t, script, nil, cadence.NewArray([]cadence.Value{})) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.InvalidNonImportableTransactionParameterTypeError{}, errs[0]) }) @@ -1110,7 +1110,7 @@ func TestRuntimeTransactionParameterTypeValidation(t *testing.T) { if test.expectErrors { - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, &sema.InvalidNonImportableTransactionParameterTypeError{}, errs[0]) } else { diff --git a/tests/resource_duplicate_test.go b/runtime/resource_duplicate_test.go similarity index 98% rename from tests/resource_duplicate_test.go rename to runtime/resource_duplicate_test.go index 246f073a61..9304dfb07a 100644 --- a/tests/resource_duplicate_test.go +++ b/runtime/resource_duplicate_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "testing" @@ -29,8 +29,8 @@ import ( "github.com/onflow/cadence/interpreter" . "github.com/onflow/cadence/runtime" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/runtime_utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) func TestRuntimeResourceDuplicationWithContractTransferInTransaction(t *testing.T) { diff --git a/tests/resourcedictionary_test.go b/runtime/resourcedictionary_test.go similarity index 98% rename from tests/resourcedictionary_test.go rename to runtime/resourcedictionary_test.go index e1b939e74e..a1a5100423 100644 --- a/tests/resourcedictionary_test.go +++ b/runtime/resourcedictionary_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "encoding/hex" @@ -29,8 +29,7 @@ import ( "github.com/onflow/cadence" "github.com/onflow/cadence/common" . "github.com/onflow/cadence/runtime" - . "github.com/onflow/cadence/tests/runtime_utils" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) const resourceDictionaryContract = ` @@ -94,7 +93,7 @@ func TestRuntimeResourceDictionaryValues(t *testing.T) { contract := []byte(resourceDictionaryContract) - deploy := utils.DeploymentTransaction("Test", contract) + deploy := DeploymentTransaction("Test", contract) setupTx := []byte(` import Test from 0xCADE @@ -450,7 +449,7 @@ func TestRuntimeResourceDictionaryValues_Nested(t *testing.T) { } `) - deploy := utils.DeploymentTransaction("Test", contract) + deploy := DeploymentTransaction("Test", contract) setupTx := []byte(` import Test from 0xCADE @@ -754,7 +753,7 @@ func TestRuntimeResourceDictionaryValues_Removal(t *testing.T) { contract := []byte(resourceDictionaryContract) - deployTx := utils.DeploymentTransaction("Test", contract) + deployTx := DeploymentTransaction("Test", contract) setupTx := []byte(` import Test from 0x1 @@ -883,7 +882,7 @@ func TestRuntimeResourceDictionaryValues_Destruction(t *testing.T) { contract := []byte(resourceDictionaryContract) - deployTx := utils.DeploymentTransaction("Test", contract) + deployTx := DeploymentTransaction("Test", contract) setupTx := []byte(` import Test from 0x1 @@ -996,7 +995,7 @@ func TestRuntimeResourceDictionaryValues_Insertion(t *testing.T) { contract := []byte(resourceDictionaryContract) - deployTx := utils.DeploymentTransaction("Test", contract) + deployTx := DeploymentTransaction("Test", contract) setupTx := []byte(` import Test from 0x1 @@ -1137,7 +1136,7 @@ func TestRuntimeResourceDictionaryValues_ValueTransferAndDestroy(t *testing.T) { contract := []byte(resourceDictionaryContract) - deployTx := utils.DeploymentTransaction("Test", contract) + deployTx := DeploymentTransaction("Test", contract) setupTx := []byte(` import Test from 0x1 @@ -1330,7 +1329,7 @@ func BenchmarkRuntimeResourceDictionaryValues(b *testing.B) { } `) - deploy := utils.DeploymentTransaction("Test", contract) + deploy := DeploymentTransaction("Test", contract) setupTx := []byte(` import Test from 0xCADE diff --git a/tests/rlp_test.go b/runtime/rlp_test.go similarity index 98% rename from tests/rlp_test.go rename to runtime/rlp_test.go index 1aa9296eed..93cfaa1ed6 100644 --- a/tests/rlp_test.go +++ b/runtime/rlp_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "testing" @@ -28,8 +28,8 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/encoding/json" . "github.com/onflow/cadence/runtime" - . "github.com/onflow/cadence/tests/runtime_utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) func TestRuntimeRLPDecodeString(t *testing.T) { diff --git a/tests/runtime_memory_metering_test.go b/runtime/runtime_memory_metering_test.go similarity index 99% rename from tests/runtime_memory_metering_test.go rename to runtime/runtime_memory_metering_test.go index e2aac366fd..d6d389ff73 100644 --- a/tests/runtime_memory_metering_test.go +++ b/runtime/runtime_memory_metering_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "fmt" @@ -31,8 +31,8 @@ import ( "github.com/onflow/cadence/encoding/json" "github.com/onflow/cadence/errors" . "github.com/onflow/cadence/runtime" - . "github.com/onflow/cadence/tests/runtime_utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) type testMemoryGauge struct { diff --git a/tests/runtime_test.go b/runtime/runtime_test.go similarity index 99% rename from tests/runtime_test.go rename to runtime/runtime_test.go index 7deb22940a..3c41142877 100644 --- a/tests/runtime_test.go +++ b/runtime/runtime_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "crypto/rand" @@ -43,9 +43,9 @@ import ( . "github.com/onflow/cadence/runtime" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - "github.com/onflow/cadence/tests/checker" - . "github.com/onflow/cadence/tests/runtime_utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestRuntimeImport(t *testing.T) { @@ -1773,7 +1773,7 @@ func TestRuntimeStorageMultipleTransactionsInclusiveRangeFunction(t *testing.T) var checkerErr *sema.CheckerError require.ErrorAs(t, err, &checkerErr) - errs := checker.RequireCheckerErrors(t, checkerErr, 1) + errs := RequireCheckerErrors(t, checkerErr, 1) assert.IsType(t, &sema.TypeMismatchError{}, errs[0]) @@ -4883,7 +4883,7 @@ func TestRuntimeTransactionTopLevelDeclarations(t *testing.T) { var checkerErr *sema.CheckerError require.ErrorAs(t, err, &checkerErr) - errs := checker.RequireCheckerErrors(t, checkerErr, 1) + errs := RequireCheckerErrors(t, checkerErr, 1) assert.IsType(t, &sema.InvalidTopLevelDeclarationError{}, errs[0]) }) @@ -7766,7 +7766,7 @@ func TestRuntimeImportTestStdlib(t *testing.T) { RequireError(t, err) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) notDeclaredErr := &sema.NotDeclaredError{} require.ErrorAs(t, errs[0], ¬DeclaredErr) @@ -8539,7 +8539,7 @@ func TestRuntimeOptionalReferenceAttack(t *testing.T) { var checkerErr *sema.CheckerError require.ErrorAs(t, err, &checkerErr) - errs := checker.RequireCheckerErrors(t, checkerErr, 1) + errs := RequireCheckerErrors(t, checkerErr, 1) assert.IsType(t, &sema.TypeMismatchError{}, errs[0]) } @@ -9070,7 +9070,7 @@ func TestRuntimeTypesAndConversions(t *testing.T) { }) } - for name, ty := range checker.AllBaseSemaTypes() { + for name, ty := range AllBaseSemaTypes() { // Inclusive range is a dynamically created type. if _, isInclusiveRange := ty.(*sema.InclusiveRangeType); isInclusiveRange { continue @@ -9842,7 +9842,7 @@ func TestRuntimePreconditionDuplication(t *testing.T) { var checkerErr *sema.CheckerError require.ErrorAs(t, err, &checkerErr) - errs := checker.RequireCheckerErrors(t, checkerErr, 3) + errs := RequireCheckerErrors(t, checkerErr, 3) assert.IsType(t, &sema.PurityError{}, errs[0]) assert.IsType(t, &sema.InvalidInterfaceConditionResourceInvalidationError{}, errs[1]) @@ -11667,6 +11667,74 @@ func TestRuntimeIdentifierLocationToAddressLocationRewrite(t *testing.T) { assert.Equal(t, cadence.NewInt(42), result) } +func TestRuntimeBuiltInFunctionConfusion(t *testing.T) { + + t.Parallel() + + const contract = ` + access(all) contract Foo { + access(all) resource getType {} + + init() { + Foo.getType() + } + } + ` + + address := common.MustBytesToAddress([]byte{0x1}) + + newRuntimeInterface := func() Interface { + + accountCodes := map[common.AddressLocation][]byte{} + var events []cadence.Event + var loggedMessages []string + + return &TestRuntimeInterface{ + Storage: NewTestLedger(nil, nil), + OnGetSigningAccounts: func() ([]common.Address, error) { + return []common.Address{address}, nil + }, + OnResolveLocation: NewSingleIdentifierLocationResolver(t), + OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { + accountCodes[location] = code + return nil + }, + OnGetAccountContractCode: func(location common.AddressLocation) (code []byte, err error) { + code = accountCodes[location] + return code, nil + }, + OnEmitEvent: func(event cadence.Event) error { + events = append(events, event) + return nil + }, + OnProgramLog: func(message string) { + loggedMessages = append(loggedMessages, message) + }, + } + } + + runtime := NewTestInterpreterRuntime() + + nextTransactionLocation := NewTransactionLocationGenerator() + + err := runtime.ExecuteTransaction( + Script{ + Source: DeploymentTransaction( + "Foo", + []byte(contract), + ), + }, + Context{ + Interface: newRuntimeInterface(), + Location: nextTransactionLocation(), + }, + ) + RequireError(t, err) + + var redeclarationError *sema.RedeclarationError + require.ErrorAs(t, err, &redeclarationError) +} + func BenchmarkContractFunctionInvocation(b *testing.B) { runtime := NewTestInterpreterRuntime() diff --git a/tests/sharedstate_test.go b/runtime/sharedstate_test.go similarity index 97% rename from tests/sharedstate_test.go rename to runtime/sharedstate_test.go index b5d37b29a3..3008c85fff 100644 --- a/tests/sharedstate_test.go +++ b/runtime/sharedstate_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "testing" @@ -28,8 +28,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" . "github.com/onflow/cadence/runtime" - . "github.com/onflow/cadence/tests/runtime_utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) func TestRuntimeSharedState(t *testing.T) { diff --git a/tests/storage_test.go b/runtime/storage_test.go similarity index 99% rename from tests/storage_test.go rename to runtime/storage_test.go index 3895ca2327..5a7bb60bc9 100644 --- a/tests/storage_test.go +++ b/runtime/storage_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "encoding/binary" @@ -36,8 +36,9 @@ import ( "github.com/onflow/cadence/encoding/json" "github.com/onflow/cadence/interpreter" . "github.com/onflow/cadence/runtime" - . "github.com/onflow/cadence/tests/runtime_utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/interpreter_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) func withWritesToStorage( diff --git a/tests/test-export-json-deterministic.txt b/runtime/test-export-json-deterministic.json similarity index 100% rename from tests/test-export-json-deterministic.txt rename to runtime/test-export-json-deterministic.json diff --git a/tests/type_test.go b/runtime/type_test.go similarity index 98% rename from tests/type_test.go rename to runtime/type_test.go index 5ee6afc790..c96a705675 100644 --- a/tests/type_test.go +++ b/runtime/type_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "testing" @@ -27,7 +27,7 @@ import ( "github.com/onflow/cadence" "github.com/onflow/cadence/common" . "github.com/onflow/cadence/runtime" - . "github.com/onflow/cadence/tests/runtime_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) func TestRuntimeTypeStorage(t *testing.T) { diff --git a/tests/validation_test.go b/runtime/validation_test.go similarity index 96% rename from tests/validation_test.go rename to runtime/validation_test.go index b46b609df8..db212f8547 100644 --- a/tests/validation_test.go +++ b/runtime/validation_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package tests +package runtime_test import ( "testing" @@ -28,8 +28,8 @@ import ( "github.com/onflow/cadence/encoding/json" "github.com/onflow/cadence/interpreter" . "github.com/onflow/cadence/runtime" - . "github.com/onflow/cadence/tests/runtime_utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) // TestRuntimeArgumentImportMissingType tests if errors produced while validating diff --git a/tests/checker/access_test.go b/sema/accesses_test.go similarity index 99% rename from tests/checker/access_test.go rename to sema/accesses_test.go index 041fad225e..976e30811e 100644 --- a/tests/checker/access_test.go +++ b/sema/accesses_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -28,6 +28,7 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func expectSuccess(t *testing.T, err error) { diff --git a/tests/checker/account_test.go b/sema/account_test.go similarity index 99% rename from tests/checker/account_test.go rename to sema/account_test.go index 1fc36ef465..6084a5042b 100644 --- a/tests/checker/account_test.go +++ b/sema/account_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -27,7 +27,8 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckAccountStorageSave(t *testing.T) { @@ -887,7 +888,7 @@ func TestCheckAccountStorageBorrow(t *testing.T) { sema.NewEntitlementSetAccess( []*sema.EntitlementType{ { - Location: utils.TestLocation, + Location: TestLocation, Identifier: "X", }, }, diff --git a/tests/checker/any_test.go b/sema/any_test.go similarity index 96% rename from tests/checker/any_test.go rename to sema/any_test.go index fda0cd08b6..c9c0c76222 100644 --- a/tests/checker/any_test.go +++ b/sema/any_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -24,6 +24,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckAnyStruct(t *testing.T) { diff --git a/tests/checker/arrays_dictionaries_test.go b/sema/arrays_dictionaries_test.go similarity index 99% rename from tests/checker/arrays_dictionaries_test.go rename to sema/arrays_dictionaries_test.go index dea57fc1a6..6e5a512d05 100644 --- a/tests/checker/arrays_dictionaries_test.go +++ b/sema/arrays_dictionaries_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -30,6 +30,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckDictionary(t *testing.T) { diff --git a/tests/checker/assert_test.go b/sema/assert_test.go similarity index 96% rename from tests/checker/assert_test.go rename to sema/assert_test.go index ea9591bcd9..0c19bdc57e 100644 --- a/tests/checker/assert_test.go +++ b/sema/assert_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -26,6 +26,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckAssertWithoutMessage(t *testing.T) { diff --git a/tests/checker/assignment_test.go b/sema/assignment_test.go similarity index 98% rename from tests/checker/assignment_test.go rename to sema/assignment_test.go index 6342ae4174..96494ccde0 100644 --- a/tests/checker/assignment_test.go +++ b/sema/assignment_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidUnknownDeclarationAssignment(t *testing.T) { diff --git a/tests/checker/attachments_test.go b/sema/attachments_test.go similarity index 93% rename from tests/checker/attachments_test.go rename to sema/attachments_test.go index de3e3dd406..2e8bed5d9f 100644 --- a/tests/checker/attachments_test.go +++ b/sema/attachments_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -26,6 +26,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckAttachmentBasic(t *testing.T) { @@ -619,304 +620,42 @@ func TestCheckAttachmentWithMembers(t *testing.T) { }) } -func TestCheckAttachmentConformance(t *testing.T) { +func TestCheckInvalidAttachmentConformance(t *testing.T) { t.Parallel() - t.Run("basic", func(t *testing.T) { - - t.Parallel() - - _, err := ParseAndCheck(t, - ` - resource R {} - resource interface I { - } - attachment Test for R: I { - }`, - ) - - require.NoError(t, err) - }) - - t.Run("field", func(t *testing.T) { - - t.Parallel() - - _, err := ParseAndCheck(t, - ` - resource R {} - resource interface I { - let x: Int - } - attachment Test for R: I { - let x: Int - init(x: Int) { - self.x = x - } - }`, - ) - - require.NoError(t, err) - }) - - t.Run("method", func(t *testing.T) { - - t.Parallel() - - _, err := ParseAndCheck(t, - ` - resource R {} - resource interface I { - fun x(): Int - } - attachment Test for R: I { - fun x(): Int { return 0 } - }`, - ) - - require.NoError(t, err) - }) - - t.Run("field missing", func(t *testing.T) { - - t.Parallel() - - _, err := ParseAndCheck(t, - ` - resource R {} - resource interface I { - let x: Int - } - attachment Test for R: I { - }`, - ) - - errs := RequireCheckerErrors(t, err, 1) - - assert.IsType(t, &sema.ConformanceError{}, errs[0]) - }) - - t.Run("field type", func(t *testing.T) { - - t.Parallel() - - _, err := ParseAndCheck(t, - ` - resource R {} - resource interface I { - let x: Int - } - attachment Test for R: I { - let x: AnyStruct - init(x: AnyStruct) { - self.x = x - } - }`, - ) - - errs := RequireCheckerErrors(t, err, 1) - - assert.IsType(t, &sema.ConformanceError{}, errs[0]) - }) - - t.Run("method missing", func(t *testing.T) { - - t.Parallel() - - _, err := ParseAndCheck(t, - ` - resource R {} - resource interface I { - fun x(): Int - } - attachment Test for R: I { - }`, - ) - - errs := RequireCheckerErrors(t, err, 1) - - assert.IsType(t, &sema.ConformanceError{}, errs[0]) - }) - - t.Run("method type", func(t *testing.T) { - - t.Parallel() - - _, err := ParseAndCheck(t, - ` - resource R {} - resource interface I { - fun x(): Int - } - attachment Test for R: I { - fun x(): AnyStruct { return "" } - }`, - ) - - errs := RequireCheckerErrors(t, err, 1) - - assert.IsType(t, &sema.ConformanceError{}, errs[0]) - }) - - t.Run("method missing, exists in base type", func(t *testing.T) { - - t.Parallel() - - _, err := ParseAndCheck(t, - ` - resource R { - fun x(): Int { return 3 } - } - resource interface I { - fun x(): Int - } - attachment Test for R: I { - }`, - ) - - errs := RequireCheckerErrors(t, err, 1) - - assert.IsType(t, &sema.ConformanceError{}, errs[0]) - }) - - t.Run("kind mismatch resource", func(t *testing.T) { + t.Run("struct", func(t *testing.T) { t.Parallel() - _, err := ParseAndCheck(t, - ` - resource R {} - struct interface I {} - attachment Test for R: I {}`, - ) - - errs := RequireCheckerErrors(t, err, 1) - - assert.IsType(t, &sema.CompositeKindMismatchError{}, errs[0]) - }) - - t.Run("kind mismatch struct", func(t *testing.T) { + _, err := ParseAndCheck(t, ` + struct S {} - t.Parallel() + struct interface SI {} - _, err := ParseAndCheck(t, - ` - struct R {} - resource interface I {} - attachment Test for R: I {}`, - ) + attachment Test for S: SI {} + `) errs := RequireCheckerErrors(t, err, 1) - assert.IsType(t, &sema.CompositeKindMismatchError{}, errs[0]) - }) - - t.Run("conforms to base", func(t *testing.T) { - - t.Parallel() - - _, err := ParseAndCheck(t, - ` - resource interface I {} - attachment A for I: I {}`, - ) - - require.NoError(t, err) - }) - - t.Run("AnyResource base, resource conformance", func(t *testing.T) { - - t.Parallel() - - _, err := ParseAndCheck(t, - ` - resource interface I {} - attachment A for AnyResource: I {}`, - ) - - require.NoError(t, err) - }) - - t.Run("AnyStruct base, struct conformance", func(t *testing.T) { - - t.Parallel() - - _, err := ParseAndCheck(t, - ` - struct interface I {} - attachment A for AnyStruct: I {}`, - ) - - require.NoError(t, err) + assert.IsType(t, &sema.InvalidAttachmentConformancesError{}, errs[0]) }) - t.Run("AnyStruct base, resource conformance", func(t *testing.T) { + t.Run("resource", func(t *testing.T) { t.Parallel() - _, err := ParseAndCheck(t, - ` - resource interface I {} - attachment A for AnyStruct: I {}`, - ) - - errs := RequireCheckerErrors(t, err, 1) - - assert.IsType(t, &sema.CompositeKindMismatchError{}, errs[0]) - }) - - t.Run("AnyResource base, struct conformance", func(t *testing.T) { + _, err := ParseAndCheck(t, ` + resource R {} - t.Parallel() + resource interface RI {} - _, err := ParseAndCheck(t, - ` - struct interface I {} - attachment A for AnyResource: I {}`, - ) + attachment Test for R: RI {} + `) errs := RequireCheckerErrors(t, err, 1) - assert.IsType(t, &sema.CompositeKindMismatchError{}, errs[0]) - }) - - t.Run("cross-contract concrete base", func(t *testing.T) { - - t.Parallel() - - _, err := ParseAndCheck(t, - ` - contract C0 { - resource interface R {} - } - contract C1 { - resource R {} - attachment A for R: C0.R {} - } - `, - ) - - require.NoError(t, err) - }) - - t.Run("cross-contract interface base", func(t *testing.T) { - - t.Parallel() - - _, err := ParseAndCheck(t, - ` - contract C0 { - resource R {} - } - contract C1 { - resource interface R {} - attachment A for C0.R: R {} - } - `, - ) - - require.NoError(t, err) + assert.IsType(t, &sema.InvalidAttachmentConformancesError{}, errs[0]) }) } @@ -1295,42 +1034,6 @@ func TestCheckAttachmentSelfTyping(t *testing.T) { require.NoError(t, err) }) - t.Run("return self struct interface", func(t *testing.T) { - - t.Parallel() - - _, err := ParseAndCheck(t, - ` - struct R {} - struct interface I {} - attachment Test for R: I { - fun foo(): &{I} { - return self - } - }`, - ) - - require.NoError(t, err) - }) - - t.Run("return self resource interface", func(t *testing.T) { - - t.Parallel() - - _, err := ParseAndCheck(t, - ` - resource R {} - resource interface I {} - attachment Test for R: I { - fun foo(): &{I} { - return self - } - }`, - ) - - require.NoError(t, err) - }) - t.Run("self access restricted", func(t *testing.T) { t.Parallel() @@ -3517,7 +3220,7 @@ func TestCheckAttachmentAccessAttachment(t *testing.T) { fmt.Sprintf(` resource R {} resource interface I {} - attachment A for AnyResource: I {} + attachment A for AnyResource {} access(all) fun foo(r: %sR) { r[I] %s @@ -4665,7 +4368,7 @@ func TestCheckAttachmentForEachAttachment(t *testing.T) { assert.IsType(t, &sema.NotDeclaredMemberError{}, errs[0]) }) - t.Run("cannot redeclare forEachAttachment", func(t *testing.T) { + t.Run("cannot redeclare forEachAttachment as function", func(t *testing.T) { t.Parallel() @@ -4681,6 +4384,27 @@ func TestCheckAttachmentForEachAttachment(t *testing.T) { assert.IsType(t, &sema.InvalidDeclarationError{}, errs[0]) }) + t.Run("cannot redeclare forEachAttachment as field", func(t *testing.T) { + + t.Parallel() + + _, err := ParseAndCheck(t, + ` + access(all) struct S { + let forEachAttachment: Int + + init() { + self.forEachAttachment = 1 + } + } + `, + ) + + errs := RequireCheckerErrors(t, err, 2) + assert.IsType(t, &sema.InvalidDeclarationError{}, errs[0]) + assert.IsType(t, &sema.TypeMismatchError{}, errs[1]) + }) + t.Run("downcasting reference with entitlements", func(t *testing.T) { t.Parallel() diff --git a/sema/bool_type.go b/sema/bool_type.go index 36f1db3e70..1c19660bd8 100644 --- a/sema/bool_type.go +++ b/sema/bool_type.go @@ -31,6 +31,9 @@ var BoolType = &SimpleType{ Comparable: true, Exportable: true, Importable: true, + conformances: []*InterfaceType{ + StructStringerType, + }, } var BoolTypeAnnotation = NewTypeAnnotation(BoolType) diff --git a/tests/checker/boolean_test.go b/sema/boolean_test.go similarity index 93% rename from tests/checker/boolean_test.go rename to sema/boolean_test.go index a6e5224581..7c6202a5c2 100644 --- a/tests/checker/boolean_test.go +++ b/sema/boolean_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckBoolean(t *testing.T) { diff --git a/tests/checker/builtinfunctions_test.go b/sema/builtinfunctions_test.go similarity index 99% rename from tests/checker/builtinfunctions_test.go rename to sema/builtinfunctions_test.go index be7a0ba1d1..07ca190593 100644 --- a/tests/checker/builtinfunctions_test.go +++ b/sema/builtinfunctions_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -28,6 +28,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckToString(t *testing.T) { diff --git a/tests/checker/capability_controller_test.go b/sema/capability_controller_test.go similarity index 98% rename from tests/checker/capability_controller_test.go rename to sema/capability_controller_test.go index 98cd7ec076..994f600999 100644 --- a/tests/checker/capability_controller_test.go +++ b/sema/capability_controller_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -26,6 +26,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckStorageCapabilityController(t *testing.T) { diff --git a/tests/checker/capability_test.go b/sema/capability_test.go similarity index 98% rename from tests/checker/capability_test.go rename to sema/capability_test.go index 3a9ffc013e..cb430f7b82 100644 --- a/tests/checker/capability_test.go +++ b/sema/capability_test.go @@ -16,17 +16,18 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" "testing" - "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/utils" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckCapability(t *testing.T) { @@ -92,7 +93,7 @@ func TestCheckCapability_borrow(t *testing.T) { for _, auth := range []sema.Access{sema.UnauthorizedAccess, sema.NewEntitlementSetAccess([]*sema.EntitlementType{{ - Location: utils.TestLocation, + Location: TestLocation, Identifier: "X", }}, sema.Conjunction), } { @@ -319,7 +320,7 @@ func TestCheckCapability_check(t *testing.T) { for _, auth := range []sema.Access{sema.UnauthorizedAccess, sema.NewEntitlementSetAccess([]*sema.EntitlementType{{ - Location: utils.TestLocation, + Location: TestLocation, Identifier: "X", }}, sema.Conjunction), } { diff --git a/tests/checker/casting_test.go b/sema/casting_test.go similarity index 99% rename from tests/checker/casting_test.go rename to sema/casting_test.go index d8f901c874..b77dbdc466 100644 --- a/tests/checker/casting_test.go +++ b/sema/casting_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -26,6 +26,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckCastingIntLiteralToIntegerType(t *testing.T) { diff --git a/sema/character.cdc b/sema/character.cdc index 7b54afdf5d..3532e4713a 100644 --- a/sema/character.cdc +++ b/sema/character.cdc @@ -1,6 +1,6 @@ access(all) -struct Character: Storable, Primitive, Equatable, Comparable, Exportable, Importable { +struct Character: Storable, Primitive, Equatable, Comparable, Exportable, Importable, StructStringer { /// The byte array of the UTF-8 encoding. access(all) diff --git a/sema/character.gen.go b/sema/character.gen.go index b0b10694f2..308e2e0dc4 100644 --- a/sema/character.gen.go +++ b/sema/character.gen.go @@ -59,6 +59,7 @@ var CharacterType = &SimpleType{ Exportable: true, Importable: true, ContainFields: false, + conformances: []*InterfaceType{StructStringerType}, } func init() { diff --git a/tests/checker/character_test.go b/sema/character_test.go similarity index 95% rename from tests/checker/character_test.go rename to sema/character_test.go index 816ae93159..7b7c664e95 100644 --- a/tests/checker/character_test.go +++ b/sema/character_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckCharacterLiteral(t *testing.T) { diff --git a/sema/check_composite_declaration.go b/sema/check_composite_declaration.go index 9b201296cf..bbd3728aa0 100644 --- a/sema/check_composite_declaration.go +++ b/sema/check_composite_declaration.go @@ -674,9 +674,32 @@ func (checker *Checker) declareCompositeType(declaration ast.CompositeLikeDeclar // Resolve conformances - if declaration.Kind() == common.CompositeKindEnum { + switch declaration.Kind() { + case common.CompositeKindEnum: compositeType.EnumRawType = checker.enumRawType(declaration.(*ast.CompositeDeclaration)) - } else { + + case common.CompositeKindAttachment: + + // Attachments may not conform to interfaces + + conformanceList := declaration.ConformanceList() + conformanceCount := len(conformanceList) + if conformanceCount > 0 { + firstConformance := conformanceList[0] + lastConformance := conformanceList[conformanceCount-1] + + checker.report( + &InvalidAttachmentConformancesError{ + Range: ast.NewRange( + checker.memoryGauge, + firstConformance.StartPosition(), + lastConformance.EndPosition(checker.memoryGauge), + ), + }, + ) + } + + default: compositeType.ExplicitInterfaceConformances = checker.explicitInterfaceConformances(declaration, compositeType) } @@ -1681,39 +1704,84 @@ func (checker *Checker) defaultMembersAndOrigins( } predeclaredMembers := checker.predeclaredMembers(containerType) - invalidIdentifiers := make(map[string]bool, len(predeclaredMembers)) - + predeclaredMemberNames := make(map[string]struct{}, len(predeclaredMembers)) for _, predeclaredMember := range predeclaredMembers { name := predeclaredMember.Identifier.Identifier - members.Set(name, predeclaredMember) - invalidIdentifiers[name] = true + predeclaredMemberNames[name] = struct{}{} + } - if predeclaredMember.DeclarationKind == common.DeclarationKindField { - fieldNames = append(fieldNames, name) + var nestedTypes *StringTypeOrderedMap + if containerType, ok := containerType.(ContainerType); ok { + nestedTypes = containerType.GetNestedTypes() + } + + checkRedeclaration := func( + identifier ast.Identifier, + declarationKind common.DeclarationKind, + isPredeclared bool, + ) bool { + name := identifier.Identifier + + if !isPredeclared { + if _, ok := predeclaredMemberNames[name]; ok { + checker.report( + &InvalidDeclarationError{ + Identifier: identifier.Identifier, + Kind: declarationKind, + Range: ast.NewRangeFromPositioned(checker.memoryGauge, identifier), + }, + ) + return false + } + } + + if nestedTypes != nil { + if _, ok := nestedTypes.Get(name); ok { + // TODO: provide previous position + checker.report( + &RedeclarationError{ + Name: name, + Kind: declarationKind, + Pos: identifier.Pos, + }, + ) + + return false + } } + + return true } - checkInvalidIdentifier := func(declaration ast.Declaration) bool { - identifier := declaration.DeclarationIdentifier() - if invalidIdentifiers == nil || !invalidIdentifiers[identifier.Identifier] { - return true + // declare all predeclared members (built-in functions and fields) + for _, predeclaredMember := range predeclaredMembers { + identifier := predeclaredMember.Identifier + name := identifier.Identifier + declarationKind := predeclaredMember.DeclarationKind + + if !checkRedeclaration( + identifier, + declarationKind, + true, + ) { + continue } - checker.report( - &InvalidDeclarationError{ - Identifier: identifier.Identifier, - Kind: declaration.DeclarationKind(), - Range: ast.NewRangeFromPositioned(checker.memoryGauge, identifier), - }, - ) + members.Set(name, predeclaredMember) - return false + if declarationKind == common.DeclarationKindField { + fieldNames = append(fieldNames, name) + } } // declare a member for each field for _, field := range fields { - if !checkInvalidIdentifier(field) { + if !checkRedeclaration( + field.Identifier, + field.DeclarationKind(), + false, + ) { continue } @@ -1785,7 +1853,12 @@ func (checker *Checker) defaultMembersAndOrigins( // declare a member for each function for _, function := range functions { - if !checkInvalidIdentifier(function) { + + if !checkRedeclaration( + function.Identifier, + function.DeclarationKind(), + false, + ) { continue } @@ -2399,7 +2472,7 @@ func (checker *Checker) declareBaseValue(fnAccess Access, baseType Type, attachm } // checkNestedIdentifiers checks that nested identifiers, i.e. fields, functions, -// and nested interfaces and composites, are unique and aren't named `init` or `destroy` +// and nested interfaces and composites, are unique and aren't named `init` func (checker *Checker) checkNestedIdentifiers(members *ast.Members) { positions := map[string]ast.Position{} @@ -2423,7 +2496,7 @@ func (checker *Checker) checkNestedIdentifiers(members *ast.Members) { } // checkNestedIdentifier checks that the nested identifier is unique -// and isn't named `init` or `destroy` +// and isn't named `init` func (checker *Checker) checkNestedIdentifier( identifier ast.Identifier, kind common.DeclarationKind, diff --git a/sema/check_string_template_expression.go b/sema/check_string_template_expression.go new file mode 100644 index 0000000000..44aa746d0a --- /dev/null +++ b/sema/check_string_template_expression.go @@ -0,0 +1,62 @@ +/* + * Cadence - The resource-oriented smart contract programming language + * + * Copyright Flow Foundation + * + * 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 sema + +import "github.com/onflow/cadence/ast" + +// All number types, addresses, path types, bool, strings and characters are supported in string template +func isValidStringTemplateValue(valueType Type) bool { + switch valueType { + case TheAddressType, + StringType, + BoolType, + CharacterType: + return true + default: + return IsSubType(valueType, NumberType) || + IsSubType(valueType, PathType) + } +} + +func (checker *Checker) VisitStringTemplateExpression(stringTemplateExpression *ast.StringTemplateExpression) Type { + + // visit all elements + + var elementType Type + + elementCount := len(stringTemplateExpression.Expressions) + + if elementCount > 0 { + for _, element := range stringTemplateExpression.Expressions { + valueType := checker.VisitExpression(element, stringTemplateExpression, elementType) + + if !isValidStringTemplateValue(valueType) { + checker.report( + &TypeMismatchWithDescriptionError{ + ActualType: valueType, + ExpectedTypeDescription: "a type with built-in toString() or bool", + Range: ast.NewRangeFromPositioned(checker.memoryGauge, element), + }, + ) + } + } + } + + return StringType +} diff --git a/tests/checker/composite_test.go b/sema/composite_test.go similarity index 97% rename from tests/checker/composite_test.go rename to sema/composite_test.go index 241a6ce50b..2c718749bb 100644 --- a/tests/checker/composite_test.go +++ b/sema/composite_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -29,6 +29,7 @@ import ( "github.com/onflow/cadence/errors" "github.com/onflow/cadence/parser" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidCompositeRedeclaringType(t *testing.T) { @@ -2298,3 +2299,55 @@ func TestCheckKeywordsAsFieldNames(t *testing.T) { }) } } + +func TestCheckInvalidFunctionNestedTypeClash(t *testing.T) { + + t.Parallel() + interfacePossibilities := []bool{true, false} + + for _, kind := range common.CompositeKindsWithFieldsAndFunctions { + for _, isInterface := range interfacePossibilities { + + interfaceKeyword := "" + if isInterface { + interfaceKeyword = "interface" + } + + var baseType string + + switch kind { + case common.CompositeKindContract: + // Cannot nest contracts + continue + + case common.CompositeKindAttachment: + if isInterface { + continue + } + baseType = "for AnyStruct" + } + + testName := fmt.Sprintf("%s_%s", kind.Keyword(), interfaceKeyword) + + t.Run(testName, func(t *testing.T) { + + _, err := ParseAndCheck(t, + fmt.Sprintf( + ` + contract C { + %s %s getType %s {} + } + `, + kind.Keyword(), + interfaceKeyword, + baseType, + ), + ) + + errs := RequireCheckerErrors(t, err, 1) + + assert.IsType(t, &sema.RedeclarationError{}, errs[0]) + }) + } + } +} diff --git a/tests/checker/conditional_test.go b/sema/conditional_test.go similarity index 97% rename from tests/checker/conditional_test.go rename to sema/conditional_test.go index 733c3fade3..c4db51acd5 100644 --- a/tests/checker/conditional_test.go +++ b/sema/conditional_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckConditionalExpressionTest(t *testing.T) { diff --git a/tests/checker/conditions_test.go b/sema/conditions_test.go similarity index 99% rename from tests/checker/conditions_test.go rename to sema/conditions_test.go index 4c240510c9..afcc7762fc 100644 --- a/tests/checker/conditions_test.go +++ b/sema/conditions_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -26,6 +26,7 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckFunctionTestConditions(t *testing.T) { diff --git a/tests/checker/conformance_test.go b/sema/conformance_test.go similarity index 99% rename from tests/checker/conformance_test.go rename to sema/conformance_test.go index 8bb29b7548..d2f873cab5 100644 --- a/tests/checker/conformance_test.go +++ b/sema/conformance_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -27,6 +27,7 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/errors" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckEventNonTypeRequirementConformance(t *testing.T) { diff --git a/tests/checker/contract_test.go b/sema/contract_test.go similarity index 96% rename from tests/checker/contract_test.go rename to sema/contract_test.go index 9bb97a50d0..15c00749de 100644 --- a/tests/checker/contract_test.go +++ b/sema/contract_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -27,6 +27,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidContractAccountField(t *testing.T) { @@ -94,6 +95,36 @@ func TestCheckInvalidContractInterfaceAccountFunction(t *testing.T) { assert.IsType(t, &sema.InvalidDeclarationError{}, errs[0]) } +func TestCheckInvalidContractAccountType(t *testing.T) { + + t.Parallel() + + _, err := ParseAndCheck(t, ` + contract Test { + struct account {} + } + `) + + errs := RequireCheckerErrors(t, err, 1) + + assert.IsType(t, &sema.RedeclarationError{}, errs[0]) +} + +func TestCheckInvalidContractInterfaceAccountType(t *testing.T) { + + t.Parallel() + + _, err := ParseAndCheck(t, ` + contract interface Test { + struct interface account {} + } + `) + + errs := RequireCheckerErrors(t, err, 1) + + assert.IsType(t, &sema.RedeclarationError{}, errs[0]) +} + func TestCheckContractAccountFieldUse(t *testing.T) { t.Parallel() diff --git a/tests/checker/crypto_test.go b/sema/crypto_test.go similarity index 99% rename from tests/checker/crypto_test.go rename to sema/crypto_test.go index 191183d7a4..e6f751395d 100644 --- a/tests/checker/crypto_test.go +++ b/sema/crypto_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -27,6 +27,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckHashAlgorithmCases(t *testing.T) { diff --git a/tests/checker/declaration_test.go b/sema/declaration_test.go similarity index 99% rename from tests/checker/declaration_test.go rename to sema/declaration_test.go index 6d7cfd6fdc..139ae9e332 100644 --- a/tests/checker/declaration_test.go +++ b/sema/declaration_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -27,6 +27,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckConstantAndVariableDeclarations(t *testing.T) { diff --git a/tests/checker/dictionary_test.go b/sema/dictionary_test.go similarity index 95% rename from tests/checker/dictionary_test.go rename to sema/dictionary_test.go index abb66fe3b8..edd9dd83cb 100644 --- a/tests/checker/dictionary_test.go +++ b/sema/dictionary_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckIncompleteDictionaryType(t *testing.T) { diff --git a/tests/checker/dynamic_casting_test.go b/sema/dynamic_casting_test.go similarity index 99% rename from tests/checker/dynamic_casting_test.go rename to sema/dynamic_casting_test.go index ce7f2e38d7..da02975b35 100644 --- a/tests/checker/dynamic_casting_test.go +++ b/sema/dynamic_casting_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -28,7 +28,8 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) var dynamicCastingOperations = []ast.Operation{ @@ -1206,7 +1207,7 @@ func TestCheckDynamicCastingCapability(t *testing.T) { t.Parallel() structType := &sema.CompositeType{ - Location: utils.TestLocation, + Location: TestLocation, Identifier: "S", Kind: common.CompositeKindStructure, } diff --git a/tests/checker/entitlements_test.go b/sema/entitlements_test.go similarity index 98% rename from tests/checker/entitlements_test.go rename to sema/entitlements_test.go index b546de5713..d4fc27d133 100644 --- a/tests/checker/entitlements_test.go +++ b/sema/entitlements_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -27,6 +27,7 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckBasicEntitlementDeclaration(t *testing.T) { @@ -3031,116 +3032,6 @@ func TestCheckEntitlementInheritance(t *testing.T) { assert.NoError(t, err) }) - - t.Run("attachment inherited default entitled function entitlements on base", func(t *testing.T) { - t.Parallel() - - _, err := ParseAndCheck(t, ` - entitlement E - entitlement F - struct interface I { - access(E) fun foo(): auth(F) &Int { - return &1 as auth(F) &Int - } - } - struct interface I2: I {} - struct S { - access(E) fun foo() {} - } - access(all) attachment A for S: I2 {} - fun test() { - let s = attach A() to S() - let ref = &s as auth(E) &S - let attachmentRef: auth(E) &A = s[A]! - let i: auth(F) &Int = attachmentRef.foo() - } - `) - - assert.NoError(t, err) - }) - - t.Run("attachment inherited default mapped function entitlements on base", func(t *testing.T) { - t.Parallel() - - _, err := ParseAndCheck(t, ` - entitlement E - entitlement F - entitlement mapping M { - E -> F - } - struct interface I { - access(mapping M) fun foo(): auth(mapping M) &Int { - return &1 as auth(mapping M) &Int - } - } - struct interface I2: I {} - struct S { - access(E) fun foo() {} - } - access(all) attachment A for S: I2 {} - fun test() { - let s = attach A() to S() - let ref = &s as auth(E) &S - let attachmentRef: auth(E) &A = s[A]! - let i: auth(F) &Int = attachmentRef.foo() - } - `) - - assert.NoError(t, err) - }) - - t.Run("attachment inherited default mapped function entitlements not on base", func(t *testing.T) { - t.Parallel() - - _, err := ParseAndCheck(t, ` - entitlement E - entitlement F - entitlement mapping M { - E -> F - } - struct interface I { - access(mapping M) fun foo(): auth(mapping M) &Int { - return &1 as auth(mapping M) &Int - } - } - struct interface I2: I {} - struct S {} - access(all) attachment A for S: I2 {} - fun test() { - let s = attach A() to S() - let ref = &s as auth(E) &S - let i: auth(F) &Int = s[A]!.foo() - } - `) - - errs := RequireCheckerErrors(t, err, 1) - require.IsType(t, &sema.InvalidAttachmentEntitlementError{}, errs[0]) - }) - - t.Run("attachment inherited default entitled function entitlements not on base", func(t *testing.T) { - t.Parallel() - - _, err := ParseAndCheck(t, ` - entitlement E - entitlement F - struct interface I { - access(E) fun foo(): auth(F) &Int { - return &1 as auth(F) &Int - } - } - struct interface I2: I {} - struct S {} - access(all) attachment A for S: I2 {} - fun test() { - let s = attach A() to S() - let ref = &s as auth(E) &S - let i: auth(F) &Int = s[A]!.foo() - } - `) - - errs := RequireCheckerErrors(t, err, 1) - require.IsType(t, &sema.InvalidAttachmentEntitlementError{}, errs[0]) - }) } func TestCheckEntitlementTypeAnnotation(t *testing.T) { diff --git a/tests/checker/entrypoint_test.go b/sema/entrypoint_test.go similarity index 98% rename from tests/checker/entrypoint_test.go rename to sema/entrypoint_test.go index 4bbba80238..e3bc9ab1a1 100644 --- a/tests/checker/entrypoint_test.go +++ b/sema/entrypoint_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -24,6 +24,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckEntryPointParameters(t *testing.T) { diff --git a/tests/checker/enum_test.go b/sema/enum_test.go similarity index 98% rename from tests/checker/enum_test.go rename to sema/enum_test.go index 671177fd5f..96d092297c 100644 --- a/tests/checker/enum_test.go +++ b/sema/enum_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -27,6 +27,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidNonEnumCompositeEnumCases(t *testing.T) { diff --git a/tests/checker/errors_test.go b/sema/error_handling_test.go similarity index 96% rename from tests/checker/errors_test.go rename to sema/error_handling_test.go index 33da8bc032..a7cb4923c2 100644 --- a/tests/checker/errors_test.go +++ b/sema/error_handling_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -27,7 +27,8 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckErrorShortCircuiting(t *testing.T) { @@ -81,7 +82,7 @@ func TestCheckErrorShortCircuiting(t *testing.T) { access(all) let y = Y `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, Config: &sema.Config{ ErrorShortCircuitingEnabled: true, }, diff --git a/sema/errors.go b/sema/errors.go index 96edbf076e..1760e33eb9 100644 --- a/sema/errors.go +++ b/sema/errors.go @@ -1440,6 +1440,23 @@ func (e *InvalidEnumConformancesError) Error() string { return "enums cannot conform to interfaces" } +// InvalidAttachmentConformancesError + +type InvalidAttachmentConformancesError struct { + ast.Range +} + +var _ SemanticError = &InvalidAttachmentConformancesError{} +var _ errors.UserError = &InvalidAttachmentConformancesError{} + +func (*InvalidAttachmentConformancesError) isSemanticError() {} + +func (*InvalidAttachmentConformancesError) IsUserError() {} + +func (e *InvalidAttachmentConformancesError) Error() string { + return "attachments cannot conform to interfaces" +} + // ConformanceError // TODO: report each missing member and mismatch as note diff --git a/tests/checker/events_test.go b/sema/events_test.go similarity index 99% rename from tests/checker/events_test.go rename to sema/events_test.go index bf140bb749..e3d6cdbbea 100644 --- a/tests/checker/events_test.go +++ b/sema/events_test.go @@ -16,22 +16,21 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/onflow/cadence/ast" "github.com/onflow/cadence/common" "github.com/onflow/cadence/errors" - "github.com/onflow/cadence/tests/utils" - - "github.com/stretchr/testify/require" - "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckEventDeclaration(t *testing.T) { @@ -296,7 +295,7 @@ func TestCheckEmitEvent(t *testing.T) { access(all) event Transfer(to: Int, from: Int) `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) require.NoError(t, err) diff --git a/tests/checker/external_mutation_test.go b/sema/external_mutation_test.go similarity index 99% rename from tests/checker/external_mutation_test.go rename to sema/external_mutation_test.go index bd56e9b039..96936fa073 100644 --- a/tests/checker/external_mutation_test.go +++ b/sema/external_mutation_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -28,6 +28,7 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckArrayUpdateIndexAccess(t *testing.T) { diff --git a/tests/checker/fixedpoint_test.go b/sema/fixedpoint_test.go similarity index 99% rename from tests/checker/fixedpoint_test.go rename to sema/fixedpoint_test.go index 2e7d514785..bb537432b8 100644 --- a/tests/checker/fixedpoint_test.go +++ b/sema/fixedpoint_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -29,6 +29,7 @@ import ( "github.com/onflow/cadence/format" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckFixedPointLiteralTypeConversionInVariableDeclaration(t *testing.T) { diff --git a/tests/checker/for_test.go b/sema/for_test.go similarity index 99% rename from tests/checker/for_test.go rename to sema/for_test.go index d2b6a231d5..7a92fc90a8 100644 --- a/tests/checker/for_test.go +++ b/sema/for_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -28,6 +28,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckForVariableSized(t *testing.T) { diff --git a/tests/checker/force_test.go b/sema/force_test.go similarity index 97% rename from tests/checker/force_test.go rename to sema/force_test.go index 2317ebc1fc..63b93013d8 100644 --- a/tests/checker/force_test.go +++ b/sema/force_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckForce(t *testing.T) { diff --git a/tests/checker/function_expression_test.go b/sema/function_expression_test.go similarity index 95% rename from tests/checker/function_expression_test.go rename to sema/function_expression_test.go index 14f65c0e91..3ba5f2e6b4 100644 --- a/tests/checker/function_expression_test.go +++ b/sema/function_expression_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidFunctionExpressionReturnValue(t *testing.T) { diff --git a/tests/checker/function_test.go b/sema/function_test.go similarity index 99% rename from tests/checker/function_test.go rename to sema/function_test.go index 88edcf9306..1f823f9a23 100644 --- a/tests/checker/function_test.go +++ b/sema/function_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -28,6 +28,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/parser" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckReferenceInFunction(t *testing.T) { diff --git a/sema/gen/golden_test.go b/sema/gen/golden_test.go index bcb116fa0f..62555c9176 100644 --- a/sema/gen/golden_test.go +++ b/sema/gen/golden_test.go @@ -43,7 +43,7 @@ import ( _ "github.com/onflow/cadence/sema/gen/testdata/simple_struct" _ "github.com/onflow/cadence/sema/gen/testdata/storable" "github.com/onflow/cadence/stdlib" - "github.com/onflow/cadence/tests/checker" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestConstructor(t *testing.T) { @@ -57,11 +57,11 @@ func TestConstructor(t *testing.T) { Kind: common.DeclarationKindFunction, }) - _, err := checker.ParseAndCheckWithOptions(t, + _, err := ParseAndCheckWithOptions(t, ` let x = Foo(bar: 1) `, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Config: &sema.Config{ BaseValueActivationHandler: func(_ common.Location) *sema.VariableActivation { return baseValueActivation @@ -83,11 +83,11 @@ func TestContract(t *testing.T) { Kind: common.DeclarationKindContract, }) - _, err := checker.ParseAndCheckWithOptions(t, + _, err := ParseAndCheckWithOptions(t, ` let x = Test.Foo(bar: 1) `, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Config: &sema.Config{ BaseValueActivationHandler: func(_ common.Location) *sema.VariableActivation { return baseValueActivation diff --git a/sema/gen/main.go b/sema/gen/main.go index f524af2894..49fdaf24b6 100644 --- a/sema/gen/main.go +++ b/sema/gen/main.go @@ -164,6 +164,9 @@ type typeDecl struct { memberDeclarations []ast.Declaration nestedTypes []*typeDecl hasConstructor bool + + // used in simpleType generation + conformances []*sema.InterfaceType } type generator struct { @@ -429,9 +432,40 @@ func (g *generator) addConstructorDocStringDeclaration( ) } -func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ struct{}) { +func (g *generator) VisitCompositeOrInterfaceDeclaration(decl ast.ConformingDeclaration) (_ struct{}) { + var compositeKind common.CompositeKind + var typeName string + var typeDec *typeDecl + var members []ast.Declaration + var conformances []*ast.NominalType + var isInterfaceType bool + + switch actualDecl := decl.(type) { + case *ast.CompositeDeclaration: + compositeKind = actualDecl.Kind() + typeName = actualDecl.Identifier.Identifier + typeDec = &typeDecl{ + typeName: typeName, + fullTypeName: g.newFullTypeName(typeName), + compositeKind: compositeKind, + } + members = actualDecl.Members.Declarations() + conformances = actualDecl.Conformances + isInterfaceType = false + case *ast.InterfaceDeclaration: + compositeKind = actualDecl.Kind() + typeName = actualDecl.Identifier.Identifier + typeDec = &typeDecl{ + typeName: typeName, + fullTypeName: g.newFullTypeName(typeName), + compositeKind: compositeKind, + } + members = actualDecl.Members.Declarations() + isInterfaceType = true + default: + panic("Expected composite or interface declaration") + } - compositeKind := decl.CompositeKind switch compositeKind { case common.CompositeKindStructure, common.CompositeKindResource, @@ -441,25 +475,17 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ panic(fmt.Sprintf("%s declarations are not supported", compositeKind.Name())) } - typeName := decl.Identifier.Identifier - - typeDecl := &typeDecl{ - typeName: typeName, - fullTypeName: g.newFullTypeName(typeName), - compositeKind: compositeKind, - } - if len(g.typeStack) > 0 { parentType := g.typeStack[len(g.typeStack)-1] parentType.nestedTypes = append( parentType.nestedTypes, - typeDecl, + typeDec, ) } g.typeStack = append( g.typeStack, - typeDecl, + typeDec, ) defer func() { // Pop @@ -473,6 +499,8 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ // Check if the declaration is explicitly marked to be generated as a composite type. if _, ok := g.leadingPragma["compositeType"]; ok { generateSimpleType = false + } else if isInterfaceType { + generateSimpleType = false } else { // If not, decide what to generate depending on the type. @@ -492,13 +520,13 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ } } - for _, memberDeclaration := range decl.Members.Declarations() { + for _, memberDeclaration := range members { generateDeclaration(g, memberDeclaration) // Visiting unsupported declarations panics, // so only supported member declarations are added - typeDecl.memberDeclarations = append( - typeDecl.memberDeclarations, + typeDec.memberDeclarations = append( + typeDec.memberDeclarations, memberDeclaration, ) @@ -514,7 +542,7 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ } } - for _, conformance := range decl.Conformances { + for _, conformance := range conformances { switch conformance.Identifier.Identifier { case "Storable": if !generateSimpleType { @@ -523,7 +551,7 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ g.currentTypeID(), )) } - typeDecl.storable = true + typeDec.storable = true case "Primitive": if !generateSimpleType { @@ -532,7 +560,7 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ g.currentTypeID(), )) } - typeDecl.primitive = true + typeDec.primitive = true case "Equatable": if !generateSimpleType { @@ -541,7 +569,7 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ g.currentTypeID(), )) } - typeDecl.equatable = true + typeDec.equatable = true case "Comparable": if !generateSimpleType { @@ -550,7 +578,7 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ g.currentTypeID(), )) } - typeDecl.comparable = true + typeDec.comparable = true case "Exportable": if !generateSimpleType { @@ -559,10 +587,10 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ g.currentTypeID(), )) } - typeDecl.exportable = true + typeDec.exportable = true case "Importable": - typeDecl.importable = true + typeDec.importable = true case "ContainFields": if !generateSimpleType { @@ -571,18 +599,20 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ g.currentTypeID(), )) } - typeDecl.memberAccessible = true + typeDec.memberAccessible = true + case "StructStringer": + typeDec.conformances = append(typeDec.conformances, sema.StructStringerType) } } var typeVarDecl dst.Expr if generateSimpleType { - typeVarDecl = simpleTypeLiteral(typeDecl) + typeVarDecl = simpleTypeLiteral(typeDec) } else { - typeVarDecl = compositeTypeExpr(typeDecl) + typeVarDecl = compositeOrInterfaceTypeExpr(typeDec, isInterfaceType) } - fullTypeName := typeDecl.fullTypeName + fullTypeName := typeDec.fullTypeName tyVarName := typeVarName(fullTypeName) @@ -597,7 +627,7 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ ), ) - memberDeclarations := typeDecl.memberDeclarations + memberDeclarations := typeDec.memberDeclarations if len(memberDeclarations) > 0 { @@ -700,7 +730,7 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ }, } - if typeDecl.hasConstructor { + if typeDec.hasConstructor { stmts = append( stmts, &dst.AssignStmt{ @@ -736,8 +766,12 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ return } -func (*generator) VisitInterfaceDeclaration(_ *ast.InterfaceDeclaration) struct{} { - panic("interface declarations are not supported") +func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ struct{}) { + return g.VisitCompositeOrInterfaceDeclaration(decl) +} + +func (g *generator) VisitInterfaceDeclaration(decl *ast.InterfaceDeclaration) (_ struct{}) { + return g.VisitCompositeOrInterfaceDeclaration(decl) } func (*generator) VisitAttachmentDeclaration(_ *ast.AttachmentDeclaration) struct{} { @@ -1591,6 +1625,9 @@ func simpleTypeLiteral(ty *typeDecl) dst.Expr { // Comparable: false, // Exportable: false, // Importable: false, + // comformances: []*InterfaceType { + // StructStringerType, + // } //} isResource := ty.compositeKind == common.CompositeKindResource @@ -1609,6 +1646,33 @@ func simpleTypeLiteral(ty *typeDecl) dst.Expr { goKeyValue("ContainFields", goBoolLit(ty.memberAccessible)), } + if len(ty.conformances) > 0 { + var elts = []dst.Expr{} + for _, conformance := range ty.conformances { + var name = "" + switch conformance { + case sema.StructStringerType: + name = "StructStringerType" + default: + panic("Unsupported conformance typeID") + } + elts = append(elts, &dst.Ident{ + Name: name, + Path: semaPath, + }) + } + elements = append(elements, goKeyValue("conformances", &dst.CompositeLit{ + Type: &dst.ArrayType{ + Elt: &dst.StarExpr{ + X: &dst.Ident{ + Name: "InterfaceType", + }, + }, + }, + Elts: elts, + })) + } + return &dst.UnaryExpr{ Op: token.AND, X: &dst.CompositeLit{ @@ -1971,10 +2035,10 @@ func stringMemberResolverMapType() *dst.MapType { } } -func compositeTypeExpr(ty *typeDecl) dst.Expr { +func compositeOrInterfaceTypeExpr(ty *typeDecl, isInterfaceType bool) dst.Expr { // func() *CompositeType { - // var t = &CompositeType{ + // var t = &CompositeType { // Identifier: FooTypeName, // Kind: common.CompositeKindStructure, // ImportableBuiltin: false, @@ -1985,13 +2049,23 @@ func compositeTypeExpr(ty *typeDecl) dst.Expr { // return t // }() + // func() *InterfaceType { + // var t = &InterfaceType{ + // Identifier: FooTypeName, + // CompositeKind: common.CompositeKindStructure, + // } + // + // t.SetNestedType(FooBarTypeName, FooBarType) + // return t + // }() + const typeVarName = "t" statements := []dst.Stmt{ &dst.DeclStmt{ Decl: goVarDecl( typeVarName, - compositeTypeLiteral(ty), + compositeOrInterfaceTypeLiteral(ty, isInterfaceType), ), }, } @@ -2023,6 +2097,11 @@ func compositeTypeExpr(ty *typeDecl) dst.Expr { }, ) + name := "CompositeType" + if isInterfaceType { + name = "InterfaceType" + } + return &dst.CallExpr{ Fun: &dst.FuncLit{ Type: &dst.FuncType{ @@ -2032,7 +2111,7 @@ func compositeTypeExpr(ty *typeDecl) dst.Expr { { Type: &dst.StarExpr{ X: &dst.Ident{ - Name: "CompositeType", + Name: name, Path: semaPath, }, }, @@ -2047,21 +2126,30 @@ func compositeTypeExpr(ty *typeDecl) dst.Expr { } } -func compositeTypeLiteral(ty *typeDecl) dst.Expr { +func compositeOrInterfaceTypeLiteral(ty *typeDecl, isInterfaceType bool) dst.Expr { kind := compositeKindExpr(ty.compositeKind) elements := []dst.Expr{ goKeyValue("Identifier", typeNameVarIdent(ty.fullTypeName)), - goKeyValue("Kind", kind), - goKeyValue("ImportableBuiltin", goBoolLit(ty.importable)), - goKeyValue("HasComputedMembers", goBoolLit(true)), + } + + name := "InterfaceType" + if isInterfaceType { + elements = append(elements, + goKeyValue("CompositeKind", kind)) + } else { + name = "CompositeType" + elements = append(elements, + goKeyValue("Kind", kind), + goKeyValue("ImportableBuiltin", goBoolLit(ty.importable)), + goKeyValue("HasComputedMembers", goBoolLit(true))) } return &dst.UnaryExpr{ Op: token.AND, X: &dst.CompositeLit{ Type: &dst.Ident{ - Name: "CompositeType", + Name: name, Path: semaPath, }, Elts: elements, diff --git a/sema/gen/testdata/simple_interface/test.cdc b/sema/gen/testdata/simple_interface/test.cdc new file mode 100644 index 0000000000..388ef59051 --- /dev/null +++ b/sema/gen/testdata/simple_interface/test.cdc @@ -0,0 +1 @@ +access(all) struct interface Test {} diff --git a/sema/gen/testdata/simple_interface/test.golden.go b/sema/gen/testdata/simple_interface/test.golden.go new file mode 100644 index 0000000000..c976eafded --- /dev/null +++ b/sema/gen/testdata/simple_interface/test.golden.go @@ -0,0 +1,36 @@ +// Code generated from testdata/simple_interface/test.cdc. DO NOT EDIT. +/* + * Cadence - The resource-oriented smart contract programming language + * + * Copyright Flow Foundation + * + * 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 simple_interface + +import ( + "github.com/onflow/cadence/common" + "github.com/onflow/cadence/sema" +) + +const TestTypeName = "Test" + +var TestType = func() *sema.InterfaceType { + var t = &sema.InterfaceType{ + Identifier: TestTypeName, + CompositeKind: common.CompositeKindStructure, + } + + return t +}() diff --git a/tests/checker/genericfunction_test.go b/sema/genericfunction_test.go similarity index 99% rename from tests/checker/genericfunction_test.go rename to sema/genericfunction_test.go index 0d8dc3e805..f88e9ac00a 100644 --- a/tests/checker/genericfunction_test.go +++ b/sema/genericfunction_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -30,6 +30,7 @@ import ( "github.com/onflow/cadence/parser" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func parseAndCheckWithTestValue(t *testing.T, code string, ty sema.Type) (*sema.Checker, error) { diff --git a/tests/checker/hashable_struct_test.go b/sema/hashable_struct_test.go similarity index 95% rename from tests/checker/hashable_struct_test.go rename to sema/hashable_struct_test.go index 4ae190201e..82875b9f95 100644 --- a/tests/checker/hashable_struct_test.go +++ b/sema/hashable_struct_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -24,6 +24,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckHashableStruct(t *testing.T) { diff --git a/tests/checker/if_test.go b/sema/if_test.go similarity index 98% rename from tests/checker/if_test.go rename to sema/if_test.go index 5681f8f111..6fd1e517c7 100644 --- a/tests/checker/if_test.go +++ b/sema/if_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckIfStatementTest(t *testing.T) { diff --git a/tests/checker/import_test.go b/sema/import_test.go similarity index 97% rename from tests/checker/import_test.go rename to sema/import_test.go index bc586139c6..c5bf92d36e 100644 --- a/tests/checker/import_test.go +++ b/sema/import_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -30,7 +30,8 @@ import ( "github.com/onflow/cadence/errors" "github.com/onflow/cadence/parser" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidImport(t *testing.T) { @@ -56,7 +57,7 @@ func TestCheckRepeatedImport(t *testing.T) { access(all) let y = 2 `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) require.NoError(t, err) @@ -169,7 +170,7 @@ func TestCheckInvalidRepeatedImport(t *testing.T) { access(all) let x = 1 `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) @@ -287,7 +288,7 @@ func TestCheckImportAll(t *testing.T) { } `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) @@ -322,7 +323,7 @@ func TestCheckInvalidImportUnexported(t *testing.T) { access(all) let x = 1 `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) @@ -363,7 +364,7 @@ func TestCheckImportSome(t *testing.T) { access(all) let x = 1 `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) @@ -446,7 +447,7 @@ func TestCheckImportTypes(t *testing.T) { body, ), ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) @@ -552,7 +553,7 @@ func TestCheckInvalidImportCycleSelf(t *testing.T) { return err } - err = check(code, utils.TestLocation) + err = check(code, TestLocation) errs := RequireCheckerErrors(t, err, 1) @@ -739,7 +740,7 @@ func TestCheckImportContract(t *testing.T) { } }`, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) @@ -787,7 +788,7 @@ func TestCheckImportContract(t *testing.T) { } }`, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) diff --git a/tests/checker/indexing_test.go b/sema/indexing_test.go similarity index 98% rename from tests/checker/indexing_test.go rename to sema/indexing_test.go index 1e9bef01e1..1979e67610 100644 --- a/tests/checker/indexing_test.go +++ b/sema/indexing_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckArrayIndexingWithInteger(t *testing.T) { diff --git a/tests/checker/initialization_test.go b/sema/initialization_test.go similarity index 99% rename from tests/checker/initialization_test.go rename to sema/initialization_test.go index 48242a9b6c..a4656a2e3c 100644 --- a/tests/checker/initialization_test.go +++ b/sema/initialization_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) // TODO: test multiple initializers once overloading is supported diff --git a/tests/checker/integer_test.go b/sema/integer_test.go similarity index 99% rename from tests/checker/integer_test.go rename to sema/integer_test.go index 798b168393..5f53f7b0ed 100644 --- a/tests/checker/integer_test.go +++ b/sema/integer_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -28,6 +28,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) var allIntegerTypesAndAddressType = common.Concat( diff --git a/tests/checker/interface_test.go b/sema/interface_test.go similarity index 99% rename from tests/checker/interface_test.go rename to sema/interface_test.go index fd453b789a..48fc511f4a 100644 --- a/tests/checker/interface_test.go +++ b/sema/interface_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -28,6 +28,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/errors" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func constructorArguments(compositeKind common.CompositeKind) string { diff --git a/tests/checker/intersection_test.go b/sema/intersection_test.go similarity index 99% rename from tests/checker/intersection_test.go rename to sema/intersection_test.go index ee3b8bf94e..e0965d843a 100644 --- a/tests/checker/intersection_test.go +++ b/sema/intersection_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -26,6 +26,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckIntersectionType(t *testing.T) { diff --git a/tests/checker/invalid_test.go b/sema/invalid_test.go similarity index 98% rename from tests/checker/invalid_test.go rename to sema/invalid_test.go index b5f058e34c..51ea254984 100644 --- a/tests/checker/invalid_test.go +++ b/sema/invalid_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -24,6 +24,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckSpuriousIdentifierAssignmentInvalidValueTypeMismatch(t *testing.T) { diff --git a/tests/checker/invocation_test.go b/sema/invocation_test.go similarity index 97% rename from tests/checker/invocation_test.go rename to sema/invocation_test.go index ded43f11ae..1d0543b2cb 100644 --- a/tests/checker/invocation_test.go +++ b/sema/invocation_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -28,7 +28,8 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidFunctionCallWithTooFewArguments(t *testing.T) { @@ -374,7 +375,7 @@ func TestCheckArgumentLabels(t *testing.T) { fun test(foo bar: Int, baz: String) {} `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) @@ -435,7 +436,7 @@ func TestCheckArgumentLabels(t *testing.T) { } `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) @@ -496,7 +497,7 @@ func TestCheckArgumentLabels(t *testing.T) { } `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) @@ -561,7 +562,7 @@ func TestCheckArgumentLabels(t *testing.T) { } `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) diff --git a/tests/checker/member_test.go b/sema/member_test.go similarity index 99% rename from tests/checker/member_test.go rename to sema/member_test.go index c2778c7c18..9d8706dbbe 100644 --- a/tests/checker/member_test.go +++ b/sema/member_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -27,6 +27,7 @@ import ( "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckOptionalChainingNonOptionalFieldRead(t *testing.T) { diff --git a/tests/checker/metatype_test.go b/sema/metatype_test.go similarity index 99% rename from tests/checker/metatype_test.go rename to sema/metatype_test.go index cb9c5c1b7c..3f5455b0a0 100644 --- a/tests/checker/metatype_test.go +++ b/sema/metatype_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckMetaType(t *testing.T) { diff --git a/tests/checker/move_test.go b/sema/move_test.go similarity index 97% rename from tests/checker/move_test.go rename to sema/move_test.go index 848fc6c6e7..d772f2f293 100644 --- a/tests/checker/move_test.go +++ b/sema/move_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -24,6 +24,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidMoves(t *testing.T) { diff --git a/tests/checker/nesting_test.go b/sema/nesting_test.go similarity index 97% rename from tests/checker/nesting_test.go rename to sema/nesting_test.go index 40ec6ab6e9..0d43eed355 100644 --- a/tests/checker/nesting_test.go +++ b/sema/nesting_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -29,6 +29,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckCompositeDeclarationNesting(t *testing.T) { @@ -258,9 +259,10 @@ func TestCheckInvalidCompositeDeclarationNestedDuplicateNames(t *testing.T) { } `) - errs := RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 2) assert.IsType(t, &sema.RedeclarationError{}, errs[0]) + assert.IsType(t, &sema.RedeclarationError{}, errs[1]) } func TestCheckCompositeDeclarationNestedConstructorAndType(t *testing.T) { diff --git a/tests/checker/never_test.go b/sema/never_test.go similarity index 98% rename from tests/checker/never_test.go rename to sema/never_test.go index 59c62020cc..ee3ba85b1c 100644 --- a/tests/checker/never_test.go +++ b/sema/never_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckNever(t *testing.T) { diff --git a/tests/checker/nil_coalescing_test.go b/sema/nil_coalescing_test.go similarity index 98% rename from tests/checker/nil_coalescing_test.go rename to sema/nil_coalescing_test.go index 78a79677c0..2e6d505cfb 100644 --- a/tests/checker/nil_coalescing_test.go +++ b/sema/nil_coalescing_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckNilCoalescingNilIntToOptional(t *testing.T) { diff --git a/tests/utils/occurrence_matcher.go b/sema/occurrence_matcher_test.go similarity index 98% rename from tests/utils/occurrence_matcher.go rename to sema/occurrence_matcher_test.go index 830af59c65..1f672755ac 100644 --- a/tests/utils/occurrence_matcher.go +++ b/sema/occurrence_matcher_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package utils +package sema_test import ( "github.com/onflow/cadence/common" diff --git a/tests/checker/occurrences_test.go b/sema/occurrences_test.go similarity index 99% rename from tests/checker/occurrences_test.go rename to sema/occurrences_test.go index 462bb1e770..cb4454e170 100644 --- a/tests/checker/occurrences_test.go +++ b/sema/occurrences_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -26,7 +26,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) // TODO: implement occurrences for type references diff --git a/tests/checker/operations_test.go b/sema/operations_test.go similarity index 99% rename from tests/checker/operations_test.go rename to sema/operations_test.go index 3a198b4004..319e3ee5f3 100644 --- a/tests/checker/operations_test.go +++ b/sema/operations_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -30,6 +30,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidUnaryBooleanNegationOfInteger(t *testing.T) { diff --git a/tests/checker/optional_test.go b/sema/optional_test.go similarity index 99% rename from tests/checker/optional_test.go rename to sema/optional_test.go index e502aa9f26..98e797855e 100644 --- a/tests/checker/optional_test.go +++ b/sema/optional_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -27,6 +27,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckOptional(t *testing.T) { diff --git a/tests/checker/overloading_test.go b/sema/overloading_test.go similarity index 96% rename from tests/checker/overloading_test.go rename to sema/overloading_test.go index d78bc4ba9b..dfe464e1b9 100644 --- a/tests/checker/overloading_test.go +++ b/sema/overloading_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -26,6 +26,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidCompositeInitializerOverloading(t *testing.T) { diff --git a/tests/checker/path_test.go b/sema/path_test.go similarity index 98% rename from tests/checker/path_test.go rename to sema/path_test.go index c21e313830..5aceafd85e 100644 --- a/tests/checker/path_test.go +++ b/sema/path_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -27,6 +27,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckPath(t *testing.T) { diff --git a/sema/path_type.go b/sema/path_type.go index 4334054f60..042be61502 100644 --- a/sema/path_type.go +++ b/sema/path_type.go @@ -31,6 +31,9 @@ var PathType = &SimpleType{ Comparable: false, Exportable: true, Importable: true, + conformances: []*InterfaceType{ + StructStringerType, + }, } var PathTypeAnnotation = NewTypeAnnotation(PathType) @@ -48,6 +51,9 @@ var StoragePathType = &SimpleType{ Comparable: false, Exportable: true, Importable: true, + conformances: []*InterfaceType{ + StructStringerType, + }, } var StoragePathTypeAnnotation = NewTypeAnnotation(StoragePathType) @@ -65,6 +71,9 @@ var CapabilityPathType = &SimpleType{ Comparable: false, Exportable: true, Importable: true, + conformances: []*InterfaceType{ + StructStringerType, + }, } var CapabilityPathTypeAnnotation = NewTypeAnnotation(CapabilityPathType) @@ -82,6 +91,9 @@ var PublicPathType = &SimpleType{ Comparable: false, Exportable: true, Importable: true, + conformances: []*InterfaceType{ + StructStringerType, + }, } var PublicPathTypeAnnotation = NewTypeAnnotation(PublicPathType) @@ -99,6 +111,9 @@ var PrivatePathType = &SimpleType{ Comparable: false, Exportable: true, Importable: true, + conformances: []*InterfaceType{ + StructStringerType, + }, } var PrivatePathTypeAnnotation = NewTypeAnnotation(PrivatePathType) diff --git a/tests/checker/pragma_test.go b/sema/pragma_test.go similarity index 98% rename from tests/checker/pragma_test.go rename to sema/pragma_test.go index 087ea1926a..1ee6e070bb 100644 --- a/tests/checker/pragma_test.go +++ b/sema/pragma_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -26,6 +26,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckPragmaExpression(t *testing.T) { diff --git a/tests/checker/predeclaredvalues_test.go b/sema/predeclaredvalues_test.go similarity index 95% rename from tests/checker/predeclaredvalues_test.go rename to sema/predeclaredvalues_test.go index 1ebcfb7d14..046ea7435a 100644 --- a/tests/checker/predeclaredvalues_test.go +++ b/sema/predeclaredvalues_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -26,6 +26,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckPredeclaredValues(t *testing.T) { diff --git a/tests/checker/purity_test.go b/sema/purity_test.go similarity index 99% rename from tests/checker/purity_test.go rename to sema/purity_test.go index 16914158f5..76a79255d9 100644 --- a/tests/checker/purity_test.go +++ b/sema/purity_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -26,6 +26,7 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckPuritySubtyping(t *testing.T) { diff --git a/tests/checker/range_test.go b/sema/range_test.go similarity index 97% rename from tests/checker/range_test.go rename to sema/range_test.go index d72c798855..94919757fd 100644 --- a/tests/checker/range_test.go +++ b/sema/range_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "strings" @@ -27,7 +27,8 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckRange(t *testing.T) { @@ -95,7 +96,7 @@ func TestCheckRange(t *testing.T) { // assert that the unordered repr of expected matches that of ranges assertSetsEqual := func(t *testing.T, expected []sema.Range, ranges map[sema.Range]int) { bag := getCounts(expected) - utils.AssertEqualWithDiff(t, bag, ranges) + AssertEqualWithDiff(t, bag, ranges) } barTypeVariable, ok := checker.Elaboration.GetGlobalType("_TEST_Bar") diff --git a/tests/checker/range_value_test.go b/sema/range_value_test.go similarity index 99% rename from tests/checker/range_value_test.go rename to sema/range_value_test.go index f93fd5a9c9..12929896b5 100644 --- a/tests/checker/range_value_test.go +++ b/sema/range_value_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -28,6 +28,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" + . "github.com/onflow/cadence/test_utils/sema_utils" ) type inclusiveRangeConstructionTest struct { diff --git a/tests/checker/reference_test.go b/sema/reference_test.go similarity index 99% rename from tests/checker/reference_test.go rename to sema/reference_test.go index ef4b92f33b..0914180f30 100644 --- a/tests/checker/reference_test.go +++ b/sema/reference_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -28,7 +28,8 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckReference(t *testing.T) { @@ -1066,7 +1067,7 @@ func TestCheckReferenceExpressionReferenceType(t *testing.T) { refValueType := RequireGlobalValue(t, checker.Elaboration, "ref") xType := RequireGlobalType(t, checker.Elaboration, "X").(*sema.EntitlementType) - var access sema.Access = sema.UnauthorizedAccess + var access = sema.UnauthorizedAccess if !auth.Equal(sema.UnauthorizedAccess) { access = sema.NewEntitlementSetAccess([]*sema.EntitlementType{xType}, sema.Conjunction) } @@ -1088,7 +1089,7 @@ func TestCheckReferenceExpressionReferenceType(t *testing.T) { for _, auth := range []sema.Access{ sema.UnauthorizedAccess, sema.NewEntitlementSetAccess([]*sema.EntitlementType{{ - Location: utils.TestLocation, + Location: TestLocation, Identifier: "X", }}, sema.Conjunction), } { @@ -1929,7 +1930,7 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { } `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) diff --git a/tests/checker/resources_test.go b/sema/resource_test.go similarity index 99% rename from tests/checker/resources_test.go rename to sema/resource_test.go index 050a117a56..f46d1d08a7 100644 --- a/tests/checker/resources_test.go +++ b/sema/resource_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -25,11 +25,13 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + . "github.com/onflow/cadence/test_utils/sema_utils" + "github.com/onflow/cadence/ast" "github.com/onflow/cadence/common" "github.com/onflow/cadence/errors" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestCheckFailableCastingWithResourceAnnotation(t *testing.T) { diff --git a/tests/checker/return_test.go b/sema/return_test.go similarity index 99% rename from tests/checker/return_test.go rename to sema/return_test.go index 32b5cf4593..61f7f54835 100644 --- a/tests/checker/return_test.go +++ b/sema/return_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -28,6 +28,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidReturnValue(t *testing.T) { diff --git a/tests/checker/rlp_test.go b/sema/rlp_test.go similarity index 97% rename from tests/checker/rlp_test.go rename to sema/rlp_test.go index 2f77cb0708..216c1829fb 100644 --- a/tests/checker/rlp_test.go +++ b/sema/rlp_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -26,6 +26,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckRLPDecodeString(t *testing.T) { diff --git a/tests/checker/runtimetype_test.go b/sema/runtimetype_test.go similarity index 99% rename from tests/checker/runtimetype_test.go rename to sema/runtimetype_test.go index 7ee3c911e3..22a46b6248 100644 --- a/tests/checker/runtimetype_test.go +++ b/sema/runtimetype_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckOptionalTypeConstructor(t *testing.T) { diff --git a/sema/simple_type.go b/sema/simple_type.go index f05db593c5..db8f8da6bb 100644 --- a/sema/simple_type.go +++ b/sema/simple_type.go @@ -51,6 +51,12 @@ type SimpleType struct { Primitive bool IsResource bool ContainFields bool + + // allow simple types to define a set of interfaces it conforms to + // e.g. StructStringer + conformances []*InterfaceType + effectiveInterfaceConformanceSet *InterfaceSet + effectiveInterfaceConformanceSetOnce sync.Once } var _ Type = &SimpleType{} @@ -195,3 +201,18 @@ func (t *SimpleType) CompositeKind() common.CompositeKind { func (t *SimpleType) CheckInstantiated(_ ast.HasPosition, _ common.MemoryGauge, _ func(err error)) { // NO-OP } + +func (t *SimpleType) EffectiveInterfaceConformanceSet() *InterfaceSet { + t.initializeEffectiveInterfaceConformanceSet() + return t.effectiveInterfaceConformanceSet +} + +func (t *SimpleType) initializeEffectiveInterfaceConformanceSet() { + t.effectiveInterfaceConformanceSetOnce.Do(func() { + t.effectiveInterfaceConformanceSet = NewInterfaceSet() + + for _, conformance := range t.conformances { + t.effectiveInterfaceConformanceSet.Add(conformance) + } + }) +} diff --git a/tests/checker/storable_test.go b/sema/storable_test.go similarity index 99% rename from tests/checker/storable_test.go rename to sema/storable_test.go index 5d1b97c2c5..23c0b96722 100644 --- a/tests/checker/storable_test.go +++ b/sema/storable_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -29,6 +29,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckStorable(t *testing.T) { diff --git a/tests/checker/string_test.go b/sema/string_test.go similarity index 88% rename from tests/checker/string_test.go rename to sema/string_test.go index cc82a8ec00..cc46bc786d 100644 --- a/tests/checker/string_test.go +++ b/sema/string_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckCharacter(t *testing.T) { @@ -697,3 +698,94 @@ func TestCheckStringCount(t *testing.T) { require.NoError(t, err) }) } + +func TestCheckStringTemplate(t *testing.T) { + + t.Parallel() + + t.Run("valid, int", func(t *testing.T) { + + t.Parallel() + + _, err := ParseAndCheck(t, ` + let a = 1 + let x: String = "The value of a is: \(a)" + `) + + require.NoError(t, err) + }) + + t.Run("valid, string", func(t *testing.T) { + + t.Parallel() + + _, err := ParseAndCheck(t, ` + let a = "abc def" + let x: String = "\(a) ghi" + `) + + require.NoError(t, err) + }) + + t.Run("invalid, struct", func(t *testing.T) { + + t.Parallel() + + _, err := ParseAndCheck(t, ` + access(all) + struct SomeStruct {} + let a = SomeStruct() + let x: String = "\(a)" + `) + + errs := RequireCheckerErrors(t, err, 1) + + assert.IsType(t, &sema.TypeMismatchWithDescriptionError{}, errs[0]) + }) + + t.Run("invalid, array", func(t *testing.T) { + t.Parallel() + + _, err := ParseAndCheck(t, ` + let x: [AnyStruct] = ["tmp", 1] + let y = "\(x)" + `) + + errs := RequireCheckerErrors(t, err, 1) + + assert.IsType(t, &sema.TypeMismatchWithDescriptionError{}, errs[0]) + }) + + t.Run("invalid, missing variable", func(t *testing.T) { + + t.Parallel() + + _, err := ParseAndCheck(t, ` + let x: String = "\(a)" + `) + + errs := RequireCheckerErrors(t, err, 2) + + assert.IsType(t, &sema.NotDeclaredError{}, errs[0]) + assert.IsType(t, &sema.TypeMismatchWithDescriptionError{}, errs[1]) + }) + + t.Run("invalid, resource", func(t *testing.T) { + + t.Parallel() + + _, err := ParseAndCheck(t, ` + access(all) resource TestResource {} + fun test(): String { + var x <- create TestResource() + var y = "\(x)" + destroy x + return y + } + `) + + errs := RequireCheckerErrors(t, err, 1) + + assert.IsType(t, &sema.TypeMismatchWithDescriptionError{}, errs[0]) + }) +} diff --git a/sema/string_type.go b/sema/string_type.go index 37a3707561..a3091cb248 100644 --- a/sema/string_type.go +++ b/sema/string_type.go @@ -143,6 +143,9 @@ var StringType = &SimpleType{ }, IndexingType: IntegerType, }, + conformances: []*InterfaceType{ + StructStringerType, + }, } var StringTypeAnnotation = NewTypeAnnotation(StringType) diff --git a/sema/struct_stringer.cdc b/sema/struct_stringer.cdc new file mode 100644 index 0000000000..224765fd90 --- /dev/null +++ b/sema/struct_stringer.cdc @@ -0,0 +1,7 @@ +/// StructStringer is an interface implemented by all the string convertible structs. +access(all) +struct interface StructStringer { + /// Returns the string representation of this object. + access(all) + view fun toString(): String +} diff --git a/sema/struct_stringer.gen.go b/sema/struct_stringer.gen.go new file mode 100644 index 0000000000..7f23bd22df --- /dev/null +++ b/sema/struct_stringer.gen.go @@ -0,0 +1,64 @@ +// Code generated from struct_stringer.cdc. DO NOT EDIT. +/* + * Cadence - The resource-oriented smart contract programming language + * + * Copyright Flow Foundation + * + * 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 sema + +import ( + "github.com/onflow/cadence/ast" + "github.com/onflow/cadence/common" +) + +const StructStringerTypeToStringFunctionName = "toString" + +var StructStringerTypeToStringFunctionType = &FunctionType{ + Purity: FunctionPurityView, + ReturnTypeAnnotation: NewTypeAnnotation( + StringType, + ), +} + +const StructStringerTypeToStringFunctionDocString = ` +Returns the string representation of this object. +` + +const StructStringerTypeName = "StructStringer" + +var StructStringerType = func() *InterfaceType { + var t = &InterfaceType{ + Identifier: StructStringerTypeName, + CompositeKind: common.CompositeKindStructure, + } + + return t +}() + +func init() { + var members = []*Member{ + NewUnmeteredFunctionMember( + StructStringerType, + PrimitiveAccess(ast.AccessAll), + StructStringerTypeToStringFunctionName, + StructStringerTypeToStringFunctionType, + StructStringerTypeToStringFunctionDocString, + ), + } + + StructStringerType.Members = MembersAsMap(members) + StructStringerType.Fields = MembersFieldNames(members) +} diff --git a/sema/struct_stringer.go b/sema/struct_stringer.go new file mode 100644 index 0000000000..a91c8796c7 --- /dev/null +++ b/sema/struct_stringer.go @@ -0,0 +1,21 @@ +/* + * Cadence - The resource-oriented smart contract programming language + * + * Copyright Flow Foundation + * + * 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 sema + +//go:generate go run ./gen struct_stringer.cdc struct_stringer.gen.go diff --git a/sema/struct_stringer_test.go b/sema/struct_stringer_test.go new file mode 100644 index 0000000000..119f25471d --- /dev/null +++ b/sema/struct_stringer_test.go @@ -0,0 +1,76 @@ +/* + * Cadence - The resource-oriented smart contract programming language + * + * Copyright Flow Foundation + * + * 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 sema_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" +) + +func TestCheckStringer(t *testing.T) { + + t.Parallel() + + _, err := ParseAndCheck(t, ` + let a: {StructStringer} = 1 + let b: {StructStringer} = false + let c: {StructStringer} = "hey" + access(all) + struct Foo: StructStringer { + view fun toString(): String { + return "foo" + } + } + let d: {StructStringer} = Foo() + let e: {StructStringer} = /public/foo + `) + + assert.NoError(t, err) +} + +func TestCheckInvalidStringer(t *testing.T) { + + t.Parallel() + + _, err := ParseAndCheck(t, ` + resource R {} + + let a: {StructStringer} = <-create R() + let b: {StructStringer} = [<-create R()] + let c: {StructStringer} = {1: true} + struct Foo: StructStringer {} + struct Bar: StructStringer { + fun toString(): String { + return "bar" + } + } + `) + + errs := RequireCheckerErrors(t, err, 5) + + assert.IsType(t, &sema.TypeMismatchError{}, errs[0]) + assert.IsType(t, &sema.TypeMismatchError{}, errs[1]) + assert.IsType(t, &sema.TypeMismatchError{}, errs[2]) + assert.IsType(t, &sema.ConformanceError{}, errs[3]) + assert.IsType(t, &sema.ConformanceError{}, errs[4]) +} diff --git a/tests/checker/swap_test.go b/sema/swap_test.go similarity index 99% rename from tests/checker/swap_test.go rename to sema/swap_test.go index 28e708aceb..9f39ffdff5 100644 --- a/tests/checker/swap_test.go +++ b/sema/swap_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -26,6 +26,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidUnknownDeclarationSwap(t *testing.T) { diff --git a/tests/checker/switch_test.go b/sema/switch_test.go similarity index 99% rename from tests/checker/switch_test.go rename to sema/switch_test.go index 0f34d0a506..197e1dd5d5 100644 --- a/tests/checker/switch_test.go +++ b/sema/switch_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckSwitchStatementTest(t *testing.T) { diff --git a/tests/checker/transactions_test.go b/sema/transactions_test.go similarity index 99% rename from tests/checker/transactions_test.go rename to sema/transactions_test.go index 2dfde9d8c8..dd80079ecd 100644 --- a/tests/checker/transactions_test.go +++ b/sema/transactions_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckTransactions(t *testing.T) { diff --git a/sema/type.go b/sema/type.go index c8d65c6d9b..9a13a2e762 100644 --- a/sema/type.go +++ b/sema/type.go @@ -312,6 +312,12 @@ func TypeActivationNestedType(typeActivation *VariableActivation, qualifiedIdent return ty } +// ConformingType is a type that can conform to interfaces +type ConformingType interface { + Type + EffectiveInterfaceConformanceSet() *InterfaceSet +} + // CompositeKindedType is a type which has a composite kind type CompositeKindedType interface { Type @@ -1197,7 +1203,9 @@ var _ IntegerRangedType = &NumericType{} var _ SaturatingArithmeticType = &NumericType{} func NewNumericType(typeName string) *NumericType { - return &NumericType{name: typeName} + return &NumericType{ + name: typeName, + } } func (t *NumericType) Tag() TypeTag { @@ -1375,6 +1383,17 @@ func (*NumericType) CheckInstantiated(_ ast.HasPosition, _ common.MemoryGauge, _ // NO-OP } +var numericTypeEffectiveInterfaceConformanceSet *InterfaceSet + +func init() { + numericTypeEffectiveInterfaceConformanceSet = NewInterfaceSet() + numericTypeEffectiveInterfaceConformanceSet.Add(StructStringerType) +} + +func (t *NumericType) EffectiveInterfaceConformanceSet() *InterfaceSet { + return numericTypeEffectiveInterfaceConformanceSet +} + // FixedPointNumericType represents all the types in the fixed-point range. type FixedPointNumericType struct { maxFractional *big.Int @@ -4210,6 +4229,7 @@ func init() { DeploymentResultType, HashableStructType, &InclusiveRangeType{}, + StructStringerType, }, ) @@ -7405,6 +7425,16 @@ func (t *AddressType) initializeMemberResolvers() { }) } +var addressTypeEffectiveInterfaceConformanceSet *InterfaceSet + +func init() { + addressTypeEffectiveInterfaceConformanceSet = NewInterfaceSet() + addressTypeEffectiveInterfaceConformanceSet.Add(StructStringerType) +} +func (t *AddressType) AddressInterfaceConformanceSet() *InterfaceSet { + return numericTypeEffectiveInterfaceConformanceSet +} + func IsPrimitiveOrContainerOfPrimitive(referencedType Type) bool { switch ty := referencedType.(type) { case *VariableSizedType: @@ -7821,7 +7851,7 @@ func checkSubTypeWithoutEquality(subType Type, superType Type) bool { IsSubsetOf(intersectionSubtype.EffectiveInterfaceConformanceSet()) } - case *CompositeType: + case ConformingType: // A type `T` // is a subtype of an intersection type `AnyResource{Us}` / `AnyStruct{Us}` / `Any{Us}`: // if `T` is a subtype of the intersection supertype, @@ -9511,10 +9541,49 @@ func (t *EntitlementMapType) CheckInstantiated(_ ast.HasPosition, _ common.Memor // NO-OP } +func extractNativeTypes( + types []Type, +) { + for len(types) > 0 { + lastIndex := len(types) - 1 + curType := types[lastIndex] + types[lastIndex] = nil + types = types[:lastIndex] + + switch actualType := curType.(type) { + case *CompositeType: + NativeCompositeTypes[actualType.QualifiedIdentifier()] = actualType + + nestedTypes := actualType.NestedTypes + if nestedTypes == nil { + continue + } + + nestedTypes.Foreach(func(_ string, nestedType Type) { + types = append(types, nestedType) + }) + case *InterfaceType: + NativeInterfaceTypes[actualType.QualifiedIdentifier()] = actualType + + nestedTypes := actualType.NestedTypes + if nestedTypes == nil { + continue + } + + nestedTypes.Foreach(func(_ string, nestedType Type) { + types = append(types, nestedType) + }) + default: + panic("Expected only composite or interface type") + } + + } +} + var NativeCompositeTypes = map[string]*CompositeType{} func init() { - compositeTypes := []*CompositeType{ + compositeTypes := []Type{ AccountKeyType, PublicKeyType, HashAlgorithmType, @@ -9523,26 +9592,15 @@ func init() { DeploymentResultType, } - for len(compositeTypes) > 0 { - lastIndex := len(compositeTypes) - 1 - compositeType := compositeTypes[lastIndex] - compositeTypes[lastIndex] = nil - compositeTypes = compositeTypes[:lastIndex] - - NativeCompositeTypes[compositeType.QualifiedIdentifier()] = compositeType + extractNativeTypes(compositeTypes) +} - nestedTypes := compositeType.NestedTypes - if nestedTypes == nil { - continue - } +var NativeInterfaceTypes = map[string]*InterfaceType{} - nestedTypes.Foreach(func(_ string, nestedType Type) { - nestedCompositeType, ok := nestedType.(*CompositeType) - if !ok { - return - } - - compositeTypes = append(compositeTypes, nestedCompositeType) - }) +func init() { + interfaceTypes := []Type{ + StructStringerType, } + + extractNativeTypes(interfaceTypes) } diff --git a/tests/checker/type_inference_test.go b/sema/type_inference_test.go similarity index 99% rename from tests/checker/type_inference_test.go rename to sema/type_inference_test.go index 6aa900a98e..db3dcb247d 100644 --- a/tests/checker/type_inference_test.go +++ b/sema/type_inference_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -26,6 +26,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckArrayElementTypeInference(t *testing.T) { diff --git a/sema/type_test.go b/sema/type_test.go index 1ede9831c9..9d2cf503ac 100644 --- a/sema/type_test.go +++ b/sema/type_test.go @@ -2378,6 +2378,10 @@ func TestTypeInclusions(t *testing.T) { return } + if _, ok := typ.(*InterfaceType); ok { + return + } + if typ.IsResourceType() { return } diff --git a/tests/checker/typeargument_test.go b/sema/typeargument_test.go similarity index 99% rename from tests/checker/typeargument_test.go rename to sema/typeargument_test.go index 5c03e2794a..cbb85a5ff5 100644 --- a/tests/checker/typeargument_test.go +++ b/sema/typeargument_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -27,6 +27,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckTypeArguments(t *testing.T) { diff --git a/tests/checker/utils_test.go b/sema/utils_test.go similarity index 96% rename from tests/checker/utils_test.go rename to sema/utils_test.go index 5aa262f30d..f19512f82b 100644 --- a/tests/checker/utils_test.go +++ b/sema/utils_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -24,6 +24,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func ParseAndCheckWithPanic(t *testing.T, code string) (*sema.Checker, error) { diff --git a/tests/checker/while_test.go b/sema/while_test.go similarity index 97% rename from tests/checker/while_test.go rename to sema/while_test.go index a6eaa55230..3922b94315 100644 --- a/tests/checker/while_test.go +++ b/sema/while_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "testing" @@ -24,6 +24,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidWhileTest(t *testing.T) { diff --git a/stdlib/account.go b/stdlib/account.go index c62b5a69d4..e9f323cc78 100644 --- a/stdlib/account.go +++ b/stdlib/account.go @@ -1678,7 +1678,6 @@ func changeAccountContracts( memoryGauge := invocation.Interpreter.SharedState.Config.MemoryGauge legacyUpgradeEnabled := invocation.Interpreter.SharedState.Config.LegacyContractUpgradeEnabled - contractUpdateTypeRemovalEnabled := invocation.Interpreter.SharedState.Config.ContractUpdateTypeRemovalEnabled var oldProgram *ast.Program @@ -1731,8 +1730,6 @@ func changeAccountContracts( ) } - validator = validator.WithTypeRemovalEnabled(contractUpdateTypeRemovalEnabled) - err = validator.Validate() handleContractUpdateError(err, newCode) } diff --git a/stdlib/account_test.go b/stdlib/account_test.go index 0fbd4f1164..2429663cc2 100644 --- a/stdlib/account_test.go +++ b/stdlib/account_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestSemaCheckPathLiteralForInternalStorageDomains(t *testing.T) { @@ -75,7 +75,7 @@ func TestCanBorrow(t *testing.T) { `) typeID := func(qualifiedIdentifier string) sema.TypeID { - return utils.TestLocation.TypeID(nil, qualifiedIdentifier) + return TestLocation.TypeID(nil, qualifiedIdentifier) } entitlementE := inter.Program.Elaboration.EntitlementType(typeID("E")) diff --git a/stdlib/builtin_test.go b/stdlib/builtin_test.go index 676603eaa5..9ac63b1ff5 100644 --- a/stdlib/builtin_test.go +++ b/stdlib/builtin_test.go @@ -21,17 +21,16 @@ package stdlib import ( "testing" - "github.com/onflow/cadence/activations" - "github.com/onflow/cadence/common" - "github.com/onflow/cadence/tests/checker" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/onflow/cadence/activations" + "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/parser" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func newUnmeteredInMemoryStorage() interpreter.InMemoryStorage { @@ -53,7 +52,7 @@ func newInterpreter(t *testing.T, code string, valueDeclarations ...StandardLibr checker, err := sema.NewChecker( program, - utils.TestLocation, + TestLocation, nil, &sema.Config{ BaseValueActivationHandler: func(_ common.Location) *sema.VariableActivation { @@ -100,9 +99,9 @@ func TestCheckAssert(t *testing.T) { baseValueActivation.DeclareValue(AssertFunction) parseAndCheck := func(t *testing.T, code string) (*sema.Checker, error) { - return checker.ParseAndCheckWithOptions(t, + return ParseAndCheckWithOptions(t, code, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Config: &sema.Config{ BaseValueActivationHandler: func(_ common.Location) *sema.VariableActivation { return baseValueActivation @@ -116,7 +115,7 @@ func TestCheckAssert(t *testing.T) { _, err := parseAndCheck(t, `let _ = assert()`) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, errs[0], &sema.InsufficientArgumentsError{}) }) @@ -124,7 +123,7 @@ func TestCheckAssert(t *testing.T) { _, err := parseAndCheck(t, `let _ = assert(1)`) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, errs[0], &sema.TypeMismatchError{}) }) @@ -146,7 +145,7 @@ func TestCheckAssert(t *testing.T) { _, err := parseAndCheck(t, `let _ = assert(true, message: 1)`) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, errs[0], &sema.TypeMismatchError{}) }) @@ -154,7 +153,7 @@ func TestCheckAssert(t *testing.T) { _, err := parseAndCheck(t, `let _ = assert(true, "")`) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, errs[0], &sema.MissingArgumentLabelError{}) }) @@ -162,7 +161,7 @@ func TestCheckAssert(t *testing.T) { _, err := parseAndCheck(t, `let _ = assert(true, message: "foo", true)`) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, errs[0], &sema.ExcessiveArgumentsError{}) }) } @@ -184,7 +183,7 @@ func TestInterpretAssert(t *testing.T) { Err: AssertionError{ Message: "oops", }, - Location: utils.TestLocation, + Location: TestLocation, }, err, ) @@ -195,7 +194,7 @@ func TestInterpretAssert(t *testing.T) { Err: AssertionError{ Message: "", }, - Location: utils.TestLocation, + Location: TestLocation, }, err) @@ -218,9 +217,9 @@ func TestCheckPanic(t *testing.T) { baseValueActivation.DeclareValue(PanicFunction) parseAndCheck := func(t *testing.T, code string) (*sema.Checker, error) { - return checker.ParseAndCheckWithOptions(t, + return ParseAndCheckWithOptions(t, code, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Config: &sema.Config{ BaseValueActivationHandler: func(_ common.Location) *sema.VariableActivation { return baseValueActivation @@ -234,7 +233,7 @@ func TestCheckPanic(t *testing.T) { _, err := parseAndCheck(t, `let _ = panic()`) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, errs[0], &sema.InsufficientArgumentsError{}) }) @@ -250,7 +249,7 @@ func TestCheckPanic(t *testing.T) { _, err := parseAndCheck(t, `let _ = panic(true)`) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, errs[0], &sema.TypeMismatchError{}) }) @@ -258,7 +257,7 @@ func TestCheckPanic(t *testing.T) { _, err := parseAndCheck(t, `let _ = panic("test", 1)`) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) require.IsType(t, errs[0], &sema.ExcessiveArgumentsError{}) }) } @@ -278,7 +277,7 @@ func TestInterpretPanic(t *testing.T) { Err: PanicError{ Message: "oops", }, - Location: utils.TestLocation, + Location: TestLocation, }, err, ) diff --git a/stdlib/cadence_v0.42_to_v1_contract_upgrade_validation_test.go b/stdlib/cadence_v0.42_to_v1_contract_upgrade_validation_test.go index 365f0eeaf8..3aa074687b 100644 --- a/stdlib/cadence_v0.42_to_v1_contract_upgrade_validation_test.go +++ b/stdlib/cadence_v0.42_to_v1_contract_upgrade_validation_test.go @@ -33,8 +33,8 @@ import ( "github.com/onflow/cadence/runtime" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - "github.com/onflow/cadence/tests/runtime_utils" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/runtime_utils" ) func testContractUpdate(t *testing.T, oldCode string, newCode string) error { @@ -46,7 +46,7 @@ func testContractUpdate(t *testing.T, oldCode string, newCode string) error { checker, err := sema.NewChecker( newProgram, - utils.TestLocation, + TestLocation, nil, &sema.Config{ AccessCheckMode: sema.AccessCheckModeStrict, @@ -59,13 +59,13 @@ func testContractUpdate(t *testing.T, oldCode string, newCode string) error { program := interpreter.ProgramFromChecker(checker) upgradeValidator := stdlib.NewCadenceV042ToV1ContractUpdateValidator( - utils.TestLocation, + TestLocation, "Test", - &runtime_utils.TestRuntimeInterface{}, + &TestRuntimeInterface{}, oldProgram, program, map[common.Location]*sema.Elaboration{ - utils.TestLocation: checker.Elaboration, + TestLocation: checker.Elaboration, }) return upgradeValidator.Validate() } @@ -87,7 +87,7 @@ func testContractUpdateWithImports( upgradeValidator := stdlib.NewCadenceV042ToV1ContractUpdateValidator( location, contractName, - &runtime_utils.TestRuntimeInterface{ + &TestRuntimeInterface{ OnGetAccountContractNames: func(address runtime.Address) ([]string, error) { return []string{"TestImport"}, nil }, @@ -744,7 +744,7 @@ func TestContractUpgradeFieldType(t *testing.T) { upgradeValidator := stdlib.NewCadenceV042ToV1ContractUpdateValidator( location, contractName, - &runtime_utils.TestRuntimeInterface{ + &TestRuntimeInterface{ OnGetAccountContractNames: func(address runtime.Address) ([]string, error) { return []string{"TestImport"}, nil }, @@ -818,7 +818,7 @@ func TestContractUpgradeFieldType(t *testing.T) { upgradeValidator := stdlib.NewCadenceV042ToV1ContractUpdateValidator( location, contractName, - &runtime_utils.TestRuntimeInterface{ + &TestRuntimeInterface{ OnGetAccountContractNames: func(address runtime.Address) ([]string, error) { return []string{"TestImport"}, nil }, @@ -896,7 +896,7 @@ func TestContractUpgradeFieldType(t *testing.T) { upgradeValidator := stdlib.NewCadenceV042ToV1ContractUpdateValidator( location, contractName, - &runtime_utils.TestRuntimeInterface{ + &TestRuntimeInterface{ OnGetAccountContractNames: func(address runtime.Address) ([]string, error) { return []string{"TestImport"}, nil }, @@ -919,7 +919,7 @@ func TestContractUpgradeFieldType(t *testing.T) { // This should be an error. // If there are custom rules, they MUST be followed. - utils.RequireError(t, err) + RequireError(t, err) cause := getSingleContractUpdateErrorCause(t, err, "Test") var fieldMismatchError *stdlib.FieldMismatchError @@ -1031,7 +1031,7 @@ func TestContractUpgradeFieldType(t *testing.T) { upgradeValidator := stdlib.NewCadenceV042ToV1ContractUpdateValidator( location, contractName, - &runtime_utils.TestRuntimeInterface{ + &TestRuntimeInterface{ OnGetAccountContractNames: func(address runtime.Address) ([]string, error) { return []string{"TestImport"}, nil }, @@ -1161,7 +1161,7 @@ func TestContractUpgradeFieldType(t *testing.T) { upgradeValidator := stdlib.NewCadenceV042ToV1ContractUpdateValidator( location, contractName, - &runtime_utils.TestRuntimeInterface{ + &TestRuntimeInterface{ OnGetAccountContractNames: func(address runtime.Address) ([]string, error) { return []string{"TestImport"}, nil }, @@ -1257,7 +1257,7 @@ func TestContractUpgradeFieldType(t *testing.T) { upgradeValidator := stdlib.NewCadenceV042ToV1ContractUpdateValidator( location, contractName, - &runtime_utils.TestRuntimeInterface{ + &TestRuntimeInterface{ OnGetAccountContractNames: func(address runtime.Address) ([]string, error) { return []string{"TestImport"}, nil }, @@ -2443,7 +2443,7 @@ func TestInterfaceConformanceChange(t *testing.T) { upgradeValidator := stdlib.NewCadenceV042ToV1ContractUpdateValidator( location, contractName, - &runtime_utils.TestRuntimeInterface{ + &TestRuntimeInterface{ OnGetAccountContractNames: func(address runtime.Address) ([]string, error) { return []string{"TestImport"}, nil }, @@ -2528,7 +2528,7 @@ func TestInterfaceConformanceChange(t *testing.T) { upgradeValidator := stdlib.NewCadenceV042ToV1ContractUpdateValidator( location, contractName, - &runtime_utils.TestRuntimeInterface{ + &TestRuntimeInterface{ OnGetAccountContractNames: func(address runtime.Address) ([]string, error) { return []string{"TestImport"}, nil }, @@ -2602,7 +2602,7 @@ func TestInterfaceConformanceChange(t *testing.T) { upgradeValidator := stdlib.NewCadenceV042ToV1ContractUpdateValidator( location, contractName, - &runtime_utils.TestRuntimeInterface{ + &TestRuntimeInterface{ OnGetAccountContractNames: func(address runtime.Address) ([]string, error) { return []string{"TestImport"}, nil }, @@ -2626,7 +2626,7 @@ func TestInterfaceConformanceChange(t *testing.T) { // This should be an error. // If there are custom rules, they MUST be followed. - utils.RequireError(t, err) + RequireError(t, err) cause := getSingleContractUpdateErrorCause(t, err, "Test") var conformanceMismatchError *stdlib.ConformanceMismatchError @@ -2742,7 +2742,7 @@ func TestEnumUpdates(t *testing.T) { ` err := testContractUpdate(t, oldCode, newCode) - utils.RequireError(t, err) + RequireError(t, err) cause := getSingleContractUpdateErrorCause(t, err, "Test") var conformanceMismatchError *stdlib.ConformanceMismatchError @@ -2773,7 +2773,7 @@ func TestEnumUpdates(t *testing.T) { ` err := testContractUpdate(t, oldCode, newCode) - utils.RequireError(t, err) + RequireError(t, err) cause := getSingleContractUpdateErrorCause(t, err, "Test") var missingEnumCasesError *stdlib.MissingEnumCasesError diff --git a/stdlib/cadence_v0.42_to_v1_contract_upgrade_validator.go b/stdlib/cadence_v0.42_to_v1_contract_upgrade_validator.go index 7b13c6491b..ab854202b0 100644 --- a/stdlib/cadence_v0.42_to_v1_contract_upgrade_validator.go +++ b/stdlib/cadence_v0.42_to_v1_contract_upgrade_validator.go @@ -75,10 +75,6 @@ func (validator *CadenceV042ToV1ContractUpdateValidator) Location() common.Locat return validator.underlyingUpdateValidator.location } -func (validator *CadenceV042ToV1ContractUpdateValidator) isTypeRemovalEnabled() bool { - return validator.underlyingUpdateValidator.isTypeRemovalEnabled() -} - func (validator *CadenceV042ToV1ContractUpdateValidator) WithUserDefinedTypeChangeChecker( typeChangeCheckFunc func(oldTypeID common.TypeID, newTypeID common.TypeID) (checked, valid bool), ) *CadenceV042ToV1ContractUpdateValidator { @@ -86,13 +82,6 @@ func (validator *CadenceV042ToV1ContractUpdateValidator) WithUserDefinedTypeChan return validator } -func (validator *CadenceV042ToV1ContractUpdateValidator) WithTypeRemovalEnabled( - enabled bool, -) UpdateValidator { - validator.underlyingUpdateValidator.WithTypeRemovalEnabled(enabled) - return validator -} - func (validator *CadenceV042ToV1ContractUpdateValidator) getCurrentDeclaration() ast.Declaration { return validator.underlyingUpdateValidator.getCurrentDeclaration() } @@ -125,6 +114,7 @@ func (validator *CadenceV042ToV1ContractUpdateValidator) Validate() error { checkDeclarationUpdatability( validator, + validator.TypeComparator, oldRootDecl, newRootDecl, validator.checkConformanceV1, diff --git a/stdlib/contract_update_validation.go b/stdlib/contract_update_validation.go index 71e958f84e..f3ddebecc6 100644 --- a/stdlib/contract_update_validation.go +++ b/stdlib/contract_update_validation.go @@ -53,9 +53,6 @@ type UpdateValidator interface { oldDeclaration ast.Declaration, newDeclaration ast.Declaration, ) bool - - isTypeRemovalEnabled() bool - WithTypeRemovalEnabled(enabled bool) UpdateValidator } type checkConformanceFunc func( @@ -74,7 +71,6 @@ type ContractUpdateValidator struct { importLocations map[ast.Identifier]common.Location accountContractNamesProvider AccountContractNamesProvider errors []error - typeRemovalEnabled bool } // ContractUpdateValidator should implement ast.TypeEqualityChecker @@ -106,15 +102,6 @@ func (validator *ContractUpdateValidator) Location() common.Location { return validator.location } -func (validator *ContractUpdateValidator) isTypeRemovalEnabled() bool { - return validator.typeRemovalEnabled -} - -func (validator *ContractUpdateValidator) WithTypeRemovalEnabled(enabled bool) UpdateValidator { - validator.typeRemovalEnabled = enabled - return validator -} - func (validator *ContractUpdateValidator) getCurrentDeclaration() ast.Declaration { return validator.currentDecl } @@ -149,6 +136,7 @@ func (validator *ContractUpdateValidator) Validate() error { checkDeclarationUpdatability( validator, + validator.TypeComparator, oldRootDecl, newRootDecl, validator.checkConformance, @@ -299,6 +287,7 @@ func collectRemovedTypePragmas( func checkDeclarationUpdatability( validator UpdateValidator, + typeComparator *TypeComparator, oldDeclaration ast.Declaration, newDeclaration ast.Declaration, checkConformance checkConformanceFunc, @@ -327,13 +316,35 @@ func checkDeclarationUpdatability( checkFields(validator, oldDeclaration, newDeclaration) - checkNestedDeclarations(validator, oldDeclaration, newDeclaration, checkConformance) + checkNestedDeclarations( + validator, + typeComparator, + oldDeclaration, + newDeclaration, + checkConformance, + ) if newDecl, ok := newDeclaration.(*ast.CompositeDeclaration); ok { if oldDecl, ok := oldDeclaration.(*ast.CompositeDeclaration); ok { checkConformance(oldDecl, newDecl) } } + + // Check if the base type of the attachment has changed. + if oldAttachment, ok := oldDeclaration.(*ast.AttachmentDeclaration); ok && + oldAttachment.DeclarationKind() == common.DeclarationKindAttachment { + + // NOTE: no need to check declaration kinds match, already checked above + if newAttachment, ok := newDeclaration.(*ast.AttachmentDeclaration); ok { + err := typeComparator.CheckNominalTypeEquality( + oldAttachment.BaseType, + newAttachment.BaseType, + ) + if err != nil { + validator.report(err) + } + } + } } func checkFields( @@ -412,12 +423,10 @@ func (validator *ContractUpdateValidator) checkNestedDeclarationRemoval( return } - if validator.typeRemovalEnabled { - // OK to remove a type if it is included in a #removedType pragma, and it is not an interface - if removedTypes.Contains(nestedDeclaration.DeclarationIdentifier().Identifier) && - !declarationKind.IsInterfaceDeclaration() { - return - } + // OK to remove a type if it is included in a #removedType pragma, and it is not an interface + if removedTypes.Contains(nestedDeclaration.DeclarationIdentifier().Identifier) && + !declarationKind.IsInterfaceDeclaration() { + return } validator.report(&MissingDeclarationError{ @@ -443,10 +452,6 @@ func checkTypeNotRemoved( newDeclaration ast.Declaration, removedTypes *orderedmap.OrderedMap[string, struct{}], ) { - if !validator.isTypeRemovalEnabled() { - return - } - if removedTypes.Contains(newDeclaration.DeclarationIdentifier().Identifier) { validator.report(&UseOfRemovedTypeError{ Declaration: newDeclaration, @@ -457,39 +462,39 @@ func checkTypeNotRemoved( func checkNestedDeclarations( validator UpdateValidator, + typeComparator *TypeComparator, oldDeclaration ast.Declaration, newDeclaration ast.Declaration, checkConformance checkConformanceFunc, ) { var removedTypes *orderedmap.OrderedMap[string, struct{}] - if validator.isTypeRemovalEnabled() { - // process pragmas first, as they determine whether types can later be removed - oldRemovedTypes := collectRemovedTypePragmas( - validator, - oldDeclaration.DeclarationMembers().Pragmas(), - // Do not report errors for pragmas in the old code. - // We are only interested in collecting the pragmas in old code. - // This also avoid reporting mixed errors from both old and new codes. - false, - ) - removedTypes = collectRemovedTypePragmas( - validator, - newDeclaration.DeclarationMembers().Pragmas(), - true, - ) + // process pragmas first, as they determine whether types can later be removed + oldRemovedTypes := collectRemovedTypePragmas( + validator, + oldDeclaration.DeclarationMembers().Pragmas(), + // Do not report errors for pragmas in the old code. + // We are only interested in collecting the pragmas in old code. + // This also avoid reporting mixed errors from both old and new codes. + false, + ) - // #typeRemoval pragmas cannot be removed, so any that appear in the old program must appear in the new program - // they can however, be added, so use the new program's type removals for the purposes of checking the upgrade - oldRemovedTypes.Foreach(func(oldRemovedType string, _ struct{}) { - if !removedTypes.Contains(oldRemovedType) { - validator.report(&TypeRemovalPragmaRemovalError{ - RemovedType: oldRemovedType, - }) - } - }) - } + removedTypes = collectRemovedTypePragmas( + validator, + newDeclaration.DeclarationMembers().Pragmas(), + true, + ) + + // #typeRemoval pragmas cannot be removed, so any that appear in the old program must appear in the new program + // they can however, be added, so use the new program's type removals for the purposes of checking the upgrade + oldRemovedTypes.Foreach(func(oldRemovedType string, _ struct{}) { + if !removedTypes.Contains(oldRemovedType) { + validator.report(&TypeRemovalPragmaRemovalError{ + RemovedType: oldRemovedType, + }) + } + }) oldNominalTypeDecls := getNestedNominalTypeDecls(oldDeclaration) @@ -503,7 +508,13 @@ func checkNestedDeclarations( continue } - checkDeclarationUpdatability(validator, oldNestedDecl, newNestedDecl, checkConformance) + checkDeclarationUpdatability( + validator, + typeComparator, + oldNestedDecl, + newNestedDecl, + checkConformance, + ) // If there's a matching new decl, then remove the old one from the map. delete(oldNominalTypeDecls, newNestedDecl.Identifier.Identifier) @@ -519,7 +530,13 @@ func checkNestedDeclarations( continue } - checkDeclarationUpdatability(validator, oldNestedDecl, newNestedDecl, checkConformance) + checkDeclarationUpdatability( + validator, + typeComparator, + oldNestedDecl, + newNestedDecl, + checkConformance, + ) // If there's a matching new decl, then remove the old one from the map. delete(oldNominalTypeDecls, newNestedDecl.Identifier.Identifier) @@ -535,7 +552,13 @@ func checkNestedDeclarations( continue } - checkDeclarationUpdatability(validator, oldNestedDecl, newNestedDecl, checkConformance) + checkDeclarationUpdatability( + validator, + typeComparator, + oldNestedDecl, + newNestedDecl, + checkConformance, + ) // If there's a matching new decl, then remove the old one from the map. delete(oldNominalTypeDecls, newNestedDecl.Identifier.Identifier) diff --git a/stdlib/rlp/rlp_test.go b/stdlib/rlp/rlp_test.go index f707026356..ce07309d82 100644 --- a/stdlib/rlp/rlp_test.go +++ b/stdlib/rlp/rlp_test.go @@ -24,7 +24,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/stdlib/rlp" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestRLPReadSize(t *testing.T) { diff --git a/stdlib/test_test.go b/stdlib/test_test.go index 19912f763c..9e602af451 100644 --- a/stdlib/test_test.go +++ b/stdlib/test_test.go @@ -34,8 +34,8 @@ import ( "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/parser" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/checker" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func newTestContractInterpreter(t *testing.T, code string) (*interpreter.Interpreter, error) { @@ -65,7 +65,7 @@ func newTestContractInterpreterWithTestFramework( checker, err := sema.NewChecker( program, - utils.TestLocation, + TestLocation, nil, &sema.Config{ BaseValueActivationHandler: func(_ common.Location) *sema.VariableActivation { @@ -288,7 +288,7 @@ func TestTestNewMatcher(t *testing.T) { _, err := newTestContractInterpreter(t, script) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.TypeMismatchError{}, errs[0]) }) @@ -334,7 +334,7 @@ func TestTestNewMatcher(t *testing.T) { _, err := newTestContractInterpreter(t, script) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.TypeMismatchError{}, errs[0]) }) @@ -461,7 +461,7 @@ func TestTestEqualMatcher(t *testing.T) { _, err := newTestContractInterpreter(t, script) require.Error(t, err) - errs := checker.RequireCheckerErrors(t, err, 2) + errs := RequireCheckerErrors(t, err, 2) assert.IsType(t, &sema.TypeMismatchError{}, errs[0]) assert.IsType(t, &sema.TypeMismatchError{}, errs[1]) }) @@ -499,7 +499,7 @@ func TestTestEqualMatcher(t *testing.T) { _, err := newTestContractInterpreter(t, script) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.TypeMismatchError{}, errs[0]) }) @@ -671,7 +671,7 @@ func TestTestEqualMatcher(t *testing.T) { _, err := newTestContractInterpreter(t, script) - errs := checker.RequireCheckerErrors(t, err, 4) + errs := RequireCheckerErrors(t, err, 4) assert.IsType(t, &sema.TypeMismatchError{}, errs[0]) assert.IsType(t, &sema.TypeMismatchError{}, errs[1]) assert.IsType(t, &sema.TypeMismatchError{}, errs[2]) @@ -705,7 +705,7 @@ func TestTestEqualMatcher(t *testing.T) { _, err := newTestContractInterpreter(t, script) - errs := checker.RequireCheckerErrors(t, err, 3) + errs := RequireCheckerErrors(t, err, 3) assert.IsType(t, &sema.TypeMismatchError{}, errs[0]) assert.IsType(t, &sema.TypeMismatchError{}, errs[1]) assert.IsType(t, &sema.TypeMismatchError{}, errs[2]) @@ -990,7 +990,7 @@ func TestAssertEqual(t *testing.T) { _, err := newTestContractInterpreter(t, script) - errs := checker.RequireCheckerErrors(t, err, 2) + errs := RequireCheckerErrors(t, err, 2) assert.IsType(t, &sema.TypeMismatchError{}, errs[0]) assert.IsType(t, &sema.TypeMismatchError{}, errs[1]) }) @@ -1016,7 +1016,7 @@ func TestAssertEqual(t *testing.T) { _, err := newTestContractInterpreter(t, script) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.TypeMismatchError{}, errs[0]) }) @@ -1041,7 +1041,7 @@ func TestAssertEqual(t *testing.T) { _, err := newTestContractInterpreter(t, script) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.TypeMismatchError{}, errs[0]) }) } @@ -1931,7 +1931,7 @@ func TestTestExpect(t *testing.T) { _, err := newTestContractInterpreter(t, script) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.TypeMismatchError{}, errs[0]) }) @@ -1955,7 +1955,7 @@ func TestTestExpect(t *testing.T) { _, err := newTestContractInterpreter(t, script) - errs := checker.RequireCheckerErrors(t, err, 2) + errs := RequireCheckerErrors(t, err, 2) assert.IsType(t, &sema.TypeMismatchError{}, errs[0]) assert.IsType(t, &sema.TypeMismatchError{}, errs[1]) }) @@ -1981,7 +1981,7 @@ func TestTestExpect(t *testing.T) { _, err := newTestContractInterpreter(t, script) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.TypeMismatchError{}, errs[0]) }) @@ -2006,7 +2006,7 @@ func TestTestExpect(t *testing.T) { _, err := newTestContractInterpreter(t, script) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.TypeMismatchError{}, errs[0]) }) } @@ -2176,7 +2176,7 @@ func TestTestExpectFailure(t *testing.T) { ` _, err := newTestContractInterpreter(t, script) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.TypeMismatchError{}, errs[0]) }) @@ -2213,7 +2213,7 @@ func TestTestExpectFailure(t *testing.T) { ` _, err := newTestContractInterpreter(t, script) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.TypeMismatchError{}, errs[0]) }) } @@ -2377,7 +2377,7 @@ func TestBlockchain(t *testing.T) { } _, err := newTestContractInterpreterWithTestFramework(t, script, testFramework) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.TypeMismatchError{}, errs[0]) assert.False(t, resetInvoked) }) @@ -2481,7 +2481,7 @@ func TestBlockchain(t *testing.T) { } _, err := newTestContractInterpreterWithTestFramework(t, script, testFramework) - errs := checker.RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.TypeMismatchError{}, errs[0]) assert.False(t, moveTimeInvoked) }) diff --git a/test_utils/common_utils/utils.go b/test_utils/common_utils/utils.go new file mode 100644 index 0000000000..009494e373 --- /dev/null +++ b/test_utils/common_utils/utils.go @@ -0,0 +1,112 @@ +/* + * Cadence - The resource-oriented smart contract programming language + * + * Copyright Flow Foundation + * + * 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 common_utils + +import ( + "strings" + "testing" + + "github.com/k0kubun/pp" + "github.com/kr/pretty" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/onflow/cadence/ast" + "github.com/onflow/cadence/errors" + + "github.com/onflow/cadence/common" +) + +func init() { + pp.ColoringEnabled = false +} + +// TestLocation is used as the default location for programs in tests. +const TestLocation = common.StringLocation("test") + +// ImportedLocation is used as the default location for imported programs in tests. +const ImportedLocation = common.StringLocation("imported") + +// AssertEqualWithDiff asserts that two objects are equal. +// +// If the objects are not equal, this function prints a human-readable diff. +func AssertEqualWithDiff(t *testing.T, expected, actual any) { + + // the maximum levels of a struct to recurse into + // this prevents infinite recursion from circular references + diff := pretty.Diff(expected, actual) + + if len(diff) != 0 { + s := strings.Builder{} + + for i, d := range diff { + if i == 0 { + s.WriteString("diff : ") + } else { + s.WriteString(" ") + } + + s.WriteString(d) + s.WriteString("\n") + } + + t.Errorf( + "Not equal: \n"+ + "expected: %s\n"+ + "actual : %s\n\n"+ + "%s", + pp.Sprint(expected), + pp.Sprint(actual), + s.String(), + ) + } +} + +// RequireError is a wrapper around require.Error which also ensures +// that the error message, the secondary message (if any), +// and the error notes' (if any) messages can be successfully produced +func RequireError(t *testing.T, err error) { + require.Error(t, err) + + _ = err.Error() + + if hasImportLocation, ok := err.(common.HasLocation); ok { + location := hasImportLocation.ImportLocation() + assert.NotNil(t, location) + } + + if hasPosition, ok := err.(ast.HasPosition); ok { + _ = hasPosition.StartPosition() + _ = hasPosition.EndPosition(nil) + } + + if hasErrorNotes, ok := err.(errors.ErrorNotes); ok { + for _, note := range hasErrorNotes.ErrorNotes() { + _ = note.Message() + } + } + + if hasSecondaryError, ok := err.(errors.SecondaryError); ok { + _ = hasSecondaryError.SecondaryError() + } + + if hasSuggestedFixes, ok := err.(errors.HasSuggestedFixes[ast.TextEdit]); ok { + _ = hasSuggestedFixes.SuggestFixes("") + } +} diff --git a/tests/runtime_utils/interpreter.go b/test_utils/interpreter_utils/interpreter.go similarity index 92% rename from tests/runtime_utils/interpreter.go rename to test_utils/interpreter_utils/interpreter.go index e7458be09b..46a8182023 100644 --- a/tests/runtime_utils/interpreter.go +++ b/test_utils/interpreter_utils/interpreter.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package runtime_utils +package interpreter_utils import ( "testing" @@ -24,7 +24,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/interpreter" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func NewTestInterpreter(tb testing.TB) *interpreter.Interpreter { @@ -32,7 +32,7 @@ func NewTestInterpreter(tb testing.TB) *interpreter.Interpreter { inter, err := interpreter.NewInterpreter( nil, - utils.TestLocation, + TestLocation, &interpreter.Config{ Storage: storage, AtreeValueValidationEnabled: true, diff --git a/tests/utils/utils.go b/test_utils/interpreter_utils/values.go similarity index 56% rename from tests/utils/utils.go rename to test_utils/interpreter_utils/values.go index 1c6d840712..f271ba944b 100644 --- a/tests/utils/utils.go +++ b/test_utils/interpreter_utils/values.go @@ -16,113 +16,37 @@ * limitations under the License. */ -package utils +package interpreter_utils import ( - "encoding/hex" "fmt" "strings" "testing" - "github.com/k0kubun/pp" "github.com/kr/pretty" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "github.com/onflow/cadence/ast" - "github.com/onflow/cadence/errors" "github.com/onflow/cadence/interpreter" - - "github.com/onflow/cadence/common" ) -func init() { - pp.ColoringEnabled = false +func RequireValuesEqual(t testing.TB, inter *interpreter.Interpreter, expected, actual interpreter.Value) { + if !AssertValuesEqual(t, inter, expected, actual) { + t.FailNow() + } } -// TestLocation is used as the default location for programs in tests. -const TestLocation = common.StringLocation("test") - -// ImportedLocation is used as the default location for imported programs in tests. -const ImportedLocation = common.StringLocation("imported") - -// AssertEqualWithDiff asserts that two objects are equal. -// -// If the objects are not equal, this function prints a human-readable diff. -func AssertEqualWithDiff(t *testing.T, expected, actual any) { - - // the maximum levels of a struct to recurse into - // this prevents infinite recursion from circular references - diff := pretty.Diff(expected, actual) - - if len(diff) != 0 { - s := strings.Builder{} - - for i, d := range diff { - if i == 0 { - s.WriteString("diff : ") - } else { - s.WriteString(" ") - } +func AssertValueSlicesEqual(t testing.TB, inter *interpreter.Interpreter, expected, actual []interpreter.Value) bool { + if !assert.Equal(t, len(expected), len(actual)) { + return false + } - s.WriteString(d) - s.WriteString("\n") + for i, value := range expected { + if !AssertValuesEqual(t, inter, value, actual[i]) { + return false } - - t.Errorf( - "Not equal: \n"+ - "expected: %s\n"+ - "actual : %s\n\n"+ - "%s", - pp.Sprint(expected), - pp.Sprint(actual), - s.String(), - ) } -} - -func DeploymentTransaction(name string, contract []byte) []byte { - return []byte(fmt.Sprintf( - ` - transaction { - - prepare(signer: auth(Contracts) &Account) { - signer.contracts.add(name: "%s", code: "%s".decodeHex()) - } - } - `, - name, - hex.EncodeToString(contract), - )) -} - -func RemovalTransaction(name string) []byte { - return []byte(fmt.Sprintf( - ` - transaction { - prepare(signer: auth(Contracts) &Account) { - signer.contracts.remove(name: "%s") - } - } - `, - name, - )) -} - -func UpdateTransaction(name string, contract []byte) []byte { - return []byte(fmt.Sprintf( - ` - transaction { - - prepare(signer: auth(Contracts) &Account) { - signer.contracts.update(name: "%s", code: "%s".decodeHex()) - } - } - `, - name, - hex.EncodeToString(contract), - )) + return true } func ValuesAreEqual(inter *interpreter.Interpreter, expected, actual interpreter.Value) bool { @@ -173,59 +97,6 @@ func AssertValuesEqual(t testing.TB, interpreter *interpreter.Interpreter, expec return true } -func RequireValuesEqual(t testing.TB, inter *interpreter.Interpreter, expected, actual interpreter.Value) { - if !AssertValuesEqual(t, inter, expected, actual) { - t.FailNow() - } -} - -func AssertValueSlicesEqual(t testing.TB, inter *interpreter.Interpreter, expected, actual []interpreter.Value) bool { - if !assert.Equal(t, len(expected), len(actual)) { - return false - } - - for i, value := range expected { - if !AssertValuesEqual(t, inter, value, actual[i]) { - return false - } - } - - return true -} - -// RequireError is a wrapper around require.Error which also ensures -// that the error message, the secondary message (if any), -// and the error notes' (if any) messages can be successfully produced -func RequireError(t *testing.T, err error) { - require.Error(t, err) - - _ = err.Error() - - if hasImportLocation, ok := err.(common.HasLocation); ok { - location := hasImportLocation.ImportLocation() - assert.NotNil(t, location) - } - - if hasPosition, ok := err.(ast.HasPosition); ok { - _ = hasPosition.StartPosition() - _ = hasPosition.EndPosition(nil) - } - - if hasErrorNotes, ok := err.(errors.ErrorNotes); ok { - for _, note := range hasErrorNotes.ErrorNotes() { - _ = note.Message() - } - } - - if hasSecondaryError, ok := err.(errors.SecondaryError); ok { - _ = hasSecondaryError.SecondaryError() - } - - if hasSuggestedFixes, ok := err.(errors.HasSuggestedFixes[ast.TextEdit]); ok { - _ = hasSuggestedFixes.SuggestFixes("") - } -} - func ArrayElements(inter *interpreter.Interpreter, array *interpreter.ArrayValue) []interpreter.Value { count := array.Count() result := make([]interpreter.Value, count) diff --git a/tests/runtime_utils/location.go b/test_utils/runtime_utils/location.go similarity index 100% rename from tests/runtime_utils/location.go rename to test_utils/runtime_utils/location.go diff --git a/tests/runtime_utils/testinterface.go b/test_utils/runtime_utils/testinterface.go similarity index 98% rename from tests/runtime_utils/testinterface.go rename to test_utils/runtime_utils/testinterface.go index 9b3b8199e3..f874d7bbf3 100644 --- a/tests/runtime_utils/testinterface.go +++ b/test_utils/runtime_utils/testinterface.go @@ -131,6 +131,7 @@ type TestRuntimeInterface struct { path interpreter.PathValue, capabilityBorrowType *interpreter.ReferenceStaticType, ) (bool, error) + OnMinimumRequiredVersion func() (string, error) lastUUID uint64 accountIDs map[common.Address]uint64 @@ -663,3 +664,10 @@ func (i *TestRuntimeInterface) ValidateAccountCapabilitiesPublish( capabilityBorrowType, ) } + +func (i *TestRuntimeInterface) MinimumRequiredVersion() (string, error) { + if i.OnMinimumRequiredVersion == nil { + return "", nil + } + return i.OnMinimumRequiredVersion() +} diff --git a/tests/runtime_utils/testledger.go b/test_utils/runtime_utils/testledger.go similarity index 100% rename from tests/runtime_utils/testledger.go rename to test_utils/runtime_utils/testledger.go diff --git a/tests/runtime_utils/testruntime.go b/test_utils/runtime_utils/testruntime.go similarity index 100% rename from tests/runtime_utils/testruntime.go rename to test_utils/runtime_utils/testruntime.go diff --git a/test_utils/runtime_utils/transactions.go b/test_utils/runtime_utils/transactions.go new file mode 100644 index 0000000000..72f8af976c --- /dev/null +++ b/test_utils/runtime_utils/transactions.go @@ -0,0 +1,68 @@ +/* + * Cadence - The resource-oriented smart contract programming language + * + * Copyright Flow Foundation + * + * 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_utils + +import ( + "encoding/hex" + "fmt" +) + +func DeploymentTransaction(name string, contract []byte) []byte { + return []byte(fmt.Sprintf( + ` + transaction { + + prepare(signer: auth(Contracts) &Account) { + signer.contracts.add(name: "%s", code: "%s".decodeHex()) + } + } + `, + name, + hex.EncodeToString(contract), + )) +} + +func RemovalTransaction(name string) []byte { + return []byte(fmt.Sprintf( + ` + transaction { + + prepare(signer: auth(Contracts) &Account) { + signer.contracts.remove(name: "%s") + } + } + `, + name, + )) +} + +func UpdateTransaction(name string, contract []byte) []byte { + return []byte(fmt.Sprintf( + ` + transaction { + + prepare(signer: auth(Contracts) &Account) { + signer.contracts.update(name: "%s", code: "%s".decodeHex()) + } + } + `, + name, + hex.EncodeToString(contract), + )) +} diff --git a/tests/checker/utils.go b/test_utils/sema_utils/utils.go similarity index 96% rename from tests/checker/utils.go rename to test_utils/sema_utils/utils.go index 3afe516b80..220d0e653f 100644 --- a/tests/checker/utils.go +++ b/test_utils/sema_utils/utils.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_utils import ( "flag" @@ -25,7 +25,6 @@ import ( "testing" gopretty "github.com/kr/pretty" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -33,7 +32,7 @@ import ( "github.com/onflow/cadence/parser" "github.com/onflow/cadence/pretty" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func ParseAndCheck(t testing.TB, code string) (*sema.Checker, error) { @@ -69,7 +68,7 @@ func ParseAndCheckWithOptionsAndMemoryMetering( ) (*sema.Checker, error) { if options.Location == nil { - options.Location = utils.TestLocation + options.Location = TestLocation } program, err := parser.ParseProgram(memoryGauge, []byte(code), options.ParseOptions) @@ -170,7 +169,7 @@ func RequireCheckerErrors(t *testing.T, err error, count int) []error { return nil } - utils.RequireError(t, err) + RequireError(t, err) var checkerErr *sema.CheckerError require.ErrorAs(t, err, &checkerErr) @@ -182,7 +181,7 @@ func RequireCheckerErrors(t *testing.T, err error, count int) []error { // Get the error message, to check that it can be successfully generated for _, checkerErr := range errs { - utils.RequireError(t, checkerErr) + RequireError(t, checkerErr) } return errs diff --git a/tests/interpreter/fib_test.go b/tests/interpreter/fib_test.go deleted file mode 100644 index d6581959f5..0000000000 --- a/tests/interpreter/fib_test.go +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Cadence - The resource-oriented smart contract programming language - * - * Copyright Flow Foundation - * - * 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 interpreter_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - - "github.com/onflow/cadence/interpreter" -) - -const imperativeFib = ` - fun fib(_ n: Int): Int { - var fib1 = 1 - var fib2 = 1 - var fibonacci = fib1 - var i = 2 - while i < n { - fibonacci = fib1 + fib2 - fib1 = fib2 - fib2 = fibonacci - i = i + 1 - } - return fibonacci - } -` - -func TestImperativeFib(t *testing.T) { - - t.Parallel() - - inter := parseCheckAndInterpret(t, imperativeFib) - - var value interpreter.Value = interpreter.NewUnmeteredIntValueFromInt64(7) - - result, err := inter.Invoke("fib", value) - require.NoError(t, err) - require.Equal(t, interpreter.NewUnmeteredIntValueFromInt64(13), result) -} - -func BenchmarkImperativeFib(b *testing.B) { - - inter := parseCheckAndInterpret(b, imperativeFib) - - var value interpreter.Value = interpreter.NewUnmeteredIntValueFromInt64(14) - - b.ReportAllocs() - b.ResetTimer() - - for i := 0; i < b.N; i++ { - _, err := inter.Invoke("fib", value) - require.NoError(b, err) - } -} diff --git a/tools/analysis/analysis_test.go b/tools/analysis/analysis_test.go index 61e1d54ec4..da09e6dd74 100644 --- a/tools/analysis/analysis_test.go +++ b/tools/analysis/analysis_test.go @@ -29,7 +29,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/parser" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/checker" + . "github.com/onflow/cadence/test_utils/sema_utils" "github.com/onflow/cadence/tools/analysis" ) @@ -558,7 +558,7 @@ func TestCyclicImports(t *testing.T) { var checkerError *sema.CheckerError require.ErrorAs(t, err, &checkerError) - errs := checker.RequireCheckerErrors(t, checkerError, 1) + errs := RequireCheckerErrors(t, checkerError, 1) var importedProgramErr *sema.ImportedProgramError require.ErrorAs(t, errs[0], &importedProgramErr) @@ -566,6 +566,6 @@ func TestCyclicImports(t *testing.T) { var nestedCheckerErr *sema.CheckerError require.ErrorAs(t, importedProgramErr.Err, &nestedCheckerErr) - errs = checker.RequireCheckerErrors(t, nestedCheckerErr, 1) + errs = RequireCheckerErrors(t, nestedCheckerErr, 1) require.IsType(t, &sema.CyclicImportsError{}, errs[0]) } diff --git a/tools/compatibility-check/contracts_checker.go b/tools/compatibility-check/contracts_checker.go index 887cb02a0c..99bd2149c4 100644 --- a/tools/compatibility-check/contracts_checker.go +++ b/tools/compatibility-check/contracts_checker.go @@ -19,14 +19,13 @@ package compatibility_check import ( + "encoding/csv" "fmt" "io" "log" "reflect" "strings" - "encoding/csv" - "github.com/onflow/cadence/ast" "github.com/onflow/cadence/common" "github.com/onflow/cadence/parser" diff --git a/tools/compatibility-check/go.mod b/tools/compatibility-check/go.mod index 44484aee7a..628bfdc184 100644 --- a/tools/compatibility-check/go.mod +++ b/tools/compatibility-check/go.mod @@ -4,6 +4,8 @@ go 1.22 require ( github.com/onflow/cadence v1.1.1-0.20241018202510-7f1b6fbc57c2 + github.com/onflow/flow-core-contracts/lib/go/contracts v1.4.0 + github.com/onflow/flow-go v0.38.0-preview.0.0.20241018215103-774056466e36 github.com/rs/zerolog v1.29.0 github.com/stretchr/testify v1.9.0 ) @@ -43,11 +45,9 @@ require ( github.com/multiformats/go-varint v0.0.7 // indirect github.com/onflow/atree v0.8.0 // indirect github.com/onflow/crypto v0.25.2 // indirect - github.com/onflow/flow-core-contracts/lib/go/contracts v1.4.0 // indirect github.com/onflow/flow-core-contracts/lib/go/templates v1.3.3-0.20241017220455-79fdc6c8ba53 // indirect github.com/onflow/flow-ft/lib/go/contracts v1.0.1 // indirect github.com/onflow/flow-ft/lib/go/templates v1.0.1 // indirect - github.com/onflow/flow-go v0.38.0-preview.0.0.20241018215103-774056466e36 // indirect github.com/onflow/flow-go-sdk v1.1.0 // indirect github.com/onflow/flow-nft/lib/go/contracts v1.2.2 // indirect github.com/onflow/flow-nft/lib/go/templates v1.2.1 // indirect @@ -75,10 +75,10 @@ require ( github.com/x448/float16 v0.8.4 // indirect github.com/zeebo/blake3 v0.2.3 // indirect go.opentelemetry.io/otel v1.24.0 // indirect - golang.org/x/crypto v0.26.0 // indirect + golang.org/x/crypto v0.28.0 // indirect golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect - golang.org/x/sys v0.23.0 // indirect - golang.org/x/text v0.17.0 // indirect + golang.org/x/sys v0.26.0 // indirect + golang.org/x/text v0.19.0 // indirect golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect gonum.org/v1/gonum v0.14.0 // indirect google.golang.org/appengine v1.6.8 // indirect diff --git a/tools/compatibility-check/go.sum b/tools/compatibility-check/go.sum index ee2555e618..3c453fa707 100644 --- a/tools/compatibility-check/go.sum +++ b/tools/compatibility-check/go.sum @@ -38,6 +38,8 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8= +github.com/DataDog/zstd v1.5.2/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/SaveTheRbtz/mph v0.1.1-0.20240117162131-4166ec7869bc h1:DCHzPQOcU/7gwDTWbFQZc5qHMPS1g0xTO56k8NXsv9M= github.com/SaveTheRbtz/mph v0.1.1-0.20240117162131-4166ec7869bc/go.mod h1:LJM5a3zcIJ/8TmZwlUczvROEJT8ntOdhdG9jjcR1B0I= @@ -46,14 +48,19 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= -github.com/bits-and-blooms/bitset v1.5.0 h1:NpE8frKRLGHIcEzkR+gZhiioW1+WbYV6fKwD6ZIpQT8= -github.com/bits-and-blooms/bitset v1.5.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bits-and-blooms/bitset v1.10.0 h1:ePXTeiPEazB5+opbv5fr8umg2R/1NlzgDsyepwsSr88= github.com/bits-and-blooms/bitset v1.10.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ= github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= +github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= +github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= @@ -61,6 +68,18 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cockroachdb/errors v1.11.3 h1:5bA+k2Y6r+oz/6Z/RFlNeVCesGARKuC6YymtcDrbC/I= +github.com/cockroachdb/errors v1.11.3/go.mod h1:m4UIW4CDjx+R5cybPsNrRbreomiFqt8o1h1wUVazSd8= +github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce h1:giXvy4KSc/6g/esnpM7Geqxka4WSqI1SZc7sMJFd3y4= +github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce/go.mod h1:9/y3cnZ5GKakj/H4y9r9GTjCvAFta7KLgSHPJJYc52M= +github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= +github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= +github.com/cockroachdb/pebble v1.1.1 h1:XnKU22oiCLy2Xn8vp1re67cXg4SAasg/WDt1NtcRFaw= +github.com/cockroachdb/pebble v1.1.1/go.mod h1:4exszw1r40423ZsmkG/09AFEG83I0uDgfujJdbL6kYU= +github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30= +github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= +github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= +github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= @@ -68,7 +87,6 @@ github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= @@ -79,8 +97,18 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= +github.com/dgraph-io/badger/v2 v2.2007.4 h1:TRWBQg8UrlUhaFdco01nO2uXwzKS7zd+HVdwV/GHc4o= +github.com/dgraph-io/badger/v2 v2.2007.4/go.mod h1:vSw/ax2qojzbN6eXHIx6KPKtCSHJN/Uz0X0VPruTIhk= +github.com/dgraph-io/ristretto v0.1.0 h1:Jv3CGQHp9OjuMBSne1485aDpUkTKEcUqF+jm/LuerPI= +github.com/dgraph-io/ristretto v0.1.0/go.mod h1:fux0lOrBhrVCJd3lcTHsIJhq1T2rokOu6v9Vcb3Q9ug= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA= +github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= +github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/ef-ds/deque v1.0.4 h1:iFAZNmveMT9WERAkqLJ+oaABF9AcVQ5AjXem/hroniI= +github.com/ef-ds/deque v1.0.4/go.mod h1:gXDnTC3yqvBcHbq2lcExjtAcVrOnJCbMcZXmuj8Z4tg= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -89,6 +117,8 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/ethereum/go-ethereum v1.13.10 h1:Ppdil79nN+Vc+mXfge0AuUgmKWuVv4eMqzoIVSdqZek= github.com/ethereum/go-ethereum v1.13.10/go.mod h1:sc48XYQxCzH3fG9BcrXCOOgQk2JfZzNAmIKnceogzsA= +github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= +github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= @@ -96,6 +126,8 @@ github.com/fxamacker/cbor/v2 v2.4.1-0.20230228173756-c0c9f774e40c h1:5tm/Wbs9d9r github.com/fxamacker/cbor/v2 v2.4.1-0.20230228173756-c0c9f774e40c/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo= github.com/fxamacker/circlehash v0.3.0 h1:XKdvTtIJV9t7DDUtsf0RIpC1OcxZtPbmgIH7ekx28WA= github.com/fxamacker/circlehash v0.3.0/go.mod h1:3aq3OfVvsWtkWMb6A1owjOQFA+TLsD5FgJflnaQwtMM= +github.com/getsentry/sentry-go v0.27.0 h1:Pv98CIbtB3LkMWmXi4Joa5OOcwbmnX88sF5qbK3r3Ps= +github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -103,11 +135,19 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2 github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= +github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68= +github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -137,6 +177,8 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk= +github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -149,8 +191,8 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= -github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= @@ -166,39 +208,77 @@ github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.9.0 h1:bM6ZAFZmc/wPFaRDi0d5L7hGEZEx/2u+Tmr2evNHDiI= github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 h1:Wqo399gCIufwto+VfwCSvsnfGpF/w5E9CNxSwbpD6No= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0/go.mod h1:qmOFXW2epJhM0qSnUUYpldc7gVz2KMQwJ/QYCDIa7XU= +github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= +github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c= +github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= +github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/holiman/uint256 v1.3.0 h1:4wdcm/tnd0xXdu7iS3ruNvxkWwrb4aeBQv19ayYn8F4= github.com/holiman/uint256 v1.3.0/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E= +github.com/huandu/go-clone v1.6.0 h1:HMo5uvg4wgfiy5FoGOqlFLQED/VGRm2D9Pi8g1FXPGc= +github.com/huandu/go-clone v1.6.0/go.mod h1:ReGivhG6op3GYr+UY3lS6mxjKp7MIGTknuU5TbTVaXE= +github.com/huandu/go-clone/generic v1.7.2 h1:47pQphxs1Xc9cVADjOHN+Bm5D0hNagwH9UXErbxgVKA= +github.com/huandu/go-clone/generic v1.7.2/go.mod h1:xgd9ZebcMsBWWcBx5mVMCoqMX24gLWr5lQicr+nVXNs= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs= +github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0= +github.com/ipfs/boxo v0.17.1-0.20240131173518-89bceff34bf1 h1:5H/HYvdmbxp09+sAvdqJzyrWoyCS6OroeW9Ym06Tb+0= +github.com/ipfs/boxo v0.17.1-0.20240131173518-89bceff34bf1/go.mod h1:pIZgTWdm3k3pLF9Uq6MB8JEcW07UDwNJjlXW1HELW80= +github.com/ipfs/go-block-format v0.2.0 h1:ZqrkxBA2ICbDRbK8KJs/u0O3dlp6gmAuuXUJNiW1Ycs= +github.com/ipfs/go-block-format v0.2.0/go.mod h1:+jpL11nFx5A/SPpsoBn6Bzkra/zaArfSmsknbPMYgzM= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk= +github.com/ipfs/go-datastore v0.6.0 h1:JKyz+Gvz1QEZw0LsX1IBn+JFCJQH4SJVFtM4uWU0Myk= +github.com/ipfs/go-datastore v0.6.0/go.mod h1:rt5M3nNbSO/8q1t4LNkLyUwRs8HupMeN/8O4Vn9YAT8= +github.com/ipfs/go-ipfs-util v0.0.3 h1:2RFdGez6bu2ZlZdI+rWfIdbQb1KudQp3VGwPtdNCmE0= +github.com/ipfs/go-ipfs-util v0.0.3/go.mod h1:LHzG1a0Ig4G+iZ26UUOMjHd+lfM84LZCrn17xAKWBvs= +github.com/ipfs/go-ipld-format v0.6.0 h1:VEJlA2kQ3LqFSIm5Vu6eIlSxD/Ze90xtc4Meten1F5U= +github.com/ipfs/go-ipld-format v0.6.0/go.mod h1:g4QVMTn3marU3qXchwjpKPKgJv+zF+OlaKMyhJ4LHPg= +github.com/ipfs/go-log v1.0.5 h1:2dOuUCB1Z7uoczMWgAyDck5JLb72zHzrMnGnCNNbvY8= +github.com/ipfs/go-log/v2 v2.5.1 h1:1XdUzF7048prq4aBjDQQ4SL5RxftpRGdXhNRwKSAlcY= +github.com/ipfs/go-log/v2 v2.5.1/go.mod h1:prSpmC1Gpllc9UYWxDiZDreBYw7zp4Iqp1kOLU9U5UI= +github.com/ipfs/go-metrics-interface v0.0.1 h1:j+cpbjYvu4R8zbleSs36gvB7jR+wsL2fGD6n0jO4kdg= +github.com/ipfs/go-metrics-interface v0.0.1/go.mod h1:6s6euYU4zowdslK0GKHmqaIZ3j/b/tL7HTWtJ4VPgWY= +github.com/jbenet/goprocess v0.1.4 h1:DRGOFReOMqqDNXwW70QkacFW0YN9QnwLV0Vqk+3oU0o= +github.com/jbenet/goprocess v0.1.4/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 h1:uC1QfSlInpQF+M0ao65imhwqKnz3Q2z/d8PWZRMQvDM= +github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k= github.com/k0kubun/pp v3.0.1+incompatible h1:3tqvf7QgUnZ5tXO6pNAZlrvHgl6DvifjDrd9g2S9Z40= github.com/k0kubun/pp v3.0.1+incompatible/go.mod h1:GWse8YhT0p8pT4ir3ZgBbfZild3tgzSScAn6HmfYukg= github.com/kevinburke/go-bindata v3.24.0+incompatible h1:qajFA3D0pH94OTLU4zcCCKCDgR+Zr2cZK/RPJHDdFoY= github.com/kevinburke/go-bindata v3.24.0+incompatible/go.mod h1:/pEEZ72flUW2p0yi30bslSp9YqD9pysLxunQDdb2CPM= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4= +github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= -github.com/klauspost/cpuid/v2 v2.2.0 h1:4ZexSFt8agMNzNisrsilL6RClWDC5YJnLHNIfTy4iuc= -github.com/klauspost/cpuid/v2 v2.2.0/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc= github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -213,6 +293,14 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= +github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8= +github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg= +github.com/libp2p/go-libp2p v0.32.2 h1:s8GYN4YJzgUoyeYNPdW7JZeZ5Ee31iNaIBfGYMAY4FQ= +github.com/libp2p/go-libp2p v0.32.2/go.mod h1:E0LKe+diV/ZVJVnOJby8VC5xzHF0660osg71skcxJvk= +github.com/libp2p/go-libp2p-pubsub v0.10.0 h1:wS0S5FlISavMaAbxyQn3dxMOe2eegMfswM471RuHJwA= +github.com/libp2p/go-libp2p-pubsub v0.10.0/go.mod h1:1OxbaT/pFRO5h+Dpze8hdHQ63R0ke55XTs6b6NwLLkw= +github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0= +github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM= github.com/logrusorgru/aurora/v4 v4.0.0 h1:sRjfPpun/63iADiSvGGjgA1cAYegEWMPCJdUpJYn9JA= github.com/logrusorgru/aurora/v4 v4.0.0/go.mod h1:lP0iIa2nrnT/qoFXcOZSrZQpJ1o6n2CUf/hyHi2Q4ZQ= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= @@ -226,6 +314,9 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI= +github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg= +github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k= github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM= github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= @@ -238,21 +329,24 @@ github.com/multiformats/go-base32 v0.1.0 h1:pVx9xoSPqEIQG8o+UbAe7DNi51oej1NtK+aG github.com/multiformats/go-base32 v0.1.0/go.mod h1:Kj3tFY6zNr+ABYMqeUNeGvkIC/UYgtWibDcT0rExnbI= github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9rQyccr0= github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= +github.com/multiformats/go-multiaddr v0.12.2 h1:9G9sTY/wCYajKa9lyfWPmpZAwe6oV+Wb1zcmMS1HG24= +github.com/multiformats/go-multiaddr v0.12.2/go.mod h1:GKyaTYjZRdcUhyOetrxTk9z0cW+jA/YrnqTOvKgi44M= github.com/multiformats/go-multibase v0.2.0 h1:isdYCVLvksgWlMW9OZRYJEa9pZETFivncJHmHnnd87g= github.com/multiformats/go-multibase v0.2.0/go.mod h1:bFBZX4lKCA/2lyOFSAoKH5SS6oPyjtnzK/XTFDPkNuk= +github.com/multiformats/go-multicodec v0.9.0 h1:pb/dlPnzee/Sxv/j4PmkDRxCOi3hXTz3IbPKOXWJkmg= +github.com/multiformats/go-multicodec v0.9.0/go.mod h1:L3QTQvMIaVBkXOXXtVmYE+LI16i14xuaojr/H7Ai54k= github.com/multiformats/go-multihash v0.2.3 h1:7Lyc8XfX/IY2jWb/gI7JP+o7JEq9hOa7BFvVU9RSh+U= github.com/multiformats/go-multihash v0.2.3/go.mod h1:dXgKXCXjBzdscBLk9JkjINiEsCKRVch90MdaGiKsvSM= +github.com/multiformats/go-multistream v0.5.0 h1:5htLSLl7lvJk3xx3qT/8Zm9J4K8vEOf/QGkvOGQAyiE= +github.com/multiformats/go-multistream v0.5.0/go.mod h1:n6tMZiwiP2wUsR8DgfDWw1dydlEqV3l6N3/GBsX6ILA= github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8= github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/onflow/atree v0.8.0 h1:qg5c6J1gVDNObughpEeWm8oxqhPGdEyGrda121GM4u0= github.com/onflow/atree v0.8.0/go.mod h1:yccR+LR7xc1Jdic0mrjocbHvUD7lnVvg8/Ct1AA5zBo= -github.com/onflow/crypto v0.25.0 h1:BeWbLsh3ZD13Ej+Uky6kg1PL1ZIVBDVX+2MVBNwqddg= -github.com/onflow/crypto v0.25.0/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI= github.com/onflow/crypto v0.25.2 h1:GjHunqVt+vPcdqhxxhAXiMIF3YiLX7gTuTR5O+VG2ns= github.com/onflow/crypto v0.25.2/go.mod h1:fY7eLqUdMKV8EGOw301unP8h7PvLVy8/6gVR++/g0BY= -github.com/onflow/flow v0.3.4 h1:FXUWVdYB90f/rjNcY0Owo30gL790tiYff9Pb/sycXYE= github.com/onflow/flow-core-contracts/lib/go/contracts v1.4.0 h1:R86HaOuk6vpuECZnriEUE7bw9inC2AtdSn8lL/iwQLQ= github.com/onflow/flow-core-contracts/lib/go/contracts v1.4.0/go.mod h1:9asTBnB6Tw2UlVVtQKyS/egYv3xr4zVlJnJ75z1dfac= github.com/onflow/flow-core-contracts/lib/go/templates v1.3.3-0.20241017220455-79fdc6c8ba53 h1:swCMX7k//QjHatAZ3URX4GhfUWmLc6S/tmaw2mS/0ZU= @@ -273,9 +367,13 @@ github.com/onflow/flow/protobuf/go/flow v0.4.7 h1:iP6DFx4wZ3ETORsyeqzHu7neFT3d1C github.com/onflow/flow/protobuf/go/flow v0.4.7/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk= github.com/onflow/go-ethereum v1.14.7 h1:gg3awYqI02e3AypRdpJKEvNTJ6kz/OhAqRti0h54Wlc= github.com/onflow/go-ethereum v1.14.7/go.mod h1:zV14QLrXyYu5ucvcwHUA0r6UaqveqbXaehAVQJlSW+I= +github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0= +github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU= github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek= +github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM= +github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -285,13 +383,21 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= +github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk= +github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= +github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lneoxM= +github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= +github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/psiemens/sconfig v0.1.0 h1:xfWqW+TRpih7mXZIqKYTmpRhlZLQ1kbxV8EjllPv76s= github.com/psiemens/sconfig v0.1.0/go.mod h1:+MLKqdledP/8G3rOBpknbLh0IclCf4WneJUtS26JB2U= @@ -299,18 +405,19 @@ github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= -github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.26.1 h1:/ihwxqH+4z8UxyI70wM1z9yCvkWcfz/a3mj48k/Zngc= -github.com/rs/zerolog v1.26.1/go.mod h1:/wSSJWX7lVrsOwlbyTRSOJvqRlc+WjWlfes+CiJ+tmc= +github.com/rs/zerolog v1.29.0 h1:Zes4hju04hjbvkVkOhdl2HpZa+0PmVwigmo8XoORE5w= github.com/rs/zerolog v1.29.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= +github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/slok/go-http-metrics v0.10.0 h1:rh0LaYEKza5eaYRGDXujKrOln57nHBi4TtVhmNEpbgM= +github.com/slok/go-http-metrics v0.10.0/go.mod h1:lFqdaS4kWMfUKCSukjC47PdCeTk+hXDUVm8kLHRqJ38= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= @@ -372,7 +479,6 @@ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/zeebo/assert v1.1.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0= github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ= @@ -388,15 +494,31 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= -go.opentelemetry.io/otel v1.8.0 h1:zcvBFizPbpa1q7FehvFiHbQwGzmPILebO0tyqIR5Djg= -go.opentelemetry.io/otel v1.8.0/go.mod h1:2pkj+iMj0o03Y+cW6/m8Y4WkRdYN3AvCXCnzRMp9yvM= go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 h1:cl5P5/GIfFh4t6xyruOgJP5QiA1pw4fYYdv6nc6CBWw= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0/go.mod h1:zgBdWWAu7oEEMC06MMKc5NLbA/1YDXV1sMpSqEeLQLg= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0 h1:tIqheXEFWAZ7O8A7m+J0aPTmpJN3YQ7qetUAdkkkKpk= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0/go.mod h1:nUeKExfxAQVbiVFn32YXpXZZHZ61Cc3s3Rn1pDBGAb0= +go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI= +go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco= +go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw= +go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg= +go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI= +go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU= +go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I= +go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/goleak v1.1.10 h1:z+mqJhf6ss6BSfSM671tgKyZBFPTTJM+HLxnhPC3wu0= -go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= +go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= +go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= +go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= +go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= +go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= +go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -406,12 +528,9 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU= -golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= -golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= -golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= +golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= +golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -422,8 +541,6 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= -golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc h1:ao2WRsKSzW6KuUY9IWPwWahcHCgR0s52IfwutMfEbdM= -golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI= golang.org/x/exp v0.0.0-20240119083558-1b970713d09a h1:Q8/wZp0KX97QFTc2ywcOE0YRjZPVIx+MXInMzdvQqcA= golang.org/x/exp v0.0.0-20240119083558-1b970713d09a/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= @@ -437,7 +554,6 @@ golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= @@ -450,10 +566,9 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= -golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -488,9 +603,10 @@ golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -510,8 +626,9 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -552,19 +669,15 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= -golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -576,10 +689,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= -golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= -golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= -golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= +golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -631,19 +742,15 @@ golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= -golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM= -golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU= golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= -gonum.org/v1/gonum v0.6.1 h1:/LSrTrgZtpbXyAR6+0e152SROCkJJSh7goYWVmdPFGc= -gonum.org/v1/gonum v0.6.1/go.mod h1:9mxDZsDKxgMAuccQkewq682L+0eCu4dCN2yonUJTCLU= gonum.org/v1/gonum v0.14.0 h1:2NiG67LD1tEH0D7kM+ps2V+fXmsAnpUeec7n8tcr4S0= gonum.org/v1/gonum v0.14.0/go.mod h1:AoWeoz0becf9QMWtE8iWXNXc27fK4fNeHNf/oMejGfU= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= @@ -710,6 +817,11 @@ google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de h1:F6qOa9AZTYJXOUEr4jDysRDLrm4PHePlge4v4TGAlxY= +google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de h1:jFNzHPIeuzhdRwVhbZdiym9q0ory/xY3sA+v2wPg8I0= +google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:5iCWqnniDlqZHrd3neWVTOwvh/v6s3232omMecelax8= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de h1:cZGRis4/ot9uVm639a+rHCUaG0JJHEsdyzSQTMX+suY= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -727,6 +839,8 @@ google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8= google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM= +google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -742,9 +856,10 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= @@ -752,9 +867,13 @@ gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= +gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= @@ -764,6 +883,8 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9 honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= lukechampine.com/blake3 v1.3.0 h1:sJ3XhFINmHSrYCgl958hscfIa3bw8x4DqMP3u1YvoYE= lukechampine.com/blake3 v1.3.0/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k= +pgregory.net/rapid v1.1.0 h1:CMa0sjHSru3puNx+J0MIAuiiEV4N0qj8/cMWGBBCsjw= +pgregory.net/rapid v1.1.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/types_test.go b/types_test.go index 27f0edd4c9..45412ae7c5 100644 --- a/types_test.go +++ b/types_test.go @@ -26,7 +26,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestType_ID(t *testing.T) { @@ -85,7 +85,7 @@ func TestType_ID(t *testing.T) { }, { &StructType{ - Location: utils.TestLocation, + Location: TestLocation, QualifiedIdentifier: "Foo", }, "S.test.Foo", @@ -98,7 +98,7 @@ func TestType_ID(t *testing.T) { }, { &StructInterfaceType{ - Location: utils.TestLocation, + Location: TestLocation, QualifiedIdentifier: "FooI", }, "S.test.FooI", @@ -111,7 +111,7 @@ func TestType_ID(t *testing.T) { }, { &ResourceType{ - Location: utils.TestLocation, + Location: TestLocation, QualifiedIdentifier: "Bar", }, "S.test.Bar", @@ -124,7 +124,7 @@ func TestType_ID(t *testing.T) { }, { &ResourceInterfaceType{ - Location: utils.TestLocation, + Location: TestLocation, QualifiedIdentifier: "BarI", }, "S.test.BarI", @@ -133,7 +133,7 @@ func TestType_ID(t *testing.T) { &IntersectionType{ Types: []Type{ &ResourceInterfaceType{ - Location: utils.TestLocation, + Location: TestLocation, QualifiedIdentifier: "FooI", }, }, @@ -167,7 +167,7 @@ func TestType_ID(t *testing.T) { }, { &EventType{ - Location: utils.TestLocation, + Location: TestLocation, QualifiedIdentifier: "Event", }, "S.test.Event", @@ -180,7 +180,7 @@ func TestType_ID(t *testing.T) { }, { &EnumType{ - Location: utils.TestLocation, + Location: TestLocation, QualifiedIdentifier: "Enum", }, "S.test.Enum", @@ -193,7 +193,7 @@ func TestType_ID(t *testing.T) { }, { &ContractType{ - Location: utils.TestLocation, + Location: TestLocation, QualifiedIdentifier: "Contract", }, "S.test.Contract", @@ -206,7 +206,7 @@ func TestType_ID(t *testing.T) { }, { &ContractInterfaceType{ - Location: utils.TestLocation, + Location: TestLocation, QualifiedIdentifier: "ContractI", }, "S.test.ContractI", @@ -2287,7 +2287,7 @@ func TestDecodeFields(t *testing.T) { NewStruct([]Value{ NewInt(42), }).WithType(NewStructType( - utils.TestLocation, + TestLocation, "NestedStruct", []Field{ { @@ -2299,7 +2299,7 @@ func TestDecodeFields(t *testing.T) { )), }, ).WithType(NewEventType( - utils.TestLocation, + TestLocation, "SimpleEvent", []Field{ { diff --git a/values_test.go b/values_test.go index d70200a911..ac5ea3b067 100644 --- a/values_test.go +++ b/values_test.go @@ -29,7 +29,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) type valueTestCase struct { @@ -242,7 +242,7 @@ func newValueTestCases() map[string]valueTestCase { "struct": { value: NewStruct([]Value{String("bar")}), exampleType: NewStructType( - utils.TestLocation, + TestLocation, "FooStruct", []Field{ { @@ -260,7 +260,7 @@ func newValueTestCases() map[string]valueTestCase { "resource": { value: NewResource([]Value{NewInt(1)}), exampleType: NewResourceType( - utils.TestLocation, + TestLocation, "FooResource", []Field{ { @@ -283,7 +283,7 @@ func newValueTestCases() map[string]valueTestCase { }, ), exampleType: NewEventType( - utils.TestLocation, + TestLocation, "FooEvent", []Field{ { @@ -305,7 +305,7 @@ func newValueTestCases() map[string]valueTestCase { "contract": { value: NewContract([]Value{String("bar")}), exampleType: NewContractType( - utils.TestLocation, + TestLocation, "FooContract", []Field{ { @@ -323,7 +323,7 @@ func newValueTestCases() map[string]valueTestCase { "enum": { value: NewEnum([]Value{UInt8(1)}), exampleType: NewEnumType( - utils.TestLocation, + TestLocation, "FooEnum", nil, []Field{ @@ -342,7 +342,7 @@ func newValueTestCases() map[string]valueTestCase { "attachment": { value: NewAttachment([]Value{NewInt(1)}), exampleType: NewAttachmentType( - utils.TestLocation, + TestLocation, "FooAttachment", nil, []Field{ @@ -960,7 +960,7 @@ func TestEvent_GetFieldByName(t *testing.T) { assert.Nil(t, SearchFieldByName(simpleEvent, "a")) simpleEventWithType := simpleEvent.WithType(NewEventType( - utils.TestLocation, + TestLocation, "SimpleEvent", []Field{ { diff --git a/version.go b/version.go index e72ee43566..5052b1647e 100644 --- a/version.go +++ b/version.go @@ -21,4 +21,4 @@ package cadence -const Version = "v1.2.1" +const Version = "v1.2.2"