From d0783263f5ea99bf77398b031529be4d85e8d7ea Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Wed, 18 Sep 2024 11:08:02 -0400 Subject: [PATCH 01/70] Modify lexer to support modes for string templates. --- runtime/parser/lexer/lexer.go | 15 ++++ runtime/parser/lexer/lexer_test.go | 114 +++++++++++++++++++++++++++++ runtime/parser/lexer/state.go | 10 +++ runtime/parser/lexer/tokentype.go | 3 + 4 files changed, 142 insertions(+) diff --git a/runtime/parser/lexer/lexer.go b/runtime/parser/lexer/lexer.go index 7b69245ce2..5e9caf2f79 100644 --- a/runtime/parser/lexer/lexer.go +++ b/runtime/parser/lexer/lexer.go @@ -49,6 +49,14 @@ type position struct { column int } +type LexerMode int + +const ( + NORMAL = iota + STR_IDENTIFIER + STR_EXPRESSION +) + type lexer struct { // memoryGauge is used for metering memory usage memoryGauge common.MemoryGauge @@ -74,6 +82,8 @@ type lexer struct { prev rune // canBackup indicates whether stepping back is allowed canBackup bool + // lexer mode is used for string templates + mode LexerMode } var _ TokenStream = &lexer{} @@ -414,6 +424,11 @@ func (l *lexer) scanString(quote rune) { l.backupOne() return } + case '$': + // string template, stop and set mode + l.backupOne() + l.mode = STR_IDENTIFIER + return } r = l.next() } diff --git a/runtime/parser/lexer/lexer_test.go b/runtime/parser/lexer/lexer_test.go index 51f8f53f34..4206edd22e 100644 --- a/runtime/parser/lexer/lexer_test.go +++ b/runtime/parser/lexer/lexer_test.go @@ -1014,6 +1014,120 @@ 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: 1, Offset: 1}, + }, + }, + Source: `$`, + }, + { + Token: Token{ + Type: TokenIdentifier, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 2, Offset: 2}, + EndPos: ast.Position{Line: 1, Column: 4, Offset: 4}, + }, + }, + Source: `abc`, + }, + { + Token: Token{ + Type: TokenString, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 5, Offset: 5}, + EndPos: ast.Position{Line: 1, Column: 12, Offset: 12}, + }, + }, + Source: `.length"`, + }, + { + Token: Token{ + Type: TokenEOF, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 13, Offset: 13}, + EndPos: ast.Position{Line: 1, Column: 13, Offset: 13}, + }, + }, + }, + }, + ) + }) + + t.Run("invalid, string template", func(t *testing.T) { + testLex(t, + `"$1"`, + []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: 1, Offset: 1}, + }, + }, + Source: `$`, + }, + { + Token: Token{ + Type: TokenDecimalIntegerLiteral, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 2, Offset: 2}, + EndPos: ast.Position{Line: 1, Column: 2, Offset: 2}, + }, + }, + Source: `1`, + }, + { + Token: Token{ + Type: TokenString, + 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: TokenEOF, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 4, Offset: 4}, + EndPos: ast.Position{Line: 1, Column: 4, Offset: 4}, + }, + }, + }, + }, + ) + }) + t.Run("invalid, empty, not terminated at line end", func(t *testing.T) { testLex(t, "\"\n", diff --git a/runtime/parser/lexer/state.go b/runtime/parser/lexer/state.go index 4b252d6f09..7e9561ba32 100644 --- a/runtime/parser/lexer/state.go +++ b/runtime/parser/lexer/state.go @@ -40,6 +40,12 @@ func rootState(l *lexer) stateFn { switch r { case EOF: return nil + case '$': + if l.mode == STR_EXPRESSION || l.mode == STR_IDENTIFIER { + l.emitType(TokenStringTemplate) + } else { + return l.error(fmt.Errorf("unrecognized character: %#U", r)) + } case '+': l.emitType(TokenPlus) case '-': @@ -296,6 +302,10 @@ func identifierState(l *lexer) stateFn { } } l.emitType(TokenIdentifier) + if l.mode == STR_IDENTIFIER { + l.mode = NORMAL + return stringState + } return rootState } diff --git a/runtime/parser/lexer/tokentype.go b/runtime/parser/lexer/tokentype.go index 0a15c19b6f..a7b3cb2f92 100644 --- a/runtime/parser/lexer/tokentype.go +++ b/runtime/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()) } From 7ebe45bee7b77f940b46920a39bbe9f864f6e404 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Wed, 18 Sep 2024 12:53:33 -0400 Subject: [PATCH 02/70] Add parsing support for string templates. --- runtime/ast/expression.go | 57 ++++++++++++++++ runtime/ast/precedence.go | 1 + runtime/parser/expression.go | 106 ++++++++++++++++++++++++++---- runtime/parser/expression_test.go | 64 ++++++++++++++++++ 4 files changed, 215 insertions(+), 13 deletions(-) diff --git a/runtime/ast/expression.go b/runtime/ast/expression.go index 0142b92b20..800cf44668 100644 --- a/runtime/ast/expression.go +++ b/runtime/ast/expression.go @@ -220,6 +220,63 @@ func (*StringExpression) precedence() precedence { return precedenceLiteral } +// StringTemplateExpression + +type StringTemplateExpression struct { + Values []string + Expressions []Expression + Range +} + +var _ Expression = &StringTemplateExpression{} + +func NewStringTemplateExpression(gauge common.MemoryGauge, values []string, exprs []Expression, exprRange Range) *StringTemplateExpression { + common.UseMemory(gauge, common.StringExpressionMemoryUsage) + return &StringTemplateExpression{ + Values: values, + Expressions: exprs, + Range: exprRange, + } +} + +var _ Element = &StringExpression{} +var _ Expression = &StringExpression{} + +func (*StringTemplateExpression) ElementType() ElementType { + return ElementTypeStringExpression +} + +func (*StringTemplateExpression) isExpression() {} + +func (*StringTemplateExpression) isIfStatementTest() {} + +func (*StringTemplateExpression) Walk(_ func(Element)) { + // NO-OP +} + +func (e *StringTemplateExpression) String() string { + return Prettier(e) +} + +func (e *StringTemplateExpression) Doc() prettier.Doc { + return prettier.Text(QuoteString("String template")) +} + +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 { diff --git a/runtime/ast/precedence.go b/runtime/ast/precedence.go index 3e42f6a8f1..fcc78d259f 100644 --- a/runtime/ast/precedence.go +++ b/runtime/ast/precedence.go @@ -83,6 +83,7 @@ const ( // - BoolExpression // - NilExpression // - StringExpression + // - StringTemplateExpression // - IntegerExpression // - FixedPointExpression // - ArrayExpression diff --git a/runtime/parser/expression.go b/runtime/parser/expression.go index 41f44df7a7..0cf9186704 100644 --- a/runtime/parser/expression.go +++ b/runtime/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,98 @@ 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 + + // early check for start " of string literal because of string templates + 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 late end " check + missingEnd := true + + for curToken.Is(lexer.TokenString) { + literal = p.tokenSource(curToken) + length = len(literal) + + if length >= 1 && literal[0] == '"' { + 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) { + p.next() + // advance to the expression + value, err := parseExpression(p, lowestBindingPower) + 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 + } + } + + // late check for end " of string literal because of string templates + 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/runtime/parser/expression_test.go b/runtime/parser/expression_test.go index eb8b348c45..9f12f47cec 100644 --- a/runtime/parser/expression_test.go +++ b/runtime/parser/expression_test.go @@ -6055,6 +6055,70 @@ func TestParseStringWithUnicode(t *testing.T) { utils.AssertEqualWithDiff(t, expected, actual) } +func TestParseStringTemplates(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: 24, Line: 2, Column: 23}, + }, + }, + &ast.IdentifierExpression{ + Identifier: ast.Identifier{ + Identifier: "def", + Pos: ast.Position{Offset: 29, Line: 2, Column: 28}, + }, + }, + }, + Range: ast.Range{ + StartPos: ast.Position{Offset: 7, Line: 2, Column: 6}, + EndPos: ast.Position{Offset: 37, Line: 2, Column: 36}, + }, + } + + utils.AssertEqualWithDiff(t, expected, actual) +} + +func TestParseStringTemplateFail(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) +} + func TestParseNilCoalescing(t *testing.T) { t.Parallel() From 0795b4c02b55b5eb59e5b7fbedb64367750f4319 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Wed, 18 Sep 2024 15:58:10 -0400 Subject: [PATCH 03/70] Checking and interpreting for string templates. --- runtime/ast/elementtype.go | 1 + runtime/ast/expression.go | 2 +- runtime/ast/expression_extractor.go | 84 +++++++++++++------ runtime/ast/visitor.go | 4 + runtime/interpreter/interpreter_expression.go | 28 +++++++ runtime/parser/expression.go | 11 +-- runtime/parser/expression_test.go | 41 ++++++++- .../sema/check_string_template_expression.go | 52 ++++++++++++ runtime/sema/elaboration.go | 20 +++++ runtime/tests/checker/string_test.go | 42 ++++++++++ 10 files changed, 253 insertions(+), 32 deletions(-) create mode 100644 runtime/sema/check_string_template_expression.go diff --git a/runtime/ast/elementtype.go b/runtime/ast/elementtype.go index 1ceee39f3e..2369cf5080 100644 --- a/runtime/ast/elementtype.go +++ b/runtime/ast/elementtype.go @@ -85,4 +85,5 @@ const ( ElementTypeForceExpression ElementTypePathExpression ElementTypeAttachExpression + ElementTypeStringTemplateExpression ) diff --git a/runtime/ast/expression.go b/runtime/ast/expression.go index 800cf44668..2e2ee2f7f2 100644 --- a/runtime/ast/expression.go +++ b/runtime/ast/expression.go @@ -243,7 +243,7 @@ var _ Element = &StringExpression{} var _ Expression = &StringExpression{} func (*StringTemplateExpression) ElementType() ElementType { - return ElementTypeStringExpression + return ElementTypeStringTemplateExpression } func (*StringTemplateExpression) isExpression() {} diff --git a/runtime/ast/expression_extractor.go b/runtime/ast/expression_extractor.go index 777dc8e4d3..4039b0370b 100644 --- a/runtime/ast/expression_extractor.go +++ b/runtime/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/runtime/ast/visitor.go b/runtime/ast/visitor.go index c18fdd797f..a2fea22db0 100644 --- a/runtime/ast/visitor.go +++ b/runtime/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/runtime/interpreter/interpreter_expression.go b/runtime/interpreter/interpreter_expression.go index d2894749bf..4d25ab9c11 100644 --- a/runtime/interpreter/interpreter_expression.go +++ b/runtime/interpreter/interpreter_expression.go @@ -957,6 +957,34 @@ func (interpreter *Interpreter) VisitStringExpression(expression *ast.StringExpr return NewUnmeteredStringValue(expression.Value) } +func (interpreter *Interpreter) VisitStringTemplateExpression(expression *ast.StringTemplateExpression) Value { + values := interpreter.visitExpressionsNonCopying(expression.Expressions) + + templateExpressionTypes := interpreter.Program.Elaboration.StringTemplateExpressionTypes(expression) + argumentTypes := templateExpressionTypes.ArgumentTypes + + var copies []Value + + count := len(values) + if count > 0 { + copies = make([]Value, count) + for i, argument := range values { + argumentType := argumentTypes[i] + argumentExpression := expression.Expressions[i] + locationRange := LocationRange{ + Location: interpreter.Location, + HasPosition: argumentExpression, + } + copies[i] = interpreter.transferAndConvert(argument, argumentType, sema.StringType, locationRange) + } + } + + result := "" + + // NOTE: already metered in lexer/parser + return NewUnmeteredStringValue(result) +} + func (interpreter *Interpreter) VisitArrayExpression(expression *ast.ArrayExpression) Value { values := interpreter.visitExpressionsNonCopying(expression.Values) diff --git a/runtime/parser/expression.go b/runtime/parser/expression.go index 0cf9186704..45290a3093 100644 --- a/runtime/parser/expression.go +++ b/runtime/parser/expression.go @@ -1167,16 +1167,17 @@ func defineStringExpression() { literal = p.tokenSource(curToken) length = len(literal) - if length >= 1 && literal[0] == '"' { - literal = literal[1:] - length = len(literal) - } - + // this order of removal matters in case the token is the single quotation " if length >= 1 && literal[length-1] == '"' { literal = literal[:length-1] + length = len(literal) missingEnd = false } + if length >= 1 && literal[0] == '"' { + literal = literal[1:] + } + parsedString := parseStringLiteralContent(p, literal) literals = append(literals, parsedString) endToken = curToken diff --git a/runtime/parser/expression_test.go b/runtime/parser/expression_test.go index 9f12f47cec..95ea2cb792 100644 --- a/runtime/parser/expression_test.go +++ b/runtime/parser/expression_test.go @@ -6055,7 +6055,46 @@ func TestParseStringWithUnicode(t *testing.T) { utils.AssertEqualWithDiff(t, expected, actual) } -func TestParseStringTemplates(t *testing.T) { +func TestParseStringTemplateSimple(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: 9, Line: 2, Column: 8}, + }, + }, + }, + Range: ast.Range{ + StartPos: ast.Position{Offset: 7, Line: 2, Column: 6}, + EndPos: ast.Position{Offset: 13, Line: 2, Column: 12}, + }, + } + + utils.AssertEqualWithDiff(t, expected, actual) +} + +func TestParseStringTemplateMulti(t *testing.T) { t.Parallel() diff --git a/runtime/sema/check_string_template_expression.go b/runtime/sema/check_string_template_expression.go new file mode 100644 index 0000000000..276b8c0f14 --- /dev/null +++ b/runtime/sema/check_string_template_expression.go @@ -0,0 +1,52 @@ +/* + * 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/runtime/ast" + +func (checker *Checker) VisitStringTemplateExpression(stringTemplateExpression *ast.StringTemplateExpression) Type { + + // visit all elements + + var elementType Type + + elementCount := len(stringTemplateExpression.Expressions) + + var argumentTypes []Type + if elementCount > 0 { + argumentTypes = make([]Type, elementCount) + + for i, element := range stringTemplateExpression.Expressions { + valueType := checker.VisitExpression(element, stringTemplateExpression, elementType) + + argumentTypes[i] = valueType + + checker.checkResourceMoveOperation(element, valueType) + } + } + + checker.Elaboration.SetStringTemplateExpressionTypes( + stringTemplateExpression, + StringTemplateExpressionTypes{ + ArgumentTypes: argumentTypes, + }, + ) + + return StringType +} diff --git a/runtime/sema/elaboration.go b/runtime/sema/elaboration.go index b6b025eef0..d2ef948a78 100644 --- a/runtime/sema/elaboration.go +++ b/runtime/sema/elaboration.go @@ -79,6 +79,10 @@ type ArrayExpressionTypes struct { ArgumentTypes []Type } +type StringTemplateExpressionTypes struct { + ArgumentTypes []Type +} + type DictionaryExpressionTypes struct { DictionaryType *DictionaryType EntryTypes []DictionaryEntryType @@ -140,6 +144,7 @@ type Elaboration struct { dictionaryExpressionTypes map[*ast.DictionaryExpression]DictionaryExpressionTypes integerExpressionTypes map[*ast.IntegerExpression]Type stringExpressionTypes map[*ast.StringExpression]Type + stringTemplateExpressionTypes map[*ast.StringTemplateExpression]StringTemplateExpressionTypes returnStatementTypes map[*ast.ReturnStatement]ReturnStatementTypes functionDeclarationFunctionTypes map[*ast.FunctionDeclaration]*FunctionType variableDeclarationTypes map[*ast.VariableDeclaration]VariableDeclarationTypes @@ -480,6 +485,21 @@ func (e *Elaboration) SetStringExpressionType(expression *ast.StringExpression, e.stringExpressionTypes[expression] = ty } +func (e *Elaboration) StringTemplateExpressionTypes(expression *ast.StringTemplateExpression) (types StringTemplateExpressionTypes) { + if e.stringTemplateExpressionTypes == nil { + return + } + // default, Elaboration.SetStringExpressionType + return e.stringTemplateExpressionTypes[expression] +} + +func (e *Elaboration) SetStringTemplateExpressionTypes(expression *ast.StringTemplateExpression, types StringTemplateExpressionTypes) { + if e.stringTemplateExpressionTypes == nil { + e.stringTemplateExpressionTypes = map[*ast.StringTemplateExpression]StringTemplateExpressionTypes{} + } + e.stringTemplateExpressionTypes[expression] = types +} + func (e *Elaboration) ReturnStatementTypes(statement *ast.ReturnStatement) (types ReturnStatementTypes) { if e.returnStatementTypes == nil { return diff --git a/runtime/tests/checker/string_test.go b/runtime/tests/checker/string_test.go index d857185350..de16b37bcc 100644 --- a/runtime/tests/checker/string_test.go +++ b/runtime/tests/checker/string_test.go @@ -697,3 +697,45 @@ 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, missing variable", func(t *testing.T) { + + t.Parallel() + + _, err := ParseAndCheck(t, ` + let x: String = "$a" + `) + + errs := RequireCheckerErrors(t, err, 1) + + assert.IsType(t, &sema.NotDeclaredError{}, errs[0]) + }) +} From 32f1c1d734adfd3ea7b4201933155c84cd305ba1 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Thu, 19 Sep 2024 11:13:05 -0400 Subject: [PATCH 04/70] Interpret string templates with basic tests --- runtime/ast/expression.go | 1 + runtime/interpreter/interpreter_expression.go | 38 ++++++------ runtime/tests/interpreter/interpreter_test.go | 61 +++++++++++++++++++ 3 files changed, 81 insertions(+), 19 deletions(-) diff --git a/runtime/ast/expression.go b/runtime/ast/expression.go index 2e2ee2f7f2..2efc783155 100644 --- a/runtime/ast/expression.go +++ b/runtime/ast/expression.go @@ -231,6 +231,7 @@ type StringTemplateExpression struct { var _ Expression = &StringTemplateExpression{} func NewStringTemplateExpression(gauge common.MemoryGauge, values []string, exprs []Expression, exprRange Range) *StringTemplateExpression { + // STRINGTODO: change to be similar to array memory usage? common.UseMemory(gauge, common.StringExpressionMemoryUsage) return &StringTemplateExpression{ Values: values, diff --git a/runtime/interpreter/interpreter_expression.go b/runtime/interpreter/interpreter_expression.go index 4d25ab9c11..264b39edf8 100644 --- a/runtime/interpreter/interpreter_expression.go +++ b/runtime/interpreter/interpreter_expression.go @@ -20,6 +20,7 @@ package interpreter import ( "math/big" + "strings" "time" "github.com/onflow/atree" @@ -960,29 +961,28 @@ func (interpreter *Interpreter) VisitStringExpression(expression *ast.StringExpr func (interpreter *Interpreter) VisitStringTemplateExpression(expression *ast.StringTemplateExpression) Value { values := interpreter.visitExpressionsNonCopying(expression.Expressions) - templateExpressionTypes := interpreter.Program.Elaboration.StringTemplateExpressionTypes(expression) - argumentTypes := templateExpressionTypes.ArgumentTypes - - var copies []Value - - count := len(values) - if count > 0 { - copies = make([]Value, count) - for i, argument := range values { - argumentType := argumentTypes[i] - argumentExpression := expression.Expressions[i] - locationRange := LocationRange{ - Location: interpreter.Location, - HasPosition: argumentExpression, + templatesType := interpreter.Program.Elaboration.StringTemplateExpressionTypes(expression) + argumentTypes := templatesType.ArgumentTypes + + var builder strings.Builder + for i, str := range expression.Values { + builder.WriteString(str) + if i < len(values) { + // STRINGTODO: is this how the conversion should happen? + s := values[i].String() + switch argumentTypes[i] { + case sema.StringType: + // remove quotations + s = s[1 : len(s)-1] + builder.WriteString(s) + default: + builder.WriteString(s) } - copies[i] = interpreter.transferAndConvert(argument, argumentType, sema.StringType, locationRange) } } - result := "" - - // NOTE: already metered in lexer/parser - return NewUnmeteredStringValue(result) + // STRINGTODO: already metered as a string constant in parser? + return NewUnmeteredStringValue(builder.String()) } func (interpreter *Interpreter) VisitArrayExpression(expression *ast.ArrayExpression) Value { diff --git a/runtime/tests/interpreter/interpreter_test.go b/runtime/tests/interpreter/interpreter_test.go index f525e8d6ff..86e89ac73b 100644 --- a/runtime/tests/interpreter/interpreter_test.go +++ b/runtime/tests/interpreter/interpreter_test.go @@ -12283,3 +12283,64 @@ 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), + ) + }) +} From 6a36212d1a3f71280eb15684fb2f66d623fa5db1 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Thu, 19 Sep 2024 11:34:12 -0400 Subject: [PATCH 05/70] Add placeholder for compiler linting. --- runtime/compiler/compiler.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/runtime/compiler/compiler.go b/runtime/compiler/compiler.go index 342333adaa..6e052f4a17 100644 --- a/runtime/compiler/compiler.go +++ b/runtime/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{ From d90bbf689b8f88367180088fc3c0ce9a5cb58270 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Thu, 19 Sep 2024 11:54:20 -0400 Subject: [PATCH 06/70] Fix parsing of invalid strings. --- runtime/parser/expression.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/runtime/parser/expression.go b/runtime/parser/expression.go index 45290a3093..e3b6bfface 100644 --- a/runtime/parser/expression.go +++ b/runtime/parser/expression.go @@ -1167,15 +1167,14 @@ func defineStringExpression() { literal = p.tokenSource(curToken) length = len(literal) - // this order of removal matters in case the token is the single quotation " - if length >= 1 && literal[length-1] == '"' { - literal = literal[:length-1] + if curToken == startToken { + literal = literal[1:] length = len(literal) - missingEnd = false } - if length >= 1 && literal[0] == '"' { - literal = literal[1:] + if length >= 1 && literal[length-1] == '"' { + literal = literal[:length-1] + missingEnd = false } parsedString := parseStringLiteralContent(p, literal) From 81c300460114580adaaaec9eb4aaf82c95236f96 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Thu, 19 Sep 2024 12:38:39 -0400 Subject: [PATCH 07/70] Run stringer to update elementtype file. --- runtime/ast/elementtype_string.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/runtime/ast/elementtype_string.go b/runtime/ast/elementtype_string.go index 9f2e36d996..07044923bb 100644 --- a/runtime/ast/elementtype_string.go +++ b/runtime/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) { From 99f4ae46cc3371e7f82561062de8d8113ea4f78f Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Fri, 20 Sep 2024 13:59:56 -0400 Subject: [PATCH 08/70] Improve error messages and tests --- runtime/parser/expression.go | 3 + runtime/parser/expression_test.go | 214 ++++++++++++------ runtime/parser/lexer/lexer_test.go | 146 +++++++++++- runtime/tests/checker/string_test.go | 14 ++ runtime/tests/interpreter/interpreter_test.go | 55 +++++ 5 files changed, 358 insertions(+), 74 deletions(-) diff --git a/runtime/parser/expression.go b/runtime/parser/expression.go index e3b6bfface..01d9dba5d1 100644 --- a/runtime/parser/expression.go +++ b/runtime/parser/expression.go @@ -1186,6 +1186,9 @@ func defineStringExpression() { if curToken.Is(lexer.TokenStringTemplate) { p.next() // advance to the expression + if !p.current.Is(lexer.TokenIdentifier) { + return nil, p.syntaxError("expected an identifier got: %s", p.currentTokenSource()) + } value, err := parseExpression(p, lowestBindingPower) if err != nil { return nil, err diff --git a/runtime/parser/expression_test.go b/runtime/parser/expression_test.go index 95ea2cb792..dabaff5057 100644 --- a/runtime/parser/expression_test.go +++ b/runtime/parser/expression_test.go @@ -6055,107 +6055,175 @@ func TestParseStringWithUnicode(t *testing.T) { utils.AssertEqualWithDiff(t, expected, actual) } -func TestParseStringTemplateSimple(t *testing.T) { +func TestParseStringTemplate(t *testing.T) { t.Parallel() - actual, errs := testParseExpression(` - "$test" - `) + t.Run("simple", func(t *testing.T) { - var err error - if len(errs) > 0 { - err = Error{ - Errors: errs, + t.Parallel() + + actual, errs := testParseExpression(` + "$test" + `) + + var err error + if len(errs) > 0 { + err = Error{ + Errors: errs, + } } - } - require.NoError(t, err) + require.NoError(t, err) - expected := &ast.StringTemplateExpression{ - Values: []string{ - "", - "", - }, - Expressions: []ast.Expression{ - &ast.IdentifierExpression{ - Identifier: ast.Identifier{ - Identifier: "test", - Pos: ast.Position{Offset: 9, Line: 2, Column: 8}, + expected := &ast.StringTemplateExpression{ + Values: []string{ + "", + "", + }, + Expressions: []ast.Expression{ + &ast.IdentifierExpression{ + Identifier: ast.Identifier{ + Identifier: "test", + Pos: ast.Position{Offset: 5, Line: 2, Column: 4}, + }, }, }, - }, - Range: ast.Range{ - StartPos: ast.Position{Offset: 7, Line: 2, Column: 6}, - EndPos: ast.Position{Offset: 13, Line: 2, Column: 12}, - }, - } + Range: ast.Range{ + StartPos: ast.Position{Offset: 3, Line: 2, Column: 2}, + EndPos: ast.Position{Offset: 9, Line: 2, Column: 8}, + }, + } - utils.AssertEqualWithDiff(t, expected, actual) -} + utils.AssertEqualWithDiff(t, expected, actual) + }) -func TestParseStringTemplateMulti(t *testing.T) { + t.Run("multi", func(t *testing.T) { - t.Parallel() + t.Parallel() - actual, errs := testParseExpression(` - "this is a test $abc $def test" - `) + actual, errs := testParseExpression(` + "this is a test $abc$def test" + `) - var err error - if len(errs) > 0 { - err = Error{ - Errors: errs, + var err error + if len(errs) > 0 { + err = Error{ + Errors: errs, + } } - } - require.NoError(t, err) + 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: 24, Line: 2, Column: 23}, + expected := &ast.StringTemplateExpression{ + Values: []string{ + "this is a test ", + "", + " test", + }, + Expressions: []ast.Expression{ + &ast.IdentifierExpression{ + Identifier: ast.Identifier{ + Identifier: "abc", + Pos: ast.Position{Offset: 20, Line: 2, Column: 19}, + }, + }, + &ast.IdentifierExpression{ + Identifier: ast.Identifier{ + Identifier: "def", + Pos: ast.Position{Offset: 24, Line: 2, Column: 24}, + }, }, }, - &ast.IdentifierExpression{ - Identifier: ast.Identifier{ - Identifier: "def", - Pos: ast.Position{Offset: 29, Line: 2, Column: 28}, + Range: ast.Range{ + StartPos: ast.Position{Offset: 3, Line: 2, Column: 2}, + EndPos: ast.Position{Offset: 32, Line: 2, Column: 32}, + }, + } + + utils.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) + utils.AssertEqualWithDiff(t, + []error{ + &SyntaxError{ + Message: "invalid end of string literal: missing '\"'", + Pos: ast.Position{Offset: 25, Line: 2, Column: 25}, }, }, - }, - Range: ast.Range{ - StartPos: ast.Position{Offset: 7, Line: 2, Column: 6}, - EndPos: ast.Position{Offset: 37, Line: 2, Column: 36}, - }, - } + errs, + ) + }) - utils.AssertEqualWithDiff(t, expected, actual) -} + t.Run("invalid identifier", func(t *testing.T) { -func TestParseStringTemplateFail(t *testing.T) { + t.Parallel() - t.Parallel() + _, errs := testParseExpression(` + "$$" + `) - _, errs := testParseExpression(` - "this is a test $FOO - `) + var err error + if len(errs) > 0 { + err = Error{ + Errors: errs, + } + } - var err error - if len(errs) > 0 { - err = Error{ - Errors: errs, + require.Error(t, err) + utils.AssertEqualWithDiff(t, + []error{ + &SyntaxError{ + Message: "expected an identifier got: $", + Pos: ast.Position{Offset: 7, Line: 2, Column: 6}, + }, + }, + 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) + require.Error(t, err) + utils.AssertEqualWithDiff(t, + []error{ + &SyntaxError{ + Message: "expected an identifier got: (", + Pos: ast.Position{Offset: 7, Line: 2, Column: 6}, + }, + }, + errs, + ) + }) } func TestParseNilCoalescing(t *testing.T) { diff --git a/runtime/parser/lexer/lexer_test.go b/runtime/parser/lexer/lexer_test.go index 4206edd22e..643f57e902 100644 --- a/runtime/parser/lexer/lexer_test.go +++ b/runtime/parser/lexer/lexer_test.go @@ -1071,7 +1071,7 @@ func TestLexString(t *testing.T) { ) }) - t.Run("invalid, string template", func(t *testing.T) { + t.Run("invalid, number string template", func(t *testing.T) { testLex(t, `"$1"`, []token{ @@ -1128,6 +1128,150 @@ func TestLexString(t *testing.T) { ) }) + t.Run("invalid, 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: 1, Offset: 1}, + }, + }, + Source: `$`, + }, + { + Token: Token{ + Type: TokenIdentifier, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 2, Offset: 2}, + EndPos: ast.Position{Line: 1, Column: 2, Offset: 2}, + }, + }, + Source: `a`, + }, + { + Token: Token{ + Type: TokenString, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 3, Offset: 3}, + EndPos: ast.Position{Line: 1, Column: 6, Offset: 6}, + }, + }, + Source: ` + 2`, + }, + { + Token: Token{ + Type: TokenEOF, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 7, Offset: 7}, + EndPos: ast.Position{Line: 1, Column: 7, Offset: 7}, + }, + }, + }, + }, + ) + }) + + 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: 1, Offset: 1}, + }, + }, + Source: `$`, + }, + { + Token: Token{ + Type: TokenIdentifier, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 2, Offset: 2}, + EndPos: ast.Position{Line: 1, Column: 2, Offset: 2}, + }, + }, + Source: `a`, + }, + { + Token: Token{ + Type: TokenString, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 3, Offset: 3}, + EndPos: ast.Position{Line: 1, Column: 3, Offset: 2}, + }, + }, + Source: ``, + }, + { + Token: Token{ + Type: TokenStringTemplate, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 4, Offset: 3}, + EndPos: ast.Position{Line: 1, Column: 4, Offset: 3}, + }, + }, + Source: `$`, + }, + { + Token: Token{ + Type: TokenIdentifier, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 5, Offset: 4}, + EndPos: ast.Position{Line: 1, Column: 5, Offset: 4}, + }, + }, + Source: `b`, + }, + { + Token: Token{ + Type: TokenString, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 6, Offset: 5}, + EndPos: ast.Position{Line: 1, Column: 6, Offset: 5}, + }, + }, + Source: `"`, + }, + { + Token: Token{ + Type: TokenEOF, + Range: ast.Range{ + StartPos: ast.Position{Line: 1, Column: 7, Offset: 6}, + EndPos: ast.Position{Line: 1, Column: 7, Offset: 6}, + }, + }, + }, + }, + ) + }) + t.Run("invalid, empty, not terminated at line end", func(t *testing.T) { testLex(t, "\"\n", diff --git a/runtime/tests/checker/string_test.go b/runtime/tests/checker/string_test.go index de16b37bcc..ee2609758f 100644 --- a/runtime/tests/checker/string_test.go +++ b/runtime/tests/checker/string_test.go @@ -726,6 +726,20 @@ func TestCheckStringTemplate(t *testing.T) { require.NoError(t, err) }) + t.Run("valid, struct", func(t *testing.T) { + + t.Parallel() + + _, err := ParseAndCheck(t, ` + access(all) + struct SomeStruct {} + let a = SomeStruct() + let x: String = "$a" + `) + + require.NoError(t, err) + }) + t.Run("invalid, missing variable", func(t *testing.T) { t.Parallel() diff --git a/runtime/tests/interpreter/interpreter_test.go b/runtime/tests/interpreter/interpreter_test.go index 86e89ac73b..3669f17960 100644 --- a/runtime/tests/interpreter/interpreter_test.go +++ b/runtime/tests/interpreter/interpreter_test.go @@ -12343,4 +12343,59 @@ func TestInterpretStringTemplates(t *testing.T) { inter.Globals.Get("z").GetValue(inter), ) }) + + t.Run("struct", func(t *testing.T) { + t.Parallel() + + inter := parseCheckAndInterpret(t, ` + access(all) + struct SomeStruct {} + let a = SomeStruct() + let x: String = "$a" + `) + + AssertValuesEqual( + t, + inter, + interpreter.NewUnmeteredStringValue("S.test.SomeStruct()"), + inter.Globals.Get("x").GetValue(inter), + ) + }) + + t.Run("func", func(t *testing.T) { + t.Parallel() + + inter := parseCheckAndInterpret(t, ` + let add = fun(): Int { + return 2+2 + } + let x: String = "$add()" + `) + + AssertValuesEqual( + t, + inter, + interpreter.NewUnmeteredStringValue("fun(): Int()"), + inter.Globals.Get("x").GetValue(inter), + ) + }) + + t.Run("func", 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), + ) + }) } From cfa540ecd8299df8190919ae76669b6361353473 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Mon, 23 Sep 2024 12:07:45 -0400 Subject: [PATCH 09/70] Allow escaping of string template $ and add tests. --- runtime/parser/expression.go | 2 ++ runtime/parser/expression_test.go | 28 +++++++++++++++++++ runtime/parser/lexer/lexer_test.go | 27 ++++++++++++++++++ runtime/tests/interpreter/interpreter_test.go | 16 +++++++++++ 4 files changed, 73 insertions(+) diff --git a/runtime/parser/expression.go b/runtime/parser/expression.go index 01d9dba5d1..9e93990e0b 100644 --- a/runtime/parser/expression.go +++ b/runtime/parser/expression.go @@ -1735,6 +1735,8 @@ func parseStringLiteralContent(p *parser, s []byte) (result string) { builder.WriteByte('\t') case '"': builder.WriteByte('"') + case '$': + builder.WriteByte('$') case '\'': builder.WriteByte('\'') case '\\': diff --git a/runtime/parser/expression_test.go b/runtime/parser/expression_test.go index dabaff5057..b7b8489a5f 100644 --- a/runtime/parser/expression_test.go +++ b/runtime/parser/expression_test.go @@ -6098,6 +6098,34 @@ func TestParseStringTemplate(t *testing.T) { utils.AssertEqualWithDiff(t, expected, actual) }) + t.Run("escaped", func(t *testing.T) { + + t.Parallel() + + actual, errs := testParseExpression(` + "\$1.00" + `) + + var err error + if len(errs) > 0 { + err = Error{ + Errors: errs, + } + } + + require.NoError(t, err) + + expected := &ast.StringExpression{ + Value: "$1.00", + Range: ast.Range{ + StartPos: ast.Position{Offset: 3, Line: 2, Column: 2}, + EndPos: ast.Position{Offset: 10, Line: 2, Column: 9}, + }, + } + + utils.AssertEqualWithDiff(t, expected, actual) + }) + t.Run("multi", func(t *testing.T) { t.Parallel() diff --git a/runtime/parser/lexer/lexer_test.go b/runtime/parser/lexer/lexer_test.go index 643f57e902..fddebcf064 100644 --- a/runtime/parser/lexer/lexer_test.go +++ b/runtime/parser/lexer/lexer_test.go @@ -1071,6 +1071,33 @@ func TestLexString(t *testing.T) { ) }) + t.Run("valid, escaped 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, `"$1"`, diff --git a/runtime/tests/interpreter/interpreter_test.go b/runtime/tests/interpreter/interpreter_test.go index 3669f17960..74e49cf968 100644 --- a/runtime/tests/interpreter/interpreter_test.go +++ b/runtime/tests/interpreter/interpreter_test.go @@ -12398,4 +12398,20 @@ func TestInterpretStringTemplates(t *testing.T) { inter.Globals.Get("x").GetValue(inter), ) }) + + t.Run("escaped", func(t *testing.T) { + t.Parallel() + + inter := parseCheckAndInterpret(t, ` + let x = 123 + let y = "x is worth \$$x" + `) + + AssertValuesEqual( + t, + inter, + interpreter.NewUnmeteredStringValue("x is worth $123"), + inter.Globals.Get("y").GetValue(inter), + ) + }) } From 0cc3a365ae7f3022506f81c8be315881e6e1c9bf Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Mon, 23 Sep 2024 12:41:54 -0400 Subject: [PATCH 10/70] Reset lexer state. --- runtime/parser/lexer/lexer.go | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/parser/lexer/lexer.go b/runtime/parser/lexer/lexer.go index 5e9caf2f79..e5e224f850 100644 --- a/runtime/parser/lexer/lexer.go +++ b/runtime/parser/lexer/lexer.go @@ -140,6 +140,7 @@ func (l *lexer) clear() { l.cursor = 0 l.tokens = l.tokens[:0] l.tokenCount = 0 + l.mode = NORMAL } func (l *lexer) Reclaim() { From 942eb034392aa100179fb3d77d403badd5f96419 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Tue, 24 Sep 2024 11:40:27 -0400 Subject: [PATCH 11/70] Change string template token to \( for backwards compatibility. --- runtime/parser/expression.go | 4 + runtime/parser/expression_test.go | 109 +++++--- runtime/parser/lexer/lexer.go | 20 +- runtime/parser/lexer/lexer_test.go | 253 ++++++++++++++---- runtime/parser/lexer/state.go | 32 ++- runtime/parser/lexer/tokentype.go | 2 +- runtime/tests/checker/string_test.go | 27 +- runtime/tests/interpreter/interpreter_test.go | 64 +++-- 8 files changed, 373 insertions(+), 138 deletions(-) diff --git a/runtime/parser/expression.go b/runtime/parser/expression.go index 9e93990e0b..3537de9b93 100644 --- a/runtime/parser/expression.go +++ b/runtime/parser/expression.go @@ -1193,6 +1193,10 @@ func defineStringExpression() { if err != nil { return nil, err } + _, err = p.mustOne(lexer.TokenParenClose) + if err != nil { + return nil, err + } values = append(values, value) // parser already points to next token curToken = p.current diff --git a/runtime/parser/expression_test.go b/runtime/parser/expression_test.go index b7b8489a5f..2f78ddfe59 100644 --- a/runtime/parser/expression_test.go +++ b/runtime/parser/expression_test.go @@ -6064,7 +6064,7 @@ func TestParseStringTemplate(t *testing.T) { t.Parallel() actual, errs := testParseExpression(` - "$test" + "\(test)" `) var err error @@ -6085,41 +6085,13 @@ func TestParseStringTemplate(t *testing.T) { &ast.IdentifierExpression{ Identifier: ast.Identifier{ Identifier: "test", - Pos: ast.Position{Offset: 5, Line: 2, Column: 4}, + 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: 9, Line: 2, Column: 8}, - }, - } - - utils.AssertEqualWithDiff(t, expected, actual) - }) - - t.Run("escaped", func(t *testing.T) { - - t.Parallel() - - actual, errs := testParseExpression(` - "\$1.00" - `) - - var err error - if len(errs) > 0 { - err = Error{ - Errors: errs, - } - } - - require.NoError(t, err) - - expected := &ast.StringExpression{ - Value: "$1.00", - Range: ast.Range{ - StartPos: ast.Position{Offset: 3, Line: 2, Column: 2}, - EndPos: ast.Position{Offset: 10, Line: 2, Column: 9}, + EndPos: ast.Position{Offset: 11, Line: 2, Column: 10}, }, } @@ -6131,7 +6103,7 @@ func TestParseStringTemplate(t *testing.T) { t.Parallel() actual, errs := testParseExpression(` - "this is a test $abc$def test" + "this is a test \(abc)\(def) test" `) var err error @@ -6153,19 +6125,19 @@ func TestParseStringTemplate(t *testing.T) { &ast.IdentifierExpression{ Identifier: ast.Identifier{ Identifier: "abc", - Pos: ast.Position{Offset: 20, Line: 2, Column: 19}, + Pos: ast.Position{Offset: 21, Line: 2, Column: 20}, }, }, &ast.IdentifierExpression{ Identifier: ast.Identifier{ Identifier: "def", - Pos: ast.Position{Offset: 24, Line: 2, Column: 24}, + 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: 32, Line: 2, Column: 32}, + EndPos: ast.Position{Offset: 36, Line: 2, Column: 36}, }, } @@ -6177,7 +6149,7 @@ func TestParseStringTemplate(t *testing.T) { t.Parallel() _, errs := testParseExpression(` - "this is a test $FOO + "this is a test \(FOO) `) var err error @@ -6192,7 +6164,7 @@ func TestParseStringTemplate(t *testing.T) { []error{ &SyntaxError{ Message: "invalid end of string literal: missing '\"'", - Pos: ast.Position{Offset: 25, Line: 2, Column: 25}, + Pos: ast.Position{Offset: 27, Line: 2, Column: 27}, }, }, errs, @@ -6204,7 +6176,7 @@ func TestParseStringTemplate(t *testing.T) { t.Parallel() _, errs := testParseExpression(` - "$$" + "\(.)" `) var err error @@ -6218,8 +6190,8 @@ func TestParseStringTemplate(t *testing.T) { utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ - Message: "expected an identifier got: $", - Pos: ast.Position{Offset: 7, Line: 2, Column: 6}, + Message: "expected an identifier got: .", + Pos: ast.Position{Offset: 8, Line: 2, Column: 7}, }, }, errs, @@ -6231,7 +6203,34 @@ func TestParseStringTemplate(t *testing.T) { t.Parallel() _, errs := testParseExpression(` - "$(2 + 2) is a" + "\(2 + 2) is a" + `) + + var err error + if len(errs) > 0 { + err = Error{ + Errors: errs, + } + } + + require.Error(t, err) + utils.AssertEqualWithDiff(t, + []error{ + &SyntaxError{ + Message: "expected an identifier got: 2", + Pos: ast.Position{Offset: 8, Line: 2, Column: 7}, + }, + }, + errs, + ) + }) + + t.Run("invalid, nested identifier", func(t *testing.T) { + + t.Parallel() + + _, errs := testParseExpression(` + "\((a))" `) var err error @@ -6246,7 +6245,33 @@ func TestParseStringTemplate(t *testing.T) { []error{ &SyntaxError{ Message: "expected an identifier got: (", - Pos: ast.Position{Offset: 7, Line: 2, Column: 6}, + Pos: ast.Position{Offset: 8, Line: 2, Column: 7}, + }, + }, + errs, + ) + }) + 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) + utils.AssertEqualWithDiff(t, + []error{ + &SyntaxError{ + Message: "expected an identifier got: )", + Pos: ast.Position{Offset: 8, Line: 2, Column: 7}, }, }, errs, diff --git a/runtime/parser/lexer/lexer.go b/runtime/parser/lexer/lexer.go index e5e224f850..6b9c0714b8 100644 --- a/runtime/parser/lexer/lexer.go +++ b/runtime/parser/lexer/lexer.go @@ -54,7 +54,6 @@ type LexerMode int const ( NORMAL = iota STR_IDENTIFIER - STR_EXPRESSION ) type lexer struct { @@ -84,6 +83,8 @@ type lexer struct { 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{} @@ -141,6 +142,7 @@ func (l *lexer) clear() { l.tokens = l.tokens[:0] l.tokenCount = 0 l.mode = NORMAL + l.openBrackets = 0 } func (l *lexer) Reclaim() { @@ -418,18 +420,24 @@ 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 = STR_IDENTIFIER + // 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() return } - case '$': - // string template, stop and set mode - l.backupOne() - l.mode = STR_IDENTIFIER - return } r = l.next() } diff --git a/runtime/parser/lexer/lexer_test.go b/runtime/parser/lexer/lexer_test.go index fddebcf064..f2a77db4b2 100644 --- a/runtime/parser/lexer/lexer_test.go +++ b/runtime/parser/lexer/lexer_test.go @@ -1016,7 +1016,7 @@ func TestLexString(t *testing.T) { t.Run("valid, string template", func(t *testing.T) { testLex(t, - `"$abc.length"`, + `"\(abc).length"`, []token{ { Token: Token{ @@ -1033,27 +1033,37 @@ func TestLexString(t *testing.T) { Type: TokenStringTemplate, Range: ast.Range{ StartPos: ast.Position{Line: 1, Column: 1, Offset: 1}, - EndPos: ast.Position{Line: 1, Column: 1, Offset: 1}, + EndPos: ast.Position{Line: 1, Column: 2, Offset: 2}, }, }, - Source: `$`, + Source: `\(`, }, { Token: Token{ Type: TokenIdentifier, Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 2, Offset: 2}, - EndPos: ast.Position{Line: 1, Column: 4, Offset: 4}, + 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: 5, Offset: 5}, - EndPos: ast.Position{Line: 1, Column: 12, Offset: 12}, + StartPos: ast.Position{Line: 1, Column: 7, Offset: 7}, + EndPos: ast.Position{Line: 1, Column: 14, Offset: 14}, }, }, Source: `.length"`, @@ -1062,8 +1072,8 @@ func TestLexString(t *testing.T) { Token: Token{ Type: TokenEOF, Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 13, Offset: 13}, - EndPos: ast.Position{Line: 1, Column: 13, Offset: 13}, + StartPos: ast.Position{Line: 1, Column: 15, Offset: 15}, + EndPos: ast.Position{Line: 1, Column: 15, Offset: 15}, }, }, }, @@ -1071,9 +1081,9 @@ func TestLexString(t *testing.T) { ) }) - t.Run("valid, escaped string template", func(t *testing.T) { + t.Run("valid, not a string template", func(t *testing.T) { testLex(t, - `"\$1.00"`, + `"(1.00)"`, []token{ { Token: Token{ @@ -1083,7 +1093,7 @@ func TestLexString(t *testing.T) { EndPos: ast.Position{Line: 1, Column: 7, Offset: 7}, }, }, - Source: `"\$1.00"`, + Source: `"(1.00)"`, }, { Token: Token{ @@ -1100,7 +1110,7 @@ func TestLexString(t *testing.T) { t.Run("invalid, number string template", func(t *testing.T) { testLex(t, - `"$1"`, + `"\(7)"`, []token{ { Token: Token{ @@ -1117,27 +1127,37 @@ func TestLexString(t *testing.T) { Type: TokenStringTemplate, Range: ast.Range{ StartPos: ast.Position{Line: 1, Column: 1, Offset: 1}, - EndPos: ast.Position{Line: 1, Column: 1, Offset: 1}, + EndPos: ast.Position{Line: 1, Column: 2, Offset: 2}, }, }, - Source: `$`, + Source: `\(`, }, { Token: Token{ Type: TokenDecimalIntegerLiteral, Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 2, Offset: 2}, - EndPos: ast.Position{Line: 1, Column: 2, Offset: 2}, + 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: `1`, + Source: `)`, }, { Token: Token{ Type: TokenString, Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 3, Offset: 3}, - EndPos: ast.Position{Line: 1, Column: 3, Offset: 3}, + StartPos: ast.Position{Line: 1, Column: 5, Offset: 5}, + EndPos: ast.Position{Line: 1, Column: 5, Offset: 5}, }, }, Source: `"`, @@ -1146,8 +1166,8 @@ func TestLexString(t *testing.T) { Token: Token{ Type: TokenEOF, Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 4, Offset: 4}, - EndPos: ast.Position{Line: 1, Column: 4, Offset: 4}, + StartPos: ast.Position{Line: 1, Column: 6, Offset: 6}, + EndPos: ast.Position{Line: 1, Column: 6, Offset: 6}, }, }, }, @@ -1155,9 +1175,9 @@ func TestLexString(t *testing.T) { ) }) - t.Run("invalid, string template", func(t *testing.T) { + t.Run("invalid identifier string template", func(t *testing.T) { testLex(t, - `"$a + 2`, + `"\(a+2)"`, []token{ { Token: Token{ @@ -1174,39 +1194,69 @@ func TestLexString(t *testing.T) { Type: TokenStringTemplate, Range: ast.Range{ StartPos: ast.Position{Line: 1, Column: 1, Offset: 1}, - EndPos: ast.Position{Line: 1, Column: 1, Offset: 1}, + EndPos: ast.Position{Line: 1, Column: 2, Offset: 2}, }, }, - Source: `$`, + Source: `\(`, }, { Token: Token{ Type: TokenIdentifier, Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 2, Offset: 2}, - EndPos: ast.Position{Line: 1, Column: 2, Offset: 2}, + StartPos: ast.Position{Line: 1, Column: 3, Offset: 3}, + EndPos: ast.Position{Line: 1, Column: 3, Offset: 3}, }, }, Source: `a`, }, { Token: Token{ - Type: TokenString, + Type: TokenPlus, Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 3, Offset: 3}, + 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: ` + 2`, + Source: `)`, }, { Token: Token{ - Type: TokenEOF, + 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}, + }, + }, }, }, ) @@ -1214,7 +1264,7 @@ func TestLexString(t *testing.T) { t.Run("valid, multi string template", func(t *testing.T) { testLex(t, - `"$a$b"`, + `"\(a)\(b)"`, []token{ { Token: Token{ @@ -1231,27 +1281,37 @@ func TestLexString(t *testing.T) { Type: TokenStringTemplate, Range: ast.Range{ StartPos: ast.Position{Line: 1, Column: 1, Offset: 1}, - EndPos: ast.Position{Line: 1, Column: 1, Offset: 1}, + EndPos: ast.Position{Line: 1, Column: 2, Offset: 2}, }, }, - Source: `$`, + Source: `\(`, }, { Token: Token{ Type: TokenIdentifier, Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 2, Offset: 2}, - EndPos: ast.Position{Line: 1, Column: 2, Offset: 2}, + 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: 3, Offset: 3}, - EndPos: ast.Position{Line: 1, Column: 3, Offset: 2}, + StartPos: ast.Position{Line: 1, Column: 5, Offset: 5}, + EndPos: ast.Position{Line: 1, Column: 5, Offset: 4}, }, }, Source: ``, @@ -1260,28 +1320,38 @@ func TestLexString(t *testing.T) { Token: Token{ Type: TokenStringTemplate, Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 4, Offset: 3}, - EndPos: ast.Position{Line: 1, Column: 4, Offset: 3}, + StartPos: ast.Position{Line: 1, Column: 6, Offset: 5}, + EndPos: ast.Position{Line: 1, Column: 7, Offset: 6}, }, }, - Source: `$`, + Source: `\(`, }, { Token: Token{ Type: TokenIdentifier, Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 5, Offset: 4}, - EndPos: ast.Position{Line: 1, Column: 5, Offset: 4}, + 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: 6, Offset: 5}, - EndPos: ast.Position{Line: 1, Column: 6, Offset: 5}, + StartPos: ast.Position{Line: 1, Column: 10, Offset: 9}, + EndPos: ast.Position{Line: 1, Column: 10, Offset: 9}, }, }, Source: `"`, @@ -1290,8 +1360,95 @@ func TestLexString(t *testing.T) { Token: Token{ Type: TokenEOF, Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 7, Offset: 6}, - EndPos: ast.Position{Line: 1, Column: 7, Offset: 6}, + 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}, }, }, }, diff --git a/runtime/parser/lexer/state.go b/runtime/parser/lexer/state.go index 7e9561ba32..f2775b81dc 100644 --- a/runtime/parser/lexer/state.go +++ b/runtime/parser/lexer/state.go @@ -40,12 +40,6 @@ func rootState(l *lexer) stateFn { switch r { case EOF: return nil - case '$': - if l.mode == STR_EXPRESSION || l.mode == STR_IDENTIFIER { - l.emitType(TokenStringTemplate) - } else { - return l.error(fmt.Errorf("unrecognized character: %#U", r)) - } case '+': l.emitType(TokenPlus) case '-': @@ -62,9 +56,20 @@ func rootState(l *lexer) stateFn { case '%': l.emitType(TokenPercent) case '(': + if l.mode == STR_IDENTIFIER { + // 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 == STR_IDENTIFIER { + l.openBrackets-- + if l.openBrackets == 0 { + l.mode = NORMAL + return stringState + } + } case '{': l.emitType(TokenBraceOpen) case '}': @@ -124,6 +129,17 @@ func rootState(l *lexer) stateFn { return numberState case '"': return stringState + case '\\': + if l.mode == STR_IDENTIFIER { + 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 { @@ -302,10 +318,6 @@ func identifierState(l *lexer) stateFn { } } l.emitType(TokenIdentifier) - if l.mode == STR_IDENTIFIER { - l.mode = NORMAL - return stringState - } return rootState } diff --git a/runtime/parser/lexer/tokentype.go b/runtime/parser/lexer/tokentype.go index a7b3cb2f92..d2aa45fa8e 100644 --- a/runtime/parser/lexer/tokentype.go +++ b/runtime/parser/lexer/tokentype.go @@ -207,7 +207,7 @@ func (t TokenType) String() string { case TokenPragma: return `'#'` case TokenStringTemplate: - return `'$'` + return `'\('` default: panic(errors.NewUnreachableError()) } diff --git a/runtime/tests/checker/string_test.go b/runtime/tests/checker/string_test.go index ee2609758f..572c4ebc20 100644 --- a/runtime/tests/checker/string_test.go +++ b/runtime/tests/checker/string_test.go @@ -708,7 +708,7 @@ func TestCheckStringTemplate(t *testing.T) { _, err := ParseAndCheck(t, ` let a = 1 - let x: String = "The value of a is: $a" + let x: String = "The value of a is: \(a)" `) require.NoError(t, err) @@ -720,7 +720,7 @@ func TestCheckStringTemplate(t *testing.T) { _, err := ParseAndCheck(t, ` let a = "abc def" - let x: String = "$a ghi" + let x: String = "\(a) ghi" `) require.NoError(t, err) @@ -734,7 +734,7 @@ func TestCheckStringTemplate(t *testing.T) { access(all) struct SomeStruct {} let a = SomeStruct() - let x: String = "$a" + let x: String = "\(a)" `) require.NoError(t, err) @@ -745,11 +745,30 @@ func TestCheckStringTemplate(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - let x: String = "$a" + let x: String = "\(a)" `) errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.NotDeclaredError{}, errs[0]) }) + + 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.MissingMoveOperationError{}, errs[0]) + }) } diff --git a/runtime/tests/interpreter/interpreter_test.go b/runtime/tests/interpreter/interpreter_test.go index 74e49cf968..3c24c70571 100644 --- a/runtime/tests/interpreter/interpreter_test.go +++ b/runtime/tests/interpreter/interpreter_test.go @@ -12292,8 +12292,8 @@ func TestInterpretStringTemplates(t *testing.T) { t.Parallel() inter := parseCheckAndInterpret(t, ` - let x = 123 - let y = "x = $x" + let x = 123 + let y = "x = \(x)" `) AssertValuesEqual( @@ -12314,9 +12314,9 @@ func TestInterpretStringTemplates(t *testing.T) { t.Parallel() inter := parseCheckAndInterpret(t, ` - let x = 123.321 - let y = "abc" - let z = "$y and $x" + let x = 123.321 + let y = "abc" + let z = "\(y) and \(x)" `) AssertValuesEqual( @@ -12331,9 +12331,9 @@ func TestInterpretStringTemplates(t *testing.T) { t.Parallel() inter := parseCheckAndInterpret(t, ` - let x = "{}" - let y = "[$x]" - let z = "($y)" + let x = "{}" + let y = "[\(x)]" + let z = "(\(y))" `) AssertValuesEqual( @@ -12348,10 +12348,10 @@ func TestInterpretStringTemplates(t *testing.T) { t.Parallel() inter := parseCheckAndInterpret(t, ` - access(all) - struct SomeStruct {} - let a = SomeStruct() - let x: String = "$a" + access(all) + struct SomeStruct {} + let a = SomeStruct() + let x: String = "\(a)" `) AssertValuesEqual( @@ -12366,16 +12366,16 @@ func TestInterpretStringTemplates(t *testing.T) { t.Parallel() inter := parseCheckAndInterpret(t, ` - let add = fun(): Int { - return 2+2 - } - let x: String = "$add()" + let add = fun(): Int { + return 2+2 + } + let x: String = "\(add())" `) AssertValuesEqual( t, inter, - interpreter.NewUnmeteredStringValue("fun(): Int()"), + interpreter.NewUnmeteredStringValue("4"), inter.Globals.Get("x").GetValue(inter), ) }) @@ -12384,11 +12384,11 @@ func TestInterpretStringTemplates(t *testing.T) { t.Parallel() inter := parseCheckAndInterpret(t, ` - let add = fun(): Int { - return 2+2 - } - let y = add() - let x: String = "$y" + let add = fun(): Int { + return 2+2 + } + let y = add() + let x: String = "\(y)" `) AssertValuesEqual( @@ -12399,19 +12399,29 @@ func TestInterpretStringTemplates(t *testing.T) { ) }) - t.Run("escaped", func(t *testing.T) { + t.Run("resource reference", func(t *testing.T) { t.Parallel() inter := parseCheckAndInterpret(t, ` - let x = 123 - let y = "x is worth \$$x" + resource R {} + + fun test(): String { + let r <- create R() + let ref = &r as &R + let y = "\(ref)" + destroy r + return y + } `) + value, err := inter.Invoke("test") + require.NoError(t, err) + AssertValuesEqual( t, inter, - interpreter.NewUnmeteredStringValue("x is worth $123"), - inter.Globals.Get("y").GetValue(inter), + interpreter.NewUnmeteredStringValue("S.test.R(uuid: 1)"), + value, ) }) } From e3d152d10540198f04fb77a6b857e7efcfabd099 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Tue, 24 Sep 2024 17:21:17 -0400 Subject: [PATCH 12/70] Restrict supported types in template. --- .../sema/check_string_template_expression.go | 12 +++++ runtime/tests/checker/string_test.go | 45 +++++++++++++------ runtime/tests/interpreter/interpreter_test.go | 38 +++------------- 3 files changed, 48 insertions(+), 47 deletions(-) diff --git a/runtime/sema/check_string_template_expression.go b/runtime/sema/check_string_template_expression.go index 276b8c0f14..e2f865391f 100644 --- a/runtime/sema/check_string_template_expression.go +++ b/runtime/sema/check_string_template_expression.go @@ -37,6 +37,18 @@ func (checker *Checker) VisitStringTemplateExpression(stringTemplateExpression * argumentTypes[i] = valueType + // All number types, addresses, path types, bool and strings are supported in string template + if !(IsSubType(valueType, NumberType) || IsSubType(valueType, TheAddressType) || + IsSubType(valueType, PathType) || IsSubType(valueType, StringType) || IsSubType(valueType, BoolType)) { + checker.report( + &TypeMismatchWithDescriptionError{ + ActualType: valueType, + ExpectedTypeDescription: "a type with built-in toString() or bool", + Range: ast.NewRangeFromPositioned(checker.memoryGauge, element), + }, + ) + } + checker.checkResourceMoveOperation(element, valueType) } } diff --git a/runtime/tests/checker/string_test.go b/runtime/tests/checker/string_test.go index 572c4ebc20..313d8f08ee 100644 --- a/runtime/tests/checker/string_test.go +++ b/runtime/tests/checker/string_test.go @@ -707,8 +707,8 @@ func TestCheckStringTemplate(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - let a = 1 - let x: String = "The value of a is: \(a)" + let a = 1 + let x: String = "The value of a is: \(a)" `) require.NoError(t, err) @@ -719,25 +719,40 @@ func TestCheckStringTemplate(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - let a = "abc def" - let x: String = "\(a) ghi" + let a = "abc def" + let x: String = "\(a) ghi" `) require.NoError(t, err) }) - t.Run("valid, struct", func(t *testing.T) { + t.Run("invalid, struct", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - access(all) - struct SomeStruct {} - let a = SomeStruct() - let x: String = "\(a)" + access(all) + struct SomeStruct {} + let a = SomeStruct() + let x: String = "\(a)" `) - require.NoError(t, err) + 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) { @@ -745,12 +760,13 @@ func TestCheckStringTemplate(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - let x: String = "\(a)" + let x: String = "\(a)" `) - errs := RequireCheckerErrors(t, err, 1) + 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) { @@ -767,8 +783,9 @@ func TestCheckStringTemplate(t *testing.T) { } `) - errs := RequireCheckerErrors(t, err, 1) + errs := RequireCheckerErrors(t, err, 2) - assert.IsType(t, &sema.MissingMoveOperationError{}, errs[0]) + assert.IsType(t, &sema.TypeMismatchWithDescriptionError{}, errs[0]) + assert.IsType(t, &sema.MissingMoveOperationError{}, errs[1]) }) } diff --git a/runtime/tests/interpreter/interpreter_test.go b/runtime/tests/interpreter/interpreter_test.go index 3c24c70571..69f203652f 100644 --- a/runtime/tests/interpreter/interpreter_test.go +++ b/runtime/tests/interpreter/interpreter_test.go @@ -12344,21 +12344,19 @@ func TestInterpretStringTemplates(t *testing.T) { ) }) - t.Run("struct", func(t *testing.T) { + t.Run("boolean", func(t *testing.T) { t.Parallel() inter := parseCheckAndInterpret(t, ` - access(all) - struct SomeStruct {} - let a = SomeStruct() - let x: String = "\(a)" + let x = false + let y = "\(x)" `) AssertValuesEqual( t, inter, - interpreter.NewUnmeteredStringValue("S.test.SomeStruct()"), - inter.Globals.Get("x").GetValue(inter), + interpreter.NewUnmeteredStringValue("false"), + inter.Globals.Get("y").GetValue(inter), ) }) @@ -12398,30 +12396,4 @@ func TestInterpretStringTemplates(t *testing.T) { inter.Globals.Get("x").GetValue(inter), ) }) - - t.Run("resource reference", func(t *testing.T) { - t.Parallel() - - inter := parseCheckAndInterpret(t, ` - resource R {} - - fun test(): String { - let r <- create R() - let ref = &r as &R - let y = "\(ref)" - destroy r - return y - } - `) - - value, err := inter.Invoke("test") - require.NoError(t, err) - - AssertValuesEqual( - t, - inter, - interpreter.NewUnmeteredStringValue("S.test.R(uuid: 1)"), - value, - ) - }) } From 1ec5b7eb7c230831d7927cf1476e583945bae4a4 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Wed, 25 Sep 2024 10:26:04 -0400 Subject: [PATCH 13/70] Limit string templates to identifiers only. --- runtime/parser/expression.go | 10 +-- runtime/parser/expression_test.go | 64 +++++++++++++++---- runtime/tests/interpreter/interpreter_test.go | 20 +----- 3 files changed, 59 insertions(+), 35 deletions(-) diff --git a/runtime/parser/expression.go b/runtime/parser/expression.go index 3537de9b93..395a6befa3 100644 --- a/runtime/parser/expression.go +++ b/runtime/parser/expression.go @@ -1184,15 +1184,17 @@ func defineStringExpression() { // parser already points to next token curToken = p.current if curToken.Is(lexer.TokenStringTemplate) { - p.next() // advance to the expression - if !p.current.Is(lexer.TokenIdentifier) { - return nil, p.syntaxError("expected an identifier got: %s", p.currentTokenSource()) - } + 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 diff --git a/runtime/parser/expression_test.go b/runtime/parser/expression_test.go index 2f78ddfe59..3804c13ce6 100644 --- a/runtime/parser/expression_test.go +++ b/runtime/parser/expression_test.go @@ -6190,8 +6190,8 @@ func TestParseStringTemplate(t *testing.T) { utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ - Message: "expected an identifier got: .", - Pos: ast.Position{Offset: 8, Line: 2, Column: 7}, + Message: "unexpected token in expression: '.'", + Pos: ast.Position{Offset: 9, Line: 2, Column: 8}, }, }, errs, @@ -6217,19 +6217,19 @@ func TestParseStringTemplate(t *testing.T) { utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ - Message: "expected an identifier got: 2", - Pos: ast.Position{Offset: 8, Line: 2, Column: 7}, + Message: "expected identifier got: 2 + 2", + Pos: ast.Position{Offset: 13, Line: 2, Column: 12}, }, }, errs, ) }) - t.Run("invalid, nested identifier", func(t *testing.T) { + t.Run("valid, nested identifier", func(t *testing.T) { t.Parallel() - _, errs := testParseExpression(` + actual, errs := testParseExpression(` "\((a))" `) @@ -6240,23 +6240,63 @@ func TestParseStringTemplate(t *testing.T) { } } + 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}, + }, + } + + utils.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) utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ - Message: "expected an identifier got: (", - Pos: ast.Position{Offset: 8, Line: 2, Column: 7}, + Message: "unexpected token in expression: ')'", + Pos: ast.Position{Offset: 9, Line: 2, Column: 8}, }, }, errs, ) }) - t.Run("invalid, empty", func(t *testing.T) { + + t.Run("invalid, function identifier", func(t *testing.T) { t.Parallel() _, errs := testParseExpression(` - "\()" + "\(add())" `) var err error @@ -6270,8 +6310,8 @@ func TestParseStringTemplate(t *testing.T) { utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ - Message: "expected an identifier got: )", - Pos: ast.Position{Offset: 8, Line: 2, Column: 7}, + Message: "expected identifier got: add()", + Pos: ast.Position{Offset: 12, Line: 2, Column: 11}, }, }, errs, diff --git a/runtime/tests/interpreter/interpreter_test.go b/runtime/tests/interpreter/interpreter_test.go index 69f203652f..728011fbd7 100644 --- a/runtime/tests/interpreter/interpreter_test.go +++ b/runtime/tests/interpreter/interpreter_test.go @@ -12360,25 +12360,7 @@ func TestInterpretStringTemplates(t *testing.T) { ) }) - t.Run("func", func(t *testing.T) { - t.Parallel() - - inter := parseCheckAndInterpret(t, ` - let add = fun(): Int { - return 2+2 - } - let x: String = "\(add())" - `) - - AssertValuesEqual( - t, - inter, - interpreter.NewUnmeteredStringValue("4"), - inter.Globals.Get("x").GetValue(inter), - ) - }) - - t.Run("func", func(t *testing.T) { + t.Run("func extracted", func(t *testing.T) { t.Parallel() inter := parseCheckAndInterpret(t, ` From 1ae7fe9123e2c2160abcba72a19fd9f04e1ed661 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Wed, 25 Sep 2024 13:25:20 -0400 Subject: [PATCH 14/70] Clean up changes. --- runtime/ast/expression.go | 1 - runtime/interpreter/interpreter_expression.go | 3 +-- runtime/parser/expression.go | 9 ++++----- runtime/sema/check_string_template_expression.go | 8 ++++---- runtime/tests/interpreter/interpreter_test.go | 16 ++++++++++++++++ 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/runtime/ast/expression.go b/runtime/ast/expression.go index 2efc783155..2e2ee2f7f2 100644 --- a/runtime/ast/expression.go +++ b/runtime/ast/expression.go @@ -231,7 +231,6 @@ type StringTemplateExpression struct { var _ Expression = &StringTemplateExpression{} func NewStringTemplateExpression(gauge common.MemoryGauge, values []string, exprs []Expression, exprRange Range) *StringTemplateExpression { - // STRINGTODO: change to be similar to array memory usage? common.UseMemory(gauge, common.StringExpressionMemoryUsage) return &StringTemplateExpression{ Values: values, diff --git a/runtime/interpreter/interpreter_expression.go b/runtime/interpreter/interpreter_expression.go index 264b39edf8..05272cb606 100644 --- a/runtime/interpreter/interpreter_expression.go +++ b/runtime/interpreter/interpreter_expression.go @@ -968,7 +968,7 @@ func (interpreter *Interpreter) VisitStringTemplateExpression(expression *ast.St for i, str := range expression.Values { builder.WriteString(str) if i < len(values) { - // STRINGTODO: is this how the conversion should happen? + // this is equivalent to toString() for supported types s := values[i].String() switch argumentTypes[i] { case sema.StringType: @@ -981,7 +981,6 @@ func (interpreter *Interpreter) VisitStringTemplateExpression(expression *ast.St } } - // STRINGTODO: already metered as a string constant in parser? return NewUnmeteredStringValue(builder.String()) } diff --git a/runtime/parser/expression.go b/runtime/parser/expression.go index 395a6befa3..78a53c77ad 100644 --- a/runtime/parser/expression.go +++ b/runtime/parser/expression.go @@ -1141,7 +1141,7 @@ func defineStringExpression() { curToken := startToken endToken := startToken - // early check for start " of string literal because of string templates + // check for start " of string literal literal := p.tokenSource(curToken) length := len(literal) if length == 0 { @@ -1160,13 +1160,14 @@ func defineStringExpression() { } } - // flag for late end " check + // flag for ending " check missingEnd := true for curToken.Is(lexer.TokenString) { literal = p.tokenSource(curToken) length = len(literal) + // remove quotation marks if they exist if curToken == startToken { literal = literal[1:] length = len(literal) @@ -1208,7 +1209,7 @@ func defineStringExpression() { } } - // late check for end " of string literal because of string templates + // check for end " of string literal if missingEnd { p.reportSyntaxError("invalid end of string literal: missing '\"'") } @@ -1741,8 +1742,6 @@ func parseStringLiteralContent(p *parser, s []byte) (result string) { builder.WriteByte('\t') case '"': builder.WriteByte('"') - case '$': - builder.WriteByte('$') case '\'': builder.WriteByte('\'') case '\\': diff --git a/runtime/sema/check_string_template_expression.go b/runtime/sema/check_string_template_expression.go index e2f865391f..7a7eac8b3d 100644 --- a/runtime/sema/check_string_template_expression.go +++ b/runtime/sema/check_string_template_expression.go @@ -38,8 +38,10 @@ func (checker *Checker) VisitStringTemplateExpression(stringTemplateExpression * argumentTypes[i] = valueType // All number types, addresses, path types, bool and strings are supported in string template - if !(IsSubType(valueType, NumberType) || IsSubType(valueType, TheAddressType) || - IsSubType(valueType, PathType) || IsSubType(valueType, StringType) || IsSubType(valueType, BoolType)) { + if IsSubType(valueType, NumberType) || IsSubType(valueType, TheAddressType) || + IsSubType(valueType, PathType) || IsSubType(valueType, StringType) || IsSubType(valueType, BoolType) { + checker.checkResourceMoveOperation(element, valueType) + } else { checker.report( &TypeMismatchWithDescriptionError{ ActualType: valueType, @@ -48,8 +50,6 @@ func (checker *Checker) VisitStringTemplateExpression(stringTemplateExpression * }, ) } - - checker.checkResourceMoveOperation(element, valueType) } } diff --git a/runtime/tests/interpreter/interpreter_test.go b/runtime/tests/interpreter/interpreter_test.go index 728011fbd7..855888eea0 100644 --- a/runtime/tests/interpreter/interpreter_test.go +++ b/runtime/tests/interpreter/interpreter_test.go @@ -12378,4 +12378,20 @@ func TestInterpretStringTemplates(t *testing.T) { 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), + ) + }) } From 8799cac377654e613af872b7ed8e043cfa0f7e06 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Wed, 25 Sep 2024 13:39:43 -0400 Subject: [PATCH 15/70] Fix checker test. --- runtime/tests/checker/string_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/runtime/tests/checker/string_test.go b/runtime/tests/checker/string_test.go index 313d8f08ee..4bea07a7dd 100644 --- a/runtime/tests/checker/string_test.go +++ b/runtime/tests/checker/string_test.go @@ -783,9 +783,8 @@ func TestCheckStringTemplate(t *testing.T) { } `) - errs := RequireCheckerErrors(t, err, 2) + errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.TypeMismatchWithDescriptionError{}, errs[0]) - assert.IsType(t, &sema.MissingMoveOperationError{}, errs[1]) }) } From 67d950b66be06ff201aca4ee10bcdabba9999822 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Thu, 26 Sep 2024 12:26:20 -0400 Subject: [PATCH 16/70] Initial test of stringer interface. --- runtime/sema/stringer.go | 65 +++++++++++++++++++++++++ runtime/sema/type.go | 18 +++++++ runtime/tests/checker/stringer_test.go | 66 ++++++++++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 runtime/sema/stringer.go create mode 100644 runtime/tests/checker/stringer_test.go diff --git a/runtime/sema/stringer.go b/runtime/sema/stringer.go new file mode 100644 index 0000000000..67fef4abaf --- /dev/null +++ b/runtime/sema/stringer.go @@ -0,0 +1,65 @@ +/* + * 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/runtime/ast" + "github.com/onflow/cadence/runtime/common" +) + +const StringerTypeToStringFunctionName = "toString" + +var StringerTypeToStringFunctionType = &FunctionType{ + Purity: FunctionPurityView, + ReturnTypeAnnotation: NewTypeAnnotation( + StringType, + ), +} + +const StringerTypeToStringFunctionDocString = ` + Returns this object as a String. + ` + +const StringerTypeName = "Stringer" + +var StringerType = InterfaceType{ + Location: nil, + Identifier: StringerTypeName, + CompositeKind: common.CompositeKindStructure, + Members: &StringMemberOrderedMap{}, +} + +func init() { + StringerType.Members.Set(StringerTypeToStringFunctionName, NewUnmeteredFunctionMember( + &StringerType, + PrimitiveAccess(ast.AccessAll), + StringerTypeToStringFunctionName, + StringerTypeToStringFunctionType, + StringerTypeToStringFunctionDocString, + )) + StringerType.memberResolvers = MembersAsResolvers([]*Member{ + NewUnmeteredFunctionMember( + &StringerType, + PrimitiveAccess(ast.AccessAll), + StringerTypeToStringFunctionName, + StringerTypeToStringFunctionType, + StringerTypeToStringFunctionDocString, + ), + }) +} diff --git a/runtime/sema/type.go b/runtime/sema/type.go index 42d72439ae..f659ccf4ac 100644 --- a/runtime/sema/type.go +++ b/runtime/sema/type.go @@ -4198,6 +4198,7 @@ func init() { DeploymentResultType, HashableStructType, &InclusiveRangeType{}, + &StringerType, }, ) @@ -4899,6 +4900,17 @@ func IsHashableStructType(t Type) bool { } } +// which simple types conform to stringer interface (except Bool?) +func IsStringerType(t Type) bool { + switch t { + case BoolType, CharacterType, StringType: + return true + default: + return IsSubType(t, NumberType) || + IsSubType(t, PathType) || IsSubType(t, TheAddressType) + } +} + func (t *CompositeType) GetBaseType() Type { return t.baseType } @@ -7825,6 +7837,12 @@ func checkSubTypeWithoutEquality(subType Type, superType Type) bool { IsSubsetOf(typedSubType.EffectiveInterfaceConformanceSet()) } + // STRINGERTODO: other options? how to make existing simple types + // conform to an intersection type? + if typedSuperType.Types[0].Identifier == StringerTypeName { + return IsStringerType(subType) + } + default: // Supertype (intersection) has a non-Any* legacy type diff --git a/runtime/tests/checker/stringer_test.go b/runtime/tests/checker/stringer_test.go new file mode 100644 index 0000000000..a8d0c9cdbd --- /dev/null +++ b/runtime/tests/checker/stringer_test.go @@ -0,0 +1,66 @@ +/* + * Cadence - The resource-oriented smart contract programming language + * + * Copyright Dapper Labs, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package checker + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/onflow/cadence/runtime/sema" +) + +func TestCheckStringer(t *testing.T) { + + t.Parallel() + + _, err := ParseAndCheck(t, ` + let a: {Stringer} = 1 + let b: {Stringer} = false + let c: {Stringer} = "hey" + access(all) + struct Foo: Stringer { + view fun toString():String { + return "foo" + } + } + let d: {Stringer} = Foo() + `) + + assert.NoError(t, err) +} + +func TestCheckInvalidStringer(t *testing.T) { + + t.Parallel() + + _, err := ParseAndCheck(t, ` + resource R {} + + let a: {Stringer} = <-create R() + let b: {Stringer} = [<-create R()] + let c: {Stringer} = {1: true} + `) + + 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]) +} From 6d60b9d94f9ece80b8c56e1286e00256484fb379 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Thu, 26 Sep 2024 14:15:02 -0400 Subject: [PATCH 17/70] Add test for custom toString. --- runtime/tests/interpreter/stringer_test.go | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 runtime/tests/interpreter/stringer_test.go diff --git a/runtime/tests/interpreter/stringer_test.go b/runtime/tests/interpreter/stringer_test.go new file mode 100644 index 0000000000..2ebf40cabd --- /dev/null +++ b/runtime/tests/interpreter/stringer_test.go @@ -0,0 +1,54 @@ +/* + * 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/onflow/cadence/runtime/interpreter" + . "github.com/onflow/cadence/runtime/tests/utils" + "github.com/stretchr/testify/require" +) + +func TestStringerBasic(t *testing.T) { + + t.Parallel() + + inter := parseCheckAndInterpret(t, ` + access(all) + struct Example: Stringer { + 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, + ) +} From 6298e1fb49df434c397ae6405aef1558c495a119 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Thu, 26 Sep 2024 14:55:35 -0400 Subject: [PATCH 18/70] Add test for conformance error. --- runtime/tests/checker/stringer_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/runtime/tests/checker/stringer_test.go b/runtime/tests/checker/stringer_test.go index a8d0c9cdbd..e9b953f4e3 100644 --- a/runtime/tests/checker/stringer_test.go +++ b/runtime/tests/checker/stringer_test.go @@ -56,11 +56,13 @@ func TestCheckInvalidStringer(t *testing.T) { let a: {Stringer} = <-create R() let b: {Stringer} = [<-create R()] let c: {Stringer} = {1: true} + struct Foo: Stringer {} `) - errs := RequireCheckerErrors(t, err, 3) + 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]) + assert.IsType(t, &sema.ConformanceError{}, errs[3]) } From aa514550ad5eca99db4f43bd99f643f4ef79bdad Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Fri, 27 Sep 2024 11:44:41 -0400 Subject: [PATCH 19/70] Fix tests for native interface types. --- runtime/interpreter/interpreter.go | 4 ++ runtime/sema/stringer.go | 52 ++++++++++------------ runtime/sema/type.go | 33 +++++++++++++- runtime/sema/type_test.go | 4 ++ runtime/tests/interpreter/stringer_test.go | 26 ++++++++++- 5 files changed, 88 insertions(+), 31 deletions(-) diff --git a/runtime/interpreter/interpreter.go b/runtime/interpreter/interpreter.go index a99f854410..b1576c1216 100644 --- a/runtime/interpreter/interpreter.go +++ b/runtime/interpreter/interpreter.go @@ -4866,6 +4866,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/runtime/sema/stringer.go b/runtime/sema/stringer.go index 67fef4abaf..1331fdc3eb 100644 --- a/runtime/sema/stringer.go +++ b/runtime/sema/stringer.go @@ -23,43 +23,37 @@ import ( "github.com/onflow/cadence/runtime/common" ) -const StringerTypeToStringFunctionName = "toString" +const StringerTypeName = "Stringer" -var StringerTypeToStringFunctionType = &FunctionType{ - Purity: FunctionPurityView, - ReturnTypeAnnotation: NewTypeAnnotation( - StringType, - ), -} +var StringerType = func() *InterfaceType { -const StringerTypeToStringFunctionDocString = ` - Returns this object as a String. - ` + stringerType := &InterfaceType{ + Identifier: StringerTypeName, + CompositeKind: common.CompositeKindStructure, + Members: &StringMemberOrderedMap{}, + } -const StringerTypeName = "Stringer" + const StringerTypeToStringFunctionDocString = `Returns this object as a String.` -var StringerType = InterfaceType{ - Location: nil, - Identifier: StringerTypeName, - CompositeKind: common.CompositeKindStructure, - Members: &StringMemberOrderedMap{}, -} + const StringerTypeToStringFunctionName = "toString" -func init() { - StringerType.Members.Set(StringerTypeToStringFunctionName, NewUnmeteredFunctionMember( - &StringerType, - PrimitiveAccess(ast.AccessAll), - StringerTypeToStringFunctionName, - StringerTypeToStringFunctionType, - StringerTypeToStringFunctionDocString, - )) - StringerType.memberResolvers = MembersAsResolvers([]*Member{ + var StringerTypeToStringFunctionType = &FunctionType{ + Purity: FunctionPurityView, + ReturnTypeAnnotation: NewTypeAnnotation( + StringType, + ), + } + + var members = []*Member{ NewUnmeteredFunctionMember( - &StringerType, + stringerType, PrimitiveAccess(ast.AccessAll), StringerTypeToStringFunctionName, StringerTypeToStringFunctionType, StringerTypeToStringFunctionDocString, ), - }) -} + } + + stringerType.Members = MembersAsMap(members) + return stringerType +}() diff --git a/runtime/sema/type.go b/runtime/sema/type.go index f659ccf4ac..c9ab715c7f 100644 --- a/runtime/sema/type.go +++ b/runtime/sema/type.go @@ -4198,7 +4198,7 @@ func init() { DeploymentResultType, HashableStructType, &InclusiveRangeType{}, - &StringerType, + StringerType, }, ) @@ -9552,3 +9552,34 @@ func init() { }) } } + +var NativeInterfaceTypes = map[string]*InterfaceType{} + +func init() { + interfaceTypes := []*InterfaceType{ + StringerType, + } + + for len(interfaceTypes) > 0 { + lastIndex := len(interfaceTypes) - 1 + interfaceType := interfaceTypes[lastIndex] + interfaceTypes[lastIndex] = nil + interfaceTypes = interfaceTypes[:lastIndex] + + NativeInterfaceTypes[interfaceType.QualifiedIdentifier()] = interfaceType + + nestedTypes := interfaceType.NestedTypes + if nestedTypes == nil { + continue + } + + nestedTypes.Foreach(func(_ string, nestedType Type) { + nestedInterfaceType, ok := nestedType.(*InterfaceType) + if !ok { + return + } + + interfaceTypes = append(interfaceTypes, nestedInterfaceType) + }) + } +} diff --git a/runtime/sema/type_test.go b/runtime/sema/type_test.go index 0f0bcf40cf..ebaca4f36b 100644 --- a/runtime/sema/type_test.go +++ b/runtime/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/runtime/tests/interpreter/stringer_test.go b/runtime/tests/interpreter/stringer_test.go index 2ebf40cabd..fbd6da1388 100644 --- a/runtime/tests/interpreter/stringer_test.go +++ b/runtime/tests/interpreter/stringer_test.go @@ -21,9 +21,10 @@ package interpreter_test import ( "testing" + "github.com/stretchr/testify/require" + "github.com/onflow/cadence/runtime/interpreter" . "github.com/onflow/cadence/runtime/tests/utils" - "github.com/stretchr/testify/require" ) func TestStringerBasic(t *testing.T) { @@ -52,3 +53,26 @@ func TestStringerBasic(t *testing.T) { 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, + ) +} From bda6b28fb29cff50e635a3e9d94b926290001b33 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Wed, 2 Oct 2024 10:58:51 -0400 Subject: [PATCH 20/70] Refactor code from review. --- runtime/ast/expression.go | 9 +- runtime/common/memorykind.go | 1 + runtime/common/memorykind_string.go | 95 ++++++++++--------- runtime/common/metering.go | 7 ++ runtime/interpreter/interpreter_expression.go | 18 ++-- runtime/parser/expression_test.go | 54 +++++++++++ runtime/parser/lexer/lexer.go | 10 +- runtime/parser/lexer/state.go | 6 +- .../sema/check_string_template_expression.go | 12 ++- runtime/tests/interpreter/interpreter_test.go | 18 ++++ 10 files changed, 157 insertions(+), 73 deletions(-) diff --git a/runtime/ast/expression.go b/runtime/ast/expression.go index 2e2ee2f7f2..b8bf93e86d 100644 --- a/runtime/ast/expression.go +++ b/runtime/ast/expression.go @@ -230,8 +230,13 @@ type StringTemplateExpression struct { var _ Expression = &StringTemplateExpression{} -func NewStringTemplateExpression(gauge common.MemoryGauge, values []string, exprs []Expression, exprRange Range) *StringTemplateExpression { - common.UseMemory(gauge, common.StringExpressionMemoryUsage) +func NewStringTemplateExpression( + gauge common.MemoryGauge, + values []string, + exprs []Expression, + exprRange Range, +) *StringTemplateExpression { + common.UseMemory(gauge, common.NewStringTemplateExpressionMemoryUsage(len(values)+len(exprs))) return &StringTemplateExpression{ Values: values, Expressions: exprs, diff --git a/runtime/common/memorykind.go b/runtime/common/memorykind.go index 06e6748e9a..0754c397f5 100644 --- a/runtime/common/memorykind.go +++ b/runtime/common/memorykind.go @@ -204,6 +204,7 @@ const ( MemoryKindIntegerExpression MemoryKindFixedPointExpression MemoryKindArrayExpression + MemoryKindStringTemplateExpression MemoryKindDictionaryExpression MemoryKindIdentifierExpression MemoryKindInvocationExpression diff --git a/runtime/common/memorykind_string.go b/runtime/common/memorykind_string.go index 9b022e9495..67d6a0b8f8 100644 --- a/runtime/common/memorykind_string.go +++ b/runtime/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/runtime/common/metering.go b/runtime/common/metering.go index a4b4afc2dd..e6e6249571 100644 --- a/runtime/common/metering.go +++ b/runtime/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/runtime/interpreter/interpreter_expression.go b/runtime/interpreter/interpreter_expression.go index 05272cb606..13e2f192e3 100644 --- a/runtime/interpreter/interpreter_expression.go +++ b/runtime/interpreter/interpreter_expression.go @@ -961,22 +961,18 @@ func (interpreter *Interpreter) VisitStringExpression(expression *ast.StringExpr func (interpreter *Interpreter) VisitStringTemplateExpression(expression *ast.StringTemplateExpression) Value { values := interpreter.visitExpressionsNonCopying(expression.Expressions) - templatesType := interpreter.Program.Elaboration.StringTemplateExpressionTypes(expression) - argumentTypes := templatesType.ArgumentTypes - var builder strings.Builder for i, str := range expression.Values { builder.WriteString(str) if i < len(values) { - // this is equivalent to toString() for supported types - s := values[i].String() - switch argumentTypes[i] { - case sema.StringType: - // remove quotations - s = s[1 : len(s)-1] - builder.WriteString(s) + // 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(s) + builder.WriteString(value.String()) } } } diff --git a/runtime/parser/expression_test.go b/runtime/parser/expression_test.go index 3804c13ce6..8f68a7b468 100644 --- a/runtime/parser/expression_test.go +++ b/runtime/parser/expression_test.go @@ -6317,6 +6317,60 @@ func TestParseStringTemplate(t *testing.T) { errs, ) }) + + t.Run("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) + utils.AssertEqualWithDiff(t, + []error{ + &SyntaxError{ + Message: "expected token ')'", + Pos: ast.Position{Offset: 10, Line: 2, Column: 9}, + }, + }, + errs, + ) + }) + + t.Run("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) + utils.AssertEqualWithDiff(t, + []error{ + &SyntaxError{ + Message: "expected token ')'", + Pos: ast.Position{Offset: 30, Line: 2, Column: 29}, + }, + }, + errs, + ) + }) } func TestParseNilCoalescing(t *testing.T) { diff --git a/runtime/parser/lexer/lexer.go b/runtime/parser/lexer/lexer.go index 6b9c0714b8..25e7635594 100644 --- a/runtime/parser/lexer/lexer.go +++ b/runtime/parser/lexer/lexer.go @@ -49,11 +49,11 @@ type position struct { column int } -type LexerMode int +type lexerMode uint8 const ( - NORMAL = iota - STR_IDENTIFIER + NORMAL lexerMode = iota + STR_INTERPOLATION ) type lexer struct { @@ -82,7 +82,7 @@ type lexer struct { // canBackup indicates whether stepping back is allowed canBackup bool // lexer mode is used for string templates - mode LexerMode + mode lexerMode // counts the number of unclosed brackets for string templates \((())) openBrackets int } @@ -427,7 +427,7 @@ func (l *lexer) scanString(quote rune) { switch r { case '(': // string template, stop and set mode - l.mode = STR_IDENTIFIER + l.mode = STR_INTERPOLATION // no need to update prev values because these next tokens will not backup l.endOffset = tmpBackupOffset l.current = tmpBackup diff --git a/runtime/parser/lexer/state.go b/runtime/parser/lexer/state.go index f2775b81dc..b536111c86 100644 --- a/runtime/parser/lexer/state.go +++ b/runtime/parser/lexer/state.go @@ -56,14 +56,14 @@ func rootState(l *lexer) stateFn { case '%': l.emitType(TokenPercent) case '(': - if l.mode == STR_IDENTIFIER { + if l.mode == STR_INTERPOLATION { // 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 == STR_IDENTIFIER { + if l.mode == STR_INTERPOLATION { l.openBrackets-- if l.openBrackets == 0 { l.mode = NORMAL @@ -130,7 +130,7 @@ func rootState(l *lexer) stateFn { case '"': return stringState case '\\': - if l.mode == STR_IDENTIFIER { + if l.mode == STR_INTERPOLATION { r = l.next() switch r { case '(': diff --git a/runtime/sema/check_string_template_expression.go b/runtime/sema/check_string_template_expression.go index 7a7eac8b3d..ddb0d6ed0d 100644 --- a/runtime/sema/check_string_template_expression.go +++ b/runtime/sema/check_string_template_expression.go @@ -20,6 +20,12 @@ package sema import "github.com/onflow/cadence/runtime/ast" +// All number types, addresses, path types, bool, strings and characters are supported in string template +func isValidStringTemplateValue(valueType Type) bool { + return valueType == TheAddressType || valueType == StringType || valueType == BoolType || valueType == CharacterType || + IsSubType(valueType, NumberType) || IsSubType(valueType, PathType) +} + func (checker *Checker) VisitStringTemplateExpression(stringTemplateExpression *ast.StringTemplateExpression) Type { // visit all elements @@ -37,11 +43,7 @@ func (checker *Checker) VisitStringTemplateExpression(stringTemplateExpression * argumentTypes[i] = valueType - // All number types, addresses, path types, bool and strings are supported in string template - if IsSubType(valueType, NumberType) || IsSubType(valueType, TheAddressType) || - IsSubType(valueType, PathType) || IsSubType(valueType, StringType) || IsSubType(valueType, BoolType) { - checker.checkResourceMoveOperation(element, valueType) - } else { + if !isValidStringTemplateValue(valueType) { checker.report( &TypeMismatchWithDescriptionError{ ActualType: valueType, diff --git a/runtime/tests/interpreter/interpreter_test.go b/runtime/tests/interpreter/interpreter_test.go index 855888eea0..bf1f3a5c30 100644 --- a/runtime/tests/interpreter/interpreter_test.go +++ b/runtime/tests/interpreter/interpreter_test.go @@ -12394,4 +12394,22 @@ func TestInterpretStringTemplates(t *testing.T) { 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), + ) + }) } From 5f163333eb1290df11bd7e1443b08ea03eb8a3c0 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Wed, 2 Oct 2024 15:18:47 -0400 Subject: [PATCH 21/70] Refactor stringer, improve generator, update simple types. --- runtime/sema/bool_type.go | 3 + runtime/sema/character.cdc | 2 +- runtime/sema/character.gen.go | 1 + runtime/sema/gen/main.go | 263 +++++++++++++++++- runtime/sema/path_type.go | 3 + runtime/sema/simple_type.go | 21 ++ runtime/sema/string_type.go | 3 + runtime/sema/struct_stringer.cdc | 7 + .../{stringer.go => struct_stringer.gen.go} | 49 ++-- runtime/sema/struct_stringer.go | 21 ++ runtime/sema/type.go | 116 ++++---- 11 files changed, 412 insertions(+), 77 deletions(-) create mode 100644 runtime/sema/struct_stringer.cdc rename runtime/sema/{stringer.go => struct_stringer.gen.go} (53%) create mode 100644 runtime/sema/struct_stringer.go diff --git a/runtime/sema/bool_type.go b/runtime/sema/bool_type.go index 36f1db3e70..1c19660bd8 100644 --- a/runtime/sema/bool_type.go +++ b/runtime/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/runtime/sema/character.cdc b/runtime/sema/character.cdc index 7b54afdf5d..3532e4713a 100644 --- a/runtime/sema/character.cdc +++ b/runtime/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/runtime/sema/character.gen.go b/runtime/sema/character.gen.go index 3938f01bb8..57bcc0f431 100644 --- a/runtime/sema/character.gen.go +++ b/runtime/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/runtime/sema/gen/main.go b/runtime/sema/gen/main.go index d06e081257..9871ab963f 100644 --- a/runtime/sema/gen/main.go +++ b/runtime/sema/gen/main.go @@ -164,6 +164,7 @@ type typeDecl struct { memberDeclarations []ast.Declaration nestedTypes []*typeDecl hasConstructor bool + structStringer bool } type generator struct { @@ -572,6 +573,8 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ )) } typeDecl.memberAccessible = true + case "StructStringer": + typeDecl.structStringer = true } } @@ -736,8 +739,152 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ return } -func (*generator) VisitInterfaceDeclaration(_ *ast.InterfaceDeclaration) struct{} { - panic("interface declarations are not supported") +func (g *generator) VisitInterfaceDeclaration(decl *ast.InterfaceDeclaration) (_ struct{}) { + compositeKind := decl.CompositeKind + switch compositeKind { + case common.CompositeKindStructure, + common.CompositeKindResource, + common.CompositeKindContract: + break + default: + 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, + ) + } + + g.typeStack = append( + g.typeStack, + typeDecl, + ) + defer func() { + // Pop + lastIndex := len(g.typeStack) - 1 + g.typeStack[lastIndex] = nil + g.typeStack = g.typeStack[:lastIndex] + }() + + for _, memberDeclaration := range decl.Members.Declarations() { + generateDeclaration(g, memberDeclaration) + + // Visiting unsupported declarations panics, + // so only supported member declarations are added + typeDecl.memberDeclarations = append( + typeDecl.memberDeclarations, + memberDeclaration, + ) + } + + var typeVarDecl = interfaceTypeExpr(typeDecl) + + fullTypeName := typeDecl.fullTypeName + + tyVarName := typeVarName(fullTypeName) + + g.addDecls( + goConstDecl( + typeNameVarName(fullTypeName), + goStringLit(typeName), + ), + goVarDecl( + tyVarName, + typeVarDecl, + ), + ) + + memberDeclarations := typeDecl.memberDeclarations + + if len(memberDeclarations) > 0 { + + // func init() { + // members := []*Member{...} + // t.Members = MembersAsMap(members) + // t.Fields = MembersFieldNames(members) + // t.ConstructorParameters = ... + // } + + members := membersExpr( + fullTypeName, + tyVarName, + memberDeclarations, + ) + + const membersVariableIdentifier = "members" + + stmts := []dst.Stmt{ + &dst.DeclStmt{ + Decl: goVarDecl( + membersVariableIdentifier, + members, + ), + }, + &dst.AssignStmt{ + Lhs: []dst.Expr{ + &dst.SelectorExpr{ + X: dst.NewIdent(tyVarName), + Sel: dst.NewIdent("Members"), + }, + }, + Tok: token.ASSIGN, + Rhs: []dst.Expr{ + &dst.CallExpr{ + Fun: &dst.Ident{ + Name: "MembersAsMap", + Path: semaPath, + }, + Args: []dst.Expr{ + dst.NewIdent(membersVariableIdentifier), + }, + }, + }, + }, + &dst.AssignStmt{ + Lhs: []dst.Expr{ + &dst.SelectorExpr{ + X: dst.NewIdent(tyVarName), + Sel: dst.NewIdent("Fields"), + }, + }, + Tok: token.ASSIGN, + Rhs: []dst.Expr{ + &dst.CallExpr{ + Fun: &dst.Ident{ + Name: "MembersFieldNames", + Path: semaPath, + }, + Args: []dst.Expr{ + dst.NewIdent(membersVariableIdentifier), + }, + }, + }, + }, + } + + g.addDecls( + &dst.FuncDecl{ + Name: dst.NewIdent("init"), + Type: &dst.FuncType{}, + Body: &dst.BlockStmt{ + List: stmts, + }, + }, + ) + } + + return } func (*generator) VisitAttachmentDeclaration(_ *ast.AttachmentDeclaration) struct{} { @@ -1591,6 +1738,9 @@ func simpleTypeLiteral(ty *typeDecl) dst.Expr { // Comparable: false, // Exportable: false, // Importable: false, + // comformances: []*InterfaceType { + // StructStringer, + // } //} isResource := ty.compositeKind == common.CompositeKindResource @@ -1607,6 +1757,21 @@ func simpleTypeLiteral(ty *typeDecl) dst.Expr { goKeyValue("Exportable", goBoolLit(ty.exportable)), goKeyValue("Importable", goBoolLit(ty.importable)), goKeyValue("ContainFields", goBoolLit(ty.memberAccessible)), + goKeyValue("conformances", &dst.CompositeLit{ + Type: &dst.ArrayType{ + Elt: &dst.StarExpr{ + X: &dst.Ident{ + Name: "InterfaceType", + }, + }, + }, + Elts: []dst.Expr{ + &dst.Ident{ + Name: "StructStringerType", + Path: semaPath, + }, + }, + }), } return &dst.UnaryExpr{ @@ -2069,6 +2234,100 @@ func compositeTypeLiteral(ty *typeDecl) dst.Expr { } } +func interfaceTypeExpr(ty *typeDecl) dst.Expr { + + // 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, + interfaceTypeLiteral(ty), + ), + }, + } + + for _, nestedType := range ty.nestedTypes { + statements = append( + statements, + &dst.ExprStmt{ + X: &dst.CallExpr{ + Fun: &dst.SelectorExpr{ + X: dst.NewIdent(typeVarName), + Sel: dst.NewIdent("SetNestedType"), + }, + Args: []dst.Expr{ + typeNameVarIdent(nestedType.fullTypeName), + typeVarIdent(nestedType.fullTypeName), + }, + }, + }, + ) + } + + statements = append( + statements, + &dst.ReturnStmt{ + Results: []dst.Expr{ + dst.NewIdent(typeVarName), + }, + }, + ) + + return &dst.CallExpr{ + Fun: &dst.FuncLit{ + Type: &dst.FuncType{ + Func: true, + Results: &dst.FieldList{ + List: []*dst.Field{ + { + Type: &dst.StarExpr{ + X: &dst.Ident{ + Name: "InterfaceType", + Path: semaPath, + }, + }, + }, + }, + }, + }, + Body: &dst.BlockStmt{ + List: statements, + }, + }, + } +} + +func interfaceTypeLiteral(ty *typeDecl) dst.Expr { + kind := compositeKindExpr(ty.compositeKind) + + elements := []dst.Expr{ + goKeyValue("Identifier", typeNameVarIdent(ty.fullTypeName)), + goKeyValue("CompositeKind", kind), + } + + return &dst.UnaryExpr{ + Op: token.AND, + X: &dst.CompositeLit{ + Type: &dst.Ident{ + Name: "InterfaceType", + Path: semaPath, + }, + Elts: elements, + }, + } +} + func typeAnnotationCallExpr(ty dst.Expr) *dst.CallExpr { return &dst.CallExpr{ Fun: &dst.Ident{ diff --git a/runtime/sema/path_type.go b/runtime/sema/path_type.go index 4334054f60..018a189aec 100644 --- a/runtime/sema/path_type.go +++ b/runtime/sema/path_type.go @@ -31,6 +31,9 @@ var PathType = &SimpleType{ Comparable: false, Exportable: true, Importable: true, + conformances: []*InterfaceType{ + StructStringerType, + }, } var PathTypeAnnotation = NewTypeAnnotation(PathType) diff --git a/runtime/sema/simple_type.go b/runtime/sema/simple_type.go index 7f2d7e362a..eea74d1060 100644 --- a/runtime/sema/simple_type.go +++ b/runtime/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/runtime/sema/string_type.go b/runtime/sema/string_type.go index 200c599f88..9257c4b5bb 100644 --- a/runtime/sema/string_type.go +++ b/runtime/sema/string_type.go @@ -143,6 +143,9 @@ var StringType = &SimpleType{ }, IndexingType: IntegerType, }, + conformances: []*InterfaceType{ + StructStringerType, + }, } var StringTypeAnnotation = NewTypeAnnotation(StringType) diff --git a/runtime/sema/struct_stringer.cdc b/runtime/sema/struct_stringer.cdc new file mode 100644 index 0000000000..224765fd90 --- /dev/null +++ b/runtime/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/runtime/sema/stringer.go b/runtime/sema/struct_stringer.gen.go similarity index 53% rename from runtime/sema/stringer.go rename to runtime/sema/struct_stringer.gen.go index 1331fdc3eb..fd583822cd 100644 --- a/runtime/sema/stringer.go +++ b/runtime/sema/struct_stringer.gen.go @@ -1,3 +1,4 @@ +// Code generated from struct_stringer.cdc. DO NOT EDIT. /* * Cadence - The resource-oriented smart contract programming language * @@ -23,37 +24,41 @@ import ( "github.com/onflow/cadence/runtime/common" ) -const StringerTypeName = "Stringer" +const StructStringerTypeToStringFunctionName = "toString" -var StringerType = func() *InterfaceType { +var StructStringerTypeToStringFunctionType = &FunctionType{ + Purity: FunctionPurityView, + ReturnTypeAnnotation: NewTypeAnnotation( + StringType, + ), +} - stringerType := &InterfaceType{ - Identifier: StringerTypeName, - CompositeKind: common.CompositeKindStructure, - Members: &StringMemberOrderedMap{}, - } +const StructStringerTypeToStringFunctionDocString = ` +Returns the string representation of this object. +` - const StringerTypeToStringFunctionDocString = `Returns this object as a String.` +const StructStringerTypeName = "StructStringer" - const StringerTypeToStringFunctionName = "toString" - - var StringerTypeToStringFunctionType = &FunctionType{ - Purity: FunctionPurityView, - ReturnTypeAnnotation: NewTypeAnnotation( - StringType, - ), +var StructStringerType = func() *InterfaceType { + var t = &InterfaceType{ + Identifier: StructStringerTypeName, + CompositeKind: common.CompositeKindStructure, } + return t +}() + +func init() { var members = []*Member{ NewUnmeteredFunctionMember( - stringerType, + StructStringerType, PrimitiveAccess(ast.AccessAll), - StringerTypeToStringFunctionName, - StringerTypeToStringFunctionType, - StringerTypeToStringFunctionDocString, + StructStringerTypeToStringFunctionName, + StructStringerTypeToStringFunctionType, + StructStringerTypeToStringFunctionDocString, ), } - stringerType.Members = MembersAsMap(members) - return stringerType -}() + StructStringerType.Members = MembersAsMap(members) + StructStringerType.Fields = MembersFieldNames(members) +} diff --git a/runtime/sema/struct_stringer.go b/runtime/sema/struct_stringer.go new file mode 100644 index 0000000000..a91c8796c7 --- /dev/null +++ b/runtime/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/runtime/sema/type.go b/runtime/sema/type.go index c9ab715c7f..221b6ce67b 100644 --- a/runtime/sema/type.go +++ b/runtime/sema/type.go @@ -4198,7 +4198,7 @@ func init() { DeploymentResultType, HashableStructType, &InclusiveRangeType{}, - StringerType, + StructStringerType, }, ) @@ -4900,7 +4900,7 @@ func IsHashableStructType(t Type) bool { } } -// which simple types conform to stringer interface (except Bool?) +// which simple types conform to stringer interface func IsStringerType(t Type) bool { switch t { case BoolType, CharacterType, StringType: @@ -7723,6 +7723,14 @@ func checkSubTypeWithoutEquality(subType Type, superType Type) bool { case *IntersectionType: + switch typedSubType := subType.(type) { + case *SimpleType: + // An simple type `T` is a subtype of an intersection type `{Vs}` / `{Vs}` / `{Vs}`: + // when `T` conforms to `Vs`. + return typedSuperType.EffectiveIntersectionSet(). + IsSubsetOf(typedSubType.EffectiveInterfaceConformanceSet()) + } + // TODO: replace with // //switch typedSubType := subType.(type) { @@ -7837,9 +7845,8 @@ func checkSubTypeWithoutEquality(subType Type, superType Type) bool { IsSubsetOf(typedSubType.EffectiveInterfaceConformanceSet()) } - // STRINGERTODO: other options? how to make existing simple types - // conform to an intersection type? - if typedSuperType.Types[0].Identifier == StringerTypeName { + // deal with non-simple types such as NumberType and AddressType + if typedSuperType.EffectiveIntersectionSet().Contains(StructStringerType) { return IsStringerType(subType) } @@ -9517,10 +9524,57 @@ 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) { + nestedCompositeType, ok := nestedType.(*CompositeType) + if !ok { + return + } + + types = append(types, nestedCompositeType) + }) + case *InterfaceType: + NativeInterfaceTypes[actualType.QualifiedIdentifier()] = actualType + + nestedTypes := actualType.NestedTypes + if nestedTypes == nil { + continue + } + + nestedTypes.Foreach(func(_ string, nestedType Type) { + nestedInterfaceType, ok := nestedType.(*InterfaceType) + if !ok { + return + } + + types = append(types, nestedInterfaceType) + }) + } + + } +} + var NativeCompositeTypes = map[string]*CompositeType{} func init() { - compositeTypes := []*CompositeType{ + compositeTypes := []Type{ AccountKeyType, PublicKeyType, HashAlgorithmType, @@ -9529,57 +9583,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 - - nestedTypes := compositeType.NestedTypes - if nestedTypes == nil { - continue - } - - nestedTypes.Foreach(func(_ string, nestedType Type) { - nestedCompositeType, ok := nestedType.(*CompositeType) - if !ok { - return - } - - compositeTypes = append(compositeTypes, nestedCompositeType) - }) - } + extractNativeTypes(compositeTypes) } var NativeInterfaceTypes = map[string]*InterfaceType{} func init() { - interfaceTypes := []*InterfaceType{ - StringerType, + interfaceTypes := []Type{ + StructStringerType, } - for len(interfaceTypes) > 0 { - lastIndex := len(interfaceTypes) - 1 - interfaceType := interfaceTypes[lastIndex] - interfaceTypes[lastIndex] = nil - interfaceTypes = interfaceTypes[:lastIndex] - - NativeInterfaceTypes[interfaceType.QualifiedIdentifier()] = interfaceType - - nestedTypes := interfaceType.NestedTypes - if nestedTypes == nil { - continue - } - - nestedTypes.Foreach(func(_ string, nestedType Type) { - nestedInterfaceType, ok := nestedType.(*InterfaceType) - if !ok { - return - } - - interfaceTypes = append(interfaceTypes, nestedInterfaceType) - }) - } + extractNativeTypes(interfaceTypes) } From ab157ad8e4b0fb15147493aca0beab5d08be0203 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Wed, 2 Oct 2024 15:19:42 -0400 Subject: [PATCH 22/70] Update tests. --- runtime/tests/checker/stringer_test.go | 18 ++++++------ runtime/tests/interpreter/stringer_test.go | 32 +++++++++++++++++++--- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/runtime/tests/checker/stringer_test.go b/runtime/tests/checker/stringer_test.go index e9b953f4e3..eb6897e232 100644 --- a/runtime/tests/checker/stringer_test.go +++ b/runtime/tests/checker/stringer_test.go @@ -31,16 +31,16 @@ func TestCheckStringer(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - let a: {Stringer} = 1 - let b: {Stringer} = false - let c: {Stringer} = "hey" + let a: {StructStringer} = 1 + let b: {StructStringer} = false + let c: {StructStringer} = "hey" access(all) - struct Foo: Stringer { + struct Foo: StructStringer { view fun toString():String { return "foo" } } - let d: {Stringer} = Foo() + let d: {StructStringer} = Foo() `) assert.NoError(t, err) @@ -53,10 +53,10 @@ func TestCheckInvalidStringer(t *testing.T) { _, err := ParseAndCheck(t, ` resource R {} - let a: {Stringer} = <-create R() - let b: {Stringer} = [<-create R()] - let c: {Stringer} = {1: true} - struct Foo: Stringer {} + let a: {StructStringer} = <-create R() + let b: {StructStringer} = [<-create R()] + let c: {StructStringer} = {1: true} + struct Foo: StructStringer {} `) errs := RequireCheckerErrors(t, err, 4) diff --git a/runtime/tests/interpreter/stringer_test.go b/runtime/tests/interpreter/stringer_test.go index fbd6da1388..eca78e7b5c 100644 --- a/runtime/tests/interpreter/stringer_test.go +++ b/runtime/tests/interpreter/stringer_test.go @@ -33,12 +33,12 @@ func TestStringerBasic(t *testing.T) { inter := parseCheckAndInterpret(t, ` access(all) - struct Example: Stringer { - view fun toString():String { + struct Example: StructStringer { + view fun toString(): String { return "example" } } - fun test() :String { + fun test(): String { return Example().toString() } `) @@ -60,7 +60,7 @@ func TestStringerBuiltIn(t *testing.T) { inter := parseCheckAndInterpret(t, ` access(all) - fun test() :String { + fun test(): String { let v = 1 return v.toString() } @@ -76,3 +76,27 @@ func TestStringerBuiltIn(t *testing.T) { result, ) } + +func TestStringerAsValue(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, + ) +} From 72ff98ca1832b518b26f8d1e438e17cf709b62c2 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Wed, 2 Oct 2024 15:29:44 -0400 Subject: [PATCH 23/70] Fix generator conditional conformances check. --- runtime/sema/gen/main.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/runtime/sema/gen/main.go b/runtime/sema/gen/main.go index 9871ab963f..7588b742ec 100644 --- a/runtime/sema/gen/main.go +++ b/runtime/sema/gen/main.go @@ -1757,7 +1757,10 @@ func simpleTypeLiteral(ty *typeDecl) dst.Expr { goKeyValue("Exportable", goBoolLit(ty.exportable)), goKeyValue("Importable", goBoolLit(ty.importable)), goKeyValue("ContainFields", goBoolLit(ty.memberAccessible)), - goKeyValue("conformances", &dst.CompositeLit{ + } + + if ty.structStringer { + elements = append(elements, goKeyValue("conformances", &dst.CompositeLit{ Type: &dst.ArrayType{ Elt: &dst.StarExpr{ X: &dst.Ident{ @@ -1771,7 +1774,7 @@ func simpleTypeLiteral(ty *typeDecl) dst.Expr { Path: semaPath, }, }, - }), + })) } return &dst.UnaryExpr{ From 060945d93dd7152538f39201156e32e842930014 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Wed, 2 Oct 2024 16:41:10 -0400 Subject: [PATCH 24/70] Code cleanup. --- runtime/parser/expression.go | 3 +-- runtime/parser/lexer/lexer.go | 8 ++++---- runtime/parser/lexer/state.go | 8 ++++---- .../sema/check_string_template_expression.go | 19 ++++++++++--------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/runtime/parser/expression.go b/runtime/parser/expression.go index 78a53c77ad..4d2dbbeef1 100644 --- a/runtime/parser/expression.go +++ b/runtime/parser/expression.go @@ -1165,14 +1165,13 @@ func defineStringExpression() { for curToken.Is(lexer.TokenString) { literal = p.tokenSource(curToken) - length = len(literal) // remove quotation marks if they exist if curToken == startToken { literal = literal[1:] - length = len(literal) } + length = len(literal) if length >= 1 && literal[length-1] == '"' { literal = literal[:length-1] missingEnd = false diff --git a/runtime/parser/lexer/lexer.go b/runtime/parser/lexer/lexer.go index 25e7635594..4bd89aabf6 100644 --- a/runtime/parser/lexer/lexer.go +++ b/runtime/parser/lexer/lexer.go @@ -52,8 +52,8 @@ type position struct { type lexerMode uint8 const ( - NORMAL lexerMode = iota - STR_INTERPOLATION + normal lexerMode = iota + stringInterpolation ) type lexer struct { @@ -141,7 +141,7 @@ func (l *lexer) clear() { l.cursor = 0 l.tokens = l.tokens[:0] l.tokenCount = 0 - l.mode = NORMAL + l.mode = normal l.openBrackets = 0 } @@ -427,7 +427,7 @@ func (l *lexer) scanString(quote rune) { switch r { case '(': // string template, stop and set mode - l.mode = STR_INTERPOLATION + l.mode = stringInterpolation // no need to update prev values because these next tokens will not backup l.endOffset = tmpBackupOffset l.current = tmpBackup diff --git a/runtime/parser/lexer/state.go b/runtime/parser/lexer/state.go index b536111c86..0a436760af 100644 --- a/runtime/parser/lexer/state.go +++ b/runtime/parser/lexer/state.go @@ -56,17 +56,17 @@ func rootState(l *lexer) stateFn { case '%': l.emitType(TokenPercent) case '(': - if l.mode == STR_INTERPOLATION { + if l.mode == stringInterpolation { // 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 == STR_INTERPOLATION { + if l.mode == stringInterpolation { l.openBrackets-- if l.openBrackets == 0 { - l.mode = NORMAL + l.mode = normal return stringState } } @@ -130,7 +130,7 @@ func rootState(l *lexer) stateFn { case '"': return stringState case '\\': - if l.mode == STR_INTERPOLATION { + if l.mode == stringInterpolation { r = l.next() switch r { case '(': diff --git a/runtime/sema/check_string_template_expression.go b/runtime/sema/check_string_template_expression.go index ddb0d6ed0d..5baf38cd83 100644 --- a/runtime/sema/check_string_template_expression.go +++ b/runtime/sema/check_string_template_expression.go @@ -22,8 +22,16 @@ import "github.com/onflow/cadence/runtime/ast" // All number types, addresses, path types, bool, strings and characters are supported in string template func isValidStringTemplateValue(valueType Type) bool { - return valueType == TheAddressType || valueType == StringType || valueType == BoolType || valueType == CharacterType || - IsSubType(valueType, NumberType) || IsSubType(valueType, PathType) + 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 { @@ -55,12 +63,5 @@ func (checker *Checker) VisitStringTemplateExpression(stringTemplateExpression * } } - checker.Elaboration.SetStringTemplateExpressionTypes( - stringTemplateExpression, - StringTemplateExpressionTypes{ - ArgumentTypes: argumentTypes, - }, - ) - return StringType } From ad94aebd34a09163b10822b2404362f5b0c0302e Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Thu, 3 Oct 2024 10:35:33 -0400 Subject: [PATCH 25/70] Add ConformingType interface. --- runtime/sema/gen/main.go | 22 ++++--- runtime/sema/path_type.go | 12 ++++ runtime/sema/type.go | 71 ++++++++++++++++++---- runtime/tests/checker/stringer_test.go | 1 + runtime/tests/interpreter/stringer_test.go | 25 +++++++- 5 files changed, 108 insertions(+), 23 deletions(-) diff --git a/runtime/sema/gen/main.go b/runtime/sema/gen/main.go index 7588b742ec..ae16966da5 100644 --- a/runtime/sema/gen/main.go +++ b/runtime/sema/gen/main.go @@ -164,7 +164,9 @@ type typeDecl struct { memberDeclarations []ast.Declaration nestedTypes []*typeDecl hasConstructor bool - structStringer bool + + // used in simpleType generation + conformances []string } type generator struct { @@ -574,7 +576,7 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ } typeDecl.memberAccessible = true case "StructStringer": - typeDecl.structStringer = true + typeDecl.conformances = append(typeDecl.conformances, "StructStringerType") } } @@ -1759,7 +1761,14 @@ func simpleTypeLiteral(ty *typeDecl) dst.Expr { goKeyValue("ContainFields", goBoolLit(ty.memberAccessible)), } - if ty.structStringer { + if len(ty.conformances) > 0 { + var elts = []dst.Expr{} + for _, conformance := range ty.conformances { + elts = append(elts, &dst.Ident{ + Name: conformance, + Path: semaPath, + }) + } elements = append(elements, goKeyValue("conformances", &dst.CompositeLit{ Type: &dst.ArrayType{ Elt: &dst.StarExpr{ @@ -1768,12 +1777,7 @@ func simpleTypeLiteral(ty *typeDecl) dst.Expr { }, }, }, - Elts: []dst.Expr{ - &dst.Ident{ - Name: "StructStringerType", - Path: semaPath, - }, - }, + Elts: elts, })) } diff --git a/runtime/sema/path_type.go b/runtime/sema/path_type.go index 018a189aec..042be61502 100644 --- a/runtime/sema/path_type.go +++ b/runtime/sema/path_type.go @@ -51,6 +51,9 @@ var StoragePathType = &SimpleType{ Comparable: false, Exportable: true, Importable: true, + conformances: []*InterfaceType{ + StructStringerType, + }, } var StoragePathTypeAnnotation = NewTypeAnnotation(StoragePathType) @@ -68,6 +71,9 @@ var CapabilityPathType = &SimpleType{ Comparable: false, Exportable: true, Importable: true, + conformances: []*InterfaceType{ + StructStringerType, + }, } var CapabilityPathTypeAnnotation = NewTypeAnnotation(CapabilityPathType) @@ -85,6 +91,9 @@ var PublicPathType = &SimpleType{ Comparable: false, Exportable: true, Importable: true, + conformances: []*InterfaceType{ + StructStringerType, + }, } var PublicPathTypeAnnotation = NewTypeAnnotation(PublicPathType) @@ -102,6 +111,9 @@ var PrivatePathType = &SimpleType{ Comparable: false, Exportable: true, Importable: true, + conformances: []*InterfaceType{ + StructStringerType, + }, } var PrivatePathTypeAnnotation = NewTypeAnnotation(PrivatePathType) diff --git a/runtime/sema/type.go b/runtime/sema/type.go index 221b6ce67b..3687c385b1 100644 --- a/runtime/sema/type.go +++ b/runtime/sema/type.go @@ -312,6 +312,12 @@ func TypeActivationNestedType(typeActivation *VariableActivation, qualifiedIdent return ty } +// allow all types to specify interface conformances +type ConformingType interface { + Type + EffectiveInterfaceConformanceSet() *InterfaceSet +} + // CompositeKindedType is a type which has a composite kind type CompositeKindedType interface { Type @@ -1190,6 +1196,11 @@ type NumericType struct { memberResolversOnce sync.Once saturatingArithmetic SaturatingArithmeticSupport isSuperType bool + + // allow numeric types to conform to interfaces + conformances []*InterfaceType + effectiveInterfaceConformanceSet *InterfaceSet + effectiveInterfaceConformanceSetOnce sync.Once } var _ Type = &NumericType{} @@ -1197,7 +1208,12 @@ var _ IntegerRangedType = &NumericType{} var _ SaturatingArithmeticType = &NumericType{} func NewNumericType(typeName string) *NumericType { - return &NumericType{name: typeName} + return &NumericType{ + name: typeName, + conformances: []*InterfaceType{ + StructStringerType, + }, + } } func (t *NumericType) Tag() TypeTag { @@ -1375,6 +1391,21 @@ func (*NumericType) CheckInstantiated(_ ast.HasPosition, _ common.MemoryGauge, _ // NO-OP } +func (t *NumericType) EffectiveInterfaceConformanceSet() *InterfaceSet { + t.initializeEffectiveInterfaceConformanceSet() + return t.effectiveInterfaceConformanceSet +} + +func (t *NumericType) initializeEffectiveInterfaceConformanceSet() { + t.effectiveInterfaceConformanceSetOnce.Do(func() { + t.effectiveInterfaceConformanceSet = NewInterfaceSet() + + for _, conformance := range t.conformances { + t.effectiveInterfaceConformanceSet.Add(conformance) + } + }) +} + // FixedPointNumericType represents all the types in the fixed-point range. type FixedPointNumericType struct { maxFractional *big.Int @@ -7256,11 +7287,18 @@ const AddressTypeName = "Address" // AddressType represents the address type type AddressType struct { - memberResolvers map[string]MemberResolver - memberResolversOnce sync.Once + memberResolvers map[string]MemberResolver + memberResolversOnce sync.Once + conformances []*InterfaceType + effectiveInterfaceConformanceSet *InterfaceSet + effectiveInterfaceConformanceSetOnce sync.Once } -var TheAddressType = &AddressType{} +var TheAddressType = &AddressType{ + conformances: []*InterfaceType{ + StructStringerType, + }, +} var AddressTypeAnnotation = NewTypeAnnotation(TheAddressType) var _ Type = &AddressType{} @@ -7405,6 +7443,21 @@ func (t *AddressType) initializeMemberResolvers() { }) } +func (t *AddressType) EffectiveInterfaceConformanceSet() *InterfaceSet { + t.initializeEffectiveInterfaceConformanceSet() + return t.effectiveInterfaceConformanceSet +} + +func (t *AddressType) initializeEffectiveInterfaceConformanceSet() { + t.effectiveInterfaceConformanceSetOnce.Do(func() { + t.effectiveInterfaceConformanceSet = NewInterfaceSet() + + for _, conformance := range t.conformances { + t.effectiveInterfaceConformanceSet.Add(conformance) + } + }) +} + func IsPrimitiveOrContainerOfPrimitive(referencedType Type) bool { switch ty := referencedType.(type) { case *VariableSizedType: @@ -7723,14 +7776,6 @@ func checkSubTypeWithoutEquality(subType Type, superType Type) bool { case *IntersectionType: - switch typedSubType := subType.(type) { - case *SimpleType: - // An simple type `T` is a subtype of an intersection type `{Vs}` / `{Vs}` / `{Vs}`: - // when `T` conforms to `Vs`. - return typedSuperType.EffectiveIntersectionSet(). - IsSubsetOf(typedSubType.EffectiveInterfaceConformanceSet()) - } - // TODO: replace with // //switch typedSubType := subType.(type) { @@ -7829,7 +7874,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, diff --git a/runtime/tests/checker/stringer_test.go b/runtime/tests/checker/stringer_test.go index eb6897e232..5bfc2c7fcb 100644 --- a/runtime/tests/checker/stringer_test.go +++ b/runtime/tests/checker/stringer_test.go @@ -41,6 +41,7 @@ func TestCheckStringer(t *testing.T) { } } let d: {StructStringer} = Foo() + let e: {StructStringer} = /public/foo `) assert.NoError(t, err) diff --git a/runtime/tests/interpreter/stringer_test.go b/runtime/tests/interpreter/stringer_test.go index eca78e7b5c..eafe44652f 100644 --- a/runtime/tests/interpreter/stringer_test.go +++ b/runtime/tests/interpreter/stringer_test.go @@ -77,7 +77,7 @@ func TestStringerBuiltIn(t *testing.T) { ) } -func TestStringerAsValue(t *testing.T) { +func TestStringerCast(t *testing.T) { t.Parallel() @@ -100,3 +100,26 @@ func TestStringerAsValue(t *testing.T) { 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, + ) +} From 26428cb0f2fe7993080a8e87dbd43ae903388120 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Thu, 3 Oct 2024 10:39:45 -0400 Subject: [PATCH 26/70] Clean up unnecessary code. --- runtime/sema/type.go | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/runtime/sema/type.go b/runtime/sema/type.go index 3687c385b1..b22f23f9d0 100644 --- a/runtime/sema/type.go +++ b/runtime/sema/type.go @@ -4931,17 +4931,6 @@ func IsHashableStructType(t Type) bool { } } -// which simple types conform to stringer interface -func IsStringerType(t Type) bool { - switch t { - case BoolType, CharacterType, StringType: - return true - default: - return IsSubType(t, NumberType) || - IsSubType(t, PathType) || IsSubType(t, TheAddressType) - } -} - func (t *CompositeType) GetBaseType() Type { return t.baseType } @@ -7890,11 +7879,6 @@ func checkSubTypeWithoutEquality(subType Type, superType Type) bool { IsSubsetOf(typedSubType.EffectiveInterfaceConformanceSet()) } - // deal with non-simple types such as NumberType and AddressType - if typedSuperType.EffectiveIntersectionSet().Contains(StructStringerType) { - return IsStringerType(subType) - } - default: // Supertype (intersection) has a non-Any* legacy type From 447f05565ac9c6d4092edd117822407b5c02e069 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Thu, 3 Oct 2024 16:02:36 -0400 Subject: [PATCH 27/70] Remove unused code. --- runtime/sema/elaboration.go | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/runtime/sema/elaboration.go b/runtime/sema/elaboration.go index d2ef948a78..b6b025eef0 100644 --- a/runtime/sema/elaboration.go +++ b/runtime/sema/elaboration.go @@ -79,10 +79,6 @@ type ArrayExpressionTypes struct { ArgumentTypes []Type } -type StringTemplateExpressionTypes struct { - ArgumentTypes []Type -} - type DictionaryExpressionTypes struct { DictionaryType *DictionaryType EntryTypes []DictionaryEntryType @@ -144,7 +140,6 @@ type Elaboration struct { dictionaryExpressionTypes map[*ast.DictionaryExpression]DictionaryExpressionTypes integerExpressionTypes map[*ast.IntegerExpression]Type stringExpressionTypes map[*ast.StringExpression]Type - stringTemplateExpressionTypes map[*ast.StringTemplateExpression]StringTemplateExpressionTypes returnStatementTypes map[*ast.ReturnStatement]ReturnStatementTypes functionDeclarationFunctionTypes map[*ast.FunctionDeclaration]*FunctionType variableDeclarationTypes map[*ast.VariableDeclaration]VariableDeclarationTypes @@ -485,21 +480,6 @@ func (e *Elaboration) SetStringExpressionType(expression *ast.StringExpression, e.stringExpressionTypes[expression] = ty } -func (e *Elaboration) StringTemplateExpressionTypes(expression *ast.StringTemplateExpression) (types StringTemplateExpressionTypes) { - if e.stringTemplateExpressionTypes == nil { - return - } - // default, Elaboration.SetStringExpressionType - return e.stringTemplateExpressionTypes[expression] -} - -func (e *Elaboration) SetStringTemplateExpressionTypes(expression *ast.StringTemplateExpression, types StringTemplateExpressionTypes) { - if e.stringTemplateExpressionTypes == nil { - e.stringTemplateExpressionTypes = map[*ast.StringTemplateExpression]StringTemplateExpressionTypes{} - } - e.stringTemplateExpressionTypes[expression] = types -} - func (e *Elaboration) ReturnStatementTypes(statement *ast.ReturnStatement) (types ReturnStatementTypes) { if e.returnStatementTypes == nil { return From fc7df6cf4f962fa6429e59954a9fc8d728cd7bc0 Mon Sep 17 00:00:00 2001 From: SupunS Date: Tue, 8 Oct 2024 20:22:32 +0000 Subject: [PATCH 28/70] v1.0.1 --- npm-packages/cadence-parser/package.json | 2 +- version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/npm-packages/cadence-parser/package.json b/npm-packages/cadence-parser/package.json index 7cbff25e53..0a3cf1e26f 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.0.0-preview.52", + "version": "1.0.1-preview.52", "description": "The Cadence parser", "homepage": "https://github.com/onflow/cadence", "repository": { diff --git a/version.go b/version.go index ec1468a4d3..61904d635a 100644 --- a/version.go +++ b/version.go @@ -21,4 +21,4 @@ package cadence -const Version = "v1.0.0" +const Version = "v1.0.1" From c81e69c17bf32f9deb9368fba58d9fb5077cf049 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Thu, 10 Oct 2024 15:33:59 -0700 Subject: [PATCH 29/70] Add simple tests, fix formatting. --- runtime/sema/gen/main.go | 3 +-- runtime/tests/checker/stringer_test.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/runtime/sema/gen/main.go b/runtime/sema/gen/main.go index ae16966da5..1b07af1fe6 100644 --- a/runtime/sema/gen/main.go +++ b/runtime/sema/gen/main.go @@ -814,8 +814,7 @@ func (g *generator) VisitInterfaceDeclaration(decl *ast.InterfaceDeclaration) (_ // func init() { // members := []*Member{...} // t.Members = MembersAsMap(members) - // t.Fields = MembersFieldNames(members) - // t.ConstructorParameters = ... + // t.Fields = MembersFieldNames(members)= // } members := membersExpr( diff --git a/runtime/tests/checker/stringer_test.go b/runtime/tests/checker/stringer_test.go index 5bfc2c7fcb..c0026904ab 100644 --- a/runtime/tests/checker/stringer_test.go +++ b/runtime/tests/checker/stringer_test.go @@ -36,7 +36,7 @@ func TestCheckStringer(t *testing.T) { let c: {StructStringer} = "hey" access(all) struct Foo: StructStringer { - view fun toString():String { + view fun toString(): String { return "foo" } } @@ -58,12 +58,18 @@ func TestCheckInvalidStringer(t *testing.T) { 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, 4) + 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]) } From 57805ee7d985eeddd7590e295ff123292df4914e Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Wed, 16 Oct 2024 10:45:53 -0400 Subject: [PATCH 30/70] Update code after review. --- runtime/ast/expression.go | 7 +- runtime/ast/string_template_test.go | 48 ++++++ runtime/parser/expression_test.go | 142 +++++++++++++++++- runtime/parser/lexer/lexer.go | 8 +- runtime/parser/lexer/state.go | 8 +- .../sema/check_string_template_expression.go | 3 +- 6 files changed, 203 insertions(+), 13 deletions(-) create mode 100644 runtime/ast/string_template_test.go diff --git a/runtime/ast/expression.go b/runtime/ast/expression.go index b8bf93e86d..8cf54fdce5 100644 --- a/runtime/ast/expression.go +++ b/runtime/ast/expression.go @@ -264,7 +264,12 @@ func (e *StringTemplateExpression) String() string { } func (e *StringTemplateExpression) Doc() prettier.Doc { - return prettier.Text(QuoteString("String template")) + if len(e.Expressions) == 0 { + return prettier.Text(e.Values[0]) + } + + // TODO: must reproduce expressions as literals + panic("not implemented") } func (e *StringTemplateExpression) MarshalJSON() ([]byte, error) { diff --git a/runtime/ast/string_template_test.go b/runtime/ast/string_template_test.go new file mode 100644 index 0000000000..d6aecb0299 --- /dev/null +++ b/runtime/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_test + +import ( + "testing" + + "github.com/onflow/cadence/runtime/ast" + "github.com/stretchr/testify/assert" + "github.com/turbolent/prettier" +) + +func TestStringTemplate_Doc(t *testing.T) { + + t.Parallel() + + stmt := &ast.StringTemplateExpression{ + Values: []string{ + "abc", + }, + Expressions: []ast.Expression{}, + Range: ast.Range{ + StartPos: ast.Position{Offset: 4, Line: 2, Column: 3}, + EndPos: ast.Position{Offset: 11, Line: 2, Column: 10}, + }, + } + + assert.Equal(t, + prettier.Text("abc"), + stmt.Doc(), + ) +} diff --git a/runtime/parser/expression_test.go b/runtime/parser/expression_test.go index 8f68a7b468..e2377cf934 100644 --- a/runtime/parser/expression_test.go +++ b/runtime/parser/expression_test.go @@ -6318,7 +6318,7 @@ func TestParseStringTemplate(t *testing.T) { ) }) - t.Run("unbalanced paren", func(t *testing.T) { + t.Run("invalid, unbalanced paren", func(t *testing.T) { t.Parallel() @@ -6345,7 +6345,7 @@ func TestParseStringTemplate(t *testing.T) { ) }) - t.Run("nested templates", func(t *testing.T) { + t.Run("invalid, nested templates", func(t *testing.T) { t.Parallel() @@ -6371,6 +6371,144 @@ func TestParseStringTemplate(t *testing.T) { 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}, + }, + } + + utils.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}, + }, + } + + utils.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}, + }, + } + + utils.AssertEqualWithDiff(t, expected, actual) + }) } func TestParseNilCoalescing(t *testing.T) { diff --git a/runtime/parser/lexer/lexer.go b/runtime/parser/lexer/lexer.go index 4bd89aabf6..08f689be0e 100644 --- a/runtime/parser/lexer/lexer.go +++ b/runtime/parser/lexer/lexer.go @@ -52,8 +52,8 @@ type position struct { type lexerMode uint8 const ( - normal lexerMode = iota - stringInterpolation + lexerModeNormal lexerMode = iota + lexerModeStringInterpolation ) type lexer struct { @@ -141,7 +141,7 @@ func (l *lexer) clear() { l.cursor = 0 l.tokens = l.tokens[:0] l.tokenCount = 0 - l.mode = normal + l.mode = lexerModeNormal l.openBrackets = 0 } @@ -427,7 +427,7 @@ func (l *lexer) scanString(quote rune) { switch r { case '(': // string template, stop and set mode - l.mode = stringInterpolation + l.mode = lexerModeStringInterpolation // no need to update prev values because these next tokens will not backup l.endOffset = tmpBackupOffset l.current = tmpBackup diff --git a/runtime/parser/lexer/state.go b/runtime/parser/lexer/state.go index 0a436760af..08558c6b78 100644 --- a/runtime/parser/lexer/state.go +++ b/runtime/parser/lexer/state.go @@ -56,17 +56,17 @@ func rootState(l *lexer) stateFn { case '%': l.emitType(TokenPercent) case '(': - if l.mode == stringInterpolation { + 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 == stringInterpolation { + if l.mode == lexerModeStringInterpolation { l.openBrackets-- if l.openBrackets == 0 { - l.mode = normal + l.mode = lexerModeNormal return stringState } } @@ -130,7 +130,7 @@ func rootState(l *lexer) stateFn { case '"': return stringState case '\\': - if l.mode == stringInterpolation { + if l.mode == lexerModeStringInterpolation { r = l.next() switch r { case '(': diff --git a/runtime/sema/check_string_template_expression.go b/runtime/sema/check_string_template_expression.go index 5baf38cd83..8b4be45b48 100644 --- a/runtime/sema/check_string_template_expression.go +++ b/runtime/sema/check_string_template_expression.go @@ -42,9 +42,8 @@ func (checker *Checker) VisitStringTemplateExpression(stringTemplateExpression * elementCount := len(stringTemplateExpression.Expressions) - var argumentTypes []Type if elementCount > 0 { - argumentTypes = make([]Type, elementCount) + argumentTypes := make([]Type, elementCount) for i, element := range stringTemplateExpression.Expressions { valueType := checker.VisitExpression(element, stringTemplateExpression, elementType) From cd83793f8d65f9a5dcf67c09370891c536c496f8 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Wed, 16 Oct 2024 10:53:56 -0400 Subject: [PATCH 31/70] Fix linting. --- runtime/ast/string_template_test.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/runtime/ast/string_template_test.go b/runtime/ast/string_template_test.go index d6aecb0299..a19a399bb9 100644 --- a/runtime/ast/string_template_test.go +++ b/runtime/ast/string_template_test.go @@ -16,12 +16,11 @@ * limitations under the License. */ -package ast_test +package ast import ( "testing" - "github.com/onflow/cadence/runtime/ast" "github.com/stretchr/testify/assert" "github.com/turbolent/prettier" ) @@ -30,14 +29,14 @@ func TestStringTemplate_Doc(t *testing.T) { t.Parallel() - stmt := &ast.StringTemplateExpression{ + stmt := &StringTemplateExpression{ Values: []string{ "abc", }, - Expressions: []ast.Expression{}, - Range: ast.Range{ - StartPos: ast.Position{Offset: 4, Line: 2, Column: 3}, - EndPos: ast.Position{Offset: 11, Line: 2, Column: 10}, + Expressions: []Expression{}, + Range: Range{ + StartPos: Position{Offset: 4, Line: 2, Column: 3}, + EndPos: Position{Offset: 11, Line: 2, Column: 10}, }, } From fab5f6c196f07d1ed822c931ddc2febafedafd19 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Wed, 16 Oct 2024 14:54:46 -0400 Subject: [PATCH 32/70] Abstract common functionality, clean up. --- runtime/sema/gen/main.go | 361 +++++------------- .../gen/testdata/simple_interface/test.cdc | 1 + .../testdata/simple_interface/test.golden.go | 36 ++ runtime/sema/type.go | 76 ++-- 4 files changed, 151 insertions(+), 323 deletions(-) create mode 100644 runtime/sema/gen/testdata/simple_interface/test.cdc create mode 100644 runtime/sema/gen/testdata/simple_interface/test.golden.go diff --git a/runtime/sema/gen/main.go b/runtime/sema/gen/main.go index 1b07af1fe6..a56f0efa14 100644 --- a/runtime/sema/gen/main.go +++ b/runtime/sema/gen/main.go @@ -166,7 +166,7 @@ type typeDecl struct { hasConstructor bool // used in simpleType generation - conformances []string + conformances []*sema.InterfaceType } type generator struct { @@ -432,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 isCompositeType 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 + isCompositeType = true + case *ast.InterfaceDeclaration: + compositeKind = actualDecl.Kind() + typeName = actualDecl.Identifier.Identifier + typeDec = &typeDecl{ + typeName: typeName, + fullTypeName: g.newFullTypeName(typeName), + compositeKind: compositeKind, + } + members = actualDecl.Members.Declarations() + isCompositeType = false + default: + panic("Expected composite or interface declaration") + } - compositeKind := decl.CompositeKind switch compositeKind { case common.CompositeKindStructure, common.CompositeKindResource, @@ -444,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 @@ -476,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 !isCompositeType { + generateSimpleType = false } else { // If not, decide what to generate depending on the type. @@ -495,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, ) @@ -517,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 { @@ -526,7 +551,7 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ g.currentTypeID(), )) } - typeDecl.storable = true + typeDec.storable = true case "Primitive": if !generateSimpleType { @@ -535,7 +560,7 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ g.currentTypeID(), )) } - typeDecl.primitive = true + typeDec.primitive = true case "Equatable": if !generateSimpleType { @@ -544,7 +569,7 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ g.currentTypeID(), )) } - typeDecl.equatable = true + typeDec.equatable = true case "Comparable": if !generateSimpleType { @@ -553,7 +578,7 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ g.currentTypeID(), )) } - typeDecl.comparable = true + typeDec.comparable = true case "Exportable": if !generateSimpleType { @@ -562,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 { @@ -574,20 +599,20 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ g.currentTypeID(), )) } - typeDecl.memberAccessible = true + typeDec.memberAccessible = true case "StructStringer": - typeDecl.conformances = append(typeDecl.conformances, "StructStringerType") + 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, isCompositeType) } - fullTypeName := typeDecl.fullTypeName + fullTypeName := typeDec.fullTypeName tyVarName := typeVarName(fullTypeName) @@ -602,7 +627,7 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ ), ) - memberDeclarations := typeDecl.memberDeclarations + memberDeclarations := typeDec.memberDeclarations if len(memberDeclarations) > 0 { @@ -705,7 +730,7 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ }, } - if typeDecl.hasConstructor { + if typeDec.hasConstructor { stmts = append( stmts, &dst.AssignStmt{ @@ -741,151 +766,12 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ return } -func (g *generator) VisitInterfaceDeclaration(decl *ast.InterfaceDeclaration) (_ struct{}) { - compositeKind := decl.CompositeKind - switch compositeKind { - case common.CompositeKindStructure, - common.CompositeKindResource, - common.CompositeKindContract: - break - default: - 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, - ) - } - - g.typeStack = append( - g.typeStack, - typeDecl, - ) - defer func() { - // Pop - lastIndex := len(g.typeStack) - 1 - g.typeStack[lastIndex] = nil - g.typeStack = g.typeStack[:lastIndex] - }() - - for _, memberDeclaration := range decl.Members.Declarations() { - generateDeclaration(g, memberDeclaration) - - // Visiting unsupported declarations panics, - // so only supported member declarations are added - typeDecl.memberDeclarations = append( - typeDecl.memberDeclarations, - memberDeclaration, - ) - } - - var typeVarDecl = interfaceTypeExpr(typeDecl) - - fullTypeName := typeDecl.fullTypeName - - tyVarName := typeVarName(fullTypeName) - - g.addDecls( - goConstDecl( - typeNameVarName(fullTypeName), - goStringLit(typeName), - ), - goVarDecl( - tyVarName, - typeVarDecl, - ), - ) - - memberDeclarations := typeDecl.memberDeclarations - - if len(memberDeclarations) > 0 { - - // func init() { - // members := []*Member{...} - // t.Members = MembersAsMap(members) - // t.Fields = MembersFieldNames(members)= - // } - - members := membersExpr( - fullTypeName, - tyVarName, - memberDeclarations, - ) - - const membersVariableIdentifier = "members" - - stmts := []dst.Stmt{ - &dst.DeclStmt{ - Decl: goVarDecl( - membersVariableIdentifier, - members, - ), - }, - &dst.AssignStmt{ - Lhs: []dst.Expr{ - &dst.SelectorExpr{ - X: dst.NewIdent(tyVarName), - Sel: dst.NewIdent("Members"), - }, - }, - Tok: token.ASSIGN, - Rhs: []dst.Expr{ - &dst.CallExpr{ - Fun: &dst.Ident{ - Name: "MembersAsMap", - Path: semaPath, - }, - Args: []dst.Expr{ - dst.NewIdent(membersVariableIdentifier), - }, - }, - }, - }, - &dst.AssignStmt{ - Lhs: []dst.Expr{ - &dst.SelectorExpr{ - X: dst.NewIdent(tyVarName), - Sel: dst.NewIdent("Fields"), - }, - }, - Tok: token.ASSIGN, - Rhs: []dst.Expr{ - &dst.CallExpr{ - Fun: &dst.Ident{ - Name: "MembersFieldNames", - Path: semaPath, - }, - Args: []dst.Expr{ - dst.NewIdent(membersVariableIdentifier), - }, - }, - }, - }, - } - - g.addDecls( - &dst.FuncDecl{ - Name: dst.NewIdent("init"), - Type: &dst.FuncType{}, - Body: &dst.BlockStmt{ - List: stmts, - }, - }, - ) - } +func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ struct{}) { + return g.VisitCompositeOrInterfaceDeclaration(decl) +} - return +func (g *generator) VisitInterfaceDeclaration(decl *ast.InterfaceDeclaration) (_ struct{}) { + return g.VisitCompositeOrInterfaceDeclaration(decl) } func (*generator) VisitAttachmentDeclaration(_ *ast.AttachmentDeclaration) struct{} { @@ -1740,7 +1626,7 @@ func simpleTypeLiteral(ty *typeDecl) dst.Expr { // Exportable: false, // Importable: false, // comformances: []*InterfaceType { - // StructStringer, + // StructStringerType, // } //} @@ -1763,8 +1649,15 @@ func simpleTypeLiteral(ty *typeDecl) dst.Expr { 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: conformance, + Name: name, Path: semaPath, }) } @@ -2142,10 +2035,10 @@ func stringMemberResolverMapType() *dst.MapType { } } -func compositeTypeExpr(ty *typeDecl) dst.Expr { +func compositeOrInterfaceTypeExpr(ty *typeDecl, isCompositeType bool) dst.Expr { // func() *CompositeType { - // var t = &CompositeType{ + // var t = &CompositeType { // Identifier: FooTypeName, // Kind: common.CompositeKindStructure, // ImportableBuiltin: false, @@ -2156,92 +2049,6 @@ func compositeTypeExpr(ty *typeDecl) dst.Expr { // return t // }() - const typeVarName = "t" - - statements := []dst.Stmt{ - &dst.DeclStmt{ - Decl: goVarDecl( - typeVarName, - compositeTypeLiteral(ty), - ), - }, - } - - for _, nestedType := range ty.nestedTypes { - statements = append( - statements, - &dst.ExprStmt{ - X: &dst.CallExpr{ - Fun: &dst.SelectorExpr{ - X: dst.NewIdent(typeVarName), - Sel: dst.NewIdent("SetNestedType"), - }, - Args: []dst.Expr{ - typeNameVarIdent(nestedType.fullTypeName), - typeVarIdent(nestedType.fullTypeName), - }, - }, - }, - ) - } - - statements = append( - statements, - &dst.ReturnStmt{ - Results: []dst.Expr{ - dst.NewIdent(typeVarName), - }, - }, - ) - - return &dst.CallExpr{ - Fun: &dst.FuncLit{ - Type: &dst.FuncType{ - Func: true, - Results: &dst.FieldList{ - List: []*dst.Field{ - { - Type: &dst.StarExpr{ - X: &dst.Ident{ - Name: "CompositeType", - Path: semaPath, - }, - }, - }, - }, - }, - }, - Body: &dst.BlockStmt{ - List: statements, - }, - }, - } -} - -func compositeTypeLiteral(ty *typeDecl) 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)), - } - - return &dst.UnaryExpr{ - Op: token.AND, - X: &dst.CompositeLit{ - Type: &dst.Ident{ - Name: "CompositeType", - Path: semaPath, - }, - Elts: elements, - }, - } -} - -func interfaceTypeExpr(ty *typeDecl) dst.Expr { - // func() *InterfaceType { // var t = &InterfaceType{ // Identifier: FooTypeName, @@ -2258,7 +2065,7 @@ func interfaceTypeExpr(ty *typeDecl) dst.Expr { &dst.DeclStmt{ Decl: goVarDecl( typeVarName, - interfaceTypeLiteral(ty), + compositeOrInterfaceTypeLiteral(ty, isCompositeType), ), }, } @@ -2290,6 +2097,11 @@ func interfaceTypeExpr(ty *typeDecl) dst.Expr { }, ) + name := "InterfaceType" + if isCompositeType { + name = "CompositeType" + } + return &dst.CallExpr{ Fun: &dst.FuncLit{ Type: &dst.FuncType{ @@ -2299,7 +2111,7 @@ func interfaceTypeExpr(ty *typeDecl) dst.Expr { { Type: &dst.StarExpr{ X: &dst.Ident{ - Name: "InterfaceType", + Name: name, Path: semaPath, }, }, @@ -2314,19 +2126,30 @@ func interfaceTypeExpr(ty *typeDecl) dst.Expr { } } -func interfaceTypeLiteral(ty *typeDecl) dst.Expr { +func compositeOrInterfaceTypeLiteral(ty *typeDecl, isCompositeType bool) dst.Expr { kind := compositeKindExpr(ty.compositeKind) elements := []dst.Expr{ goKeyValue("Identifier", typeNameVarIdent(ty.fullTypeName)), - goKeyValue("CompositeKind", kind), + } + + name := "InterfaceType" + if isCompositeType { + name = "CompositeType" + elements = append(elements, + goKeyValue("Kind", kind), + goKeyValue("ImportableBuiltin", goBoolLit(ty.importable)), + goKeyValue("HasComputedMembers", goBoolLit(true))) + } else { + elements = append(elements, + goKeyValue("CompositeKind", kind)) } return &dst.UnaryExpr{ Op: token.AND, X: &dst.CompositeLit{ Type: &dst.Ident{ - Name: "InterfaceType", + Name: name, Path: semaPath, }, Elts: elements, diff --git a/runtime/sema/gen/testdata/simple_interface/test.cdc b/runtime/sema/gen/testdata/simple_interface/test.cdc new file mode 100644 index 0000000000..388ef59051 --- /dev/null +++ b/runtime/sema/gen/testdata/simple_interface/test.cdc @@ -0,0 +1 @@ +access(all) struct interface Test {} diff --git a/runtime/sema/gen/testdata/simple_interface/test.golden.go b/runtime/sema/gen/testdata/simple_interface/test.golden.go new file mode 100644 index 0000000000..ae15975a61 --- /dev/null +++ b/runtime/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/runtime/common" + "github.com/onflow/cadence/runtime/sema" +) + +const TestTypeName = "Test" + +var TestType = func() *sema.InterfaceType { + var t = &sema.InterfaceType{ + Identifier: TestTypeName, + CompositeKind: common.CompositeKindStructure, + } + + return t +}() diff --git a/runtime/sema/type.go b/runtime/sema/type.go index b22f23f9d0..0955934c6e 100644 --- a/runtime/sema/type.go +++ b/runtime/sema/type.go @@ -312,7 +312,7 @@ func TypeActivationNestedType(typeActivation *VariableActivation, qualifiedIdent return ty } -// allow all types to specify interface conformances +// ConformingType is a type that can conform to interfaces type ConformingType interface { Type EffectiveInterfaceConformanceSet() *InterfaceSet @@ -1196,11 +1196,6 @@ type NumericType struct { memberResolversOnce sync.Once saturatingArithmetic SaturatingArithmeticSupport isSuperType bool - - // allow numeric types to conform to interfaces - conformances []*InterfaceType - effectiveInterfaceConformanceSet *InterfaceSet - effectiveInterfaceConformanceSetOnce sync.Once } var _ Type = &NumericType{} @@ -1210,9 +1205,6 @@ var _ SaturatingArithmeticType = &NumericType{} func NewNumericType(typeName string) *NumericType { return &NumericType{ name: typeName, - conformances: []*InterfaceType{ - StructStringerType, - }, } } @@ -1391,19 +1383,15 @@ func (*NumericType) CheckInstantiated(_ ast.HasPosition, _ common.MemoryGauge, _ // NO-OP } -func (t *NumericType) EffectiveInterfaceConformanceSet() *InterfaceSet { - t.initializeEffectiveInterfaceConformanceSet() - return t.effectiveInterfaceConformanceSet -} +var numericTypeEffectiveInterfaceConformanceSet *InterfaceSet -func (t *NumericType) initializeEffectiveInterfaceConformanceSet() { - t.effectiveInterfaceConformanceSetOnce.Do(func() { - t.effectiveInterfaceConformanceSet = NewInterfaceSet() +func init() { + numericTypeEffectiveInterfaceConformanceSet = NewInterfaceSet() + numericTypeEffectiveInterfaceConformanceSet.Add(StructStringerType) +} - for _, conformance := range t.conformances { - t.effectiveInterfaceConformanceSet.Add(conformance) - } - }) +func (t *NumericType) EffectiveInterfaceConformanceSet() *InterfaceSet { + return numericTypeEffectiveInterfaceConformanceSet } // FixedPointNumericType represents all the types in the fixed-point range. @@ -7276,18 +7264,11 @@ const AddressTypeName = "Address" // AddressType represents the address type type AddressType struct { - memberResolvers map[string]MemberResolver - memberResolversOnce sync.Once - conformances []*InterfaceType - effectiveInterfaceConformanceSet *InterfaceSet - effectiveInterfaceConformanceSetOnce sync.Once + memberResolvers map[string]MemberResolver + memberResolversOnce sync.Once } -var TheAddressType = &AddressType{ - conformances: []*InterfaceType{ - StructStringerType, - }, -} +var TheAddressType = &AddressType{} var AddressTypeAnnotation = NewTypeAnnotation(TheAddressType) var _ Type = &AddressType{} @@ -7432,19 +7413,14 @@ func (t *AddressType) initializeMemberResolvers() { }) } -func (t *AddressType) EffectiveInterfaceConformanceSet() *InterfaceSet { - t.initializeEffectiveInterfaceConformanceSet() - return t.effectiveInterfaceConformanceSet -} - -func (t *AddressType) initializeEffectiveInterfaceConformanceSet() { - t.effectiveInterfaceConformanceSetOnce.Do(func() { - t.effectiveInterfaceConformanceSet = NewInterfaceSet() +var addressTypeEffectiveInterfaceConformanceSet *InterfaceSet - for _, conformance := range t.conformances { - t.effectiveInterfaceConformanceSet.Add(conformance) - } - }) +func init() { + addressTypeEffectiveInterfaceConformanceSet = NewInterfaceSet() + addressTypeEffectiveInterfaceConformanceSet.Add(StructStringerType) +} +func (t *AddressType) AddressInterfaceConformanceSet() *InterfaceSet { + return numericTypeEffectiveInterfaceConformanceSet } func IsPrimitiveOrContainerOfPrimitive(referencedType Type) bool { @@ -9572,12 +9548,7 @@ func extractNativeTypes( } nestedTypes.Foreach(func(_ string, nestedType Type) { - nestedCompositeType, ok := nestedType.(*CompositeType) - if !ok { - return - } - - types = append(types, nestedCompositeType) + types = append(types, nestedType) }) case *InterfaceType: NativeInterfaceTypes[actualType.QualifiedIdentifier()] = actualType @@ -9588,13 +9559,10 @@ func extractNativeTypes( } nestedTypes.Foreach(func(_ string, nestedType Type) { - nestedInterfaceType, ok := nestedType.(*InterfaceType) - if !ok { - return - } - - types = append(types, nestedInterfaceType) + types = append(types, nestedType) }) + default: + panic("Expected only composite or interface type") } } From 698328897d5e97ae72d98825bab583e9f329b290 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Wed, 16 Oct 2024 15:22:20 -0400 Subject: [PATCH 33/70] Code cleanup. --- runtime/ast/expression.go | 14 +++++++++++--- runtime/ast/string_template_test.go | 2 +- runtime/sema/check_string_template_expression.go | 6 +----- runtime/tests/checker/string_test.go | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/runtime/ast/expression.go b/runtime/ast/expression.go index 8cf54fdce5..7f6fe4b502 100644 --- a/runtime/ast/expression.go +++ b/runtime/ast/expression.go @@ -223,6 +223,10 @@ func (*StringExpression) precedence() precedence { // 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 @@ -237,6 +241,10 @@ func NewStringTemplateExpression( 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, @@ -255,8 +263,8 @@ func (*StringTemplateExpression) isExpression() {} func (*StringTemplateExpression) isIfStatementTest() {} -func (*StringTemplateExpression) Walk(_ func(Element)) { - // NO-OP +func (e *StringTemplateExpression) Walk(walkChild func(Element)) { + walkExpressions(walkChild, e.Expressions) } func (e *StringTemplateExpression) String() string { @@ -265,7 +273,7 @@ func (e *StringTemplateExpression) String() string { func (e *StringTemplateExpression) Doc() prettier.Doc { if len(e.Expressions) == 0 { - return prettier.Text(e.Values[0]) + return prettier.Text(QuoteString(e.Values[0])) } // TODO: must reproduce expressions as literals diff --git a/runtime/ast/string_template_test.go b/runtime/ast/string_template_test.go index a19a399bb9..c6167aaffb 100644 --- a/runtime/ast/string_template_test.go +++ b/runtime/ast/string_template_test.go @@ -41,7 +41,7 @@ func TestStringTemplate_Doc(t *testing.T) { } assert.Equal(t, - prettier.Text("abc"), + prettier.Text("\"abc\""), stmt.Doc(), ) } diff --git a/runtime/sema/check_string_template_expression.go b/runtime/sema/check_string_template_expression.go index 8b4be45b48..6cbd8d80ec 100644 --- a/runtime/sema/check_string_template_expression.go +++ b/runtime/sema/check_string_template_expression.go @@ -43,13 +43,9 @@ func (checker *Checker) VisitStringTemplateExpression(stringTemplateExpression * elementCount := len(stringTemplateExpression.Expressions) if elementCount > 0 { - argumentTypes := make([]Type, elementCount) - - for i, element := range stringTemplateExpression.Expressions { + for _, element := range stringTemplateExpression.Expressions { valueType := checker.VisitExpression(element, stringTemplateExpression, elementType) - argumentTypes[i] = valueType - if !isValidStringTemplateValue(valueType) { checker.report( &TypeMismatchWithDescriptionError{ diff --git a/runtime/tests/checker/string_test.go b/runtime/tests/checker/string_test.go index 4bea07a7dd..84e305d3b3 100644 --- a/runtime/tests/checker/string_test.go +++ b/runtime/tests/checker/string_test.go @@ -746,7 +746,7 @@ func TestCheckStringTemplate(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - let x :[AnyStruct] = ["tmp", 1] + let x: [AnyStruct] = ["tmp", 1] let y = "\(x)" `) From b9243e369e7d2e25f0545ef8fd71b15e1ed34197 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Mon, 21 Oct 2024 10:13:46 -0400 Subject: [PATCH 34/70] Fix imports. --- sema/gen/testdata/simple_interface/test.golden.go | 4 ++-- sema/struct_stringer.gen.go | 4 ++-- tests/checker/stringer_test.go | 2 +- tests/interpreter/stringer_test.go | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sema/gen/testdata/simple_interface/test.golden.go b/sema/gen/testdata/simple_interface/test.golden.go index ae15975a61..c976eafded 100644 --- a/sema/gen/testdata/simple_interface/test.golden.go +++ b/sema/gen/testdata/simple_interface/test.golden.go @@ -20,8 +20,8 @@ package simple_interface import ( - "github.com/onflow/cadence/runtime/common" - "github.com/onflow/cadence/runtime/sema" + "github.com/onflow/cadence/common" + "github.com/onflow/cadence/sema" ) const TestTypeName = "Test" diff --git a/sema/struct_stringer.gen.go b/sema/struct_stringer.gen.go index fd583822cd..7f23bd22df 100644 --- a/sema/struct_stringer.gen.go +++ b/sema/struct_stringer.gen.go @@ -20,8 +20,8 @@ package sema import ( - "github.com/onflow/cadence/runtime/ast" - "github.com/onflow/cadence/runtime/common" + "github.com/onflow/cadence/ast" + "github.com/onflow/cadence/common" ) const StructStringerTypeToStringFunctionName = "toString" diff --git a/tests/checker/stringer_test.go b/tests/checker/stringer_test.go index c0026904ab..315cb1d4da 100644 --- a/tests/checker/stringer_test.go +++ b/tests/checker/stringer_test.go @@ -23,7 +23,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/onflow/cadence/runtime/sema" + "github.com/onflow/cadence/sema" ) func TestCheckStringer(t *testing.T) { diff --git a/tests/interpreter/stringer_test.go b/tests/interpreter/stringer_test.go index eafe44652f..d01acd5b43 100644 --- a/tests/interpreter/stringer_test.go +++ b/tests/interpreter/stringer_test.go @@ -23,8 +23,8 @@ import ( "github.com/stretchr/testify/require" - "github.com/onflow/cadence/runtime/interpreter" - . "github.com/onflow/cadence/runtime/tests/utils" + "github.com/onflow/cadence/interpreter" + . "github.com/onflow/cadence/tests/utils" ) func TestStringerBasic(t *testing.T) { From babf34aadffd29a9bb920f7fe13c14d3bc5ec6ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Thu, 24 Oct 2024 15:29:26 -0700 Subject: [PATCH 35/70] run Cadence tests --- compat/main.py | 231 +++++++++++++++------ compat/suite/flow-core-contracts.yaml | 3 + compat/suite/green-goo-dao-flow-utils.yaml | 8 + 3 files changed, 175 insertions(+), 67 deletions(-) create mode 100644 compat/suite/green-goo-dao-flow-utils.yaml 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 From f30b70cb372fde5684ede6bfef2392f2dbb907eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Thu, 24 Oct 2024 18:15:17 -0700 Subject: [PATCH 36/70] Update tests/checker/stringer_test.go --- tests/checker/stringer_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/checker/stringer_test.go b/tests/checker/stringer_test.go index 315cb1d4da..0939eb76fc 100644 --- a/tests/checker/stringer_test.go +++ b/tests/checker/stringer_test.go @@ -1,7 +1,7 @@ /* * Cadence - The resource-oriented smart contract programming language * - * Copyright Dapper Labs, Inc. + * 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. From bd4c77de6645f58cf0ee3a7ce96311c17cce15b0 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Mon, 28 Oct 2024 10:01:33 -0400 Subject: [PATCH 37/70] Invert flag for readability. --- sema/gen/main.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/sema/gen/main.go b/sema/gen/main.go index bf97d23819..c203adf180 100644 --- a/sema/gen/main.go +++ b/sema/gen/main.go @@ -438,7 +438,7 @@ func (g *generator) VisitCompositeOrInterfaceDeclaration(decl ast.ConformingDecl var typeDec *typeDecl var members []ast.Declaration var conformances []*ast.NominalType - var isCompositeType bool + var isInterfaceType bool switch actualDecl := decl.(type) { case *ast.CompositeDeclaration: @@ -451,7 +451,7 @@ func (g *generator) VisitCompositeOrInterfaceDeclaration(decl ast.ConformingDecl } members = actualDecl.Members.Declarations() conformances = actualDecl.Conformances - isCompositeType = true + isInterfaceType = false case *ast.InterfaceDeclaration: compositeKind = actualDecl.Kind() typeName = actualDecl.Identifier.Identifier @@ -461,7 +461,7 @@ func (g *generator) VisitCompositeOrInterfaceDeclaration(decl ast.ConformingDecl compositeKind: compositeKind, } members = actualDecl.Members.Declarations() - isCompositeType = false + isInterfaceType = true default: panic("Expected composite or interface declaration") } @@ -499,7 +499,7 @@ func (g *generator) VisitCompositeOrInterfaceDeclaration(decl ast.ConformingDecl // Check if the declaration is explicitly marked to be generated as a composite type. if _, ok := g.leadingPragma["compositeType"]; ok { generateSimpleType = false - } else if !isCompositeType { + } else if isInterfaceType { generateSimpleType = false } else { // If not, decide what to generate depending on the type. @@ -2035,7 +2035,7 @@ func stringMemberResolverMapType() *dst.MapType { } } -func compositeOrInterfaceTypeExpr(ty *typeDecl, isCompositeType bool) dst.Expr { +func compositeOrInterfaceTypeExpr(ty *typeDecl, isInterfaceType bool) dst.Expr { // func() *CompositeType { // var t = &CompositeType { @@ -2097,9 +2097,9 @@ func compositeOrInterfaceTypeExpr(ty *typeDecl, isCompositeType bool) dst.Expr { }, ) - name := "InterfaceType" - if isCompositeType { - name = "CompositeType" + name := "CompositeType" + if isInterfaceType { + name = "InterfaceType" } return &dst.CallExpr{ @@ -2126,7 +2126,7 @@ func compositeOrInterfaceTypeExpr(ty *typeDecl, isCompositeType bool) dst.Expr { } } -func compositeOrInterfaceTypeLiteral(ty *typeDecl, isCompositeType bool) dst.Expr { +func compositeOrInterfaceTypeLiteral(ty *typeDecl, isInterfaceType bool) dst.Expr { kind := compositeKindExpr(ty.compositeKind) elements := []dst.Expr{ @@ -2134,15 +2134,15 @@ func compositeOrInterfaceTypeLiteral(ty *typeDecl, isCompositeType bool) dst.Exp } name := "InterfaceType" - if isCompositeType { + 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))) - } else { - elements = append(elements, - goKeyValue("CompositeKind", kind)) } return &dst.UnaryExpr{ From 58d7d66dbbb8b1430273e4c5c41dedec450dc6e2 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Mon, 28 Oct 2024 10:06:48 -0400 Subject: [PATCH 38/70] Small fix. --- sema/gen/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sema/gen/main.go b/sema/gen/main.go index c203adf180..49fdaf24b6 100644 --- a/sema/gen/main.go +++ b/sema/gen/main.go @@ -609,7 +609,7 @@ func (g *generator) VisitCompositeOrInterfaceDeclaration(decl ast.ConformingDecl if generateSimpleType { typeVarDecl = simpleTypeLiteral(typeDec) } else { - typeVarDecl = compositeOrInterfaceTypeExpr(typeDec, isCompositeType) + typeVarDecl = compositeOrInterfaceTypeExpr(typeDec, isInterfaceType) } fullTypeName := typeDec.fullTypeName @@ -2065,7 +2065,7 @@ func compositeOrInterfaceTypeExpr(ty *typeDecl, isInterfaceType bool) dst.Expr { &dst.DeclStmt{ Decl: goVarDecl( typeVarName, - compositeOrInterfaceTypeLiteral(ty, isCompositeType), + compositeOrInterfaceTypeLiteral(ty, isInterfaceType), ), }, } From aceb8845bc06ff01f44fca3c3c8807ce560cb76e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 28 Oct 2024 09:51:12 -0700 Subject: [PATCH 39/70] update old uses of pub and priv --- docs/cadence.ebnf | 6 ++---- docs/development.md | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) 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..e3f5364736 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!" ``` From a0ef085006b78ce3ca7fb15908048d8745af8202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 28 Oct 2024 15:10:17 -0700 Subject: [PATCH 40/70] document Go patterns used in the codebase --- docs/go.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 docs/go.md 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 + From 52bbfa4150a442a05cb914a4eb0f36bcc16befa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 28 Oct 2024 15:13:23 -0700 Subject: [PATCH 41/70] move architecture diagram to contributor documentation directory --- .../runtime.monopic => docs/architecture.monopic | Bin runtime/runtime.png => docs/architecture.png | Bin runtime/runtime.svg => docs/architecture.svg | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename runtime/runtime.monopic => docs/architecture.monopic (100%) rename runtime/runtime.png => docs/architecture.png (100%) rename runtime/runtime.svg => docs/architecture.svg (100%) 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 From dccae9affb09cae9cf861d0722842152b3e8c081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 28 Oct 2024 15:36:25 -0700 Subject: [PATCH 42/70] move runtime tests --- {tests => runtime}/account_test.go | 2 +- {tests => runtime}/attachments_test.go | 2 +- {tests => runtime}/capabilities_test.go | 2 +- {tests => runtime}/capabilitycontrollers_test.go | 2 +- {tests => runtime}/contract_test.go | 2 +- {tests => runtime}/contract_update_test.go | 2 +- {tests => runtime}/contract_update_validation_test.go | 2 +- {tests => runtime}/convertTypes_test.go | 2 +- {tests => runtime}/convertValues_test.go | 4 ++-- {tests => runtime}/coverage_test.go | 2 +- {tests => runtime}/crypto_test.go | 2 +- {tests => runtime}/debugger_test.go | 2 +- {tests => runtime}/deployedcontract_test.go | 2 +- {tests => runtime}/deployment_test.go | 2 +- {tests => runtime}/entitlements_test.go | 2 +- {tests => runtime}/error_test.go | 2 +- {tests => runtime}/errors_test.go | 2 +- {tests => runtime}/ft_test.go | 2 +- {tests => runtime}/import_test.go | 2 +- {tests => runtime}/imported_values_memory_metering_test.go | 2 +- {tests => runtime}/inbox_test.go | 2 +- {tests => runtime}/literal_test.go | 2 +- {tests => runtime}/nft_test.go | 2 +- {tests => runtime}/predeclaredvalues_test.go | 2 +- {tests => runtime}/program_params_validation_test.go | 2 +- {tests => runtime}/resource_duplicate_test.go | 2 +- {tests => runtime}/resourcedictionary_test.go | 2 +- {tests => runtime}/rlp_test.go | 2 +- {tests => runtime}/runtime_memory_metering_test.go | 2 +- {tests => runtime}/runtime_test.go | 2 +- {tests => runtime}/sharedstate_test.go | 2 +- {tests => runtime}/storage_test.go | 2 +- {tests => runtime}/type_test.go | 2 +- {tests => runtime}/validation_test.go | 2 +- 34 files changed, 35 insertions(+), 35 deletions(-) rename {tests => runtime}/account_test.go (99%) rename {tests => runtime}/attachments_test.go (99%) rename {tests => runtime}/capabilities_test.go (99%) rename {tests => runtime}/capabilitycontrollers_test.go (99%) rename {tests => runtime}/contract_test.go (99%) rename {tests => runtime}/contract_update_test.go (99%) rename {tests => runtime}/contract_update_validation_test.go (99%) rename {tests => runtime}/convertTypes_test.go (99%) rename {tests => runtime}/convertValues_test.go (99%) rename {tests => runtime}/coverage_test.go (99%) rename {tests => runtime}/crypto_test.go (99%) rename {tests => runtime}/debugger_test.go (99%) rename {tests => runtime}/deployedcontract_test.go (99%) rename {tests => runtime}/deployment_test.go (99%) rename {tests => runtime}/entitlements_test.go (99%) rename {tests => runtime}/error_test.go (99%) rename {tests => runtime}/errors_test.go (99%) rename {tests => runtime}/ft_test.go (99%) rename {tests => runtime}/import_test.go (99%) rename {tests => runtime}/imported_values_memory_metering_test.go (99%) rename {tests => runtime}/inbox_test.go (99%) rename {tests => runtime}/literal_test.go (99%) rename {tests => runtime}/nft_test.go (99%) rename {tests => runtime}/predeclaredvalues_test.go (99%) rename {tests => runtime}/program_params_validation_test.go (99%) rename {tests => runtime}/resource_duplicate_test.go (99%) rename {tests => runtime}/resourcedictionary_test.go (99%) rename {tests => runtime}/rlp_test.go (99%) rename {tests => runtime}/runtime_memory_metering_test.go (99%) rename {tests => runtime}/runtime_test.go (99%) rename {tests => runtime}/sharedstate_test.go (99%) rename {tests => runtime}/storage_test.go (99%) rename {tests => runtime}/type_test.go (99%) rename {tests => runtime}/validation_test.go (99%) 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..ad8540f6e2 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" 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..e03c72dc22 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" 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..ade86c8d24 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" 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..fbb0d924cc 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" 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..5cc9579322 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" 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..c032eb7124 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" diff --git a/tests/contract_update_validation_test.go b/runtime/contract_update_validation_test.go similarity index 99% rename from tests/contract_update_validation_test.go rename to runtime/contract_update_validation_test.go index 0bebbb99a0..f4e77b8c85 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" diff --git a/tests/convertTypes_test.go b/runtime/convertTypes_test.go similarity index 99% rename from tests/convertTypes_test.go rename to runtime/convertTypes_test.go index 5d5ea6b2a9..fea1f8a697 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" 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..22cd45c5bc 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" @@ -2322,7 +2322,7 @@ func TestRuntimeExportCompositeValueWithFunctionValueField(t *testing.T) { assert.Equal(t, expected, actual) } -//go:embed test-export-json-deterministic.txt +//go:embed ../tests/test-export-json-deterministic.txt 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..2c244b4c4d 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" 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..71da0b283a 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" diff --git a/tests/debugger_test.go b/runtime/debugger_test.go similarity index 99% rename from tests/debugger_test.go rename to runtime/debugger_test.go index 3289668907..7d5d5f8907 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" diff --git a/tests/deployedcontract_test.go b/runtime/deployedcontract_test.go similarity index 99% rename from tests/deployedcontract_test.go rename to runtime/deployedcontract_test.go index 7090f7ad77..b73b16f71d 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" diff --git a/tests/deployment_test.go b/runtime/deployment_test.go similarity index 99% rename from tests/deployment_test.go rename to runtime/deployment_test.go index 475cceb86f..6b6cbe83bd 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" 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..8ffee3052b 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" 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..a27aecbcf2 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" 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..5d7d78b5e6 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" diff --git a/tests/import_test.go b/runtime/import_test.go similarity index 99% rename from tests/import_test.go rename to runtime/import_test.go index 2e75215a84..14a47febe0 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" 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..c3e7a882a8 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" 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..00380e23e4 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" 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..e35033b250 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" 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 99% rename from tests/predeclaredvalues_test.go rename to runtime/predeclaredvalues_test.go index acefd56e08..58757a8bb7 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" diff --git a/tests/program_params_validation_test.go b/runtime/program_params_validation_test.go similarity index 99% rename from tests/program_params_validation_test.go rename to runtime/program_params_validation_test.go index 827de1ebe5..f2ec7c4882 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" diff --git a/tests/resource_duplicate_test.go b/runtime/resource_duplicate_test.go similarity index 99% rename from tests/resource_duplicate_test.go rename to runtime/resource_duplicate_test.go index 246f073a61..5f5f12c666 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" diff --git a/tests/resourcedictionary_test.go b/runtime/resourcedictionary_test.go similarity index 99% rename from tests/resourcedictionary_test.go rename to runtime/resourcedictionary_test.go index e1b939e74e..088d4e977f 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" diff --git a/tests/rlp_test.go b/runtime/rlp_test.go similarity index 99% rename from tests/rlp_test.go rename to runtime/rlp_test.go index 1aa9296eed..17582dceee 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" 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..f7e91fd7bf 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" 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 de7487cab3..abee65f080 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" diff --git a/tests/sharedstate_test.go b/runtime/sharedstate_test.go similarity index 99% rename from tests/sharedstate_test.go rename to runtime/sharedstate_test.go index b5d37b29a3..660c439b1c 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" 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..b82b77a2cb 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" diff --git a/tests/type_test.go b/runtime/type_test.go similarity index 99% rename from tests/type_test.go rename to runtime/type_test.go index 5ee6afc790..2ae870e408 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" diff --git a/tests/validation_test.go b/runtime/validation_test.go similarity index 99% rename from tests/validation_test.go rename to runtime/validation_test.go index b46b609df8..980654b941 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" From 08eae83676fec388dcfd3747f87721eb8d2524ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 28 Oct 2024 15:48:09 -0700 Subject: [PATCH 43/70] fix test expectation --- runtime/convertValues_test.go | 2 +- .../test-export-json-deterministic.json | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/test-export-json-deterministic.txt => runtime/test-export-json-deterministic.json (100%) diff --git a/runtime/convertValues_test.go b/runtime/convertValues_test.go index 22cd45c5bc..bebbf750ca 100644 --- a/runtime/convertValues_test.go +++ b/runtime/convertValues_test.go @@ -2322,7 +2322,7 @@ func TestRuntimeExportCompositeValueWithFunctionValueField(t *testing.T) { assert.Equal(t, expected, actual) } -//go:embed ../tests/test-export-json-deterministic.txt +//go:embed test-export-json-deterministic.json var exportJsonDeterministicExpected string func TestRuntimeExportJsonDeterministic(t *testing.T) { 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 From ed36b6ccf59804199cd67dac11f7392e074e8814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 28 Oct 2024 15:48:26 -0700 Subject: [PATCH 44/70] remove outdated gitattributes for old parser --- runtime/.gitattributes | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 runtime/.gitattributes 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 - From 258b177c5c227e51f8d266a30ce8868293ba1c15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 28 Oct 2024 16:21:50 -0700 Subject: [PATCH 45/70] move checker tests to sema package --- cmd/info/main.go | 6 +- compiler/compiler_test.go | 4 +- encoding/ccf/ccf_test.go | 4 +- encoding/json/encoding_test.go | 4 +- interpreter/value_test.go | 10 +- runtime/account_test.go | 16 +- runtime/contract_test.go | 4 +- runtime/entitlements_test.go | 4 +- runtime/import_test.go | 16 +- runtime/predeclaredvalues_test.go | 4 +- runtime/program_params_validation_test.go | 22 +- runtime/runtime_test.go | 14 +- sema/access_test.go | 636 ------------------ .../access_test.go => sema/accesses_test.go | 3 +- {tests/checker => sema}/account_test.go | 3 +- {tests/checker => sema}/any_test.go | 3 +- .../arrays_dictionaries_test.go | 3 +- {tests/checker => sema}/assert_test.go | 3 +- {tests/checker => sema}/assignment_test.go | 3 +- {tests/checker => sema}/attachments_test.go | 3 +- {tests/checker => sema}/boolean_test.go | 3 +- .../checker => sema}/builtinfunctions_test.go | 3 +- .../capability_controller_test.go | 3 +- {tests/checker => sema}/capability_test.go | 4 +- {tests/checker => sema}/casting_test.go | 3 +- {tests/checker => sema}/character_test.go | 3 +- {tests/checker => sema}/composite_test.go | 3 +- {tests/checker => sema}/conditional_test.go | 3 +- {tests/checker => sema}/conditions_test.go | 3 +- {tests/checker => sema}/conformance_test.go | 3 +- {tests/checker => sema}/contract_test.go | 3 +- {tests/checker => sema}/crypto_test.go | 3 +- {tests/checker => sema}/declaration_test.go | 3 +- {tests/checker => sema}/dictionary_test.go | 3 +- .../checker => sema}/dynamic_casting_test.go | 3 +- {tests/checker => sema}/entitlements_test.go | 3 +- {tests/checker => sema}/entrypoint_test.go | 3 +- {tests/checker => sema}/enum_test.go | 3 +- .../error_handling_test.go | 3 +- {tests/checker => sema}/events_test.go | 9 +- .../external_mutation_test.go | 3 +- {tests/checker => sema}/fixedpoint_test.go | 3 +- {tests/checker => sema}/for_test.go | 3 +- {tests/checker => sema}/force_test.go | 3 +- .../function_expression_test.go | 3 +- {tests/checker => sema}/function_test.go | 3 +- sema/gen/golden_test.go | 10 +- .../checker => sema}/genericfunction_test.go | 3 +- .../checker => sema}/hashable_struct_test.go | 3 +- {tests/checker => sema}/if_test.go | 3 +- {tests/checker => sema}/import_test.go | 3 +- {tests/checker => sema}/indexing_test.go | 3 +- .../checker => sema}/initialization_test.go | 3 +- {tests/checker => sema}/integer_test.go | 3 +- {tests/checker => sema}/interface_test.go | 3 +- {tests/checker => sema}/intersection_test.go | 3 +- {tests/checker => sema}/invalid_test.go | 3 +- {tests/checker => sema}/invocation_test.go | 3 +- {tests/checker => sema}/member_test.go | 3 +- {tests/checker => sema}/metatype_test.go | 3 +- {tests/checker => sema}/move_test.go | 3 +- {tests/checker => sema}/nesting_test.go | 3 +- {tests/checker => sema}/never_test.go | 3 +- .../checker => sema}/nil_coalescing_test.go | 3 +- {tests/checker => sema}/occurrences_test.go | 3 +- {tests/checker => sema}/operations_test.go | 3 +- {tests/checker => sema}/optional_test.go | 3 +- {tests/checker => sema}/overloading_test.go | 3 +- {tests/checker => sema}/path_test.go | 3 +- {tests/checker => sema}/pragma_test.go | 3 +- .../predeclaredvalues_test.go | 3 +- {tests/checker => sema}/purity_test.go | 3 +- {tests/checker => sema}/range_test.go | 3 +- {tests/checker => sema}/range_value_test.go | 3 +- {tests/checker => sema}/reference_test.go | 3 +- .../resource_test.go | 3 +- {tests/checker => sema}/return_test.go | 3 +- {tests/checker => sema}/rlp_test.go | 3 +- {tests/checker => sema}/runtimetype_test.go | 3 +- {tests/checker => sema}/storable_test.go | 3 +- {tests/checker => sema}/string_test.go | 3 +- {tests/checker => sema}/swap_test.go | 3 +- {tests/checker => sema}/switch_test.go | 3 +- {tests/checker => sema}/transactions_test.go | 3 +- .../checker => sema}/type_inference_test.go | 3 +- {tests/checker => sema}/typeargument_test.go | 3 +- {tests/checker => sema}/utils_test.go | 3 +- {tests/checker => sema}/while_test.go | 3 +- stdlib/builtin_test.go | 26 +- stdlib/test_test.go | 36 +- tests/interpreter/condition_test.go | 4 +- tests/interpreter/function_test.go | 6 +- tests/interpreter/if_test.go | 4 +- tests/interpreter/import_test.go | 24 +- tests/interpreter/interpreter_test.go | 46 +- tests/interpreter/member_test.go | 10 +- tests/interpreter/memory_metering_test.go | 10 +- tests/interpreter/metering_test.go | 26 +- tests/interpreter/reference_test.go | 26 +- tests/interpreter/resources_test.go | 96 +-- tests/interpreter/switch_test.go | 10 +- tests/interpreter/transactions_test.go | 4 +- tests/interpreter/uuid_test.go | 10 +- tests/{checker => sema_utils}/utils.go | 2 +- tools/analysis/analysis_test.go | 6 +- 105 files changed, 383 insertions(+), 946 deletions(-) delete mode 100644 sema/access_test.go rename tests/checker/access_test.go => sema/accesses_test.go (99%) rename {tests/checker => sema}/account_test.go (99%) rename {tests/checker => sema}/any_test.go (96%) rename {tests/checker => sema}/arrays_dictionaries_test.go (99%) rename {tests/checker => sema}/assert_test.go (96%) rename {tests/checker => sema}/assignment_test.go (98%) rename {tests/checker => sema}/attachments_test.go (99%) rename {tests/checker => sema}/boolean_test.go (94%) rename {tests/checker => sema}/builtinfunctions_test.go (99%) rename {tests/checker => sema}/capability_controller_test.go (98%) rename {tests/checker => sema}/capability_test.go (99%) rename {tests/checker => sema}/casting_test.go (99%) rename {tests/checker => sema}/character_test.go (96%) rename {tests/checker => sema}/composite_test.go (99%) rename {tests/checker => sema}/conditional_test.go (98%) rename {tests/checker => sema}/conditions_test.go (99%) rename {tests/checker => sema}/conformance_test.go (99%) rename {tests/checker => sema}/contract_test.go (99%) rename {tests/checker => sema}/crypto_test.go (99%) rename {tests/checker => sema}/declaration_test.go (99%) rename {tests/checker => sema}/dictionary_test.go (95%) rename {tests/checker => sema}/dynamic_casting_test.go (99%) rename {tests/checker => sema}/entitlements_test.go (99%) rename {tests/checker => sema}/entrypoint_test.go (98%) rename {tests/checker => sema}/enum_test.go (98%) rename tests/checker/errors_test.go => sema/error_handling_test.go (98%) rename {tests/checker => sema}/events_test.go (99%) rename {tests/checker => sema}/external_mutation_test.go (99%) rename {tests/checker => sema}/fixedpoint_test.go (99%) rename {tests/checker => sema}/for_test.go (99%) rename {tests/checker => sema}/force_test.go (97%) rename {tests/checker => sema}/function_expression_test.go (95%) rename {tests/checker => sema}/function_test.go (99%) rename {tests/checker => sema}/genericfunction_test.go (99%) rename {tests/checker => sema}/hashable_struct_test.go (95%) rename {tests/checker => sema}/if_test.go (98%) rename {tests/checker => sema}/import_test.go (99%) rename {tests/checker => sema}/indexing_test.go (98%) rename {tests/checker => sema}/initialization_test.go (99%) rename {tests/checker => sema}/integer_test.go (99%) rename {tests/checker => sema}/interface_test.go (99%) rename {tests/checker => sema}/intersection_test.go (99%) rename {tests/checker => sema}/invalid_test.go (98%) rename {tests/checker => sema}/invocation_test.go (99%) rename {tests/checker => sema}/member_test.go (99%) rename {tests/checker => sema}/metatype_test.go (99%) rename {tests/checker => sema}/move_test.go (97%) rename {tests/checker => sema}/nesting_test.go (99%) rename {tests/checker => sema}/never_test.go (98%) rename {tests/checker => sema}/nil_coalescing_test.go (98%) rename {tests/checker => sema}/occurrences_test.go (99%) rename {tests/checker => sema}/operations_test.go (99%) rename {tests/checker => sema}/optional_test.go (99%) rename {tests/checker => sema}/overloading_test.go (96%) rename {tests/checker => sema}/path_test.go (98%) rename {tests/checker => sema}/pragma_test.go (98%) rename {tests/checker => sema}/predeclaredvalues_test.go (95%) rename {tests/checker => sema}/purity_test.go (99%) rename {tests/checker => sema}/range_test.go (99%) rename {tests/checker => sema}/range_value_test.go (99%) rename {tests/checker => sema}/reference_test.go (99%) rename tests/checker/resources_test.go => sema/resource_test.go (99%) rename {tests/checker => sema}/return_test.go (99%) rename {tests/checker => sema}/rlp_test.go (97%) rename {tests/checker => sema}/runtimetype_test.go (99%) rename {tests/checker => sema}/storable_test.go (99%) rename {tests/checker => sema}/string_test.go (99%) rename {tests/checker => sema}/swap_test.go (99%) rename {tests/checker => sema}/switch_test.go (99%) rename {tests/checker => sema}/transactions_test.go (99%) rename {tests/checker => sema}/type_inference_test.go (99%) rename {tests/checker => sema}/typeargument_test.go (99%) rename {tests/checker => sema}/utils_test.go (96%) rename {tests/checker => sema}/while_test.go (97%) rename tests/{checker => sema_utils}/utils.go (99%) diff --git a/cmd/info/main.go b/cmd/info/main.go index 5f737ba99c..62a91f8a6c 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/tests/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/compiler/compiler_test.go b/compiler/compiler_test.go index 17acf177d1..60c96154aa 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/tests/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/encoding/ccf/ccf_test.go b/encoding/ccf/ccf_test.go index db427edd67..3332bbb065 100644 --- a/encoding/ccf/ccf_test.go +++ b/encoding/ccf/ccf_test.go @@ -38,8 +38,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/sema_utils" "github.com/onflow/cadence/tests/utils" ) @@ -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 diff --git a/encoding/json/encoding_test.go b/encoding/json/encoding_test.go index 5a22360dd0..308c8e0e7c 100644 --- a/encoding/json/encoding_test.go +++ b/encoding/json/encoding_test.go @@ -31,7 +31,7 @@ import ( "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/tests/sema_utils" "github.com/onflow/cadence" "github.com/onflow/cadence/sema" @@ -1123,7 +1123,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 diff --git a/interpreter/value_test.go b/interpreter/value_test.go index 1bfc7d3cc5..8f4df2bcc1 100644 --- a/interpreter/value_test.go +++ b/interpreter/value_test.go @@ -36,7 +36,7 @@ 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/sema_utils" "github.com/onflow/cadence/tests/utils" ) @@ -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) @@ -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) diff --git a/runtime/account_test.go b/runtime/account_test.go index ad8540f6e2..371cbba4cb 100644 --- a/runtime/account_test.go +++ b/runtime/account_test.go @@ -35,8 +35,8 @@ 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/sema_utils" "github.com/onflow/cadence/tests/utils" . "github.com/onflow/cadence/tests/utils" ) @@ -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/runtime/contract_test.go b/runtime/contract_test.go index 5cc9579322..6cd2b4caaa 100644 --- a/runtime/contract_test.go +++ b/runtime/contract_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/checker" . "github.com/onflow/cadence/tests/runtime_utils" + . "github.com/onflow/cadence/tests/sema_utils" . "github.com/onflow/cadence/tests/utils" ) @@ -1234,7 +1234,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/runtime/entitlements_test.go b/runtime/entitlements_test.go index 8ffee3052b..d241cb6c4d 100644 --- a/runtime/entitlements_test.go +++ b/runtime/entitlements_test.go @@ -28,8 +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/sema_utils" . "github.com/onflow/cadence/tests/utils" ) @@ -497,7 +497,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/import_test.go b/runtime/import_test.go index 14a47febe0..295353b5f6 100644 --- a/runtime/import_test.go +++ b/runtime/import_test.go @@ -30,8 +30,8 @@ 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/sema_utils" . "github.com/onflow/cadence/tests/utils" ) @@ -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/runtime/predeclaredvalues_test.go b/runtime/predeclaredvalues_test.go index 58757a8bb7..c60d3efb5b 100644 --- a/runtime/predeclaredvalues_test.go +++ b/runtime/predeclaredvalues_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/checker" . "github.com/onflow/cadence/tests/runtime_utils" + . "github.com/onflow/cadence/tests/sema_utils" . "github.com/onflow/cadence/tests/utils" ) @@ -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/runtime/program_params_validation_test.go b/runtime/program_params_validation_test.go index f2ec7c4882..2e1a7f3ec1 100644 --- a/runtime/program_params_validation_test.go +++ b/runtime/program_params_validation_test.go @@ -30,8 +30,8 @@ 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/sema_utils" . "github.com/onflow/cadence/tests/utils" ) @@ -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/runtime/runtime_test.go b/runtime/runtime_test.go index abee65f080..07e76ce395 100644 --- a/runtime/runtime_test.go +++ b/runtime/runtime_test.go @@ -43,8 +43,8 @@ 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/sema_utils" . "github.com/onflow/cadence/tests/utils" ) @@ -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]) diff --git a/sema/access_test.go b/sema/access_test.go deleted file mode 100644 index a5472f468c..0000000000 --- a/sema/access_test.go +++ /dev/null @@ -1,636 +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 sema - -import ( - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/onflow/cadence/ast" - "github.com/onflow/cadence/common" -) - -func TestPrimitiveAccess_QualifiedKeyword(t *testing.T) { - - t.Parallel() - - expected := map[ast.PrimitiveAccess]string{ - ast.AccessNotSpecified: "", - ast.AccessSelf: "access(self)", - ast.AccessAll: "access(all)", - ast.AccessAccount: "access(account)", - ast.AccessContract: "access(contract)", - ast.AccessPubSettableLegacy: "pub(set)", - ast.AccessNone: "inaccessible", - } - - for access := 0; access < ast.PrimitiveAccessCount(); access++ { - assert.Equal(t, - expected[ast.PrimitiveAccess(access)], - PrimitiveAccess(access).QualifiedKeyword(), - ) - } -} - -func TestNewEntitlementAccess(t *testing.T) { - - t.Parallel() - - t.Run("empty", func(t *testing.T) { - t.Parallel() - - assert.PanicsWithError(t, - "neither map entitlement nor set entitlements given", - func() { - newEntitlementAccess(nil, Conjunction) - }, - ) - }) - - t.Run("invalid", func(t *testing.T) { - t.Parallel() - - assert.PanicsWithError(t, - "invalid entitlement type: Void", - func() { - newEntitlementAccess([]Type{VoidType}, Conjunction) - }, - ) - }) - - t.Run("map + entitlement", func(t *testing.T) { - t.Parallel() - - assert.PanicsWithError(t, - "mixed entitlement types", - func() { - newEntitlementAccess( - []Type{ - IdentityType, - MutateType, - }, - Conjunction, - ) - }, - ) - }) - - t.Run("entitlement + map", func(t *testing.T) { - t.Parallel() - - assert.PanicsWithError(t, - "mixed entitlement types", - func() { - newEntitlementAccess( - []Type{ - MutateType, - IdentityType, - }, - Conjunction, - ) - }, - ) - }) - - t.Run("single entitlement", func(t *testing.T) { - t.Parallel() - - assert.Equal(t, - NewEntitlementSetAccess( - []*EntitlementType{ - MutateType, - }, - Conjunction, - ), - newEntitlementAccess( - []Type{ - MutateType, - }, - Conjunction, - ), - ) - }) - - t.Run("two entitlements, conjunction", func(t *testing.T) { - t.Parallel() - - assert.Equal(t, - NewEntitlementSetAccess( - []*EntitlementType{ - MutateType, - InsertType, - }, - Conjunction, - ), - newEntitlementAccess( - []Type{ - MutateType, - InsertType, - }, - Conjunction, - ), - ) - }) - - t.Run("two entitlements, disjunction", func(t *testing.T) { - t.Parallel() - - assert.Equal(t, - NewEntitlementSetAccess( - []*EntitlementType{ - MutateType, - InsertType, - }, - Disjunction, - ), - newEntitlementAccess( - []Type{ - MutateType, - InsertType, - }, - Disjunction, - ), - ) - }) - - t.Run("single map", func(t *testing.T) { - t.Parallel() - - assert.Equal(t, - NewEntitlementMapAccess( - IdentityType, - ), - newEntitlementAccess( - []Type{ - IdentityType, - }, - Conjunction, - ), - ) - }) - - t.Run("two maps", func(t *testing.T) { - t.Parallel() - - assert.PanicsWithError(t, - "extra entitlement map type", - func() { - newEntitlementAccess( - []Type{ - IdentityType, - AccountMappingType, - }, - Conjunction, - ) - }, - ) - }) -} - -func TestEntitlementSetAccess_QualifiedKeyword(t *testing.T) { - - t.Parallel() - - location := common.NewAddressLocation(nil, common.MustBytesToAddress([]byte{0x1}), "Foo") - - fooType := &CompositeType{ - Location: location, - Identifier: "Foo", - } - - barType := NewEntitlementType( - nil, - location, - "Bar", - ) - barType.SetContainerType(fooType) - - bazType := NewEntitlementType( - nil, - location, - "Baz", - ) - bazType.SetContainerType(fooType) - - assert.Equal(t, - "access(Foo.Bar | Foo.Baz)", - newEntitlementAccess( - []Type{ - barType, - bazType, - }, - Disjunction, - ).QualifiedKeyword(), - ) -} - -func TestEntitlementMapAccess_ID(t *testing.T) { - t.Parallel() - - testLocation := common.StringLocation("test") - - t.Run("top-level", func(t *testing.T) { - t.Parallel() - - access := NewEntitlementMapAccess(NewEntitlementMapType(nil, testLocation, "M")) - assert.Equal(t, TypeID("S.test.M"), access.ID()) - }) - - t.Run("nested", func(t *testing.T) { - t.Parallel() - - mapType := NewEntitlementMapType(nil, testLocation, "M") - - mapType.SetContainerType(&CompositeType{ - Location: testLocation, - Identifier: "C", - }) - - access := NewEntitlementMapAccess(mapType) - assert.Equal(t, TypeID("S.test.C.M"), access.ID()) - }) - -} - -func TestEntitlementMapAccess_String(t *testing.T) { - t.Parallel() - - testLocation := common.StringLocation("test") - - access := NewEntitlementMapAccess(NewEntitlementMapType(nil, testLocation, "M")) - assert.Equal(t, "M", access.String()) -} - -func TestEntitlementMapAccess_QualifiedString(t *testing.T) { - t.Parallel() - - testLocation := common.StringLocation("test") - - t.Run("top-level", func(t *testing.T) { - t.Parallel() - - access := NewEntitlementMapAccess(NewEntitlementMapType(nil, testLocation, "M")) - assert.Equal(t, "M", access.QualifiedString()) - }) - - t.Run("nested", func(t *testing.T) { - t.Parallel() - - mapType := NewEntitlementMapType(nil, testLocation, "M") - - mapType.SetContainerType(&CompositeType{ - Location: testLocation, - Identifier: "C", - }) - - access := NewEntitlementMapAccess(mapType) - assert.Equal(t, "C.M", access.QualifiedString()) - }) -} - -func TestEntitlementSetAccess_ID(t *testing.T) { - t.Parallel() - - testLocation := common.StringLocation("test") - - t.Run("single", func(t *testing.T) { - t.Parallel() - - access := NewEntitlementSetAccess( - []*EntitlementType{ - NewEntitlementType(nil, testLocation, "E"), - }, - Conjunction, - ) - assert.Equal(t, - TypeID("S.test.E"), - access.ID(), - ) - }) - - t.Run("two, conjunction", func(t *testing.T) { - t.Parallel() - - access := NewEntitlementSetAccess( - []*EntitlementType{ - // NOTE: order - NewEntitlementType(nil, testLocation, "E2"), - NewEntitlementType(nil, testLocation, "E1"), - }, - Conjunction, - ) - // NOTE: sorted - assert.Equal(t, - TypeID("S.test.E1,S.test.E2"), - access.ID(), - ) - }) - - t.Run("two, disjunction", func(t *testing.T) { - t.Parallel() - - access := NewEntitlementSetAccess( - []*EntitlementType{ - // NOTE: order - NewEntitlementType(nil, testLocation, "E2"), - NewEntitlementType(nil, testLocation, "E1"), - }, - Disjunction, - ) - // NOTE: sorted - assert.Equal(t, - TypeID("S.test.E1|S.test.E2"), - access.ID(), - ) - }) - - t.Run("three, conjunction", func(t *testing.T) { - t.Parallel() - - access := NewEntitlementSetAccess( - []*EntitlementType{ - // NOTE: order - NewEntitlementType(nil, testLocation, "E3"), - NewEntitlementType(nil, testLocation, "E2"), - NewEntitlementType(nil, testLocation, "E1"), - }, - Conjunction, - ) - // NOTE: sorted - assert.Equal(t, - TypeID("S.test.E1,S.test.E2,S.test.E3"), - access.ID(), - ) - }) - - t.Run("three, disjunction", func(t *testing.T) { - t.Parallel() - - access := NewEntitlementSetAccess( - []*EntitlementType{ - // NOTE: order - NewEntitlementType(nil, testLocation, "E3"), - NewEntitlementType(nil, testLocation, "E2"), - NewEntitlementType(nil, testLocation, "E1"), - }, - Disjunction, - ) - // NOTE: sorted - assert.Equal(t, - TypeID("S.test.E1|S.test.E2|S.test.E3"), - access.ID(), - ) - }) - -} - -func TestEntitlementSetAccess_String(t *testing.T) { - t.Parallel() - - testLocation := common.StringLocation("test") - - t.Run("single", func(t *testing.T) { - t.Parallel() - - access := NewEntitlementSetAccess( - []*EntitlementType{ - NewEntitlementType(nil, testLocation, "E"), - }, - Conjunction, - ) - assert.Equal(t, "E", access.String()) - }) - - t.Run("two, conjunction", func(t *testing.T) { - t.Parallel() - - access := NewEntitlementSetAccess( - []*EntitlementType{ - // NOTE: order - NewEntitlementType(nil, testLocation, "E2"), - NewEntitlementType(nil, testLocation, "E1"), - }, - Conjunction, - ) - // NOTE: order - assert.Equal(t, "E2, E1", access.String()) - }) - - t.Run("two, disjunction", func(t *testing.T) { - t.Parallel() - - access := NewEntitlementSetAccess( - []*EntitlementType{ - // NOTE: order - NewEntitlementType(nil, testLocation, "E2"), - NewEntitlementType(nil, testLocation, "E1"), - }, - Disjunction, - ) - // NOTE: order - assert.Equal(t, "E2 | E1", access.String()) - }) - - t.Run("three, conjunction", func(t *testing.T) { - t.Parallel() - - access := NewEntitlementSetAccess( - []*EntitlementType{ - // NOTE: order - NewEntitlementType(nil, testLocation, "E3"), - NewEntitlementType(nil, testLocation, "E2"), - NewEntitlementType(nil, testLocation, "E1"), - }, - Conjunction, - ) - // NOTE: order - assert.Equal(t, "E3, E2, E1", access.String()) - }) - - t.Run("three, disjunction", func(t *testing.T) { - t.Parallel() - - access := NewEntitlementSetAccess( - []*EntitlementType{ - // NOTE: order - NewEntitlementType(nil, testLocation, "E3"), - NewEntitlementType(nil, testLocation, "E2"), - NewEntitlementType(nil, testLocation, "E1"), - }, - Disjunction, - ) - // NOTE: order - assert.Equal(t, "E3 | E2 | E1", access.String()) - }) -} - -func TestEntitlementSetAccess_QualifiedString(t *testing.T) { - t.Parallel() - - testLocation := common.StringLocation("test") - - containerType := &CompositeType{ - Location: testLocation, - Identifier: "C", - } - - t.Run("single", func(t *testing.T) { - t.Parallel() - - entitlementType := NewEntitlementType(nil, testLocation, "E") - entitlementType.SetContainerType(containerType) - - access := NewEntitlementSetAccess( - []*EntitlementType{ - entitlementType, - }, - Conjunction, - ) - assert.Equal(t, "C.E", access.QualifiedString()) - }) - - t.Run("two, conjunction", func(t *testing.T) { - t.Parallel() - - entitlementType1 := NewEntitlementType(nil, testLocation, "E1") - entitlementType1.SetContainerType(containerType) - - entitlementType2 := NewEntitlementType(nil, testLocation, "E2") - entitlementType2.SetContainerType(containerType) - - access := NewEntitlementSetAccess( - []*EntitlementType{ - // NOTE: order - entitlementType2, - entitlementType1, - }, - Conjunction, - ) - // NOTE: order - assert.Equal(t, - "C.E2, C.E1", - access.QualifiedString(), - ) - }) - - t.Run("two, disjunction", func(t *testing.T) { - t.Parallel() - - entitlementType1 := NewEntitlementType(nil, testLocation, "E1") - entitlementType1.SetContainerType(containerType) - - entitlementType2 := NewEntitlementType(nil, testLocation, "E2") - entitlementType2.SetContainerType(containerType) - - access := NewEntitlementSetAccess( - []*EntitlementType{ - // NOTE: order - entitlementType2, - entitlementType1, - }, - Disjunction, - ) - // NOTE: order - assert.Equal(t, - "C.E2 | C.E1", - access.QualifiedString(), - ) - }) - - t.Run("three, conjunction", func(t *testing.T) { - t.Parallel() - - entitlementType1 := NewEntitlementType(nil, testLocation, "E1") - entitlementType1.SetContainerType(containerType) - - entitlementType2 := NewEntitlementType(nil, testLocation, "E2") - entitlementType2.SetContainerType(containerType) - - entitlementType3 := NewEntitlementType(nil, testLocation, "E3") - entitlementType3.SetContainerType(containerType) - - access := NewEntitlementSetAccess( - []*EntitlementType{ - // NOTE: order - entitlementType3, - entitlementType2, - entitlementType1, - }, - Conjunction, - ) - // NOTE: order - assert.Equal(t, - "C.E3, C.E2, C.E1", - access.QualifiedString(), - ) - }) - - t.Run("three, disjunction", func(t *testing.T) { - t.Parallel() - - entitlementType1 := NewEntitlementType(nil, testLocation, "E1") - entitlementType1.SetContainerType(containerType) - - entitlementType2 := NewEntitlementType(nil, testLocation, "E2") - entitlementType2.SetContainerType(containerType) - - entitlementType3 := NewEntitlementType(nil, testLocation, "E3") - entitlementType3.SetContainerType(containerType) - - access := NewEntitlementSetAccess( - []*EntitlementType{ - // NOTE: order - entitlementType3, - entitlementType2, - entitlementType1, - }, - Disjunction, - ) - // NOTE: order - assert.Equal(t, - "C.E3 | C.E2 | C.E1", - access.QualifiedString(), - ) - }) -} - -func TestEntitlementMapAccess_QualifiedKeyword(t *testing.T) { - - t.Parallel() - - location := common.NewAddressLocation(nil, common.MustBytesToAddress([]byte{0x1}), "Foo") - - fooType := &CompositeType{ - Location: location, - Identifier: "Foo", - } - - barType := NewEntitlementMapType( - nil, - location, - "Bar", - ) - barType.SetContainerType(fooType) - - assert.Equal(t, - "access(mapping Foo.Bar)", - NewEntitlementMapAccess(barType).QualifiedKeyword(), - ) -} 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..eaa4dc16a9 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/tests/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..e993ed7303 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,6 +27,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/tests/sema_utils" "github.com/onflow/cadence/tests/utils" ) 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..6e35846d12 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/tests/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..20a306fe04 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/tests/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..2912bf380b 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/tests/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..3d415c16ee 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/tests/sema_utils" ) func TestCheckInvalidUnknownDeclarationAssignment(t *testing.T) { diff --git a/tests/checker/attachments_test.go b/sema/attachments_test.go similarity index 99% rename from tests/checker/attachments_test.go rename to sema/attachments_test.go index de3e3dd406..c1609e8e0b 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/tests/sema_utils" ) func TestCheckAttachmentBasic(t *testing.T) { diff --git a/tests/checker/boolean_test.go b/sema/boolean_test.go similarity index 94% rename from tests/checker/boolean_test.go rename to sema/boolean_test.go index a6e5224581..6d4e0cde0d 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/tests/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..41a956d1d1 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/tests/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..d2ab30eda3 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/tests/sema_utils" ) func TestCheckStorageCapabilityController(t *testing.T) { diff --git a/tests/checker/capability_test.go b/sema/capability_test.go similarity index 99% rename from tests/checker/capability_test.go rename to sema/capability_test.go index 3a9ffc013e..155442dc12 100644 --- a/tests/checker/capability_test.go +++ b/sema/capability_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_test import ( "fmt" @@ -27,6 +27,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + . "github.com/onflow/cadence/tests/sema_utils" ) func TestCheckCapability(t *testing.T) { 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..e107a4615b 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/tests/sema_utils" ) func TestCheckCastingIntLiteralToIntegerType(t *testing.T) { diff --git a/tests/checker/character_test.go b/sema/character_test.go similarity index 96% rename from tests/checker/character_test.go rename to sema/character_test.go index 816ae93159..318b101dbc 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/tests/sema_utils" ) func TestCheckCharacterLiteral(t *testing.T) { diff --git a/tests/checker/composite_test.go b/sema/composite_test.go similarity index 99% rename from tests/checker/composite_test.go rename to sema/composite_test.go index 241a6ce50b..6598505d98 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/tests/sema_utils" ) func TestCheckInvalidCompositeRedeclaringType(t *testing.T) { diff --git a/tests/checker/conditional_test.go b/sema/conditional_test.go similarity index 98% rename from tests/checker/conditional_test.go rename to sema/conditional_test.go index 733c3fade3..98ec1a75a7 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/tests/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..d845c52c1d 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/tests/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..6109516c58 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/tests/sema_utils" ) func TestCheckEventNonTypeRequirementConformance(t *testing.T) { diff --git a/tests/checker/contract_test.go b/sema/contract_test.go similarity index 99% rename from tests/checker/contract_test.go rename to sema/contract_test.go index 9bb97a50d0..2de30e7d68 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/tests/sema_utils" ) func TestCheckInvalidContractAccountField(t *testing.T) { 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..91397e95ea 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/tests/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..738c4c6d34 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/tests/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..900c53860e 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/tests/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..15861bc8e7 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,6 +28,7 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/tests/sema_utils" "github.com/onflow/cadence/tests/utils" ) diff --git a/tests/checker/entitlements_test.go b/sema/entitlements_test.go similarity index 99% rename from tests/checker/entitlements_test.go rename to sema/entitlements_test.go index b546de5713..caa5dd36e4 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/tests/sema_utils" ) func TestCheckBasicEntitlementDeclaration(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..ac76190b26 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/tests/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..2fc3233336 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/tests/sema_utils" ) func TestCheckInvalidNonEnumCompositeEnumCases(t *testing.T) { diff --git a/tests/checker/errors_test.go b/sema/error_handling_test.go similarity index 98% rename from tests/checker/errors_test.go rename to sema/error_handling_test.go index 33da8bc032..cc84b43316 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,6 +27,7 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/tests/sema_utils" "github.com/onflow/cadence/tests/utils" ) 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..d1c588392f 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/tests/sema_utils" + "github.com/onflow/cadence/tests/utils" ) func TestCheckEventDeclaration(t *testing.T) { 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..3eabd29a5a 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/tests/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..a1f0eb15e5 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/tests/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..8e2f68dcb8 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/tests/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..c3d0f41f5c 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/tests/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..5bb0467941 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/tests/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..334f1ee2c7 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/tests/sema_utils" ) func TestCheckReferenceInFunction(t *testing.T) { diff --git a/sema/gen/golden_test.go b/sema/gen/golden_test.go index bcb116fa0f..0053427d45 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/tests/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/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..6b3e443db1 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/tests/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..51f432bf25 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/tests/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..0674d66d97 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/tests/sema_utils" ) func TestCheckIfStatementTest(t *testing.T) { diff --git a/tests/checker/import_test.go b/sema/import_test.go similarity index 99% rename from tests/checker/import_test.go rename to sema/import_test.go index bc586139c6..9e92714fa9 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,6 +30,7 @@ import ( "github.com/onflow/cadence/errors" "github.com/onflow/cadence/parser" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/tests/sema_utils" "github.com/onflow/cadence/tests/utils" ) 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..5eabac65ff 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/tests/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..832bb2724e 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/tests/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..1fdcf5963f 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/tests/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..b43b4f7573 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/tests/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..763d16f1b4 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/tests/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..87e85d7a28 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/tests/sema_utils" ) func TestCheckSpuriousIdentifierAssignmentInvalidValueTypeMismatch(t *testing.T) { diff --git a/tests/checker/invocation_test.go b/sema/invocation_test.go similarity index 99% rename from tests/checker/invocation_test.go rename to sema/invocation_test.go index ded43f11ae..11abdd4073 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,6 +28,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" + . "github.com/onflow/cadence/tests/sema_utils" "github.com/onflow/cadence/tests/utils" ) 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..94fd50858b 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/tests/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..fcf185510f 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/tests/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..0791f6f744 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/tests/sema_utils" ) func TestCheckInvalidMoves(t *testing.T) { diff --git a/tests/checker/nesting_test.go b/sema/nesting_test.go similarity index 99% rename from tests/checker/nesting_test.go rename to sema/nesting_test.go index 40ec6ab6e9..184e566224 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/tests/sema_utils" ) func TestCheckCompositeDeclarationNesting(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..5195786007 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/tests/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..0f7c0364fd 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/tests/sema_utils" ) func TestCheckNilCoalescingNilIntToOptional(t *testing.T) { 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..98f9403269 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,6 +26,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/tests/sema_utils" . "github.com/onflow/cadence/tests/utils" ) 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..c5f460bc28 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/tests/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..ea92b679e3 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/tests/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..77cdea966b 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/tests/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..0b3fcd1215 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/tests/sema_utils" ) func TestCheckPath(t *testing.T) { 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..1795e86df7 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/tests/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..b402b49c80 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/tests/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..2df908b4cd 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/tests/sema_utils" ) func TestCheckPuritySubtyping(t *testing.T) { diff --git a/tests/checker/range_test.go b/sema/range_test.go similarity index 99% rename from tests/checker/range_test.go rename to sema/range_test.go index d72c798855..752cb93f64 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,6 +27,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/tests/sema_utils" "github.com/onflow/cadence/tests/utils" ) 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..1598aee163 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/tests/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..b05629424f 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,6 +28,7 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/tests/sema_utils" "github.com/onflow/cadence/tests/utils" ) 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..1bfe40da3b 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" @@ -29,6 +29,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/errors" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/tests/sema_utils" . "github.com/onflow/cadence/tests/utils" ) 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..5f9b20ed5b 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/tests/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..b079b03c33 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/tests/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..8d8b444c70 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/tests/sema_utils" ) func TestCheckOptionalTypeConstructor(t *testing.T) { 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..3720107e70 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/tests/sema_utils" ) func TestCheckStorable(t *testing.T) { diff --git a/tests/checker/string_test.go b/sema/string_test.go similarity index 99% rename from tests/checker/string_test.go rename to sema/string_test.go index cc82a8ec00..23c0ff8001 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/tests/sema_utils" ) func TestCheckCharacter(t *testing.T) { 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..63fb658906 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/tests/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..38328f1645 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/tests/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..79b362d918 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/tests/sema_utils" ) func TestCheckTransactions(t *testing.T) { 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..85a338eaf3 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/tests/sema_utils" ) func TestCheckArrayElementTypeInference(t *testing.T) { 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..66895844d4 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/tests/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..d65f31264d 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/tests/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..9d40353678 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/tests/sema_utils" ) func TestCheckInvalidWhileTest(t *testing.T) { diff --git a/stdlib/builtin_test.go b/stdlib/builtin_test.go index 676603eaa5..46bbed8071 100644 --- a/stdlib/builtin_test.go +++ b/stdlib/builtin_test.go @@ -23,7 +23,7 @@ import ( "github.com/onflow/cadence/activations" "github.com/onflow/cadence/common" - "github.com/onflow/cadence/tests/checker" + . "github.com/onflow/cadence/tests/sema_utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -100,9 +100,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 +116,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 +124,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 +146,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 +154,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 +162,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{}) }) } @@ -218,9 +218,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 +234,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 +250,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 +258,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{}) }) } diff --git a/stdlib/test_test.go b/stdlib/test_test.go index 19912f763c..47592a0de2 100644 --- a/stdlib/test_test.go +++ b/stdlib/test_test.go @@ -34,7 +34,7 @@ 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/sema_utils" "github.com/onflow/cadence/tests/utils" ) @@ -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/tests/interpreter/condition_test.go b/tests/interpreter/condition_test.go index 34d56d2f14..74d1deabc9 100644 --- a/tests/interpreter/condition_test.go +++ b/tests/interpreter/condition_test.go @@ -31,7 +31,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/sema_utils" . "github.com/onflow/cadence/tests/utils" ) @@ -855,7 +855,7 @@ func TestInterpretInitializerWithInterfacePreCondition(t *testing.T) { ) } - checker, err := checker.ParseAndCheck(t, + checker, err := ParseAndCheck(t, fmt.Sprintf( ` access(all) diff --git a/tests/interpreter/function_test.go b/tests/interpreter/function_test.go index f2e4675e4e..e4e293fa9c 100644 --- a/tests/interpreter/function_test.go +++ b/tests/interpreter/function_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/checker" + . "github.com/onflow/cadence/tests/sema_utils" "github.com/onflow/cadence/tests/utils" ) @@ -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") diff --git a/tests/interpreter/if_test.go b/tests/interpreter/if_test.go index cc7efb83c2..4242062e39 100644 --- a/tests/interpreter/if_test.go +++ b/tests/interpreter/if_test.go @@ -24,11 +24,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + . "github.com/onflow/cadence/tests/sema_utils" . "github.com/onflow/cadence/tests/utils" "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/checker" ) func TestInterpretIfStatement(t *testing.T) { @@ -83,7 +83,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/tests/interpreter/import_test.go index 45204a23c8..a5a2e808b7 100644 --- a/tests/interpreter/import_test.go +++ b/tests/interpreter/import_test.go @@ -29,7 +29,7 @@ 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/sema_utils" . "github.com/onflow/cadence/tests/utils" ) @@ -154,7 +154,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 +166,7 @@ func TestInterpretImportMultipleProgramsFromLocation(t *testing.T) { return 11 } `, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Location: common.AddressLocation{ Address: address, Name: "a", @@ -175,7 +175,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 +187,7 @@ func TestInterpretImportMultipleProgramsFromLocation(t *testing.T) { return 22 } `, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Location: common.AddressLocation{ Address: address, Name: "b", @@ -196,7 +196,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 +204,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 +316,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 +328,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 +337,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 +396,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/interpreter_test.go b/tests/interpreter/interpreter_test.go index 6a697eff69..d3c3138580 100644 --- a/tests/interpreter/interpreter_test.go +++ b/tests/interpreter/interpreter_test.go @@ -39,7 +39,7 @@ 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/sema_utils" . "github.com/onflow/cadence/tests/utils" ) @@ -168,9 +168,9 @@ func parseCheckAndInterpretWithOptionsAndMemoryMetering( err error, ) { - checker, err := checker.ParseAndCheckWithOptionsAndMemoryMetering(t, + checker, err := ParseAndCheckWithOptionsAndMemoryMetering(t, code, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Config: options.CheckerConfig, }, memoryGauge, @@ -1208,7 +1208,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 +4207,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 +4227,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 +4298,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 { @@ -6823,7 +6823,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 +6836,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 +6851,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 +7277,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 +7420,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 +7758,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 +8613,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 +8623,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 +8642,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 +10686,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]) }, }, diff --git a/tests/interpreter/member_test.go b/tests/interpreter/member_test.go index 29d14e5b82..a7dd3c454a 100644 --- a/tests/interpreter/member_test.go +++ b/tests/interpreter/member_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/interpreter" - "github.com/onflow/cadence/tests/checker" + . "github.com/onflow/cadence/tests/sema_utils" . "github.com/onflow/cadence/tests/utils" ) @@ -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/tests/interpreter/memory_metering_test.go index 5de97ddfe5..56fae49cb0 100644 --- a/tests/interpreter/memory_metering_test.go +++ b/tests/interpreter/memory_metering_test.go @@ -23,6 +23,7 @@ import ( "testing" "github.com/onflow/cadence/activations" + . "github.com/onflow/cadence/tests/sema_utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -32,7 +33,6 @@ 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" ) @@ -8147,11 +8147,11 @@ func TestInterpretASTMetering(t *testing.T) { #pragma ` - importedChecker, err := checker.ParseAndCheckWithOptions(t, + importedChecker, err := ParseAndCheckWithOptions(t, ` let Foo = 1 `, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Location: utils.ImportedLocation, }, ) @@ -8444,12 +8444,12 @@ 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{ + ParseAndCheckOptions{ Location: utils.ImportedLocation, }, ) diff --git a/tests/interpreter/metering_test.go b/tests/interpreter/metering_test.go index 243afdba05..a7ea9882d0 100644 --- a/tests/interpreter/metering_test.go +++ b/tests/interpreter/metering_test.go @@ -28,7 +28,7 @@ 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/sema_utils" "github.com/onflow/cadence/tests/utils" ) @@ -36,20 +36,20 @@ func TestInterpretStatementHandler(t *testing.T) { t.Parallel() - importedChecker, err := checker.ParseAndCheckWithOptions(t, + importedChecker, err := ParseAndCheckWithOptions(t, ` access(all) fun a() { true true } `, - checker.ParseAndCheckOptions{ + ParseAndCheckOptions{ Location: utils.ImportedLocation, }, ) require.NoError(t, err) - importingChecker, err := checker.ParseAndCheckWithOptions(t, + importingChecker, err := ParseAndCheckWithOptions(t, ` import a from "imported" @@ -69,7 +69,7 @@ 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, @@ -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,7 +193,7 @@ 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, @@ -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{ + ParseAndCheckOptions{ Location: utils.ImportedLocation, }, ) require.NoError(t, err) - importingChecker, err := checker.ParseAndCheckWithOptions(t, + importingChecker, err := ParseAndCheckWithOptions(t, ` import b from "imported" @@ -328,7 +328,7 @@ 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, diff --git a/tests/interpreter/reference_test.go b/tests/interpreter/reference_test.go index 808ff46c83..7af848436c 100644 --- a/tests/interpreter/reference_test.go +++ b/tests/interpreter/reference_test.go @@ -28,7 +28,7 @@ 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/sema_utils" . "github.com/onflow/cadence/tests/utils" ) @@ -530,7 +530,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 +637,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 +742,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 +843,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 +969,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 +1524,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 +1747,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 +1787,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 +3040,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 +3071,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 +3208,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 +3281,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/tests/interpreter/resources_test.go index f6d1b11283..fd639a5739 100644 --- a/tests/interpreter/resources_test.go +++ b/tests/interpreter/resources_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/checker" + . "github.com/onflow/cadence/tests/sema_utils" . "github.com/onflow/cadence/tests/utils" "github.com/onflow/cadence/interpreter" @@ -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/switch_test.go b/tests/interpreter/switch_test.go index 3d0dda4b90..0cbe894063 100644 --- a/tests/interpreter/switch_test.go +++ b/tests/interpreter/switch_test.go @@ -24,11 +24,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + . "github.com/onflow/cadence/tests/sema_utils" . "github.com/onflow/cadence/tests/utils" "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - "github.com/onflow/cadence/tests/checker" ) func TestInterpretSwitchStatement(t *testing.T) { @@ -53,7 +53,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 +91,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 +132,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 +219,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/tests/interpreter/transactions_test.go index 71680a184d..8a4167a0b1 100644 --- a/tests/interpreter/transactions_test.go +++ b/tests/interpreter/transactions_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/checker" + . "github.com/onflow/cadence/tests/sema_utils" . "github.com/onflow/cadence/tests/utils" ) @@ -420,7 +420,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/uuid_test.go b/tests/interpreter/uuid_test.go index 3e56037a5c..aa4154ff19 100644 --- a/tests/interpreter/uuid_test.go +++ b/tests/interpreter/uuid_test.go @@ -28,7 +28,7 @@ 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/sema_utils" . "github.com/onflow/cadence/tests/utils" ) @@ -36,7 +36,7 @@ func TestInterpretResourceUUID(t *testing.T) { t.Parallel() - importedChecker, err := checker.ParseAndCheckWithOptions(t, + importedChecker, err := ParseAndCheckWithOptions(t, ` access(all) resource R {} @@ -44,13 +44,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 +63,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/tests/checker/utils.go b/tests/sema_utils/utils.go similarity index 99% rename from tests/checker/utils.go rename to tests/sema_utils/utils.go index 3afe516b80..23d1e7756e 100644 --- a/tests/checker/utils.go +++ b/tests/sema_utils/utils.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package checker +package sema_utils import ( "flag" diff --git a/tools/analysis/analysis_test.go b/tools/analysis/analysis_test.go index 61e1d54ec4..0baebceefa 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/tests/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]) } From 0f5d513151ff53bbd3c14bb1d3a6324bb3152484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 28 Oct 2024 16:25:19 -0700 Subject: [PATCH 46/70] move occurrence matcher --- .../occurrence_matcher.go => sema/occurrence_matcher_test.go | 2 +- sema/occurrences_test.go | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) rename tests/utils/occurrence_matcher.go => sema/occurrence_matcher_test.go (98%) 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/sema/occurrences_test.go b/sema/occurrences_test.go index 98f9403269..a1854e5cef 100644 --- a/sema/occurrences_test.go +++ b/sema/occurrences_test.go @@ -27,7 +27,6 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" . "github.com/onflow/cadence/tests/sema_utils" - . "github.com/onflow/cadence/tests/utils" ) // TODO: implement occurrences for type references From a6da1a0620c76c67f1ff48dad164b54d91f03f5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 28 Oct 2024 16:33:18 -0700 Subject: [PATCH 47/70] move interpreter tests --- .../account_test.go | 0 .../arithmetic_test.go | 0 .../interpreter => interpreter}/array_test.go | 0 .../attachments_test.go | 0 .../bitwise_test.go | 0 .../builtinfunctions_test.go | 0 .../character_test.go | 0 .../composite_value_test.go | 0 .../condition_test.go | 0 .../container_mutation_test.go | 0 .../contract_test.go | 0 .../declaration_test.go | 0 interpreter/deepcopyremove_test.go | 34 ++++++++----------- .../dictionary_test.go | 0 .../dynamic_casting_test.go | 0 .../entitlements_test.go | 0 .../interpreter => interpreter}/enum_test.go | 0 .../equality_test.go | 0 .../fixedpoint_test.go | 0 .../interpreter => interpreter}/for_test.go | 0 .../function_test.go | 0 {tests/interpreter => interpreter}/if_test.go | 0 .../import_test.go | 0 .../indexing_test.go | 0 .../integers_test.go | 0 .../interface_test.go | 0 .../invocation_test.go | 0 .../member_test.go | 0 .../memory_metering_test.go | 0 .../metatype_test.go | 0 .../metering_test.go | 0 .../misc_test.go | 0 .../nesting_test.go | 0 .../interpreter => interpreter}/path_test.go | 0 .../pathcapability_test.go | 0 .../range_value_test.go | 0 .../reference_test.go | 0 .../resources_test.go | 0 .../runtimetype_test.go | 0 .../string_test.go | 0 .../switch_test.go | 0 .../transactions_test.go | 0 .../transfer_test.go | 0 .../interpreter => interpreter}/uuid_test.go | 0 .../values_test.go | 0 .../interpreter => interpreter}/while_test.go | 0 46 files changed, 15 insertions(+), 19 deletions(-) rename {tests/interpreter => interpreter}/account_test.go (100%) rename {tests/interpreter => interpreter}/arithmetic_test.go (100%) rename {tests/interpreter => interpreter}/array_test.go (100%) rename {tests/interpreter => interpreter}/attachments_test.go (100%) rename {tests/interpreter => interpreter}/bitwise_test.go (100%) rename {tests/interpreter => interpreter}/builtinfunctions_test.go (100%) rename {tests/interpreter => interpreter}/character_test.go (100%) rename {tests/interpreter => interpreter}/composite_value_test.go (100%) rename {tests/interpreter => interpreter}/condition_test.go (100%) rename {tests/interpreter => interpreter}/container_mutation_test.go (100%) rename {tests/interpreter => interpreter}/contract_test.go (100%) rename {tests/interpreter => interpreter}/declaration_test.go (100%) rename {tests/interpreter => interpreter}/dictionary_test.go (100%) rename {tests/interpreter => interpreter}/dynamic_casting_test.go (100%) rename {tests/interpreter => interpreter}/entitlements_test.go (100%) rename {tests/interpreter => interpreter}/enum_test.go (100%) rename {tests/interpreter => interpreter}/equality_test.go (100%) rename {tests/interpreter => interpreter}/fixedpoint_test.go (100%) rename {tests/interpreter => interpreter}/for_test.go (100%) rename {tests/interpreter => interpreter}/function_test.go (100%) rename {tests/interpreter => interpreter}/if_test.go (100%) rename {tests/interpreter => interpreter}/import_test.go (100%) rename {tests/interpreter => interpreter}/indexing_test.go (100%) rename {tests/interpreter => interpreter}/integers_test.go (100%) rename {tests/interpreter => interpreter}/interface_test.go (100%) rename {tests/interpreter => interpreter}/invocation_test.go (100%) rename {tests/interpreter => interpreter}/member_test.go (100%) rename {tests/interpreter => interpreter}/memory_metering_test.go (100%) rename {tests/interpreter => interpreter}/metatype_test.go (100%) rename {tests/interpreter => interpreter}/metering_test.go (100%) rename tests/interpreter/interpreter_test.go => interpreter/misc_test.go (100%) rename {tests/interpreter => interpreter}/nesting_test.go (100%) rename {tests/interpreter => interpreter}/path_test.go (100%) rename {tests/interpreter => interpreter}/pathcapability_test.go (100%) rename {tests/interpreter => interpreter}/range_value_test.go (100%) rename {tests/interpreter => interpreter}/reference_test.go (100%) rename {tests/interpreter => interpreter}/resources_test.go (100%) rename {tests/interpreter => interpreter}/runtimetype_test.go (100%) rename {tests/interpreter => interpreter}/string_test.go (100%) rename {tests/interpreter => interpreter}/switch_test.go (100%) rename {tests/interpreter => interpreter}/transactions_test.go (100%) rename {tests/interpreter => interpreter}/transfer_test.go (100%) rename {tests/interpreter => interpreter}/uuid_test.go (100%) rename {tests/interpreter => interpreter}/values_test.go (100%) rename {tests/interpreter => interpreter}/while_test.go (100%) diff --git a/tests/interpreter/account_test.go b/interpreter/account_test.go similarity index 100% rename from tests/interpreter/account_test.go rename to interpreter/account_test.go diff --git a/tests/interpreter/arithmetic_test.go b/interpreter/arithmetic_test.go similarity index 100% rename from tests/interpreter/arithmetic_test.go rename to interpreter/arithmetic_test.go 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 100% rename from tests/interpreter/attachments_test.go rename to interpreter/attachments_test.go diff --git a/tests/interpreter/bitwise_test.go b/interpreter/bitwise_test.go similarity index 100% rename from tests/interpreter/bitwise_test.go rename to interpreter/bitwise_test.go diff --git a/tests/interpreter/builtinfunctions_test.go b/interpreter/builtinfunctions_test.go similarity index 100% rename from tests/interpreter/builtinfunctions_test.go rename to interpreter/builtinfunctions_test.go diff --git a/tests/interpreter/character_test.go b/interpreter/character_test.go similarity index 100% rename from tests/interpreter/character_test.go rename to interpreter/character_test.go diff --git a/tests/interpreter/composite_value_test.go b/interpreter/composite_value_test.go similarity index 100% rename from tests/interpreter/composite_value_test.go rename to interpreter/composite_value_test.go diff --git a/tests/interpreter/condition_test.go b/interpreter/condition_test.go similarity index 100% rename from tests/interpreter/condition_test.go rename to interpreter/condition_test.go diff --git a/tests/interpreter/container_mutation_test.go b/interpreter/container_mutation_test.go similarity index 100% rename from tests/interpreter/container_mutation_test.go rename to interpreter/container_mutation_test.go diff --git a/tests/interpreter/contract_test.go b/interpreter/contract_test.go similarity index 100% rename from tests/interpreter/contract_test.go rename to interpreter/contract_test.go 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..de16e42445 100644 --- a/interpreter/deepcopyremove_test.go +++ b/interpreter/deepcopyremove_test.go @@ -26,7 +26,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/common" - . "github.com/onflow/cadence/interpreter" + "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/tests/utils" ) @@ -38,49 +38,49 @@ func TestValueDeepCopyAndDeepRemove(t *testing.T) { storage := newUnmeteredInMemoryStorage() - inter, err := NewInterpreter( + inter, err := interpreter.NewInterpreter( nil, utils.TestLocation, - &Config{ + &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 100% rename from tests/interpreter/dynamic_casting_test.go rename to interpreter/dynamic_casting_test.go diff --git a/tests/interpreter/entitlements_test.go b/interpreter/entitlements_test.go similarity index 100% rename from tests/interpreter/entitlements_test.go rename to interpreter/entitlements_test.go diff --git a/tests/interpreter/enum_test.go b/interpreter/enum_test.go similarity index 100% rename from tests/interpreter/enum_test.go rename to interpreter/enum_test.go diff --git a/tests/interpreter/equality_test.go b/interpreter/equality_test.go similarity index 100% rename from tests/interpreter/equality_test.go rename to interpreter/equality_test.go diff --git a/tests/interpreter/fixedpoint_test.go b/interpreter/fixedpoint_test.go similarity index 100% rename from tests/interpreter/fixedpoint_test.go rename to interpreter/fixedpoint_test.go diff --git a/tests/interpreter/for_test.go b/interpreter/for_test.go similarity index 100% rename from tests/interpreter/for_test.go rename to interpreter/for_test.go diff --git a/tests/interpreter/function_test.go b/interpreter/function_test.go similarity index 100% rename from tests/interpreter/function_test.go rename to interpreter/function_test.go diff --git a/tests/interpreter/if_test.go b/interpreter/if_test.go similarity index 100% rename from tests/interpreter/if_test.go rename to interpreter/if_test.go diff --git a/tests/interpreter/import_test.go b/interpreter/import_test.go similarity index 100% rename from tests/interpreter/import_test.go rename to interpreter/import_test.go 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/tests/interpreter/integers_test.go b/interpreter/integers_test.go similarity index 100% rename from tests/interpreter/integers_test.go rename to interpreter/integers_test.go diff --git a/tests/interpreter/interface_test.go b/interpreter/interface_test.go similarity index 100% rename from tests/interpreter/interface_test.go rename to interpreter/interface_test.go diff --git a/tests/interpreter/invocation_test.go b/interpreter/invocation_test.go similarity index 100% rename from tests/interpreter/invocation_test.go rename to interpreter/invocation_test.go diff --git a/tests/interpreter/member_test.go b/interpreter/member_test.go similarity index 100% rename from tests/interpreter/member_test.go rename to interpreter/member_test.go diff --git a/tests/interpreter/memory_metering_test.go b/interpreter/memory_metering_test.go similarity index 100% rename from tests/interpreter/memory_metering_test.go rename to interpreter/memory_metering_test.go diff --git a/tests/interpreter/metatype_test.go b/interpreter/metatype_test.go similarity index 100% rename from tests/interpreter/metatype_test.go rename to interpreter/metatype_test.go diff --git a/tests/interpreter/metering_test.go b/interpreter/metering_test.go similarity index 100% rename from tests/interpreter/metering_test.go rename to interpreter/metering_test.go diff --git a/tests/interpreter/interpreter_test.go b/interpreter/misc_test.go similarity index 100% rename from tests/interpreter/interpreter_test.go rename to interpreter/misc_test.go 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 100% rename from tests/interpreter/path_test.go rename to interpreter/path_test.go 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 100% rename from tests/interpreter/range_value_test.go rename to interpreter/range_value_test.go diff --git a/tests/interpreter/reference_test.go b/interpreter/reference_test.go similarity index 100% rename from tests/interpreter/reference_test.go rename to interpreter/reference_test.go diff --git a/tests/interpreter/resources_test.go b/interpreter/resources_test.go similarity index 100% rename from tests/interpreter/resources_test.go rename to interpreter/resources_test.go diff --git a/tests/interpreter/runtimetype_test.go b/interpreter/runtimetype_test.go similarity index 100% rename from tests/interpreter/runtimetype_test.go rename to interpreter/runtimetype_test.go diff --git a/tests/interpreter/string_test.go b/interpreter/string_test.go similarity index 100% rename from tests/interpreter/string_test.go rename to interpreter/string_test.go diff --git a/tests/interpreter/switch_test.go b/interpreter/switch_test.go similarity index 100% rename from tests/interpreter/switch_test.go rename to interpreter/switch_test.go diff --git a/tests/interpreter/transactions_test.go b/interpreter/transactions_test.go similarity index 100% rename from tests/interpreter/transactions_test.go rename to interpreter/transactions_test.go diff --git a/tests/interpreter/transfer_test.go b/interpreter/transfer_test.go similarity index 100% rename from tests/interpreter/transfer_test.go rename to interpreter/transfer_test.go diff --git a/tests/interpreter/uuid_test.go b/interpreter/uuid_test.go similarity index 100% rename from tests/interpreter/uuid_test.go rename to interpreter/uuid_test.go diff --git a/tests/interpreter/values_test.go b/interpreter/values_test.go similarity index 100% rename from tests/interpreter/values_test.go rename to interpreter/values_test.go diff --git a/tests/interpreter/while_test.go b/interpreter/while_test.go similarity index 100% rename from tests/interpreter/while_test.go rename to interpreter/while_test.go From bc3bc62a1c1e1600b2d9f5dbcd39d22e0a5d5f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 28 Oct 2024 16:36:09 -0700 Subject: [PATCH 48/70] bring back access tests --- sema/access_test.go | 636 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 636 insertions(+) create mode 100644 sema/access_test.go diff --git a/sema/access_test.go b/sema/access_test.go new file mode 100644 index 0000000000..a5472f468c --- /dev/null +++ b/sema/access_test.go @@ -0,0 +1,636 @@ +/* + * 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 ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/onflow/cadence/ast" + "github.com/onflow/cadence/common" +) + +func TestPrimitiveAccess_QualifiedKeyword(t *testing.T) { + + t.Parallel() + + expected := map[ast.PrimitiveAccess]string{ + ast.AccessNotSpecified: "", + ast.AccessSelf: "access(self)", + ast.AccessAll: "access(all)", + ast.AccessAccount: "access(account)", + ast.AccessContract: "access(contract)", + ast.AccessPubSettableLegacy: "pub(set)", + ast.AccessNone: "inaccessible", + } + + for access := 0; access < ast.PrimitiveAccessCount(); access++ { + assert.Equal(t, + expected[ast.PrimitiveAccess(access)], + PrimitiveAccess(access).QualifiedKeyword(), + ) + } +} + +func TestNewEntitlementAccess(t *testing.T) { + + t.Parallel() + + t.Run("empty", func(t *testing.T) { + t.Parallel() + + assert.PanicsWithError(t, + "neither map entitlement nor set entitlements given", + func() { + newEntitlementAccess(nil, Conjunction) + }, + ) + }) + + t.Run("invalid", func(t *testing.T) { + t.Parallel() + + assert.PanicsWithError(t, + "invalid entitlement type: Void", + func() { + newEntitlementAccess([]Type{VoidType}, Conjunction) + }, + ) + }) + + t.Run("map + entitlement", func(t *testing.T) { + t.Parallel() + + assert.PanicsWithError(t, + "mixed entitlement types", + func() { + newEntitlementAccess( + []Type{ + IdentityType, + MutateType, + }, + Conjunction, + ) + }, + ) + }) + + t.Run("entitlement + map", func(t *testing.T) { + t.Parallel() + + assert.PanicsWithError(t, + "mixed entitlement types", + func() { + newEntitlementAccess( + []Type{ + MutateType, + IdentityType, + }, + Conjunction, + ) + }, + ) + }) + + t.Run("single entitlement", func(t *testing.T) { + t.Parallel() + + assert.Equal(t, + NewEntitlementSetAccess( + []*EntitlementType{ + MutateType, + }, + Conjunction, + ), + newEntitlementAccess( + []Type{ + MutateType, + }, + Conjunction, + ), + ) + }) + + t.Run("two entitlements, conjunction", func(t *testing.T) { + t.Parallel() + + assert.Equal(t, + NewEntitlementSetAccess( + []*EntitlementType{ + MutateType, + InsertType, + }, + Conjunction, + ), + newEntitlementAccess( + []Type{ + MutateType, + InsertType, + }, + Conjunction, + ), + ) + }) + + t.Run("two entitlements, disjunction", func(t *testing.T) { + t.Parallel() + + assert.Equal(t, + NewEntitlementSetAccess( + []*EntitlementType{ + MutateType, + InsertType, + }, + Disjunction, + ), + newEntitlementAccess( + []Type{ + MutateType, + InsertType, + }, + Disjunction, + ), + ) + }) + + t.Run("single map", func(t *testing.T) { + t.Parallel() + + assert.Equal(t, + NewEntitlementMapAccess( + IdentityType, + ), + newEntitlementAccess( + []Type{ + IdentityType, + }, + Conjunction, + ), + ) + }) + + t.Run("two maps", func(t *testing.T) { + t.Parallel() + + assert.PanicsWithError(t, + "extra entitlement map type", + func() { + newEntitlementAccess( + []Type{ + IdentityType, + AccountMappingType, + }, + Conjunction, + ) + }, + ) + }) +} + +func TestEntitlementSetAccess_QualifiedKeyword(t *testing.T) { + + t.Parallel() + + location := common.NewAddressLocation(nil, common.MustBytesToAddress([]byte{0x1}), "Foo") + + fooType := &CompositeType{ + Location: location, + Identifier: "Foo", + } + + barType := NewEntitlementType( + nil, + location, + "Bar", + ) + barType.SetContainerType(fooType) + + bazType := NewEntitlementType( + nil, + location, + "Baz", + ) + bazType.SetContainerType(fooType) + + assert.Equal(t, + "access(Foo.Bar | Foo.Baz)", + newEntitlementAccess( + []Type{ + barType, + bazType, + }, + Disjunction, + ).QualifiedKeyword(), + ) +} + +func TestEntitlementMapAccess_ID(t *testing.T) { + t.Parallel() + + testLocation := common.StringLocation("test") + + t.Run("top-level", func(t *testing.T) { + t.Parallel() + + access := NewEntitlementMapAccess(NewEntitlementMapType(nil, testLocation, "M")) + assert.Equal(t, TypeID("S.test.M"), access.ID()) + }) + + t.Run("nested", func(t *testing.T) { + t.Parallel() + + mapType := NewEntitlementMapType(nil, testLocation, "M") + + mapType.SetContainerType(&CompositeType{ + Location: testLocation, + Identifier: "C", + }) + + access := NewEntitlementMapAccess(mapType) + assert.Equal(t, TypeID("S.test.C.M"), access.ID()) + }) + +} + +func TestEntitlementMapAccess_String(t *testing.T) { + t.Parallel() + + testLocation := common.StringLocation("test") + + access := NewEntitlementMapAccess(NewEntitlementMapType(nil, testLocation, "M")) + assert.Equal(t, "M", access.String()) +} + +func TestEntitlementMapAccess_QualifiedString(t *testing.T) { + t.Parallel() + + testLocation := common.StringLocation("test") + + t.Run("top-level", func(t *testing.T) { + t.Parallel() + + access := NewEntitlementMapAccess(NewEntitlementMapType(nil, testLocation, "M")) + assert.Equal(t, "M", access.QualifiedString()) + }) + + t.Run("nested", func(t *testing.T) { + t.Parallel() + + mapType := NewEntitlementMapType(nil, testLocation, "M") + + mapType.SetContainerType(&CompositeType{ + Location: testLocation, + Identifier: "C", + }) + + access := NewEntitlementMapAccess(mapType) + assert.Equal(t, "C.M", access.QualifiedString()) + }) +} + +func TestEntitlementSetAccess_ID(t *testing.T) { + t.Parallel() + + testLocation := common.StringLocation("test") + + t.Run("single", func(t *testing.T) { + t.Parallel() + + access := NewEntitlementSetAccess( + []*EntitlementType{ + NewEntitlementType(nil, testLocation, "E"), + }, + Conjunction, + ) + assert.Equal(t, + TypeID("S.test.E"), + access.ID(), + ) + }) + + t.Run("two, conjunction", func(t *testing.T) { + t.Parallel() + + access := NewEntitlementSetAccess( + []*EntitlementType{ + // NOTE: order + NewEntitlementType(nil, testLocation, "E2"), + NewEntitlementType(nil, testLocation, "E1"), + }, + Conjunction, + ) + // NOTE: sorted + assert.Equal(t, + TypeID("S.test.E1,S.test.E2"), + access.ID(), + ) + }) + + t.Run("two, disjunction", func(t *testing.T) { + t.Parallel() + + access := NewEntitlementSetAccess( + []*EntitlementType{ + // NOTE: order + NewEntitlementType(nil, testLocation, "E2"), + NewEntitlementType(nil, testLocation, "E1"), + }, + Disjunction, + ) + // NOTE: sorted + assert.Equal(t, + TypeID("S.test.E1|S.test.E2"), + access.ID(), + ) + }) + + t.Run("three, conjunction", func(t *testing.T) { + t.Parallel() + + access := NewEntitlementSetAccess( + []*EntitlementType{ + // NOTE: order + NewEntitlementType(nil, testLocation, "E3"), + NewEntitlementType(nil, testLocation, "E2"), + NewEntitlementType(nil, testLocation, "E1"), + }, + Conjunction, + ) + // NOTE: sorted + assert.Equal(t, + TypeID("S.test.E1,S.test.E2,S.test.E3"), + access.ID(), + ) + }) + + t.Run("three, disjunction", func(t *testing.T) { + t.Parallel() + + access := NewEntitlementSetAccess( + []*EntitlementType{ + // NOTE: order + NewEntitlementType(nil, testLocation, "E3"), + NewEntitlementType(nil, testLocation, "E2"), + NewEntitlementType(nil, testLocation, "E1"), + }, + Disjunction, + ) + // NOTE: sorted + assert.Equal(t, + TypeID("S.test.E1|S.test.E2|S.test.E3"), + access.ID(), + ) + }) + +} + +func TestEntitlementSetAccess_String(t *testing.T) { + t.Parallel() + + testLocation := common.StringLocation("test") + + t.Run("single", func(t *testing.T) { + t.Parallel() + + access := NewEntitlementSetAccess( + []*EntitlementType{ + NewEntitlementType(nil, testLocation, "E"), + }, + Conjunction, + ) + assert.Equal(t, "E", access.String()) + }) + + t.Run("two, conjunction", func(t *testing.T) { + t.Parallel() + + access := NewEntitlementSetAccess( + []*EntitlementType{ + // NOTE: order + NewEntitlementType(nil, testLocation, "E2"), + NewEntitlementType(nil, testLocation, "E1"), + }, + Conjunction, + ) + // NOTE: order + assert.Equal(t, "E2, E1", access.String()) + }) + + t.Run("two, disjunction", func(t *testing.T) { + t.Parallel() + + access := NewEntitlementSetAccess( + []*EntitlementType{ + // NOTE: order + NewEntitlementType(nil, testLocation, "E2"), + NewEntitlementType(nil, testLocation, "E1"), + }, + Disjunction, + ) + // NOTE: order + assert.Equal(t, "E2 | E1", access.String()) + }) + + t.Run("three, conjunction", func(t *testing.T) { + t.Parallel() + + access := NewEntitlementSetAccess( + []*EntitlementType{ + // NOTE: order + NewEntitlementType(nil, testLocation, "E3"), + NewEntitlementType(nil, testLocation, "E2"), + NewEntitlementType(nil, testLocation, "E1"), + }, + Conjunction, + ) + // NOTE: order + assert.Equal(t, "E3, E2, E1", access.String()) + }) + + t.Run("three, disjunction", func(t *testing.T) { + t.Parallel() + + access := NewEntitlementSetAccess( + []*EntitlementType{ + // NOTE: order + NewEntitlementType(nil, testLocation, "E3"), + NewEntitlementType(nil, testLocation, "E2"), + NewEntitlementType(nil, testLocation, "E1"), + }, + Disjunction, + ) + // NOTE: order + assert.Equal(t, "E3 | E2 | E1", access.String()) + }) +} + +func TestEntitlementSetAccess_QualifiedString(t *testing.T) { + t.Parallel() + + testLocation := common.StringLocation("test") + + containerType := &CompositeType{ + Location: testLocation, + Identifier: "C", + } + + t.Run("single", func(t *testing.T) { + t.Parallel() + + entitlementType := NewEntitlementType(nil, testLocation, "E") + entitlementType.SetContainerType(containerType) + + access := NewEntitlementSetAccess( + []*EntitlementType{ + entitlementType, + }, + Conjunction, + ) + assert.Equal(t, "C.E", access.QualifiedString()) + }) + + t.Run("two, conjunction", func(t *testing.T) { + t.Parallel() + + entitlementType1 := NewEntitlementType(nil, testLocation, "E1") + entitlementType1.SetContainerType(containerType) + + entitlementType2 := NewEntitlementType(nil, testLocation, "E2") + entitlementType2.SetContainerType(containerType) + + access := NewEntitlementSetAccess( + []*EntitlementType{ + // NOTE: order + entitlementType2, + entitlementType1, + }, + Conjunction, + ) + // NOTE: order + assert.Equal(t, + "C.E2, C.E1", + access.QualifiedString(), + ) + }) + + t.Run("two, disjunction", func(t *testing.T) { + t.Parallel() + + entitlementType1 := NewEntitlementType(nil, testLocation, "E1") + entitlementType1.SetContainerType(containerType) + + entitlementType2 := NewEntitlementType(nil, testLocation, "E2") + entitlementType2.SetContainerType(containerType) + + access := NewEntitlementSetAccess( + []*EntitlementType{ + // NOTE: order + entitlementType2, + entitlementType1, + }, + Disjunction, + ) + // NOTE: order + assert.Equal(t, + "C.E2 | C.E1", + access.QualifiedString(), + ) + }) + + t.Run("three, conjunction", func(t *testing.T) { + t.Parallel() + + entitlementType1 := NewEntitlementType(nil, testLocation, "E1") + entitlementType1.SetContainerType(containerType) + + entitlementType2 := NewEntitlementType(nil, testLocation, "E2") + entitlementType2.SetContainerType(containerType) + + entitlementType3 := NewEntitlementType(nil, testLocation, "E3") + entitlementType3.SetContainerType(containerType) + + access := NewEntitlementSetAccess( + []*EntitlementType{ + // NOTE: order + entitlementType3, + entitlementType2, + entitlementType1, + }, + Conjunction, + ) + // NOTE: order + assert.Equal(t, + "C.E3, C.E2, C.E1", + access.QualifiedString(), + ) + }) + + t.Run("three, disjunction", func(t *testing.T) { + t.Parallel() + + entitlementType1 := NewEntitlementType(nil, testLocation, "E1") + entitlementType1.SetContainerType(containerType) + + entitlementType2 := NewEntitlementType(nil, testLocation, "E2") + entitlementType2.SetContainerType(containerType) + + entitlementType3 := NewEntitlementType(nil, testLocation, "E3") + entitlementType3.SetContainerType(containerType) + + access := NewEntitlementSetAccess( + []*EntitlementType{ + // NOTE: order + entitlementType3, + entitlementType2, + entitlementType1, + }, + Disjunction, + ) + // NOTE: order + assert.Equal(t, + "C.E3 | C.E2 | C.E1", + access.QualifiedString(), + ) + }) +} + +func TestEntitlementMapAccess_QualifiedKeyword(t *testing.T) { + + t.Parallel() + + location := common.NewAddressLocation(nil, common.MustBytesToAddress([]byte{0x1}), "Foo") + + fooType := &CompositeType{ + Location: location, + Identifier: "Foo", + } + + barType := NewEntitlementMapType( + nil, + location, + "Bar", + ) + barType.SetContainerType(fooType) + + assert.Equal(t, + "access(mapping Foo.Bar)", + NewEntitlementMapAccess(barType).QualifiedKeyword(), + ) +} From 782db6c79268b469c215b130ea0fb6943918d840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 28 Oct 2024 17:41:23 -0700 Subject: [PATCH 49/70] refactor test utils --- cmd/info/main.go | 2 +- compiler/compiler_test.go | 2 +- encoding/ccf/ccf_test.go | 138 ++--- encoding/ccf/ccf_type_id_test.go | 6 +- encoding/json/encoding_test.go | 45 +- fuzz.go | 4 +- {tests/fuzz => fuzz}/crashers_test.go | 2 +- interpreter/account_test.go | 3 +- interpreter/arithmetic_test.go | 2 +- interpreter/attachments_test.go | 2 +- interpreter/bitwise_test.go | 2 +- interpreter/builtinfunctions_test.go | 3 +- interpreter/character_test.go | 2 +- interpreter/composite_value_test.go | 3 +- interpreter/condition_test.go | 5 +- interpreter/container_mutation_test.go | 5 +- interpreter/contract_test.go | 2 +- interpreter/conversion_test.go | 2 +- interpreter/deepcopyremove_test.go | 4 +- interpreter/dynamic_casting_test.go | 3 +- interpreter/encoding_test.go | 21 +- interpreter/entitlements_test.go | 2 +- interpreter/enum_test.go | 3 +- interpreter/equality_test.go | 3 +- interpreter/errors_test.go | 6 +- interpreter/fixedpoint_test.go | 3 +- interpreter/for_test.go | 3 +- interpreter/function_test.go | 12 +- interpreter/if_test.go | 5 +- interpreter/import_test.go | 5 +- interpreter/inspect_test.go | 2 +- interpreter/integers_test.go | 4 +- interpreter/interface_test.go | 14 +- interpreter/interpreter_tracing_test.go | 4 +- interpreter/invocation_test.go | 2 +- interpreter/member_test.go | 4 +- interpreter/memory_metering_test.go | 10 +- interpreter/metatype_test.go | 3 +- interpreter/metering_test.go | 20 +- interpreter/misc_test.go | 7 +- interpreter/path_test.go | 2 +- interpreter/range_value_test.go | 8 +- interpreter/reference_test.go | 5 +- interpreter/resources_test.go | 8 +- interpreter/runtimetype_test.go | 30 +- interpreter/statictype_test.go | 74 +-- interpreter/storage_test.go | 3 +- interpreter/string_test.go | 3 +- interpreter/switch_test.go | 5 +- interpreter/transactions_test.go | 5 +- interpreter/transfer_test.go | 2 +- interpreter/uuid_test.go | 5 +- interpreter/value_function_test.go | 7 +- interpreter/value_test.go | 68 +-- interpreter/value_uint64.go | 3 +- interpreter/values_test.go | 65 +-- interpreter/while_test.go | 3 +- old_parser/declaration_test.go | 340 ++++++------ old_parser/expression_test.go | 376 +++++++------- old_parser/lexer/lexer_test.go | 4 +- old_parser/parser_test.go | 26 +- old_parser/statement_test.go | 96 ++-- old_parser/type_test.go | 146 +++--- parser/declaration_test.go | 484 +++++++++--------- parser/expression_test.go | 400 +++++++-------- parser/lexer/lexer_test.go | 4 +- parser/parser_test.go | 26 +- parser/statement_test.go | 112 ++-- parser/type_test.go | 154 +++--- runtime/account_test.go | 12 +- runtime/attachments_test.go | 3 +- runtime/capabilities_test.go | 4 +- runtime/capabilitycontrollers_test.go | 4 +- runtime/contract_test.go | 7 +- runtime/contract_update_test.go | 4 +- runtime/contract_update_validation_test.go | 4 +- runtime/convertTypes_test.go | 10 +- runtime/convertValues_test.go | 5 +- runtime/coverage_test.go | 5 +- runtime/crypto_test.go | 2 +- runtime/debugger_test.go | 2 +- runtime/deployedcontract_test.go | 5 +- runtime/deployment_test.go | 5 +- runtime/entitlements_test.go | 5 +- runtime/error_test.go | 2 +- runtime/ft_test.go | 15 +- runtime/import_test.go | 6 +- .../imported_values_memory_metering_test.go | 6 +- runtime/inbox_test.go | 2 +- runtime/literal_test.go | 4 +- runtime/predeclaredvalues_test.go | 6 +- runtime/program_params_validation_test.go | 6 +- runtime/resource_duplicate_test.go | 4 +- runtime/resourcedictionary_test.go | 17 +- runtime/rlp_test.go | 4 +- runtime/runtime_memory_metering_test.go | 4 +- runtime/runtime_test.go | 6 +- runtime/sharedstate_test.go | 3 +- runtime/storage_test.go | 5 +- runtime/type_test.go | 2 +- runtime/validation_test.go | 4 +- sema/accesses_test.go | 2 +- sema/account_test.go | 6 +- sema/any_test.go | 2 +- sema/arrays_dictionaries_test.go | 2 +- sema/assert_test.go | 2 +- sema/assignment_test.go | 2 +- sema/attachments_test.go | 2 +- sema/boolean_test.go | 2 +- sema/builtinfunctions_test.go | 2 +- sema/capability_controller_test.go | 2 +- sema/capability_test.go | 11 +- sema/casting_test.go | 2 +- sema/character_test.go | 2 +- sema/composite_test.go | 2 +- sema/conditional_test.go | 2 +- sema/conditions_test.go | 2 +- sema/conformance_test.go | 2 +- sema/contract_test.go | 2 +- sema/crypto_test.go | 2 +- sema/declaration_test.go | 2 +- sema/dictionary_test.go | 2 +- sema/dynamic_casting_test.go | 6 +- sema/entitlements_test.go | 2 +- sema/entrypoint_test.go | 2 +- sema/enum_test.go | 2 +- sema/error_handling_test.go | 6 +- sema/events_test.go | 6 +- sema/external_mutation_test.go | 2 +- sema/fixedpoint_test.go | 2 +- sema/for_test.go | 2 +- sema/force_test.go | 2 +- sema/function_expression_test.go | 2 +- sema/function_test.go | 2 +- sema/gen/golden_test.go | 2 +- sema/genericfunction_test.go | 2 +- sema/hashable_struct_test.go | 2 +- sema/if_test.go | 2 +- sema/import_test.go | 22 +- sema/indexing_test.go | 2 +- sema/initialization_test.go | 2 +- sema/integer_test.go | 2 +- sema/interface_test.go | 2 +- sema/intersection_test.go | 2 +- sema/invalid_test.go | 2 +- sema/invocation_test.go | 12 +- sema/member_test.go | 2 +- sema/metatype_test.go | 2 +- sema/move_test.go | 2 +- sema/nesting_test.go | 2 +- sema/never_test.go | 2 +- sema/nil_coalescing_test.go | 2 +- sema/occurrences_test.go | 2 +- sema/operations_test.go | 2 +- sema/optional_test.go | 2 +- sema/overloading_test.go | 2 +- sema/path_test.go | 2 +- sema/pragma_test.go | 2 +- sema/predeclaredvalues_test.go | 2 +- sema/purity_test.go | 2 +- sema/range_test.go | 6 +- sema/range_value_test.go | 2 +- sema/reference_test.go | 10 +- sema/resource_test.go | 5 +- sema/return_test.go | 2 +- sema/rlp_test.go | 2 +- sema/runtimetype_test.go | 2 +- sema/storable_test.go | 2 +- sema/string_test.go | 2 +- sema/swap_test.go | 2 +- sema/switch_test.go | 2 +- sema/transactions_test.go | 2 +- sema/type_inference_test.go | 2 +- sema/typeargument_test.go | 2 +- sema/utils_test.go | 2 +- sema/while_test.go | 2 +- stdlib/account_test.go | 4 +- stdlib/builtin_test.go | 17 +- ..._to_v1_contract_upgrade_validation_test.go | 40 +- stdlib/rlp/rlp_test.go | 2 +- stdlib/test_test.go | 6 +- test_utils/common_utils/utils.go | 112 ++++ .../interpreter_utils}/interpreter.go | 6 +- .../interpreter_utils/values.go | 155 +----- .../runtime_utils/location.go | 0 .../runtime_utils/testinterface.go | 0 .../runtime_utils/testledger.go | 0 .../runtime_utils/testruntime.go | 0 test_utils/runtime_utils/transactions.go | 68 +++ {tests => test_utils}/sema_utils/utils.go | 9 +- tools/analysis/analysis_test.go | 2 +- .../compatibility-check/contracts_checker.go | 3 +- types_test.go | 24 +- values_test.go | 16 +- 194 files changed, 1874 insertions(+), 1817 deletions(-) rename {tests/fuzz => fuzz}/crashers_test.go (96%) create mode 100644 test_utils/common_utils/utils.go rename {tests/runtime_utils => test_utils/interpreter_utils}/interpreter.go (92%) rename tests/utils/utils.go => test_utils/interpreter_utils/values.go (56%) rename {tests => test_utils}/runtime_utils/location.go (100%) rename {tests => test_utils}/runtime_utils/testinterface.go (100%) rename {tests => test_utils}/runtime_utils/testledger.go (100%) rename {tests => test_utils}/runtime_utils/testruntime.go (100%) create mode 100644 test_utils/runtime_utils/transactions.go rename {tests => test_utils}/sema_utils/utils.go (97%) diff --git a/cmd/info/main.go b/cmd/info/main.go index 62a91f8a6c..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/sema_utils" + "github.com/onflow/cadence/test_utils/sema_utils" ) type command struct { diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go index 60c96154aa..b9a0e2d866 100644 --- a/compiler/compiler_test.go +++ b/compiler/compiler_test.go @@ -24,7 +24,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/compiler/ir" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCompilerSimple(t *testing.T) { diff --git a/encoding/ccf/ccf_test.go b/encoding/ccf/ccf_test.go index 3332bbb065..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/runtime_utils" - . "github.com/onflow/cadence/tests/sema_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{ { @@ -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 308c8e0e7c..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/sema_utils" - - "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 { @@ -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/interpreter/account_test.go b/interpreter/account_test.go index 9ef518efb9..a003477a56 100644 --- a/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/interpreter/arithmetic_test.go b/interpreter/arithmetic_test.go index 4c56b41345..86d966ac92 100644 --- a/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/interpreter/attachments_test.go b/interpreter/attachments_test.go index 3c61208033..384ee9f647 100644 --- a/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/interpreter/bitwise_test.go b/interpreter/bitwise_test.go index b0e9e9cd74..a288e7e667 100644 --- a/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/interpreter/builtinfunctions_test.go b/interpreter/builtinfunctions_test.go index b527af6900..93402c80e5 100644 --- a/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/interpreter/character_test.go b/interpreter/character_test.go index 298fb1c604..b079563f09 100644 --- a/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/interpreter/composite_value_test.go b/interpreter/composite_value_test.go index cacf0c145d..de85e30b22 100644 --- a/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/interpreter/condition_test.go b/interpreter/condition_test.go index 74d1deabc9..ef1df7b638 100644 --- a/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/sema_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/sema_utils" ) func TestInterpretFunctionPreTestCondition(t *testing.T) { diff --git a/interpreter/container_mutation_test.go b/interpreter/container_mutation_test.go index 10a37e6a30..5f67eab2b1 100644 --- a/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/interpreter/contract_test.go b/interpreter/contract_test.go index e4f9e8b30f..6d437fdec1 100644 --- a/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/interpreter/deepcopyremove_test.go b/interpreter/deepcopyremove_test.go index de16e42445..0f12a4b034 100644 --- a/interpreter/deepcopyremove_test.go +++ b/interpreter/deepcopyremove_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 TestValueDeepCopyAndDeepRemove(t *testing.T) { @@ -40,7 +40,7 @@ func TestValueDeepCopyAndDeepRemove(t *testing.T) { inter, err := interpreter.NewInterpreter( nil, - utils.TestLocation, + TestLocation, &interpreter.Config{ Storage: storage, }, diff --git a/interpreter/dynamic_casting_test.go b/interpreter/dynamic_casting_test.go index 03b532b119..255a7b719e 100644 --- a/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/interpreter/entitlements_test.go b/interpreter/entitlements_test.go index 0475ec1191..79d368de70 100644 --- a/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/interpreter/enum_test.go b/interpreter/enum_test.go index 54e563c784..fa3e9a0c05 100644 --- a/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/interpreter/equality_test.go b/interpreter/equality_test.go index dee8dc54c9..68cfd10f04 100644 --- a/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/interpreter/fixedpoint_test.go b/interpreter/fixedpoint_test.go index 0fe9d9258b..fa19591104 100644 --- a/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/interpreter/for_test.go b/interpreter/for_test.go index 370546ffdf..48246d29b0 100644 --- a/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/interpreter/function_test.go b/interpreter/function_test.go index e4e293fa9c..b16b77c642 100644 --- a/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/sema_utils" - "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), @@ -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/interpreter/if_test.go b/interpreter/if_test.go index 4242062e39..ef92e2a576 100644 --- a/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/sema_utils" - . "github.com/onflow/cadence/tests/utils" - "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/interpreter_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestInterpretIfStatement(t *testing.T) { diff --git a/interpreter/import_test.go b/interpreter/import_test.go index a5a2e808b7..b1599e2a09 100644 --- a/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/sema_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/sema_utils" ) func TestInterpretVirtualImport(t *testing.T) { 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/interpreter/integers_test.go b/interpreter/integers_test.go index 9da93b1745..86f1eb4f22 100644 --- a/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/interpreter/interface_test.go b/interpreter/interface_test.go index b61c422ba5..09580c8171 100644 --- a/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_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/interpreter/invocation_test.go b/interpreter/invocation_test.go index 4e9164f36f..1d08c47f14 100644 --- a/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/interpreter/member_test.go b/interpreter/member_test.go index a7dd3c454a..f73b4e8be6 100644 --- a/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/sema_utils" - . "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) { diff --git a/interpreter/memory_metering_test.go b/interpreter/memory_metering_test.go index 56fae49cb0..725ea93037 100644 --- a/interpreter/memory_metering_test.go +++ b/interpreter/memory_metering_test.go @@ -23,7 +23,7 @@ import ( "testing" "github.com/onflow/cadence/activations" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -33,7 +33,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 assumeValidPublicKeyValidator struct{} @@ -8152,7 +8152,7 @@ func TestInterpretASTMetering(t *testing.T) { let Foo = 1 `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) require.NoError(t, err) @@ -8450,7 +8450,7 @@ func TestInterpretASTMetering(t *testing.T) { let B = 1 `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + 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/interpreter/metatype_test.go b/interpreter/metatype_test.go index ad96c6b1d9..edcd83a901 100644 --- a/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/interpreter/metering_test.go b/interpreter/metering_test.go index a7ea9882d0..267b15d985 100644 --- a/interpreter/metering_test.go +++ b/interpreter/metering_test.go @@ -28,8 +28,8 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" - "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) { @@ -44,7 +44,7 @@ func TestInterpretStatementHandler(t *testing.T) { } `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) require.NoError(t, err) @@ -73,7 +73,7 @@ func TestInterpretStatementHandler(t *testing.T) { 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, ) @@ -197,7 +197,7 @@ func TestInterpretLoopIterationHandler(t *testing.T) { 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, ) @@ -303,7 +303,7 @@ func TestInterpretFunctionInvocationHandler(t *testing.T) { } `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) require.NoError(t, err) @@ -332,7 +332,7 @@ func TestInterpretFunctionInvocationHandler(t *testing.T) { 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/interpreter/misc_test.go b/interpreter/misc_test.go index d3c3138580..9c8e7c8886 100644 --- a/interpreter/misc_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/sema_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/sema_utils" ) type ParseCheckAndInterpretOptions struct { @@ -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, diff --git a/interpreter/path_test.go b/interpreter/path_test.go index 015ef66643..10ff7f32f9 100644 --- a/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/interpreter/range_value_test.go b/interpreter/range_value_test.go index ba3b714129..eb88cb4b50 100644 --- a/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/interpreter/reference_test.go b/interpreter/reference_test.go index 7af848436c..273f49d74d 100644 --- a/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/sema_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/sema_utils" ) func TestInterpretResourceReferenceInstanceOf(t *testing.T) { diff --git a/interpreter/resources_test.go b/interpreter/resources_test.go index fd639a5739..564c745258 100644 --- a/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/sema_utils" - . "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) { diff --git a/interpreter/runtimetype_test.go b/interpreter/runtimetype_test.go index c1ea4ea109..526d28856d 100644 --- a/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/interpreter/string_test.go b/interpreter/string_test.go index 410d2f478c..580608e26e 100644 --- a/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/switch_test.go b/interpreter/switch_test.go index 0cbe894063..2a30c6cbdb 100644 --- a/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/sema_utils" - . "github.com/onflow/cadence/tests/utils" - "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" + . "github.com/onflow/cadence/test_utils/interpreter_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestInterpretSwitchStatement(t *testing.T) { diff --git a/interpreter/transactions_test.go b/interpreter/transactions_test.go index 8a4167a0b1..21a1642f99 100644 --- a/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/sema_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/sema_utils" ) func TestInterpretTransactions(t *testing.T) { diff --git a/interpreter/transfer_test.go b/interpreter/transfer_test.go index c40a4f0ee3..72447e2dd9 100644 --- a/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/interpreter/uuid_test.go b/interpreter/uuid_test.go index aa4154ff19..efdc8d1010 100644 --- a/interpreter/uuid_test.go +++ b/interpreter/uuid_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/sema_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/sema_utils" ) func TestInterpretResourceUUID(t *testing.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 8f4df2bcc1..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" - . "github.com/onflow/cadence/tests/sema_utils" - "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, @@ -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, @@ -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/interpreter/values_test.go b/interpreter/values_test.go index e725b5a30c..b874aa4213 100644 --- a/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/interpreter/while_test.go b/interpreter/while_test.go index 10bcf69db6..c341dfdf57 100644 --- a/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/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_test.go b/parser/expression_test.go index 7acb0ac4eb..28e92f6404 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,7 @@ func TestParseStringWithUnicode(t *testing.T) { }, } - utils.AssertEqualWithDiff(t, expected, actual) + AssertEqualWithDiff(t, expected, actual) } func TestParseNilCoalescing(t *testing.T) { @@ -6052,7 +6052,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 +6098,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 +6201,7 @@ func TestParseFailableCasting(t *testing.T) { failableDowncast.ParentVariableDeclaration = variableDeclaration - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ variableDeclaration, }, @@ -6219,7 +6219,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 +6277,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 +6386,7 @@ func TestParseFailableCastingResourceTypeAnnotation(t *testing.T) { failableDowncast.ParentVariableDeclaration = variableDeclaration - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ variableDeclaration, }, @@ -6440,7 +6440,7 @@ func TestParseCasting(t *testing.T) { cast.ParentVariableDeclaration = variableDeclaration - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ variableDeclaration, }, @@ -6484,7 +6484,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 +6573,7 @@ func TestParseReferenceInVariableDeclaration(t *testing.T) { expected.Value.(*ast.CastingExpression).ParentVariableDeclaration = expected - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []ast.Declaration{ expected, }, @@ -6591,7 +6591,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 +6631,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 +6671,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 +6711,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_test.go b/parser/lexer/lexer_test.go index d6562fdebd..c529b750ce 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 { 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/account_test.go b/runtime/account_test.go index 371cbba4cb..0d65fa3ecd 100644 --- a/runtime/account_test.go +++ b/runtime/account_test.go @@ -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/runtime_utils" - . "github.com/onflow/cadence/tests/sema_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, ) diff --git a/runtime/attachments_test.go b/runtime/attachments_test.go index e03c72dc22..4d3d400d1b 100644 --- a/runtime/attachments_test.go +++ b/runtime/attachments_test.go @@ -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/runtime/capabilities_test.go b/runtime/capabilities_test.go index ade86c8d24..3e76980213 100644 --- a/runtime/capabilities_test.go +++ b/runtime/capabilities_test.go @@ -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/runtime/capabilitycontrollers_test.go b/runtime/capabilitycontrollers_test.go index fbb0d924cc..fc6f692fe4 100644 --- a/runtime/capabilitycontrollers_test.go +++ b/runtime/capabilitycontrollers_test.go @@ -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/contract_test.go b/runtime/contract_test.go index 6cd2b4caaa..2bb89a2cb5 100644 --- a/runtime/contract_test.go +++ b/runtime/contract_test.go @@ -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/runtime_utils" - . "github.com/onflow/cadence/tests/sema_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) { diff --git a/runtime/contract_update_test.go b/runtime/contract_update_test.go index c032eb7124..48a0ec8e48 100644 --- a/runtime/contract_update_test.go +++ b/runtime/contract_update_test.go @@ -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/runtime/contract_update_validation_test.go b/runtime/contract_update_validation_test.go index f4e77b8c85..74afc1c447 100644 --- a/runtime/contract_update_validation_test.go +++ b/runtime/contract_update_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 newContractDeployTransaction(function, name, code string) string { diff --git a/runtime/convertTypes_test.go b/runtime/convertTypes_test.go index fea1f8a697..3e50371edd 100644 --- a/runtime/convertTypes_test.go +++ b/runtime/convertTypes_test.go @@ -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/runtime/convertValues_test.go b/runtime/convertValues_test.go index bebbf750ca..f6cf51fcb2 100644 --- a/runtime/convertValues_test.go +++ b/runtime/convertValues_test.go @@ -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) { diff --git a/runtime/coverage_test.go b/runtime/coverage_test.go index 2c244b4c4d..5f5f746113 100644 --- a/runtime/coverage_test.go +++ b/runtime/coverage_test.go @@ -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/runtime/crypto_test.go b/runtime/crypto_test.go index 71da0b283a..fcce37cf8b 100644 --- a/runtime/crypto_test.go +++ b/runtime/crypto_test.go @@ -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/runtime/debugger_test.go b/runtime/debugger_test.go index 7d5d5f8907..b9d060775e 100644 --- a/runtime/debugger_test.go +++ b/runtime/debugger_test.go @@ -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/runtime/deployedcontract_test.go b/runtime/deployedcontract_test.go index b73b16f71d..bae773da2e 100644 --- a/runtime/deployedcontract_test.go +++ b/runtime/deployedcontract_test.go @@ -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/runtime/deployment_test.go b/runtime/deployment_test.go index 6b6cbe83bd..4d1ab95280 100644 --- a/runtime/deployment_test.go +++ b/runtime/deployment_test.go @@ -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/entitlements_test.go b/runtime/entitlements_test.go index d241cb6c4d..428e56615d 100644 --- a/runtime/entitlements_test.go +++ b/runtime/entitlements_test.go @@ -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/runtime_utils" - . "github.com/onflow/cadence/tests/sema_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) { diff --git a/runtime/error_test.go b/runtime/error_test.go index a27aecbcf2..4d74c390c1 100644 --- a/runtime/error_test.go +++ b/runtime/error_test.go @@ -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/runtime/ft_test.go b/runtime/ft_test.go index 5d7d78b5e6..b9374d986e 100644 --- a/runtime/ft_test.go +++ b/runtime/ft_test.go @@ -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/runtime/import_test.go b/runtime/import_test.go index 295353b5f6..cbc92d7401 100644 --- a/runtime/import_test.go +++ b/runtime/import_test.go @@ -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/runtime_utils" - . "github.com/onflow/cadence/tests/sema_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) { diff --git a/runtime/imported_values_memory_metering_test.go b/runtime/imported_values_memory_metering_test.go index c3e7a882a8..d7620f27e9 100644 --- a/runtime/imported_values_memory_metering_test.go +++ b/runtime/imported_values_memory_metering_test.go @@ -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/runtime/inbox_test.go b/runtime/inbox_test.go index 00380e23e4..7017e4a5d9 100644 --- a/runtime/inbox_test.go +++ b/runtime/inbox_test.go @@ -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/literal_test.go b/runtime/literal_test.go index e35033b250..6109662007 100644 --- a/runtime/literal_test.go +++ b/runtime/literal_test.go @@ -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/runtime/predeclaredvalues_test.go b/runtime/predeclaredvalues_test.go index c60d3efb5b..9b916a3c0f 100644 --- a/runtime/predeclaredvalues_test.go +++ b/runtime/predeclaredvalues_test.go @@ -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/runtime_utils" - . "github.com/onflow/cadence/tests/sema_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) { diff --git a/runtime/program_params_validation_test.go b/runtime/program_params_validation_test.go index 2e1a7f3ec1..5cc5485f9d 100644 --- a/runtime/program_params_validation_test.go +++ b/runtime/program_params_validation_test.go @@ -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/runtime_utils" - . "github.com/onflow/cadence/tests/sema_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) { diff --git a/runtime/resource_duplicate_test.go b/runtime/resource_duplicate_test.go index 5f5f12c666..9304dfb07a 100644 --- a/runtime/resource_duplicate_test.go +++ b/runtime/resource_duplicate_test.go @@ -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/runtime/resourcedictionary_test.go b/runtime/resourcedictionary_test.go index 088d4e977f..a1a5100423 100644 --- a/runtime/resourcedictionary_test.go +++ b/runtime/resourcedictionary_test.go @@ -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/runtime/rlp_test.go b/runtime/rlp_test.go index 17582dceee..93cfaa1ed6 100644 --- a/runtime/rlp_test.go +++ b/runtime/rlp_test.go @@ -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/runtime/runtime_memory_metering_test.go b/runtime/runtime_memory_metering_test.go index f7e91fd7bf..d6d389ff73 100644 --- a/runtime/runtime_memory_metering_test.go +++ b/runtime/runtime_memory_metering_test.go @@ -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/runtime/runtime_test.go b/runtime/runtime_test.go index 07e76ce395..91b7bcdc86 100644 --- a/runtime/runtime_test.go +++ b/runtime/runtime_test.go @@ -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/runtime_utils" - . "github.com/onflow/cadence/tests/sema_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) { diff --git a/runtime/sharedstate_test.go b/runtime/sharedstate_test.go index 660c439b1c..3008c85fff 100644 --- a/runtime/sharedstate_test.go +++ b/runtime/sharedstate_test.go @@ -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/runtime/storage_test.go b/runtime/storage_test.go index b82b77a2cb..5a7bb60bc9 100644 --- a/runtime/storage_test.go +++ b/runtime/storage_test.go @@ -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/runtime/type_test.go b/runtime/type_test.go index 2ae870e408..c96a705675 100644 --- a/runtime/type_test.go +++ b/runtime/type_test.go @@ -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/runtime/validation_test.go b/runtime/validation_test.go index 980654b941..db212f8547 100644 --- a/runtime/validation_test.go +++ b/runtime/validation_test.go @@ -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/sema/accesses_test.go b/sema/accesses_test.go index eaa4dc16a9..976e30811e 100644 --- a/sema/accesses_test.go +++ b/sema/accesses_test.go @@ -28,7 +28,7 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func expectSuccess(t *testing.T, err error) { diff --git a/sema/account_test.go b/sema/account_test.go index e993ed7303..6084a5042b 100644 --- a/sema/account_test.go +++ b/sema/account_test.go @@ -27,8 +27,8 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" - "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) { @@ -888,7 +888,7 @@ func TestCheckAccountStorageBorrow(t *testing.T) { sema.NewEntitlementSetAccess( []*sema.EntitlementType{ { - Location: utils.TestLocation, + Location: TestLocation, Identifier: "X", }, }, diff --git a/sema/any_test.go b/sema/any_test.go index 6e35846d12..c9c0c76222 100644 --- a/sema/any_test.go +++ b/sema/any_test.go @@ -24,7 +24,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckAnyStruct(t *testing.T) { diff --git a/sema/arrays_dictionaries_test.go b/sema/arrays_dictionaries_test.go index 20a306fe04..6e5a512d05 100644 --- a/sema/arrays_dictionaries_test.go +++ b/sema/arrays_dictionaries_test.go @@ -30,7 +30,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckDictionary(t *testing.T) { diff --git a/sema/assert_test.go b/sema/assert_test.go index 2912bf380b..0c19bdc57e 100644 --- a/sema/assert_test.go +++ b/sema/assert_test.go @@ -26,7 +26,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckAssertWithoutMessage(t *testing.T) { diff --git a/sema/assignment_test.go b/sema/assignment_test.go index 3d415c16ee..96494ccde0 100644 --- a/sema/assignment_test.go +++ b/sema/assignment_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidUnknownDeclarationAssignment(t *testing.T) { diff --git a/sema/attachments_test.go b/sema/attachments_test.go index c1609e8e0b..d7d5e62447 100644 --- a/sema/attachments_test.go +++ b/sema/attachments_test.go @@ -26,7 +26,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckAttachmentBasic(t *testing.T) { diff --git a/sema/boolean_test.go b/sema/boolean_test.go index 6d4e0cde0d..7c6202a5c2 100644 --- a/sema/boolean_test.go +++ b/sema/boolean_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckBoolean(t *testing.T) { diff --git a/sema/builtinfunctions_test.go b/sema/builtinfunctions_test.go index 41a956d1d1..07ca190593 100644 --- a/sema/builtinfunctions_test.go +++ b/sema/builtinfunctions_test.go @@ -28,7 +28,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckToString(t *testing.T) { diff --git a/sema/capability_controller_test.go b/sema/capability_controller_test.go index d2ab30eda3..994f600999 100644 --- a/sema/capability_controller_test.go +++ b/sema/capability_controller_test.go @@ -26,7 +26,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckStorageCapabilityController(t *testing.T) { diff --git a/sema/capability_test.go b/sema/capability_test.go index 155442dc12..cb430f7b82 100644 --- a/sema/capability_test.go +++ b/sema/capability_test.go @@ -22,13 +22,12 @@ 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/tests/sema_utils" + "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) { @@ -94,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), } { @@ -321,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/sema/casting_test.go b/sema/casting_test.go index e107a4615b..b77dbdc466 100644 --- a/sema/casting_test.go +++ b/sema/casting_test.go @@ -26,7 +26,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckCastingIntLiteralToIntegerType(t *testing.T) { diff --git a/sema/character_test.go b/sema/character_test.go index 318b101dbc..7b7c664e95 100644 --- a/sema/character_test.go +++ b/sema/character_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckCharacterLiteral(t *testing.T) { diff --git a/sema/composite_test.go b/sema/composite_test.go index 6598505d98..dc6c8dc927 100644 --- a/sema/composite_test.go +++ b/sema/composite_test.go @@ -29,7 +29,7 @@ import ( "github.com/onflow/cadence/errors" "github.com/onflow/cadence/parser" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidCompositeRedeclaringType(t *testing.T) { diff --git a/sema/conditional_test.go b/sema/conditional_test.go index 98ec1a75a7..c4db51acd5 100644 --- a/sema/conditional_test.go +++ b/sema/conditional_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckConditionalExpressionTest(t *testing.T) { diff --git a/sema/conditions_test.go b/sema/conditions_test.go index d845c52c1d..afcc7762fc 100644 --- a/sema/conditions_test.go +++ b/sema/conditions_test.go @@ -26,7 +26,7 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckFunctionTestConditions(t *testing.T) { diff --git a/sema/conformance_test.go b/sema/conformance_test.go index 6109516c58..d2f873cab5 100644 --- a/sema/conformance_test.go +++ b/sema/conformance_test.go @@ -27,7 +27,7 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/errors" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckEventNonTypeRequirementConformance(t *testing.T) { diff --git a/sema/contract_test.go b/sema/contract_test.go index 2de30e7d68..e21b6d7873 100644 --- a/sema/contract_test.go +++ b/sema/contract_test.go @@ -27,7 +27,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidContractAccountField(t *testing.T) { diff --git a/sema/crypto_test.go b/sema/crypto_test.go index 91397e95ea..e6f751395d 100644 --- a/sema/crypto_test.go +++ b/sema/crypto_test.go @@ -27,7 +27,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckHashAlgorithmCases(t *testing.T) { diff --git a/sema/declaration_test.go b/sema/declaration_test.go index 738c4c6d34..139ae9e332 100644 --- a/sema/declaration_test.go +++ b/sema/declaration_test.go @@ -27,7 +27,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckConstantAndVariableDeclarations(t *testing.T) { diff --git a/sema/dictionary_test.go b/sema/dictionary_test.go index 900c53860e..edd9dd83cb 100644 --- a/sema/dictionary_test.go +++ b/sema/dictionary_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckIncompleteDictionaryType(t *testing.T) { diff --git a/sema/dynamic_casting_test.go b/sema/dynamic_casting_test.go index 15861bc8e7..da02975b35 100644 --- a/sema/dynamic_casting_test.go +++ b/sema/dynamic_casting_test.go @@ -28,8 +28,8 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" - "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{ @@ -1207,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/sema/entitlements_test.go b/sema/entitlements_test.go index caa5dd36e4..3b47df81b3 100644 --- a/sema/entitlements_test.go +++ b/sema/entitlements_test.go @@ -27,7 +27,7 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckBasicEntitlementDeclaration(t *testing.T) { diff --git a/sema/entrypoint_test.go b/sema/entrypoint_test.go index ac76190b26..e3bc9ab1a1 100644 --- a/sema/entrypoint_test.go +++ b/sema/entrypoint_test.go @@ -24,7 +24,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckEntryPointParameters(t *testing.T) { diff --git a/sema/enum_test.go b/sema/enum_test.go index 2fc3233336..96d092297c 100644 --- a/sema/enum_test.go +++ b/sema/enum_test.go @@ -27,7 +27,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidNonEnumCompositeEnumCases(t *testing.T) { diff --git a/sema/error_handling_test.go b/sema/error_handling_test.go index cc84b43316..a7cb4923c2 100644 --- a/sema/error_handling_test.go +++ b/sema/error_handling_test.go @@ -27,8 +27,8 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" - "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) { @@ -82,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/events_test.go b/sema/events_test.go index d1c588392f..e3d6cdbbea 100644 --- a/sema/events_test.go +++ b/sema/events_test.go @@ -29,8 +29,8 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/errors" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" - "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckEventDeclaration(t *testing.T) { @@ -295,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/sema/external_mutation_test.go b/sema/external_mutation_test.go index 3eabd29a5a..96936fa073 100644 --- a/sema/external_mutation_test.go +++ b/sema/external_mutation_test.go @@ -28,7 +28,7 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckArrayUpdateIndexAccess(t *testing.T) { diff --git a/sema/fixedpoint_test.go b/sema/fixedpoint_test.go index a1f0eb15e5..bb537432b8 100644 --- a/sema/fixedpoint_test.go +++ b/sema/fixedpoint_test.go @@ -29,7 +29,7 @@ import ( "github.com/onflow/cadence/format" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckFixedPointLiteralTypeConversionInVariableDeclaration(t *testing.T) { diff --git a/sema/for_test.go b/sema/for_test.go index 8e2f68dcb8..7a92fc90a8 100644 --- a/sema/for_test.go +++ b/sema/for_test.go @@ -28,7 +28,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckForVariableSized(t *testing.T) { diff --git a/sema/force_test.go b/sema/force_test.go index c3d0f41f5c..63b93013d8 100644 --- a/sema/force_test.go +++ b/sema/force_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckForce(t *testing.T) { diff --git a/sema/function_expression_test.go b/sema/function_expression_test.go index 5bb0467941..3ba5f2e6b4 100644 --- a/sema/function_expression_test.go +++ b/sema/function_expression_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidFunctionExpressionReturnValue(t *testing.T) { diff --git a/sema/function_test.go b/sema/function_test.go index 334f1ee2c7..1f823f9a23 100644 --- a/sema/function_test.go +++ b/sema/function_test.go @@ -28,7 +28,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/parser" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "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 0053427d45..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/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestConstructor(t *testing.T) { diff --git a/sema/genericfunction_test.go b/sema/genericfunction_test.go index 6b3e443db1..f88e9ac00a 100644 --- a/sema/genericfunction_test.go +++ b/sema/genericfunction_test.go @@ -30,7 +30,7 @@ import ( "github.com/onflow/cadence/parser" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func parseAndCheckWithTestValue(t *testing.T, code string, ty sema.Type) (*sema.Checker, error) { diff --git a/sema/hashable_struct_test.go b/sema/hashable_struct_test.go index 51f432bf25..82875b9f95 100644 --- a/sema/hashable_struct_test.go +++ b/sema/hashable_struct_test.go @@ -24,7 +24,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckHashableStruct(t *testing.T) { diff --git a/sema/if_test.go b/sema/if_test.go index 0674d66d97..6fd1e517c7 100644 --- a/sema/if_test.go +++ b/sema/if_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckIfStatementTest(t *testing.T) { diff --git a/sema/import_test.go b/sema/import_test.go index 9e92714fa9..c5bf92d36e 100644 --- a/sema/import_test.go +++ b/sema/import_test.go @@ -30,8 +30,8 @@ import ( "github.com/onflow/cadence/errors" "github.com/onflow/cadence/parser" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" - "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) { @@ -57,7 +57,7 @@ func TestCheckRepeatedImport(t *testing.T) { access(all) let y = 2 `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) require.NoError(t, err) @@ -170,7 +170,7 @@ func TestCheckInvalidRepeatedImport(t *testing.T) { access(all) let x = 1 `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) @@ -288,7 +288,7 @@ func TestCheckImportAll(t *testing.T) { } `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) @@ -323,7 +323,7 @@ func TestCheckInvalidImportUnexported(t *testing.T) { access(all) let x = 1 `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) @@ -364,7 +364,7 @@ func TestCheckImportSome(t *testing.T) { access(all) let x = 1 `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) @@ -447,7 +447,7 @@ func TestCheckImportTypes(t *testing.T) { body, ), ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) @@ -553,7 +553,7 @@ func TestCheckInvalidImportCycleSelf(t *testing.T) { return err } - err = check(code, utils.TestLocation) + err = check(code, TestLocation) errs := RequireCheckerErrors(t, err, 1) @@ -740,7 +740,7 @@ func TestCheckImportContract(t *testing.T) { } }`, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) @@ -788,7 +788,7 @@ func TestCheckImportContract(t *testing.T) { } }`, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) diff --git a/sema/indexing_test.go b/sema/indexing_test.go index 5eabac65ff..1979e67610 100644 --- a/sema/indexing_test.go +++ b/sema/indexing_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckArrayIndexingWithInteger(t *testing.T) { diff --git a/sema/initialization_test.go b/sema/initialization_test.go index 832bb2724e..a4656a2e3c 100644 --- a/sema/initialization_test.go +++ b/sema/initialization_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) // TODO: test multiple initializers once overloading is supported diff --git a/sema/integer_test.go b/sema/integer_test.go index 1fdcf5963f..5f53f7b0ed 100644 --- a/sema/integer_test.go +++ b/sema/integer_test.go @@ -28,7 +28,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) var allIntegerTypesAndAddressType = common.Concat( diff --git a/sema/interface_test.go b/sema/interface_test.go index b43b4f7573..48fc511f4a 100644 --- a/sema/interface_test.go +++ b/sema/interface_test.go @@ -28,7 +28,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/errors" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func constructorArguments(compositeKind common.CompositeKind) string { diff --git a/sema/intersection_test.go b/sema/intersection_test.go index 763d16f1b4..e0965d843a 100644 --- a/sema/intersection_test.go +++ b/sema/intersection_test.go @@ -26,7 +26,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckIntersectionType(t *testing.T) { diff --git a/sema/invalid_test.go b/sema/invalid_test.go index 87e85d7a28..51ea254984 100644 --- a/sema/invalid_test.go +++ b/sema/invalid_test.go @@ -24,7 +24,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckSpuriousIdentifierAssignmentInvalidValueTypeMismatch(t *testing.T) { diff --git a/sema/invocation_test.go b/sema/invocation_test.go index 11abdd4073..1d0543b2cb 100644 --- a/sema/invocation_test.go +++ b/sema/invocation_test.go @@ -28,8 +28,8 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/sema_utils" - "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) { @@ -375,7 +375,7 @@ func TestCheckArgumentLabels(t *testing.T) { fun test(foo bar: Int, baz: String) {} `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) @@ -436,7 +436,7 @@ func TestCheckArgumentLabels(t *testing.T) { } `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) @@ -497,7 +497,7 @@ func TestCheckArgumentLabels(t *testing.T) { } `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) @@ -562,7 +562,7 @@ func TestCheckArgumentLabels(t *testing.T) { } `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) diff --git a/sema/member_test.go b/sema/member_test.go index 94fd50858b..9d8706dbbe 100644 --- a/sema/member_test.go +++ b/sema/member_test.go @@ -27,7 +27,7 @@ import ( "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckOptionalChainingNonOptionalFieldRead(t *testing.T) { diff --git a/sema/metatype_test.go b/sema/metatype_test.go index fcf185510f..3f5455b0a0 100644 --- a/sema/metatype_test.go +++ b/sema/metatype_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckMetaType(t *testing.T) { diff --git a/sema/move_test.go b/sema/move_test.go index 0791f6f744..d772f2f293 100644 --- a/sema/move_test.go +++ b/sema/move_test.go @@ -24,7 +24,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidMoves(t *testing.T) { diff --git a/sema/nesting_test.go b/sema/nesting_test.go index 184e566224..cd0cd659cf 100644 --- a/sema/nesting_test.go +++ b/sema/nesting_test.go @@ -29,7 +29,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckCompositeDeclarationNesting(t *testing.T) { diff --git a/sema/never_test.go b/sema/never_test.go index 5195786007..ee3ba85b1c 100644 --- a/sema/never_test.go +++ b/sema/never_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckNever(t *testing.T) { diff --git a/sema/nil_coalescing_test.go b/sema/nil_coalescing_test.go index 0f7c0364fd..2e6d505cfb 100644 --- a/sema/nil_coalescing_test.go +++ b/sema/nil_coalescing_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckNilCoalescingNilIntToOptional(t *testing.T) { diff --git a/sema/occurrences_test.go b/sema/occurrences_test.go index a1854e5cef..cb4454e170 100644 --- a/sema/occurrences_test.go +++ b/sema/occurrences_test.go @@ -26,7 +26,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) // TODO: implement occurrences for type references diff --git a/sema/operations_test.go b/sema/operations_test.go index c5f460bc28..319e3ee5f3 100644 --- a/sema/operations_test.go +++ b/sema/operations_test.go @@ -30,7 +30,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidUnaryBooleanNegationOfInteger(t *testing.T) { diff --git a/sema/optional_test.go b/sema/optional_test.go index ea92b679e3..98e797855e 100644 --- a/sema/optional_test.go +++ b/sema/optional_test.go @@ -27,7 +27,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckOptional(t *testing.T) { diff --git a/sema/overloading_test.go b/sema/overloading_test.go index 77cdea966b..dfe464e1b9 100644 --- a/sema/overloading_test.go +++ b/sema/overloading_test.go @@ -26,7 +26,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidCompositeInitializerOverloading(t *testing.T) { diff --git a/sema/path_test.go b/sema/path_test.go index 0b3fcd1215..5aceafd85e 100644 --- a/sema/path_test.go +++ b/sema/path_test.go @@ -27,7 +27,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckPath(t *testing.T) { diff --git a/sema/pragma_test.go b/sema/pragma_test.go index 1795e86df7..1ee6e070bb 100644 --- a/sema/pragma_test.go +++ b/sema/pragma_test.go @@ -26,7 +26,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckPragmaExpression(t *testing.T) { diff --git a/sema/predeclaredvalues_test.go b/sema/predeclaredvalues_test.go index b402b49c80..046ea7435a 100644 --- a/sema/predeclaredvalues_test.go +++ b/sema/predeclaredvalues_test.go @@ -26,7 +26,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckPredeclaredValues(t *testing.T) { diff --git a/sema/purity_test.go b/sema/purity_test.go index 2df908b4cd..76a79255d9 100644 --- a/sema/purity_test.go +++ b/sema/purity_test.go @@ -26,7 +26,7 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckPuritySubtyping(t *testing.T) { diff --git a/sema/range_test.go b/sema/range_test.go index 752cb93f64..94919757fd 100644 --- a/sema/range_test.go +++ b/sema/range_test.go @@ -27,8 +27,8 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" - "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) { @@ -96,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/sema/range_value_test.go b/sema/range_value_test.go index 1598aee163..12929896b5 100644 --- a/sema/range_value_test.go +++ b/sema/range_value_test.go @@ -28,7 +28,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) type inclusiveRangeConstructionTest struct { diff --git a/sema/reference_test.go b/sema/reference_test.go index b05629424f..0914180f30 100644 --- a/sema/reference_test.go +++ b/sema/reference_test.go @@ -28,8 +28,8 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" - "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) { @@ -1067,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) } @@ -1089,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), } { @@ -1930,7 +1930,7 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { } `, ParseAndCheckOptions{ - Location: utils.ImportedLocation, + Location: ImportedLocation, }, ) diff --git a/sema/resource_test.go b/sema/resource_test.go index 1bfe40da3b..f46d1d08a7 100644 --- a/sema/resource_test.go +++ b/sema/resource_test.go @@ -25,12 +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/sema_utils" - . "github.com/onflow/cadence/tests/utils" + . "github.com/onflow/cadence/test_utils/common_utils" ) func TestCheckFailableCastingWithResourceAnnotation(t *testing.T) { diff --git a/sema/return_test.go b/sema/return_test.go index 5f9b20ed5b..61f7f54835 100644 --- a/sema/return_test.go +++ b/sema/return_test.go @@ -28,7 +28,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidReturnValue(t *testing.T) { diff --git a/sema/rlp_test.go b/sema/rlp_test.go index b079b03c33..216c1829fb 100644 --- a/sema/rlp_test.go +++ b/sema/rlp_test.go @@ -26,7 +26,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckRLPDecodeString(t *testing.T) { diff --git a/sema/runtimetype_test.go b/sema/runtimetype_test.go index 8d8b444c70..22a46b6248 100644 --- a/sema/runtimetype_test.go +++ b/sema/runtimetype_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckOptionalTypeConstructor(t *testing.T) { diff --git a/sema/storable_test.go b/sema/storable_test.go index 3720107e70..23c0b96722 100644 --- a/sema/storable_test.go +++ b/sema/storable_test.go @@ -29,7 +29,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckStorable(t *testing.T) { diff --git a/sema/string_test.go b/sema/string_test.go index 23c0ff8001..5faa94b3d9 100644 --- a/sema/string_test.go +++ b/sema/string_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckCharacter(t *testing.T) { diff --git a/sema/swap_test.go b/sema/swap_test.go index 63fb658906..9f39ffdff5 100644 --- a/sema/swap_test.go +++ b/sema/swap_test.go @@ -26,7 +26,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidUnknownDeclarationSwap(t *testing.T) { diff --git a/sema/switch_test.go b/sema/switch_test.go index 38328f1645..197e1dd5d5 100644 --- a/sema/switch_test.go +++ b/sema/switch_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckSwitchStatementTest(t *testing.T) { diff --git a/sema/transactions_test.go b/sema/transactions_test.go index 79b362d918..dd80079ecd 100644 --- a/sema/transactions_test.go +++ b/sema/transactions_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckTransactions(t *testing.T) { diff --git a/sema/type_inference_test.go b/sema/type_inference_test.go index 85a338eaf3..db3dcb247d 100644 --- a/sema/type_inference_test.go +++ b/sema/type_inference_test.go @@ -26,7 +26,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckArrayElementTypeInference(t *testing.T) { diff --git a/sema/typeargument_test.go b/sema/typeargument_test.go index 66895844d4..cbb85a5ff5 100644 --- a/sema/typeargument_test.go +++ b/sema/typeargument_test.go @@ -27,7 +27,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckTypeArguments(t *testing.T) { diff --git a/sema/utils_test.go b/sema/utils_test.go index d65f31264d..f19512f82b 100644 --- a/sema/utils_test.go +++ b/sema/utils_test.go @@ -24,7 +24,7 @@ import ( "github.com/onflow/cadence/common" "github.com/onflow/cadence/sema" "github.com/onflow/cadence/stdlib" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func ParseAndCheckWithPanic(t *testing.T, code string) (*sema.Checker, error) { diff --git a/sema/while_test.go b/sema/while_test.go index 9d40353678..3922b94315 100644 --- a/sema/while_test.go +++ b/sema/while_test.go @@ -24,7 +24,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/onflow/cadence/sema" - . "github.com/onflow/cadence/tests/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" ) func TestCheckInvalidWhileTest(t *testing.T) { 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 46bbed8071..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/sema_utils" - "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 { @@ -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) @@ -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/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 47592a0de2..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/sema_utils" - "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 { 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 100% rename from tests/runtime_utils/testinterface.go rename to test_utils/runtime_utils/testinterface.go 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/sema_utils/utils.go b/test_utils/sema_utils/utils.go similarity index 97% rename from tests/sema_utils/utils.go rename to test_utils/sema_utils/utils.go index 23d1e7756e..220d0e653f 100644 --- a/tests/sema_utils/utils.go +++ b/test_utils/sema_utils/utils.go @@ -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/tools/analysis/analysis_test.go b/tools/analysis/analysis_test.go index 0baebceefa..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/sema_utils" + . "github.com/onflow/cadence/test_utils/sema_utils" "github.com/onflow/cadence/tools/analysis" ) 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/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{ { From ff8d29d984d0389782929bfd7be31d38153997c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 28 Oct 2024 18:17:45 -0700 Subject: [PATCH 50/70] adjust paths --- Makefile | 2 +- docs/development.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/docs/development.md b/docs/development.md index 4a166bba19..477bcf6222 100644 --- a/docs/development.md +++ b/docs/development.md @@ -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, From 487e31ac299c2d1adcee282f8018db42dd42c1e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Wed, 9 Oct 2024 14:56:27 -0700 Subject: [PATCH 51/70] prevent predeclared members to get confused using user-defined types --- runtime/ast/expression.go | 2 +- runtime/runtime_test.go | 67 +++++++++++++++ runtime/sema/check_composite_declaration.go | 94 ++++++++++++++++----- runtime/tests/checker/attachments_test.go | 23 ++++- runtime/tests/checker/composite_test.go | 52 ++++++++++++ runtime/tests/checker/contract_test.go | 30 +++++++ runtime/tests/checker/nesting_test.go | 3 +- 7 files changed, 246 insertions(+), 25 deletions(-) diff --git a/runtime/ast/expression.go b/runtime/ast/expression.go index 0142b92b20..deed882354 100644 --- a/runtime/ast/expression.go +++ b/runtime/ast/expression.go @@ -1416,7 +1416,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/runtime/runtime_test.go b/runtime/runtime_test.go index 7005274fed..2b57648779 100644 --- a/runtime/runtime_test.go +++ b/runtime/runtime_test.go @@ -11480,3 +11480,70 @@ func TestRuntimeStorageEnumAsDictionaryKey(t *testing.T) { loggedMessages, ) } + +func TestRuntimeBuiltInFunctionConfusion(t *testing.T) { + + t.Parallel() + + const contract = ` + access(all) contract Foo { + access(all) resource getType {} + + init() { + Foo.getType() + } + } + ` + + runtime := NewTestInterpreterRuntime() + + address := common.MustBytesToAddress([]byte{0x1}) + + accountCodes := map[common.AddressLocation][]byte{} + var events []cadence.Event + var loggedMessages []string + + runtimeInterface := &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) + }, + } + + nextTransactionLocation := NewTransactionLocationGenerator() + + // Deploy contract + + err := runtime.ExecuteTransaction( + Script{ + Source: DeploymentTransaction( + "Foo", + []byte(contract), + ), + }, + Context{ + Interface: runtimeInterface, + Location: nextTransactionLocation(), + }, + ) + RequireError(t, err) + + var redeclarationError *sema.RedeclarationError + require.ErrorAs(t, err, &redeclarationError) +} diff --git a/runtime/sema/check_composite_declaration.go b/runtime/sema/check_composite_declaration.go index 5bc46ecd5e..84030e0224 100644 --- a/runtime/sema/check_composite_declaration.go +++ b/runtime/sema/check_composite_declaration.go @@ -1688,39 +1688,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 } @@ -1792,7 +1837,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 } @@ -2406,7 +2456,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{} @@ -2430,7 +2480,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/runtime/tests/checker/attachments_test.go b/runtime/tests/checker/attachments_test.go index 766e075e1d..ac8f324f01 100644 --- a/runtime/tests/checker/attachments_test.go +++ b/runtime/tests/checker/attachments_test.go @@ -4757,7 +4757,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() @@ -4773,6 +4773,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/runtime/tests/checker/composite_test.go b/runtime/tests/checker/composite_test.go index fe4d0c5e5a..98f458db9d 100644 --- a/runtime/tests/checker/composite_test.go +++ b/runtime/tests/checker/composite_test.go @@ -2298,3 +2298,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/runtime/tests/checker/contract_test.go b/runtime/tests/checker/contract_test.go index 0a2edbcb0d..a3b055ca27 100644 --- a/runtime/tests/checker/contract_test.go +++ b/runtime/tests/checker/contract_test.go @@ -94,6 +94,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/runtime/tests/checker/nesting_test.go b/runtime/tests/checker/nesting_test.go index fda0d70f50..6e09c18f57 100644 --- a/runtime/tests/checker/nesting_test.go +++ b/runtime/tests/checker/nesting_test.go @@ -258,9 +258,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) { From 5f28ddaa6555cb0c7de0e053d6f71838903d0329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Wed, 9 Oct 2024 22:30:08 -0700 Subject: [PATCH 52/70] forbid attachment conformances --- runtime/sema/check_composite_declaration.go | 26 +- runtime/sema/errors.go | 17 + runtime/tests/checker/attachments_test.go | 328 +------------------- runtime/tests/checker/entitlements_test.go | 110 ------- 4 files changed, 56 insertions(+), 425 deletions(-) diff --git a/runtime/sema/check_composite_declaration.go b/runtime/sema/check_composite_declaration.go index 84030e0224..cb2fac91bd 100644 --- a/runtime/sema/check_composite_declaration.go +++ b/runtime/sema/check_composite_declaration.go @@ -681,9 +681,31 @@ 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) } diff --git a/runtime/sema/errors.go b/runtime/sema/errors.go index 64c693802a..66efa2b57d 100644 --- a/runtime/sema/errors.go +++ b/runtime/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/runtime/tests/checker/attachments_test.go b/runtime/tests/checker/attachments_test.go index ac8f324f01..f6a3c75ae3 100644 --- a/runtime/tests/checker/attachments_test.go +++ b/runtime/tests/checker/attachments_test.go @@ -619,304 +619,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.Run("struct", 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) { + _, err := ParseAndCheck(t, ` + struct S {} - t.Parallel() + struct interface SI {} - _, err := ParseAndCheck(t, - ` - resource R { - fun x(): Int { return 3 } - } - resource interface I { - fun x(): Int - } - attachment Test for R: I { - }`, - ) + attachment Test for S: SI {} + `) errs := RequireCheckerErrors(t, err, 1) - assert.IsType(t, &sema.ConformanceError{}, errs[0]) + assert.IsType(t, &sema.InvalidAttachmentConformancesError{}, errs[0]) }) - t.Run("kind mismatch resource", func(t *testing.T) { + t.Run("resource", func(t *testing.T) { t.Parallel() - _, err := ParseAndCheck(t, - ` + _, 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) { - - t.Parallel() - - _, err := ParseAndCheck(t, - ` - struct R {} - resource interface I {} - attachment Test for R: I {}`, - ) - - 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 {}`, - ) + resource interface RI {} - 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) - }) - - t.Run("AnyStruct base, resource conformance", 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) { - - t.Parallel() - - _, 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 +1033,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 +3219,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 diff --git a/runtime/tests/checker/entitlements_test.go b/runtime/tests/checker/entitlements_test.go index fb2a5f18dd..085d10370f 100644 --- a/runtime/tests/checker/entitlements_test.go +++ b/runtime/tests/checker/entitlements_test.go @@ -3031,116 +3031,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) { From 3f384d51309e8691e625a599c602e088e2d6dbfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Thu, 10 Oct 2024 15:01:14 -0700 Subject: [PATCH 53/70] forbid change of attachment base type --- runtime/contract_update_validation_test.go | 49 +++++++++++++++++ ..._v0.42_to_v1_contract_upgrade_validator.go | 1 + runtime/stdlib/contract_update_validation.go | 55 +++++++++++++++++-- 3 files changed, 99 insertions(+), 6 deletions(-) diff --git a/runtime/contract_update_validation_test.go b/runtime/contract_update_validation_test.go index 451c4a2def..2ae0bade0e 100644 --- a/runtime/contract_update_validation_test.go +++ b/runtime/contract_update_validation_test.go @@ -3666,3 +3666,52 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) { }, ) } + +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/runtime/stdlib/cadence_v0.42_to_v1_contract_upgrade_validator.go b/runtime/stdlib/cadence_v0.42_to_v1_contract_upgrade_validator.go index ee5706967b..ccebf6c2d8 100644 --- a/runtime/stdlib/cadence_v0.42_to_v1_contract_upgrade_validator.go +++ b/runtime/stdlib/cadence_v0.42_to_v1_contract_upgrade_validator.go @@ -121,6 +121,7 @@ func (validator *CadenceV042ToV1ContractUpdateValidator) Validate() error { checkDeclarationUpdatability( validator, + validator.TypeComparator, oldRootDecl, newRootDecl, validator.checkConformanceV1, diff --git a/runtime/stdlib/contract_update_validation.go b/runtime/stdlib/contract_update_validation.go index 92ad1df81e..00cbad8076 100644 --- a/runtime/stdlib/contract_update_validation.go +++ b/runtime/stdlib/contract_update_validation.go @@ -142,6 +142,7 @@ func (validator *ContractUpdateValidator) Validate() error { checkDeclarationUpdatability( validator, + validator.TypeComparator, oldRootDecl, newRootDecl, validator.checkConformance, @@ -249,8 +250,8 @@ func collectRemovedTypePragmas(validator UpdateValidator, pragmas []*ast.PragmaD }) continue } - removedTypeName, isIdentifer := invocationExpression.Arguments[0].Expression.(*ast.IdentifierExpression) - if !isIdentifer { + removedTypeName, isIdentifier := invocationExpression.Arguments[0].Expression.(*ast.IdentifierExpression) + if !isIdentifier { validator.report(&InvalidTypeRemovalPragmaError{ Expression: pragma.Expression, Range: ast.NewUnmeteredRangeFromPositioned(pragma.Expression), @@ -265,6 +266,7 @@ func collectRemovedTypePragmas(validator UpdateValidator, pragmas []*ast.PragmaD func checkDeclarationUpdatability( validator UpdateValidator, + typeComparator *TypeComparator, oldDeclaration ast.Declaration, newDeclaration ast.Declaration, checkConformance checkConformanceFunc, @@ -293,13 +295,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( @@ -423,6 +447,7 @@ func checkTypeNotRemoved( func checkNestedDeclarations( validator UpdateValidator, + typeComparator *TypeComparator, oldDeclaration ast.Declaration, newDeclaration ast.Declaration, checkConformance checkConformanceFunc, @@ -457,7 +482,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) @@ -473,7 +504,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) @@ -489,7 +526,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) From 1e6ee46d35c0202ece2c8a6bbc338d578dd00446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Thu, 10 Oct 2024 16:16:38 -0700 Subject: [PATCH 54/70] put attachment base type change validation behind a feature flag --- runtime/config.go | 2 + runtime/contract_update_validation_test.go | 50 +++++++++++++++-- runtime/environment.go | 25 +++++---- runtime/interpreter/config.go | 2 + runtime/stdlib/account.go | 5 +- ..._v0.42_to_v1_contract_upgrade_validator.go | 19 +++++-- runtime/stdlib/contract_update_validation.go | 56 ++++++++++++------- 7 files changed, 117 insertions(+), 42 deletions(-) diff --git a/runtime/config.go b/runtime/config.go index 3e3a273ff1..50b803a188 100644 --- a/runtime/config.go +++ b/runtime/config.go @@ -41,4 +41,6 @@ type Config struct { LegacyContractUpgradeEnabled bool // ContractUpdateTypeRemovalEnabled specifies if type removal is enabled in contract updates ContractUpdateTypeRemovalEnabled bool + // ContractUpdateAttachmentBaseTypeChangeEnabled specifies if attachment base type change is enabled in contract updates + ContractUpdateAttachmentBaseTypeChangeEnabled bool } diff --git a/runtime/contract_update_validation_test.go b/runtime/contract_update_validation_test.go index 2ae0bade0e..fad78918da 100644 --- a/runtime/contract_update_validation_test.go +++ b/runtime/contract_update_validation_test.go @@ -205,6 +205,43 @@ func testWithValidatorsAndTypeRemovalEnabled( } } +func testWithValidatorsAndAttachmentBaseTypeChangeEnabled( + t *testing.T, + name string, + testFunc func(t *testing.T, config Config), +) { + for _, withC1Upgrade := range []bool{true, false} { + withC1Upgrade := withC1Upgrade + name := name + + for _, withAttachmentBaseTypeChangeEnabled := range []bool{true, false} { + withAttachmentBaseTypeChangeEnabled := withAttachmentBaseTypeChangeEnabled + name := name + + switch { + case withC1Upgrade && withAttachmentBaseTypeChangeEnabled: + name = fmt.Sprintf("%s (with C1 validator and attachment base type change enabled)", name) + + case withC1Upgrade: + name = fmt.Sprintf("%s (with C1 validator)", name) + + case withAttachmentBaseTypeChangeEnabled: + name = fmt.Sprintf("%s (with attachment base type change enabled)", name) + } + + t.Run(name, func(t *testing.T) { + t.Parallel() + + config := DefaultTestInterpreterConfig + config.LegacyContractUpgradeEnabled = withC1Upgrade + config.ContractUpdateAttachmentBaseTypeChangeEnabled = withAttachmentBaseTypeChangeEnabled + + testFunc(t, config) + }) + } + } +} + func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() @@ -3670,7 +3707,7 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) { func TestAttachmentsUpdates(t *testing.T) { t.Parallel() - testWithValidators(t, + testWithValidatorsAndAttachmentBaseTypeChangeEnabled(t, "Keep base type", func(t *testing.T, config Config) { @@ -3691,7 +3728,7 @@ func TestAttachmentsUpdates(t *testing.T) { }, ) - testWithValidators(t, + testWithValidatorsAndAttachmentBaseTypeChangeEnabled(t, "Change base type", func(t *testing.T, config Config) { @@ -3709,9 +3746,12 @@ func TestAttachmentsUpdates(t *testing.T) { err := testDeployAndUpdate(t, "Test", oldCode, newCode, config) - var expectedErr *stdlib.TypeMismatchError - require.ErrorAs(t, err, &expectedErr) + if config.ContractUpdateAttachmentBaseTypeChangeEnabled { + require.NoError(t, err) + } else { + var expectedErr *stdlib.TypeMismatchError + require.ErrorAs(t, err, &expectedErr) + } }, ) - } diff --git a/runtime/environment.go b/runtime/environment.go index 95a3ac847c..7c55dbf97d 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -185,18 +185,19 @@ func (e *interpreterEnvironment) newInterpreterConfig() *interpreter.Config { // and disable storage validation after each value modification. // Instead, storage is validated after commits (if validation is enabled), // see interpreterEnvironment.CommitStorage - AtreeStorageValidationEnabled: false, - Debugger: e.config.Debugger, - OnStatement: e.newOnStatementHandler(), - OnMeterComputation: e.newOnMeterComputation(), - OnFunctionInvocation: e.newOnFunctionInvocationHandler(), - OnInvokedFunctionReturn: e.newOnInvokedFunctionReturnHandler(), - CapabilityBorrowHandler: e.newCapabilityBorrowHandler(), - CapabilityCheckHandler: e.newCapabilityCheckHandler(), - LegacyContractUpgradeEnabled: e.config.LegacyContractUpgradeEnabled, - ContractUpdateTypeRemovalEnabled: e.config.ContractUpdateTypeRemovalEnabled, - ValidateAccountCapabilitiesGetHandler: e.newValidateAccountCapabilitiesGetHandler(), - ValidateAccountCapabilitiesPublishHandler: e.newValidateAccountCapabilitiesPublishHandler(), + AtreeStorageValidationEnabled: false, + Debugger: e.config.Debugger, + OnStatement: e.newOnStatementHandler(), + OnMeterComputation: e.newOnMeterComputation(), + OnFunctionInvocation: e.newOnFunctionInvocationHandler(), + OnInvokedFunctionReturn: e.newOnInvokedFunctionReturnHandler(), + CapabilityBorrowHandler: e.newCapabilityBorrowHandler(), + CapabilityCheckHandler: e.newCapabilityCheckHandler(), + LegacyContractUpgradeEnabled: e.config.LegacyContractUpgradeEnabled, + ContractUpdateTypeRemovalEnabled: e.config.ContractUpdateTypeRemovalEnabled, + ContractUpdateAttachmentBaseTypeChangeEnabled: e.config.ContractUpdateAttachmentBaseTypeChangeEnabled, + ValidateAccountCapabilitiesGetHandler: e.newValidateAccountCapabilitiesGetHandler(), + ValidateAccountCapabilitiesPublishHandler: e.newValidateAccountCapabilitiesPublishHandler(), } } diff --git a/runtime/interpreter/config.go b/runtime/interpreter/config.go index dc052342d1..f64413aef5 100644 --- a/runtime/interpreter/config.go +++ b/runtime/interpreter/config.go @@ -74,6 +74,8 @@ type Config struct { LegacyContractUpgradeEnabled bool // ContractUpdateTypeRemovalEnabled specifies if type removal is enabled in contract updates ContractUpdateTypeRemovalEnabled bool + // ContractUpdateAttachmentBaseTypeChangeEnabled specifies if attachment base type change is enabled in contract updates + ContractUpdateAttachmentBaseTypeChangeEnabled 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/runtime/stdlib/account.go b/runtime/stdlib/account.go index f7eb85b1b6..235dc29e6f 100644 --- a/runtime/stdlib/account.go +++ b/runtime/stdlib/account.go @@ -1679,6 +1679,7 @@ func changeAccountContracts( memoryGauge := invocation.Interpreter.SharedState.Config.MemoryGauge legacyUpgradeEnabled := invocation.Interpreter.SharedState.Config.LegacyContractUpgradeEnabled contractUpdateTypeRemovalEnabled := invocation.Interpreter.SharedState.Config.ContractUpdateTypeRemovalEnabled + contractUpdateAttachmentBaseTypeChangeEnabled := invocation.Interpreter.SharedState.Config.ContractUpdateAttachmentBaseTypeChangeEnabled var oldProgram *ast.Program @@ -1731,7 +1732,9 @@ func changeAccountContracts( ) } - validator = validator.WithTypeRemovalEnabled(contractUpdateTypeRemovalEnabled) + validator = validator. + WithTypeRemovalEnabled(contractUpdateTypeRemovalEnabled). + WithAttachmentBaseTypeChangeEnabled(contractUpdateAttachmentBaseTypeChangeEnabled) err = validator.Validate() handleContractUpdateError(err, newCode) diff --git a/runtime/stdlib/cadence_v0.42_to_v1_contract_upgrade_validator.go b/runtime/stdlib/cadence_v0.42_to_v1_contract_upgrade_validator.go index ccebf6c2d8..d3fc96209b 100644 --- a/runtime/stdlib/cadence_v0.42_to_v1_contract_upgrade_validator.go +++ b/runtime/stdlib/cadence_v0.42_to_v1_contract_upgrade_validator.go @@ -71,10 +71,6 @@ func NewCadenceV042ToV1ContractUpdateValidator( var _ UpdateValidator = &CadenceV042ToV1ContractUpdateValidator{} -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 { @@ -82,6 +78,10 @@ func (validator *CadenceV042ToV1ContractUpdateValidator) WithUserDefinedTypeChan return validator } +func (validator *CadenceV042ToV1ContractUpdateValidator) isTypeRemovalEnabled() bool { + return validator.underlyingUpdateValidator.isTypeRemovalEnabled() +} + func (validator *CadenceV042ToV1ContractUpdateValidator) WithTypeRemovalEnabled( enabled bool, ) UpdateValidator { @@ -89,6 +89,17 @@ func (validator *CadenceV042ToV1ContractUpdateValidator) WithTypeRemovalEnabled( return validator } +func (validator *CadenceV042ToV1ContractUpdateValidator) isAttachmentBaseTypeChangeEnabled() bool { + return validator.underlyingUpdateValidator.isAttachmentBaseTypeChangeEnabled() +} + +func (validator *CadenceV042ToV1ContractUpdateValidator) WithAttachmentBaseTypeChangeEnabled( + enabled bool, +) UpdateValidator { + validator.underlyingUpdateValidator.WithAttachmentBaseTypeChangeEnabled(enabled) + return validator +} + func (validator *CadenceV042ToV1ContractUpdateValidator) getCurrentDeclaration() ast.Declaration { return validator.underlyingUpdateValidator.getCurrentDeclaration() } diff --git a/runtime/stdlib/contract_update_validation.go b/runtime/stdlib/contract_update_validation.go index 00cbad8076..0113ab439c 100644 --- a/runtime/stdlib/contract_update_validation.go +++ b/runtime/stdlib/contract_update_validation.go @@ -53,6 +53,9 @@ type UpdateValidator interface { isTypeRemovalEnabled() bool WithTypeRemovalEnabled(enabled bool) UpdateValidator + + isAttachmentBaseTypeChangeEnabled() bool + WithAttachmentBaseTypeChangeEnabled(enabled bool) UpdateValidator } type checkConformanceFunc func( @@ -63,15 +66,16 @@ type checkConformanceFunc func( type ContractUpdateValidator struct { *TypeComparator - location common.Location - contractName string - oldProgram *ast.Program - newProgram *ast.Program - currentDecl ast.Declaration - importLocations map[ast.Identifier]common.Location - accountContractNamesProvider AccountContractNamesProvider - errors []error - typeRemovalEnabled bool + location common.Location + contractName string + oldProgram *ast.Program + newProgram *ast.Program + currentDecl ast.Declaration + importLocations map[ast.Identifier]common.Location + accountContractNamesProvider AccountContractNamesProvider + errors []error + typeRemovalEnabled bool + attachmentBaseTypeChangeEnabled bool } // ContractUpdateValidator should implement ast.TypeEqualityChecker @@ -108,6 +112,15 @@ func (validator *ContractUpdateValidator) WithTypeRemovalEnabled(enabled bool) U return validator } +func (validator *ContractUpdateValidator) isAttachmentBaseTypeChangeEnabled() bool { + return validator.attachmentBaseTypeChangeEnabled +} + +func (validator *ContractUpdateValidator) WithAttachmentBaseTypeChangeEnabled(enabled bool) UpdateValidator { + validator.attachmentBaseTypeChangeEnabled = enabled + return validator +} + func (validator *ContractUpdateValidator) getCurrentDeclaration() ast.Declaration { return validator.currentDecl } @@ -309,18 +322,21 @@ func checkDeclarationUpdatability( } } - // Check if the base type of the attachment has changed. - if oldAttachment, ok := oldDeclaration.(*ast.AttachmentDeclaration); ok && - oldAttachment.DeclarationKind() == common.DeclarationKindAttachment { + if !validator.isAttachmentBaseTypeChangeEnabled() { - // 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) + // 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) + } } } } From 78495040812f57f720ad0f795c27d35aa8bb42ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Thu, 10 Oct 2024 16:36:41 -0700 Subject: [PATCH 55/70] put attachment conformances behind feature flag --- runtime/config.go | 2 + runtime/environment.go | 1 + runtime/sema/check_composite_declaration.go | 37 +++++---- runtime/sema/config.go | 2 + runtime/tests/checker/attachments_test.go | 86 ++++++++++++++++++--- 5 files changed, 101 insertions(+), 27 deletions(-) diff --git a/runtime/config.go b/runtime/config.go index 50b803a188..23b7e917df 100644 --- a/runtime/config.go +++ b/runtime/config.go @@ -37,6 +37,8 @@ type Config struct { CoverageReport *CoverageReport // AttachmentsEnabled specifies if attachments are enabled AttachmentsEnabled bool + // AttachmentConformancesEnabled specifies if attachment conformances are enabled + AttachmentConformancesEnabled bool // 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 diff --git a/runtime/environment.go b/runtime/environment.go index 7c55dbf97d..afbb9f763c 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -211,6 +211,7 @@ func (e *interpreterEnvironment) newCheckerConfig() *sema.Config { ImportHandler: e.resolveImport, CheckHandler: e.newCheckHandler(), AttachmentsEnabled: e.config.AttachmentsEnabled, + AttachmentConformancesEnabled: e.config.AttachmentConformancesEnabled, } } diff --git a/runtime/sema/check_composite_declaration.go b/runtime/sema/check_composite_declaration.go index cb2fac91bd..bcae42aec7 100644 --- a/runtime/sema/check_composite_declaration.go +++ b/runtime/sema/check_composite_declaration.go @@ -686,23 +686,30 @@ func (checker *Checker) declareCompositeType(declaration ast.CompositeLikeDeclar compositeType.EnumRawType = checker.enumRawType(declaration.(*ast.CompositeDeclaration)) 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] + if checker.Config.AttachmentConformancesEnabled { + compositeType.ExplicitInterfaceConformances = + checker.explicitInterfaceConformances(declaration, compositeType) - checker.report( - &InvalidAttachmentConformancesError{ - Range: ast.NewRange( - checker.memoryGauge, - firstConformance.StartPosition(), - lastConformance.EndPosition(checker.memoryGauge), - ), - }, - ) + } else { + // 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: diff --git a/runtime/sema/config.go b/runtime/sema/config.go index 06f6e9ce95..a48e620522 100644 --- a/runtime/sema/config.go +++ b/runtime/sema/config.go @@ -55,4 +55,6 @@ type Config struct { AllowStaticDeclarations bool // AttachmentsEnabled determines if attachments are enabled AttachmentsEnabled bool + // AttachmentConformancesEnabled determines if attachment conformances are enabled + AttachmentConformancesEnabled bool } diff --git a/runtime/tests/checker/attachments_test.go b/runtime/tests/checker/attachments_test.go index f6a3c75ae3..6a890e0124 100644 --- a/runtime/tests/checker/attachments_test.go +++ b/runtime/tests/checker/attachments_test.go @@ -623,34 +623,96 @@ func TestCheckInvalidAttachmentConformance(t *testing.T) { t.Parallel() - t.Run("struct", func(t *testing.T) { + t.Run("struct, enabled", func(t *testing.T) { t.Parallel() - _, err := ParseAndCheck(t, ` - struct S {} + _, err := ParseAndCheckWithOptions(t, + ` + struct S {} - struct interface SI {} + struct interface SI {} - attachment Test for S: SI {} - `) + attachment Test for S: SI {} + `, + ParseAndCheckOptions{ + Config: &sema.Config{ + AttachmentsEnabled: true, + AttachmentConformancesEnabled: true, + }, + }, + ) + + require.NoError(t, err) + }) + + t.Run("struct, disabled", func(t *testing.T) { + + t.Parallel() + + _, err := ParseAndCheckWithOptions(t, + ` + struct S {} + + struct interface SI {} + + attachment Test for S: SI {} + `, + ParseAndCheckOptions{ + Config: &sema.Config{ + AttachmentsEnabled: true, + AttachmentConformancesEnabled: false, + }, + }, + ) errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.InvalidAttachmentConformancesError{}, errs[0]) }) - t.Run("resource", func(t *testing.T) { + t.Run("resource, enabled", func(t *testing.T) { t.Parallel() - _, err := ParseAndCheck(t, ` - resource R {} + _, err := ParseAndCheckWithOptions(t, + ` + resource R {} - resource interface RI {} + resource interface RI {} - attachment Test for R: RI {} - `) + attachment Test for R: RI {} + `, + ParseAndCheckOptions{ + Config: &sema.Config{ + AttachmentsEnabled: true, + AttachmentConformancesEnabled: true, + }, + }, + ) + + require.NoError(t, err) + }) + + t.Run("resource, disabled", func(t *testing.T) { + + t.Parallel() + + _, err := ParseAndCheckWithOptions(t, + ` + resource R {} + + resource interface RI {} + + attachment Test for R: RI {} + `, + ParseAndCheckOptions{ + Config: &sema.Config{ + AttachmentsEnabled: true, + AttachmentConformancesEnabled: false, + }, + }, + ) errs := RequireCheckerErrors(t, err, 1) From 605fc9563aca1b6810f581198b080c30b6e1f5f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Fri, 11 Oct 2024 10:50:48 -0700 Subject: [PATCH 56/70] put sibling type check for members behind a feature flag --- runtime/config.go | 2 + runtime/environment.go | 1 + runtime/runtime_test.go | 81 +++++++++++++-------- runtime/sema/check_composite_declaration.go | 2 +- runtime/sema/config.go | 2 + 5 files changed, 58 insertions(+), 30 deletions(-) diff --git a/runtime/config.go b/runtime/config.go index 23b7e917df..c81d396b43 100644 --- a/runtime/config.go +++ b/runtime/config.go @@ -39,6 +39,8 @@ type Config struct { AttachmentsEnabled bool // AttachmentConformancesEnabled specifies if attachment conformances are enabled AttachmentConformancesEnabled bool + // MemberSiblingTypeCheckEnabled specifies if declaring members checks for sibling type declarations + MemberSiblingTypeCheckEnabled bool // 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 diff --git a/runtime/environment.go b/runtime/environment.go index afbb9f763c..ae9fe82cba 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -212,6 +212,7 @@ func (e *interpreterEnvironment) newCheckerConfig() *sema.Config { CheckHandler: e.newCheckHandler(), AttachmentsEnabled: e.config.AttachmentsEnabled, AttachmentConformancesEnabled: e.config.AttachmentConformancesEnabled, + MemberSiblingTypeCheckEnabled: e.config.MemberSiblingTypeCheckEnabled, } } diff --git a/runtime/runtime_test.go b/runtime/runtime_test.go index 2b57648779..393d060204 100644 --- a/runtime/runtime_test.go +++ b/runtime/runtime_test.go @@ -11495,42 +11495,46 @@ func TestRuntimeBuiltInFunctionConfusion(t *testing.T) { } ` - runtime := NewTestInterpreterRuntime() - address := common.MustBytesToAddress([]byte{0x1}) - accountCodes := map[common.AddressLocation][]byte{} - var events []cadence.Event - var loggedMessages []string + newRuntimeInterface := func() Interface { - runtimeInterface := &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) - }, + 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) + }, + } } nextTransactionLocation := NewTransactionLocationGenerator() - // Deploy contract + // Deploy contract without check enabled - err := runtime.ExecuteTransaction( + err := NewTestInterpreterRuntimeWithConfig(Config{ + AtreeValidationEnabled: true, + MemberSiblingTypeCheckEnabled: false, + }).ExecuteTransaction( Script{ Source: DeploymentTransaction( "Foo", @@ -11538,7 +11542,26 @@ func TestRuntimeBuiltInFunctionConfusion(t *testing.T) { ), }, Context{ - Interface: runtimeInterface, + Interface: newRuntimeInterface(), + Location: nextTransactionLocation(), + }, + ) + require.NoError(t, err) + + // Deploy contract with check enabled + + err = NewTestInterpreterRuntimeWithConfig(Config{ + AtreeValidationEnabled: true, + MemberSiblingTypeCheckEnabled: true, + }).ExecuteTransaction( + Script{ + Source: DeploymentTransaction( + "Foo", + []byte(contract), + ), + }, + Context{ + Interface: newRuntimeInterface(), Location: nextTransactionLocation(), }, ) diff --git a/runtime/sema/check_composite_declaration.go b/runtime/sema/check_composite_declaration.go index bcae42aec7..f8280702ac 100644 --- a/runtime/sema/check_composite_declaration.go +++ b/runtime/sema/check_composite_declaration.go @@ -1748,7 +1748,7 @@ func (checker *Checker) defaultMembersAndOrigins( } } - if nestedTypes != nil { + if nestedTypes != nil && checker.Config.MemberSiblingTypeCheckEnabled { if _, ok := nestedTypes.Get(name); ok { // TODO: provide previous position checker.report( diff --git a/runtime/sema/config.go b/runtime/sema/config.go index a48e620522..2c760d701b 100644 --- a/runtime/sema/config.go +++ b/runtime/sema/config.go @@ -57,4 +57,6 @@ type Config struct { AttachmentsEnabled bool // AttachmentConformancesEnabled determines if attachment conformances are enabled AttachmentConformancesEnabled bool + // MemberSiblingTypeCheckEnabled determines if declaring members checks for sibling type declarations + MemberSiblingTypeCheckEnabled bool } From 74b013566bb2c3005960fa5d275d4f466a3f7a82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Fri, 11 Oct 2024 14:01:15 -0700 Subject: [PATCH 57/70] invert feature flag --- runtime/config.go | 4 ++-- runtime/environment.go | 2 +- runtime/runtime_test.go | 8 ++++---- runtime/sema/check_composite_declaration.go | 2 +- runtime/sema/config.go | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/runtime/config.go b/runtime/config.go index c81d396b43..93f3d37844 100644 --- a/runtime/config.go +++ b/runtime/config.go @@ -39,8 +39,8 @@ type Config struct { AttachmentsEnabled bool // AttachmentConformancesEnabled specifies if attachment conformances are enabled AttachmentConformancesEnabled bool - // MemberSiblingTypeCheckEnabled specifies if declaring members checks for sibling type declarations - MemberSiblingTypeCheckEnabled bool + // MemberSiblingTypeOverrideEnabled specifies if declaring members checks for sibling type declarations + MemberSiblingTypeOverrideEnabled bool // 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 diff --git a/runtime/environment.go b/runtime/environment.go index ae9fe82cba..bef0cc5361 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -212,7 +212,7 @@ func (e *interpreterEnvironment) newCheckerConfig() *sema.Config { CheckHandler: e.newCheckHandler(), AttachmentsEnabled: e.config.AttachmentsEnabled, AttachmentConformancesEnabled: e.config.AttachmentConformancesEnabled, - MemberSiblingTypeCheckEnabled: e.config.MemberSiblingTypeCheckEnabled, + MemberSiblingTypeOverrideEnabled: e.config.MemberSiblingTypeOverrideEnabled, } } diff --git a/runtime/runtime_test.go b/runtime/runtime_test.go index 393d060204..b5375fb799 100644 --- a/runtime/runtime_test.go +++ b/runtime/runtime_test.go @@ -11532,8 +11532,8 @@ func TestRuntimeBuiltInFunctionConfusion(t *testing.T) { // Deploy contract without check enabled err := NewTestInterpreterRuntimeWithConfig(Config{ - AtreeValidationEnabled: true, - MemberSiblingTypeCheckEnabled: false, + AtreeValidationEnabled: true, + MemberSiblingTypeOverrideEnabled: true, }).ExecuteTransaction( Script{ Source: DeploymentTransaction( @@ -11551,8 +11551,8 @@ func TestRuntimeBuiltInFunctionConfusion(t *testing.T) { // Deploy contract with check enabled err = NewTestInterpreterRuntimeWithConfig(Config{ - AtreeValidationEnabled: true, - MemberSiblingTypeCheckEnabled: true, + AtreeValidationEnabled: true, + MemberSiblingTypeOverrideEnabled: false, }).ExecuteTransaction( Script{ Source: DeploymentTransaction( diff --git a/runtime/sema/check_composite_declaration.go b/runtime/sema/check_composite_declaration.go index f8280702ac..75b8c3a8d6 100644 --- a/runtime/sema/check_composite_declaration.go +++ b/runtime/sema/check_composite_declaration.go @@ -1748,7 +1748,7 @@ func (checker *Checker) defaultMembersAndOrigins( } } - if nestedTypes != nil && checker.Config.MemberSiblingTypeCheckEnabled { + if nestedTypes != nil && !checker.Config.MemberSiblingTypeOverrideEnabled { if _, ok := nestedTypes.Get(name); ok { // TODO: provide previous position checker.report( diff --git a/runtime/sema/config.go b/runtime/sema/config.go index 2c760d701b..c8e72c695e 100644 --- a/runtime/sema/config.go +++ b/runtime/sema/config.go @@ -57,6 +57,6 @@ type Config struct { AttachmentsEnabled bool // AttachmentConformancesEnabled determines if attachment conformances are enabled AttachmentConformancesEnabled bool - // MemberSiblingTypeCheckEnabled determines if declaring members checks for sibling type declarations - MemberSiblingTypeCheckEnabled bool + // MemberSiblingTypeOverrideEnabled determines if declaring members checks for sibling type declarations + MemberSiblingTypeOverrideEnabled bool } From 03826a54c49554ae5813f45e99a206fc4b95056e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Fri, 11 Oct 2024 14:41:17 -0700 Subject: [PATCH 58/70] enable v1.0.1 features based on current version --- runtime/config.go | 6 - runtime/contract_update_validation_test.go | 121 +++++++++++-------- runtime/empty.go | 4 + runtime/environment.go | 47 ++++--- runtime/interface.go | 2 + runtime/runtime_test.go | 19 +-- runtime/tests/runtime_utils/testinterface.go | 8 ++ 7 files changed, 126 insertions(+), 81 deletions(-) diff --git a/runtime/config.go b/runtime/config.go index 93f3d37844..3e3a273ff1 100644 --- a/runtime/config.go +++ b/runtime/config.go @@ -37,14 +37,8 @@ type Config struct { CoverageReport *CoverageReport // AttachmentsEnabled specifies if attachments are enabled AttachmentsEnabled bool - // AttachmentConformancesEnabled specifies if attachment conformances are enabled - AttachmentConformancesEnabled bool - // MemberSiblingTypeOverrideEnabled specifies if declaring members checks for sibling type declarations - MemberSiblingTypeOverrideEnabled bool // 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 - // ContractUpdateAttachmentBaseTypeChangeEnabled specifies if attachment base type change is enabled in contract updates - ContractUpdateAttachmentBaseTypeChangeEnabled bool } diff --git a/runtime/contract_update_validation_test.go b/runtime/contract_update_validation_test.go index fad78918da..1fc995699b 100644 --- a/runtime/contract_update_validation_test.go +++ b/runtime/contract_update_validation_test.go @@ -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 }, + OnCurrentVersion: func() string { + return version + }, } 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) @@ -205,43 +223,6 @@ func testWithValidatorsAndTypeRemovalEnabled( } } -func testWithValidatorsAndAttachmentBaseTypeChangeEnabled( - t *testing.T, - name string, - testFunc func(t *testing.T, config Config), -) { - for _, withC1Upgrade := range []bool{true, false} { - withC1Upgrade := withC1Upgrade - name := name - - for _, withAttachmentBaseTypeChangeEnabled := range []bool{true, false} { - withAttachmentBaseTypeChangeEnabled := withAttachmentBaseTypeChangeEnabled - name := name - - switch { - case withC1Upgrade && withAttachmentBaseTypeChangeEnabled: - name = fmt.Sprintf("%s (with C1 validator and attachment base type change enabled)", name) - - case withC1Upgrade: - name = fmt.Sprintf("%s (with C1 validator)", name) - - case withAttachmentBaseTypeChangeEnabled: - name = fmt.Sprintf("%s (with attachment base type change enabled)", name) - } - - t.Run(name, func(t *testing.T) { - t.Parallel() - - config := DefaultTestInterpreterConfig - config.LegacyContractUpgradeEnabled = withC1Upgrade - config.ContractUpdateAttachmentBaseTypeChangeEnabled = withAttachmentBaseTypeChangeEnabled - - testFunc(t, config) - }) - } - } -} - func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() @@ -3707,8 +3688,8 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) { func TestAttachmentsUpdates(t *testing.T) { t.Parallel() - testWithValidatorsAndAttachmentBaseTypeChangeEnabled(t, - "Keep base type", + testWithValidators(t, + "Keep base type, v1.0.1", func(t *testing.T, config Config) { const oldCode = ` @@ -3723,13 +3704,13 @@ func TestAttachmentsUpdates(t *testing.T) { } ` - err := testDeployAndUpdate(t, "Test", oldCode, newCode, config) + err := testDeployAndUpdateWithVersion(t, "Test", oldCode, newCode, config, "v1.0.1") require.NoError(t, err) }, ) - testWithValidatorsAndAttachmentBaseTypeChangeEnabled(t, - "Change base type", + testWithValidators(t, + "Keep base type, v1.0.2", func(t *testing.T, config Config) { const oldCode = ` @@ -3740,18 +3721,54 @@ func TestAttachmentsUpdates(t *testing.T) { const newCode = ` access(all) contract Test { - access(all) attachment A for AnyStruct {} + access(all) attachment A for AnyResource {} } ` - err := testDeployAndUpdate(t, "Test", oldCode, newCode, config) - - if config.ContractUpdateAttachmentBaseTypeChangeEnabled { - require.NoError(t, err) - } else { - var expectedErr *stdlib.TypeMismatchError - require.ErrorAs(t, err, &expectedErr) - } + err := testDeployAndUpdateWithVersion(t, "Test", oldCode, newCode, config, "v1.0.2") + require.NoError(t, err) }, ) + + testWithValidators(t, + "Change base type, v1.0.1", + 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 := testDeployAndUpdateWithVersion(t, "Test", oldCode, newCode, config, "v1.0.1") + require.NoError(t, err) + }) + + testWithValidators(t, + "Change base type, v1.0.2", + 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 := testDeployAndUpdateWithVersion(t, "Test", oldCode, newCode, config, "v1.0.2") + + var expectedErr *stdlib.TypeMismatchError + require.ErrorAs(t, err, &expectedErr) + }) } diff --git a/runtime/empty.go b/runtime/empty.go index 86b5b0abce..103c318e90 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) CurrentVersion() string { + panic("unexpected call to CurrentVersion") +} diff --git a/runtime/environment.go b/runtime/environment.go index bef0cc5361..882e3dca71 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -22,6 +22,7 @@ import ( "time" "go.opentelemetry.io/otel/attribute" + "golang.org/x/mod/semver" "github.com/onflow/cadence" "github.com/onflow/cadence/runtime/activations" @@ -185,19 +186,18 @@ func (e *interpreterEnvironment) newInterpreterConfig() *interpreter.Config { // and disable storage validation after each value modification. // Instead, storage is validated after commits (if validation is enabled), // see interpreterEnvironment.CommitStorage - AtreeStorageValidationEnabled: false, - Debugger: e.config.Debugger, - OnStatement: e.newOnStatementHandler(), - OnMeterComputation: e.newOnMeterComputation(), - OnFunctionInvocation: e.newOnFunctionInvocationHandler(), - OnInvokedFunctionReturn: e.newOnInvokedFunctionReturnHandler(), - CapabilityBorrowHandler: e.newCapabilityBorrowHandler(), - CapabilityCheckHandler: e.newCapabilityCheckHandler(), - LegacyContractUpgradeEnabled: e.config.LegacyContractUpgradeEnabled, - ContractUpdateTypeRemovalEnabled: e.config.ContractUpdateTypeRemovalEnabled, - ContractUpdateAttachmentBaseTypeChangeEnabled: e.config.ContractUpdateAttachmentBaseTypeChangeEnabled, - ValidateAccountCapabilitiesGetHandler: e.newValidateAccountCapabilitiesGetHandler(), - ValidateAccountCapabilitiesPublishHandler: e.newValidateAccountCapabilitiesPublishHandler(), + AtreeStorageValidationEnabled: false, + Debugger: e.config.Debugger, + OnStatement: e.newOnStatementHandler(), + OnMeterComputation: e.newOnMeterComputation(), + OnFunctionInvocation: e.newOnFunctionInvocationHandler(), + OnInvokedFunctionReturn: e.newOnInvokedFunctionReturnHandler(), + CapabilityBorrowHandler: e.newCapabilityBorrowHandler(), + CapabilityCheckHandler: e.newCapabilityCheckHandler(), + LegacyContractUpgradeEnabled: e.config.LegacyContractUpgradeEnabled, + ContractUpdateTypeRemovalEnabled: e.config.ContractUpdateTypeRemovalEnabled, + ValidateAccountCapabilitiesGetHandler: e.newValidateAccountCapabilitiesGetHandler(), + ValidateAccountCapabilitiesPublishHandler: e.newValidateAccountCapabilitiesPublishHandler(), } } @@ -211,8 +211,6 @@ func (e *interpreterEnvironment) newCheckerConfig() *sema.Config { ImportHandler: e.resolveImport, CheckHandler: e.newCheckHandler(), AttachmentsEnabled: e.config.AttachmentsEnabled, - AttachmentConformancesEnabled: e.config.AttachmentConformancesEnabled, - MemberSiblingTypeOverrideEnabled: e.config.MemberSiblingTypeOverrideEnabled, } } @@ -244,6 +242,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) { @@ -1461,3 +1461,20 @@ func (e *interpreterEnvironment) newValidateAccountCapabilitiesPublishHandler() return ok, err } } + +func (e *interpreterEnvironment) configureVersionedFeatures() { + var currentVersion string + errors.WrapPanic(func() { + currentVersion = e.runtimeInterface.CurrentVersion() + }) + enableOldBehaviour := useV101Behaviour(currentVersion) + + e.CheckerConfig.AttachmentConformancesEnabled = enableOldBehaviour + e.CheckerConfig.MemberSiblingTypeOverrideEnabled = enableOldBehaviour + e.InterpreterConfig.ContractUpdateAttachmentBaseTypeChangeEnabled = enableOldBehaviour +} + +func useV101Behaviour(currentVersion string) bool { + return currentVersion == "" || + semver.Compare(currentVersion, "v1.0.1") <= 0 +} diff --git a/runtime/interface.go b/runtime/interface.go index 9f20ba8f31..ea6ff29b4d 100644 --- a/runtime/interface.go +++ b/runtime/interface.go @@ -161,6 +161,8 @@ type Interface interface { path interpreter.PathValue, capabilityBorrowType *interpreter.ReferenceStaticType, ) (bool, error) + + CurrentVersion() string } type MeterInterface interface { diff --git a/runtime/runtime_test.go b/runtime/runtime_test.go index b5375fb799..f24973db89 100644 --- a/runtime/runtime_test.go +++ b/runtime/runtime_test.go @@ -11497,6 +11497,8 @@ func TestRuntimeBuiltInFunctionConfusion(t *testing.T) { address := common.MustBytesToAddress([]byte{0x1}) + var currentVersion string + newRuntimeInterface := func() Interface { accountCodes := map[common.AddressLocation][]byte{} @@ -11524,17 +11526,19 @@ func TestRuntimeBuiltInFunctionConfusion(t *testing.T) { OnProgramLog: func(message string) { loggedMessages = append(loggedMessages, message) }, + OnCurrentVersion: func() string { + return currentVersion + }, } } + runtime := NewTestInterpreterRuntime() + nextTransactionLocation := NewTransactionLocationGenerator() // Deploy contract without check enabled - err := NewTestInterpreterRuntimeWithConfig(Config{ - AtreeValidationEnabled: true, - MemberSiblingTypeOverrideEnabled: true, - }).ExecuteTransaction( + err := runtime.ExecuteTransaction( Script{ Source: DeploymentTransaction( "Foo", @@ -11550,10 +11554,9 @@ func TestRuntimeBuiltInFunctionConfusion(t *testing.T) { // Deploy contract with check enabled - err = NewTestInterpreterRuntimeWithConfig(Config{ - AtreeValidationEnabled: true, - MemberSiblingTypeOverrideEnabled: false, - }).ExecuteTransaction( + currentVersion = "v1.0.2" + + err = runtime.ExecuteTransaction( Script{ Source: DeploymentTransaction( "Foo", diff --git a/runtime/tests/runtime_utils/testinterface.go b/runtime/tests/runtime_utils/testinterface.go index e387075c54..b2fd4579dc 100644 --- a/runtime/tests/runtime_utils/testinterface.go +++ b/runtime/tests/runtime_utils/testinterface.go @@ -137,6 +137,7 @@ type TestRuntimeInterface struct { path interpreter.PathValue, capabilityBorrowType *interpreter.ReferenceStaticType, ) (bool, error) + OnCurrentVersion func() string lastUUID uint64 accountIDs map[common.Address]uint64 @@ -669,3 +670,10 @@ func (i *TestRuntimeInterface) ValidateAccountCapabilitiesPublish( capabilityBorrowType, ) } + +func (i *TestRuntimeInterface) CurrentVersion() string { + if i.OnCurrentVersion == nil { + return "" + } + return i.OnCurrentVersion() +} From 8ae61ac8bb3d739b9dcdbf6796576b7ecaf1c1ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Wed, 16 Oct 2024 14:14:45 -0700 Subject: [PATCH 59/70] rename new version function --- runtime/contract_update_validation_test.go | 2 +- runtime/empty.go | 4 ++-- runtime/environment.go | 6 +++--- runtime/interface.go | 2 +- runtime/runtime_test.go | 2 +- runtime/tests/runtime_utils/testinterface.go | 8 ++++---- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/runtime/contract_update_validation_test.go b/runtime/contract_update_validation_test.go index 1fc995699b..ce0203ea11 100644 --- a/runtime/contract_update_validation_test.go +++ b/runtime/contract_update_validation_test.go @@ -116,7 +116,7 @@ func newContractDeploymentTransactorWithVersion(t *testing.T, config Config, ver events = append(events, event) return nil }, - OnCurrentVersion: func() string { + OnMinimumRequiredVersion: func() string { return version }, } diff --git a/runtime/empty.go b/runtime/empty.go index 103c318e90..89991e0539 100644 --- a/runtime/empty.go +++ b/runtime/empty.go @@ -261,6 +261,6 @@ func (EmptyRuntimeInterface) ValidateAccountCapabilitiesPublish( panic("unexpected call to ValidateAccountCapabilitiesPublish") } -func (EmptyRuntimeInterface) CurrentVersion() string { - panic("unexpected call to CurrentVersion") +func (EmptyRuntimeInterface) MinimumRequiredVersion() string { + panic("unexpected call to MinimumRequiredVersion") } diff --git a/runtime/environment.go b/runtime/environment.go index 882e3dca71..970bb4387f 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -1463,11 +1463,11 @@ func (e *interpreterEnvironment) newValidateAccountCapabilitiesPublishHandler() } func (e *interpreterEnvironment) configureVersionedFeatures() { - var currentVersion string + var minimumRequiredVersion string errors.WrapPanic(func() { - currentVersion = e.runtimeInterface.CurrentVersion() + minimumRequiredVersion = e.runtimeInterface.MinimumRequiredVersion() }) - enableOldBehaviour := useV101Behaviour(currentVersion) + enableOldBehaviour := useV101Behaviour(minimumRequiredVersion) e.CheckerConfig.AttachmentConformancesEnabled = enableOldBehaviour e.CheckerConfig.MemberSiblingTypeOverrideEnabled = enableOldBehaviour diff --git a/runtime/interface.go b/runtime/interface.go index ea6ff29b4d..f93ae5100a 100644 --- a/runtime/interface.go +++ b/runtime/interface.go @@ -162,7 +162,7 @@ type Interface interface { capabilityBorrowType *interpreter.ReferenceStaticType, ) (bool, error) - CurrentVersion() string + MinimumRequiredVersion() string } type MeterInterface interface { diff --git a/runtime/runtime_test.go b/runtime/runtime_test.go index f24973db89..5a91ab61a7 100644 --- a/runtime/runtime_test.go +++ b/runtime/runtime_test.go @@ -11526,7 +11526,7 @@ func TestRuntimeBuiltInFunctionConfusion(t *testing.T) { OnProgramLog: func(message string) { loggedMessages = append(loggedMessages, message) }, - OnCurrentVersion: func() string { + OnMinimumRequiredVersion: func() string { return currentVersion }, } diff --git a/runtime/tests/runtime_utils/testinterface.go b/runtime/tests/runtime_utils/testinterface.go index b2fd4579dc..6bf9fbc1d5 100644 --- a/runtime/tests/runtime_utils/testinterface.go +++ b/runtime/tests/runtime_utils/testinterface.go @@ -137,7 +137,7 @@ type TestRuntimeInterface struct { path interpreter.PathValue, capabilityBorrowType *interpreter.ReferenceStaticType, ) (bool, error) - OnCurrentVersion func() string + OnMinimumRequiredVersion func() string lastUUID uint64 accountIDs map[common.Address]uint64 @@ -671,9 +671,9 @@ func (i *TestRuntimeInterface) ValidateAccountCapabilitiesPublish( ) } -func (i *TestRuntimeInterface) CurrentVersion() string { - if i.OnCurrentVersion == nil { +func (i *TestRuntimeInterface) MinimumRequiredVersion() string { + if i.OnMinimumRequiredVersion == nil { return "" } - return i.OnCurrentVersion() + return i.OnMinimumRequiredVersion() } From 88dbd9d4cede299bfb567be291a2de7b14ca8e78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Wed, 16 Oct 2024 15:59:08 -0700 Subject: [PATCH 60/70] update to latest version of golang.org/x/crypto --- go.mod | 13 +++++++------ go.sum | 31 ++++++++++++++++--------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index f650c26942..e3b766d7e3 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 2cb1deb2c9..40840eb0bb 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= From 02cd8467ad86e777aea428f8ac4fc523ad23f6ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Wed, 23 Oct 2024 11:12:33 -0700 Subject: [PATCH 61/70] remove feature flags --- runtime/contract_update_validation_test.go | 49 +---------- runtime/environment.go | 12 +-- runtime/interpreter/config.go | 2 - runtime/runtime_test.go | 25 ------ runtime/sema/check_composite_declaration.go | 38 ++++---- runtime/sema/config.go | 4 - runtime/stdlib/account.go | 4 +- ..._v0.42_to_v1_contract_upgrade_validator.go | 11 --- runtime/stdlib/contract_update_validation.go | 56 +++++------- runtime/tests/checker/attachments_test.go | 86 +++---------------- 10 files changed, 55 insertions(+), 232 deletions(-) diff --git a/runtime/contract_update_validation_test.go b/runtime/contract_update_validation_test.go index ce0203ea11..8c6c11eb3c 100644 --- a/runtime/contract_update_validation_test.go +++ b/runtime/contract_update_validation_test.go @@ -3689,7 +3689,7 @@ func TestAttachmentsUpdates(t *testing.T) { t.Parallel() testWithValidators(t, - "Keep base type, v1.0.1", + "Keep base type", func(t *testing.T, config Config) { const oldCode = ` @@ -3704,34 +3704,13 @@ func TestAttachmentsUpdates(t *testing.T) { } ` - err := testDeployAndUpdateWithVersion(t, "Test", oldCode, newCode, config, "v1.0.1") - require.NoError(t, err) - }, - ) - - testWithValidators(t, - "Keep base type, v1.0.2", - 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 := testDeployAndUpdateWithVersion(t, "Test", oldCode, newCode, config, "v1.0.2") + err := testDeployAndUpdate(t, "Test", oldCode, newCode, config) require.NoError(t, err) }, ) testWithValidators(t, - "Change base type, v1.0.1", + "Change base type", func(t *testing.T, config Config) { const oldCode = ` @@ -3746,27 +3725,7 @@ func TestAttachmentsUpdates(t *testing.T) { } ` - err := testDeployAndUpdateWithVersion(t, "Test", oldCode, newCode, config, "v1.0.1") - require.NoError(t, err) - }) - - testWithValidators(t, - "Change base type, v1.0.2", - 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 := testDeployAndUpdateWithVersion(t, "Test", oldCode, newCode, config, "v1.0.2") + err := testDeployAndUpdate(t, "Test", oldCode, newCode, config) var expectedErr *stdlib.TypeMismatchError require.ErrorAs(t, err, &expectedErr) diff --git a/runtime/environment.go b/runtime/environment.go index 970bb4387f..07c30cf23c 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -22,7 +22,6 @@ import ( "time" "go.opentelemetry.io/otel/attribute" - "golang.org/x/mod/semver" "github.com/onflow/cadence" "github.com/onflow/cadence/runtime/activations" @@ -1467,14 +1466,7 @@ func (e *interpreterEnvironment) configureVersionedFeatures() { errors.WrapPanic(func() { minimumRequiredVersion = e.runtimeInterface.MinimumRequiredVersion() }) - enableOldBehaviour := useV101Behaviour(minimumRequiredVersion) - e.CheckerConfig.AttachmentConformancesEnabled = enableOldBehaviour - e.CheckerConfig.MemberSiblingTypeOverrideEnabled = enableOldBehaviour - e.InterpreterConfig.ContractUpdateAttachmentBaseTypeChangeEnabled = enableOldBehaviour -} - -func useV101Behaviour(currentVersion string) bool { - return currentVersion == "" || - semver.Compare(currentVersion, "v1.0.1") <= 0 + // No feature flags yet + _ = minimumRequiredVersion } diff --git a/runtime/interpreter/config.go b/runtime/interpreter/config.go index f64413aef5..dc052342d1 100644 --- a/runtime/interpreter/config.go +++ b/runtime/interpreter/config.go @@ -74,8 +74,6 @@ type Config struct { LegacyContractUpgradeEnabled bool // ContractUpdateTypeRemovalEnabled specifies if type removal is enabled in contract updates ContractUpdateTypeRemovalEnabled bool - // ContractUpdateAttachmentBaseTypeChangeEnabled specifies if attachment base type change is enabled in contract updates - ContractUpdateAttachmentBaseTypeChangeEnabled 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/runtime/runtime_test.go b/runtime/runtime_test.go index 5a91ab61a7..c56c01d102 100644 --- a/runtime/runtime_test.go +++ b/runtime/runtime_test.go @@ -11497,8 +11497,6 @@ func TestRuntimeBuiltInFunctionConfusion(t *testing.T) { address := common.MustBytesToAddress([]byte{0x1}) - var currentVersion string - newRuntimeInterface := func() Interface { accountCodes := map[common.AddressLocation][]byte{} @@ -11526,9 +11524,6 @@ func TestRuntimeBuiltInFunctionConfusion(t *testing.T) { OnProgramLog: func(message string) { loggedMessages = append(loggedMessages, message) }, - OnMinimumRequiredVersion: func() string { - return currentVersion - }, } } @@ -11536,8 +11531,6 @@ func TestRuntimeBuiltInFunctionConfusion(t *testing.T) { nextTransactionLocation := NewTransactionLocationGenerator() - // Deploy contract without check enabled - err := runtime.ExecuteTransaction( Script{ Source: DeploymentTransaction( @@ -11550,24 +11543,6 @@ func TestRuntimeBuiltInFunctionConfusion(t *testing.T) { Location: nextTransactionLocation(), }, ) - require.NoError(t, err) - - // Deploy contract with check enabled - - currentVersion = "v1.0.2" - - err = runtime.ExecuteTransaction( - Script{ - Source: DeploymentTransaction( - "Foo", - []byte(contract), - ), - }, - Context{ - Interface: newRuntimeInterface(), - Location: nextTransactionLocation(), - }, - ) RequireError(t, err) var redeclarationError *sema.RedeclarationError diff --git a/runtime/sema/check_composite_declaration.go b/runtime/sema/check_composite_declaration.go index 75b8c3a8d6..0128333e90 100644 --- a/runtime/sema/check_composite_declaration.go +++ b/runtime/sema/check_composite_declaration.go @@ -687,29 +687,23 @@ func (checker *Checker) declareCompositeType(declaration ast.CompositeLikeDeclar case common.CompositeKindAttachment: - if checker.Config.AttachmentConformancesEnabled { - compositeType.ExplicitInterfaceConformances = - checker.explicitInterfaceConformances(declaration, compositeType) + // Attachments may not conform to interfaces - } else { - // Attachments may not conform to interfaces + conformanceList := declaration.ConformanceList() + conformanceCount := len(conformanceList) + if conformanceCount > 0 { + firstConformance := conformanceList[0] + lastConformance := conformanceList[conformanceCount-1] - 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), - ), - }, - ) - } + checker.report( + &InvalidAttachmentConformancesError{ + Range: ast.NewRange( + checker.memoryGauge, + firstConformance.StartPosition(), + lastConformance.EndPosition(checker.memoryGauge), + ), + }, + ) } default: @@ -1748,7 +1742,7 @@ func (checker *Checker) defaultMembersAndOrigins( } } - if nestedTypes != nil && !checker.Config.MemberSiblingTypeOverrideEnabled { + if nestedTypes != nil { if _, ok := nestedTypes.Get(name); ok { // TODO: provide previous position checker.report( diff --git a/runtime/sema/config.go b/runtime/sema/config.go index c8e72c695e..06f6e9ce95 100644 --- a/runtime/sema/config.go +++ b/runtime/sema/config.go @@ -55,8 +55,4 @@ type Config struct { AllowStaticDeclarations bool // AttachmentsEnabled determines if attachments are enabled AttachmentsEnabled bool - // AttachmentConformancesEnabled determines if attachment conformances are enabled - AttachmentConformancesEnabled bool - // MemberSiblingTypeOverrideEnabled determines if declaring members checks for sibling type declarations - MemberSiblingTypeOverrideEnabled bool } diff --git a/runtime/stdlib/account.go b/runtime/stdlib/account.go index 235dc29e6f..14f20a18d3 100644 --- a/runtime/stdlib/account.go +++ b/runtime/stdlib/account.go @@ -1679,7 +1679,6 @@ func changeAccountContracts( memoryGauge := invocation.Interpreter.SharedState.Config.MemoryGauge legacyUpgradeEnabled := invocation.Interpreter.SharedState.Config.LegacyContractUpgradeEnabled contractUpdateTypeRemovalEnabled := invocation.Interpreter.SharedState.Config.ContractUpdateTypeRemovalEnabled - contractUpdateAttachmentBaseTypeChangeEnabled := invocation.Interpreter.SharedState.Config.ContractUpdateAttachmentBaseTypeChangeEnabled var oldProgram *ast.Program @@ -1733,8 +1732,7 @@ func changeAccountContracts( } validator = validator. - WithTypeRemovalEnabled(contractUpdateTypeRemovalEnabled). - WithAttachmentBaseTypeChangeEnabled(contractUpdateAttachmentBaseTypeChangeEnabled) + WithTypeRemovalEnabled(contractUpdateTypeRemovalEnabled) err = validator.Validate() handleContractUpdateError(err, newCode) diff --git a/runtime/stdlib/cadence_v0.42_to_v1_contract_upgrade_validator.go b/runtime/stdlib/cadence_v0.42_to_v1_contract_upgrade_validator.go index d3fc96209b..838c8ecdc3 100644 --- a/runtime/stdlib/cadence_v0.42_to_v1_contract_upgrade_validator.go +++ b/runtime/stdlib/cadence_v0.42_to_v1_contract_upgrade_validator.go @@ -89,17 +89,6 @@ func (validator *CadenceV042ToV1ContractUpdateValidator) WithTypeRemovalEnabled( return validator } -func (validator *CadenceV042ToV1ContractUpdateValidator) isAttachmentBaseTypeChangeEnabled() bool { - return validator.underlyingUpdateValidator.isAttachmentBaseTypeChangeEnabled() -} - -func (validator *CadenceV042ToV1ContractUpdateValidator) WithAttachmentBaseTypeChangeEnabled( - enabled bool, -) UpdateValidator { - validator.underlyingUpdateValidator.WithAttachmentBaseTypeChangeEnabled(enabled) - return validator -} - func (validator *CadenceV042ToV1ContractUpdateValidator) getCurrentDeclaration() ast.Declaration { return validator.underlyingUpdateValidator.getCurrentDeclaration() } diff --git a/runtime/stdlib/contract_update_validation.go b/runtime/stdlib/contract_update_validation.go index 0113ab439c..00cbad8076 100644 --- a/runtime/stdlib/contract_update_validation.go +++ b/runtime/stdlib/contract_update_validation.go @@ -53,9 +53,6 @@ type UpdateValidator interface { isTypeRemovalEnabled() bool WithTypeRemovalEnabled(enabled bool) UpdateValidator - - isAttachmentBaseTypeChangeEnabled() bool - WithAttachmentBaseTypeChangeEnabled(enabled bool) UpdateValidator } type checkConformanceFunc func( @@ -66,16 +63,15 @@ type checkConformanceFunc func( type ContractUpdateValidator struct { *TypeComparator - location common.Location - contractName string - oldProgram *ast.Program - newProgram *ast.Program - currentDecl ast.Declaration - importLocations map[ast.Identifier]common.Location - accountContractNamesProvider AccountContractNamesProvider - errors []error - typeRemovalEnabled bool - attachmentBaseTypeChangeEnabled bool + location common.Location + contractName string + oldProgram *ast.Program + newProgram *ast.Program + currentDecl ast.Declaration + importLocations map[ast.Identifier]common.Location + accountContractNamesProvider AccountContractNamesProvider + errors []error + typeRemovalEnabled bool } // ContractUpdateValidator should implement ast.TypeEqualityChecker @@ -112,15 +108,6 @@ func (validator *ContractUpdateValidator) WithTypeRemovalEnabled(enabled bool) U return validator } -func (validator *ContractUpdateValidator) isAttachmentBaseTypeChangeEnabled() bool { - return validator.attachmentBaseTypeChangeEnabled -} - -func (validator *ContractUpdateValidator) WithAttachmentBaseTypeChangeEnabled(enabled bool) UpdateValidator { - validator.attachmentBaseTypeChangeEnabled = enabled - return validator -} - func (validator *ContractUpdateValidator) getCurrentDeclaration() ast.Declaration { return validator.currentDecl } @@ -322,21 +309,18 @@ func checkDeclarationUpdatability( } } - if !validator.isAttachmentBaseTypeChangeEnabled() { - - // Check if the base type of the attachment has changed. - if oldAttachment, ok := oldDeclaration.(*ast.AttachmentDeclaration); ok && - oldAttachment.DeclarationKind() == common.DeclarationKindAttachment { + // 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) - } + // 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) } } } diff --git a/runtime/tests/checker/attachments_test.go b/runtime/tests/checker/attachments_test.go index 6a890e0124..b1d6c7f646 100644 --- a/runtime/tests/checker/attachments_test.go +++ b/runtime/tests/checker/attachments_test.go @@ -623,96 +623,34 @@ func TestCheckInvalidAttachmentConformance(t *testing.T) { t.Parallel() - t.Run("struct, enabled", func(t *testing.T) { - - t.Parallel() - - _, err := ParseAndCheckWithOptions(t, - ` - struct S {} - - struct interface SI {} - - attachment Test for S: SI {} - `, - ParseAndCheckOptions{ - Config: &sema.Config{ - AttachmentsEnabled: true, - AttachmentConformancesEnabled: true, - }, - }, - ) - - require.NoError(t, err) - }) - - t.Run("struct, disabled", func(t *testing.T) { + t.Run("struct", func(t *testing.T) { t.Parallel() - _, err := ParseAndCheckWithOptions(t, - ` - struct S {} + _, err := ParseAndCheck(t, ` + struct S {} - struct interface SI {} + struct interface SI {} - attachment Test for S: SI {} - `, - ParseAndCheckOptions{ - Config: &sema.Config{ - AttachmentsEnabled: true, - AttachmentConformancesEnabled: false, - }, - }, - ) + attachment Test for S: SI {} + `) errs := RequireCheckerErrors(t, err, 1) assert.IsType(t, &sema.InvalidAttachmentConformancesError{}, errs[0]) }) - t.Run("resource, enabled", func(t *testing.T) { - - t.Parallel() - - _, err := ParseAndCheckWithOptions(t, - ` - resource R {} - - resource interface RI {} - - attachment Test for R: RI {} - `, - ParseAndCheckOptions{ - Config: &sema.Config{ - AttachmentsEnabled: true, - AttachmentConformancesEnabled: true, - }, - }, - ) - - require.NoError(t, err) - }) - - t.Run("resource, disabled", func(t *testing.T) { + t.Run("resource", func(t *testing.T) { t.Parallel() - _, err := ParseAndCheckWithOptions(t, - ` - resource R {} + _, err := ParseAndCheck(t, ` + resource R {} - resource interface RI {} + resource interface RI {} - attachment Test for R: RI {} - `, - ParseAndCheckOptions{ - Config: &sema.Config{ - AttachmentsEnabled: true, - AttachmentConformancesEnabled: false, - }, - }, - ) + attachment Test for R: RI {} + `) errs := RequireCheckerErrors(t, err, 1) From e996077a4d5d57a4526ea98b5a5521e0715d6810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Fri, 25 Oct 2024 16:15:00 -0700 Subject: [PATCH 62/70] add error return value to MinimumRequiredVersion interface function --- runtime/contract_update_validation_test.go | 4 ++-- runtime/empty.go | 2 +- runtime/environment.go | 10 ++++++++-- runtime/interface.go | 2 +- runtime/tests/runtime_utils/testinterface.go | 6 +++--- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/runtime/contract_update_validation_test.go b/runtime/contract_update_validation_test.go index 8c6c11eb3c..2a1cd279a8 100644 --- a/runtime/contract_update_validation_test.go +++ b/runtime/contract_update_validation_test.go @@ -116,8 +116,8 @@ func newContractDeploymentTransactorWithVersion(t *testing.T, config Config, ver events = append(events, event) return nil }, - OnMinimumRequiredVersion: func() string { - return version + OnMinimumRequiredVersion: func() (string, error) { + return version, nil }, } diff --git a/runtime/empty.go b/runtime/empty.go index 89991e0539..4e9c2b58b5 100644 --- a/runtime/empty.go +++ b/runtime/empty.go @@ -261,6 +261,6 @@ func (EmptyRuntimeInterface) ValidateAccountCapabilitiesPublish( panic("unexpected call to ValidateAccountCapabilitiesPublish") } -func (EmptyRuntimeInterface) MinimumRequiredVersion() string { +func (EmptyRuntimeInterface) MinimumRequiredVersion() (string, error) { panic("unexpected call to MinimumRequiredVersion") } diff --git a/runtime/environment.go b/runtime/environment.go index 07c30cf23c..f2607eb5bd 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -1462,10 +1462,16 @@ func (e *interpreterEnvironment) newValidateAccountCapabilitiesPublishHandler() } func (e *interpreterEnvironment) configureVersionedFeatures() { - var minimumRequiredVersion string + var ( + minimumRequiredVersion string + err error + ) errors.WrapPanic(func() { - minimumRequiredVersion = e.runtimeInterface.MinimumRequiredVersion() + minimumRequiredVersion, err = e.runtimeInterface.MinimumRequiredVersion() }) + if err != nil { + panic(err) + } // No feature flags yet _ = minimumRequiredVersion diff --git a/runtime/interface.go b/runtime/interface.go index f93ae5100a..d5bcad7b7c 100644 --- a/runtime/interface.go +++ b/runtime/interface.go @@ -162,7 +162,7 @@ type Interface interface { capabilityBorrowType *interpreter.ReferenceStaticType, ) (bool, error) - MinimumRequiredVersion() string + MinimumRequiredVersion() (string, error) } type MeterInterface interface { diff --git a/runtime/tests/runtime_utils/testinterface.go b/runtime/tests/runtime_utils/testinterface.go index 6bf9fbc1d5..b3ff850e03 100644 --- a/runtime/tests/runtime_utils/testinterface.go +++ b/runtime/tests/runtime_utils/testinterface.go @@ -137,7 +137,7 @@ type TestRuntimeInterface struct { path interpreter.PathValue, capabilityBorrowType *interpreter.ReferenceStaticType, ) (bool, error) - OnMinimumRequiredVersion func() string + OnMinimumRequiredVersion func() (string, error) lastUUID uint64 accountIDs map[common.Address]uint64 @@ -671,9 +671,9 @@ func (i *TestRuntimeInterface) ValidateAccountCapabilitiesPublish( ) } -func (i *TestRuntimeInterface) MinimumRequiredVersion() string { +func (i *TestRuntimeInterface) MinimumRequiredVersion() (string, error) { if i.OnMinimumRequiredVersion == nil { - return "" + return "", nil } return i.OnMinimumRequiredVersion() } From ee9735518ea0c0fbfd2b0fb01294c42bcfd815c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 28 Oct 2024 08:15:07 -0700 Subject: [PATCH 63/70] make EmptyRuntimeInterface.MinimumRequiredVersion a no-op --- runtime/empty.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/empty.go b/runtime/empty.go index 4e9c2b58b5..19c6f089e4 100644 --- a/runtime/empty.go +++ b/runtime/empty.go @@ -262,5 +262,5 @@ func (EmptyRuntimeInterface) ValidateAccountCapabilitiesPublish( } func (EmptyRuntimeInterface) MinimumRequiredVersion() (string, error) { - panic("unexpected call to MinimumRequiredVersion") + return "", nil } From bc01ae190d6124c4903b9f3234cec70da18f9fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 28 Oct 2024 08:19:02 -0700 Subject: [PATCH 64/70] return a valid semver --- runtime/empty.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/empty.go b/runtime/empty.go index 19c6f089e4..8aedf0a7fe 100644 --- a/runtime/empty.go +++ b/runtime/empty.go @@ -262,5 +262,5 @@ func (EmptyRuntimeInterface) ValidateAccountCapabilitiesPublish( } func (EmptyRuntimeInterface) MinimumRequiredVersion() (string, error) { - return "", nil + return "0.0.0", nil } From 2c239a7166456c4eb8668b0258f67d4cf2fc72fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Wed, 30 Oct 2024 09:45:42 -0700 Subject: [PATCH 65/70] go mod tidy --- tools/compatibility-check/go.mod | 10 +- tools/compatibility-check/go.sum | 219 ++++++++++++++++++++++++------- 2 files changed, 175 insertions(+), 54 deletions(-) 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= From 95f7dbd306420fc8b4888f5f7db5737f9b4b2a76 Mon Sep 17 00:00:00 2001 From: Supun Setunga Date: Wed, 30 Oct 2024 11:58:39 -0700 Subject: [PATCH 66/70] Enable type removal during contract updates --- interpreter/config.go | 2 - runtime/config.go | 2 - runtime/contract_update_validation_test.go | 135 ++++-------------- runtime/environment.go | 1 - stdlib/account.go | 3 - ..._v0.42_to_v1_contract_upgrade_validator.go | 11 -- stdlib/contract_update_validation.go | 80 ++++------- 7 files changed, 57 insertions(+), 177 deletions(-) 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/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/runtime/contract_update_validation_test.go b/runtime/contract_update_validation_test.go index 74afc1c447..b4dd71def7 100644 --- a/runtime/contract_update_validation_test.go +++ b/runtime/contract_update_validation_test.go @@ -177,31 +177,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 +3213,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 +3240,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 +3286,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 +3310,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 +3331,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 +3352,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 +3374,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 +3397,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 +3466,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 +3508,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 +3531,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 +3554,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) }, ) diff --git a/runtime/environment.go b/runtime/environment.go index ef3d0130d6..d3624998a9 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(), } diff --git a/stdlib/account.go b/stdlib/account.go index 66907a6f93..97a8e4d0f3 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/cadence_v0.42_to_v1_contract_upgrade_validator.go b/stdlib/cadence_v0.42_to_v1_contract_upgrade_validator.go index 7b13c6491b..921f0d1034 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() } diff --git a/stdlib/contract_update_validation.go b/stdlib/contract_update_validation.go index 71e958f84e..82300d662b 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 } @@ -412,12 +399,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 +428,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, @@ -463,33 +444,32 @@ func checkNestedDeclarations( ) { 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, - ) - - // #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, - }) - } - }) - } + + // 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, + ) + + // #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) From f642b8e24632eea3ac6cc94815cc1c4ce4122221 Mon Sep 17 00:00:00 2001 From: Supun Setunga Date: Wed, 30 Oct 2024 12:03:54 -0700 Subject: [PATCH 67/70] Fix tests --- parser/expression_test.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/parser/expression_test.go b/parser/expression_test.go index 92006a1914..172884de18 100644 --- a/parser/expression_test.go +++ b/parser/expression_test.go @@ -6082,7 +6082,7 @@ func TestParseStringTemplate(t *testing.T) { }, } - utils.AssertEqualWithDiff(t, expected, actual) + AssertEqualWithDiff(t, expected, actual) }) t.Run("multi", func(t *testing.T) { @@ -6128,7 +6128,7 @@ func TestParseStringTemplate(t *testing.T) { }, } - utils.AssertEqualWithDiff(t, expected, actual) + AssertEqualWithDiff(t, expected, actual) }) t.Run("missing end", func(t *testing.T) { @@ -6147,7 +6147,7 @@ func TestParseStringTemplate(t *testing.T) { } require.Error(t, err) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid end of string literal: missing '\"'", @@ -6174,7 +6174,7 @@ func TestParseStringTemplate(t *testing.T) { } require.Error(t, err) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token in expression: '.'", @@ -6201,7 +6201,7 @@ func TestParseStringTemplate(t *testing.T) { } require.Error(t, err) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected identifier got: 2 + 2", @@ -6248,7 +6248,7 @@ func TestParseStringTemplate(t *testing.T) { }, } - utils.AssertEqualWithDiff(t, expected, actual) + AssertEqualWithDiff(t, expected, actual) }) t.Run("invalid, empty", func(t *testing.T) { @@ -6267,7 +6267,7 @@ func TestParseStringTemplate(t *testing.T) { } require.Error(t, err) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token in expression: ')'", @@ -6294,7 +6294,7 @@ func TestParseStringTemplate(t *testing.T) { } require.Error(t, err) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected identifier got: add()", @@ -6321,7 +6321,7 @@ func TestParseStringTemplate(t *testing.T) { } require.Error(t, err) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token ')'", @@ -6348,7 +6348,7 @@ func TestParseStringTemplate(t *testing.T) { } require.Error(t, err) - utils.AssertEqualWithDiff(t, + AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token ')'", @@ -6395,7 +6395,7 @@ func TestParseStringTemplate(t *testing.T) { }, } - utils.AssertEqualWithDiff(t, expected, actual) + AssertEqualWithDiff(t, expected, actual) }) t.Run("valid, surrounded", func(t *testing.T) { @@ -6441,7 +6441,7 @@ func TestParseStringTemplate(t *testing.T) { }, } - utils.AssertEqualWithDiff(t, expected, actual) + AssertEqualWithDiff(t, expected, actual) }) t.Run("valid, adjacent", func(t *testing.T) { @@ -6494,7 +6494,7 @@ func TestParseStringTemplate(t *testing.T) { }, } - utils.AssertEqualWithDiff(t, expected, actual) + AssertEqualWithDiff(t, expected, actual) }) } From e57db6a87f22bfb82552bbbfb3b714408d1e373d Mon Sep 17 00:00:00 2001 From: turbolent Date: Wed, 30 Oct 2024 19:21:24 +0000 Subject: [PATCH 68/70] v1.2.2 --- npm-packages/cadence-parser/package.json | 2 +- version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/npm-packages/cadence-parser/package.json b/npm-packages/cadence-parser/package.json index 787f0ba9ea..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", + "version": "1.2.2", "description": "The Cadence parser", "homepage": "https://github.com/onflow/cadence", "repository": { 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" From 247a13d3eabdbe98af126ef762fbf527caeca4a7 Mon Sep 17 00:00:00 2001 From: Supun Setunga Date: Wed, 30 Oct 2024 12:45:58 -0700 Subject: [PATCH 69/70] Refactor and fix struct string tests --- .../stringer_test.go => interpreter/struct_stringer_test.go | 2 +- tests/checker/stringer_test.go => sema/struct_stringer_test.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) rename tests/interpreter/stringer_test.go => interpreter/struct_stringer_test.go (97%) rename tests/checker/stringer_test.go => sema/struct_stringer_test.go (96%) diff --git a/tests/interpreter/stringer_test.go b/interpreter/struct_stringer_test.go similarity index 97% rename from tests/interpreter/stringer_test.go rename to interpreter/struct_stringer_test.go index d01acd5b43..d81ea4e7a4 100644 --- a/tests/interpreter/stringer_test.go +++ b/interpreter/struct_stringer_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/interpreter_utils" ) func TestStringerBasic(t *testing.T) { diff --git a/tests/checker/stringer_test.go b/sema/struct_stringer_test.go similarity index 96% rename from tests/checker/stringer_test.go rename to sema/struct_stringer_test.go index 0939eb76fc..119f25471d 100644 --- a/tests/checker/stringer_test.go +++ b/sema/struct_stringer_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 TestCheckStringer(t *testing.T) { From db6236f7b04c3ea99fe83187b8d0b75105e6b774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Wed, 30 Oct 2024 15:34:20 -0700 Subject: [PATCH 70/70] add a GitHub Action to get all contracts --- .../compatibility-check-template.yml | 1 + .github/workflows/get-contracts.yml | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 .github/workflows/get-contracts.yml 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