Skip to content

Commit

Permalink
add support for migrating path capability values in entitlements and …
Browse files Browse the repository at this point in the history
…static type migrations
  • Loading branch information
turbolent committed Feb 6, 2024
1 parent 55925d1 commit 9cf31dc
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
15 changes: 15 additions & 0 deletions migrations/entitlements/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,21 @@ func ConvertValueToEntitlements(
capabilityStaticType,
), nil

case *interpreter.PathCapabilityValue: //nolint:staticcheck
semaType := inter.MustConvertStaticToSemaType(staticType)
entitledType, converted := ConvertToEntitledType(semaType)
if !converted {
return nil, nil
}

Check warning on line 306 in migrations/entitlements/migration.go

View check run for this annotation

Codecov / codecov/patch

migrations/entitlements/migration.go#L305-L306

Added lines #L305 - L306 were not covered by tests

entitledCapabilityValue := entitledType.(*sema.CapabilityType)
capabilityStaticType := interpreter.ConvertSemaToStaticType(inter, entitledCapabilityValue.BorrowType)
return &interpreter.PathCapabilityValue{ //nolint:staticcheck
Path: v.Path,
Address: v.Address,
BorrowType: capabilityStaticType,
}, nil

case interpreter.TypeValue:
if v.Type == nil {
return nil, nil
Expand Down
13 changes: 13 additions & 0 deletions migrations/entitlements/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,19 @@ func TestConvertToEntitledValue(t *testing.T) {
),
Name: "Capability<&S>",
},
{
Input: &interpreter.PathCapabilityValue{

Check failure on line 1032 in migrations/entitlements/migration_test.go

View workflow job for this annotation

GitHub Actions / Lint

SA1019: interpreter.PathCapabilityValue is deprecated: PathCapabilityValue (staticcheck)

Check failure on line 1032 in migrations/entitlements/migration_test.go

View workflow job for this annotation

GitHub Actions / Lint

SA1019: interpreter.PathCapabilityValue is deprecated: PathCapabilityValue (staticcheck)
Address: interpreter.NewAddressValue(inter, testAddress),
Path: testPathValue,
BorrowType: unentitledSRefStaticType,
},
Output: &interpreter.PathCapabilityValue{

Check failure on line 1037 in migrations/entitlements/migration_test.go

View workflow job for this annotation

GitHub Actions / Lint

SA1019: interpreter.PathCapabilityValue is deprecated: PathCapabilityValue (staticcheck)

Check failure on line 1037 in migrations/entitlements/migration_test.go

View workflow job for this annotation

GitHub Actions / Lint

SA1019: interpreter.PathCapabilityValue is deprecated: PathCapabilityValue (staticcheck)
Address: interpreter.NewAddressValue(inter, testAddress),
Path: testPathValue,
BorrowType: entitledSRefStaticType,
},
Name: "PathCapability<&S>",
},
{
Input: interpreter.NewCapabilityValue(
inter,
Expand Down
12 changes: 12 additions & 0 deletions migrations/statictypes/account_type_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,18 @@ func TestMigratingValuesWithAccountStaticType(t *testing.T) {
storedValue: interpreter.AccountLinkValue{}, //nolint:staticcheck
expectedValue: interpreter.AccountLinkValue{}, //nolint:staticcheck
},
"path_capability_value": {
storedValue: &interpreter.PathCapabilityValue{

Check failure on line 839 in migrations/statictypes/account_type_migration_test.go

View workflow job for this annotation

GitHub Actions / Lint

SA1019: interpreter.PathCapabilityValue is deprecated: PathCapabilityValue (staticcheck)

Check failure on line 839 in migrations/statictypes/account_type_migration_test.go

View workflow job for this annotation

GitHub Actions / Lint

SA1019: interpreter.PathCapabilityValue is deprecated: PathCapabilityValue (staticcheck)
Address: interpreter.NewAddressValue(nil, common.Address{0x42}),
Path: interpreter.NewUnmeteredPathValue(common.PathDomainStorage, "v1"),
BorrowType: interpreter.PrimitiveStaticTypePublicAccount, //nolint:staticcheck
},
expectedValue: &interpreter.PathCapabilityValue{

Check failure on line 844 in migrations/statictypes/account_type_migration_test.go

View workflow job for this annotation

GitHub Actions / Lint

SA1019: interpreter.PathCapabilityValue is deprecated: PathCapabilityValue (staticcheck)

Check failure on line 844 in migrations/statictypes/account_type_migration_test.go

View workflow job for this annotation

GitHub Actions / Lint

SA1019: interpreter.PathCapabilityValue is deprecated: PathCapabilityValue (staticcheck)
Address: interpreter.NewAddressValue(nil, common.Address{0x42}),
Path: interpreter.NewUnmeteredPathValue(common.PathDomainStorage, "v1"),
BorrowType: unauthorizedAccountReferenceType,
},
},
}

// Store values
Expand Down
11 changes: 11 additions & 0 deletions migrations/statictypes/statictype_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ func (m *StaticTypeMigration) Migrate(
}
return interpreter.NewUnmeteredCapabilityValue(value.ID, value.Address, convertedBorrowType), nil

case *interpreter.PathCapabilityValue: //nolint:staticcheck
convertedBorrowType := m.maybeConvertStaticType(value.BorrowType)
if convertedBorrowType == nil {
return
}

Check warning on line 84 in migrations/statictypes/statictype_migration.go

View check run for this annotation

Codecov / codecov/patch

migrations/statictypes/statictype_migration.go#L83-L84

Added lines #L83 - L84 were not covered by tests
return &interpreter.PathCapabilityValue{

Check failure on line 85 in migrations/statictypes/statictype_migration.go

View workflow job for this annotation

GitHub Actions / Lint

SA1019: interpreter.PathCapabilityValue is deprecated: PathCapabilityValue (staticcheck)

Check failure on line 85 in migrations/statictypes/statictype_migration.go

View workflow job for this annotation

GitHub Actions / Lint

SA1019: interpreter.PathCapabilityValue is deprecated: PathCapabilityValue (staticcheck)
BorrowType: convertedBorrowType,
Path: value.Path,
Address: value.Address,
}, nil

case interpreter.PathLinkValue: //nolint:staticcheck
convertedBorrowType := m.maybeConvertStaticType(value.Type)
if convertedBorrowType == nil {
Expand Down
8 changes: 6 additions & 2 deletions runtime/interpreter/value_pathcapability.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,12 @@ func (v *PathCapabilityValue) Transfer(
return v
}

func (v *PathCapabilityValue) Clone(_ *Interpreter) Value {
panic(errors.NewUnreachableError())
func (v *PathCapabilityValue) Clone(interpreter *Interpreter) Value {
return &PathCapabilityValue{
BorrowType: v.BorrowType,
Path: v.Path.Clone(interpreter).(PathValue),
Address: v.Address.Clone(interpreter).(AddressValue),
}
}

func (v *PathCapabilityValue) DeepRemove(interpreter *Interpreter) {
Expand Down

0 comments on commit 9cf31dc

Please sign in to comment.