Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for migrating reference to optional type #3123

Merged
merged 3 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions migrations/entitlements/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,13 +540,45 @@ func TestConvertToEntitledType(t *testing.T) {
Output: sema.NewReferenceType(
nil,
eFAndGAccess,
sema.NewIntersectionType(nil, []*sema.InterfaceType{
interfaceTypeInheriting,
interfaceTypeWithMap,
}),
sema.NewIntersectionType(
nil,
[]*sema.InterfaceType{
interfaceTypeInheriting,
interfaceTypeWithMap,
}),
),
Name: "intersection",
},
{
Input: sema.NewReferenceType(
nil,
sema.UnauthorizedAccess,
sema.NewOptionalType(
nil,
sema.NewIntersectionType(
nil,
[]*sema.InterfaceType{
interfaceTypeInheriting,
interfaceTypeWithMap,
},
),
),
),
Output: sema.NewReferenceType(
nil,
eFAndGAccess,
sema.NewOptionalType(
nil,
sema.NewIntersectionType(
nil,
[]*sema.InterfaceType{
interfaceTypeInheriting,
interfaceTypeWithMap,
}),
),
),
Name: "reference to optional",
},
// no change
{
Input: sema.NewReferenceType(nil, sema.UnauthorizedAccess, compositeTypeWithCapField),
Expand Down
20 changes: 20 additions & 0 deletions migrations/statictypes/account_type_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,26 @@ func TestAccountTypeInTypeValueMigration(t *testing.T) {
),
expectedType: nil,
},

// reference to optionals
"reference_to_optional": {
storedType: interpreter.NewReferenceStaticType(
nil,
interpreter.UnauthorizedAccess,
interpreter.NewOptionalStaticType(
nil,
interpreter.PrimitiveStaticTypeAccountKey, //nolint:staticcheck
),
),
expectedType: interpreter.NewReferenceStaticType(
nil,
interpreter.UnauthorizedAccess,
interpreter.NewOptionalStaticType(
nil,
interpreter.AccountKeyStaticType,
),
),
},
}

test := func(name string, testCase testCase) {
Expand Down
17 changes: 15 additions & 2 deletions migrations/statictypes/composite_type_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestCompositeAndInterfaceTypeMigration(t *testing.T) {

testCases := map[string]testCase{
// base cases
"compositeToInterface": {
"composite_to_interface": {
storedType: newCompositeType(),
expectedType: interpreter.NewIntersectionStaticType(
nil,
Expand All @@ -80,7 +80,7 @@ func TestCompositeAndInterfaceTypeMigration(t *testing.T) {
},
),
},
"interfaceToComposite": {
"interface_to_composite": {
storedType: newInterfaceType(),
expectedType: newCompositeType(),
},
Expand All @@ -99,6 +99,19 @@ func TestCompositeAndInterfaceTypeMigration(t *testing.T) {
storedType: interpreter.NewDictionaryStaticType(nil, newInterfaceType(), newInterfaceType()),
expectedType: interpreter.NewDictionaryStaticType(nil, newCompositeType(), newCompositeType()),
},
// reference to optional
"reference_to_optional": {
storedType: interpreter.NewReferenceStaticType(
nil,
interpreter.UnauthorizedAccess,
interpreter.NewOptionalStaticType(nil, newInterfaceType()),
),
expectedType: interpreter.NewReferenceStaticType(
nil,
interpreter.UnauthorizedAccess,
interpreter.NewOptionalStaticType(nil, newCompositeType()),
),
},
}

// Store values
Expand Down
4 changes: 2 additions & 2 deletions tools/update/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ repos:
- onflow/flow-emulator
- onflow/cadence-tools/lint
- onflow/cadence-tools/test
- onflow/flowkit
- onflow/flowkit/v2

- repo: onflow/flixkit-go
needsRelease: true
Expand All @@ -103,4 +103,4 @@ repos:
- onflow/cadence-tools/lint
- onflow/cadence-tools/languageserver
- onflow/flixkit-go
- onflow/flowkit
- onflow/flowkit/v2
Loading