Skip to content

Commit

Permalink
Merge pull request #3123 from onflow/supun/optional-references-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent authored Feb 22, 2024
2 parents 8302607 + ba7e21c commit 31cdc20
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 6 deletions.
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

0 comments on commit 31cdc20

Please sign in to comment.