Skip to content

Commit

Permalink
Merge pull request #3337 from onflow/bastian/3336-fix-missing-interfa…
Browse files Browse the repository at this point in the history
…ce-crasher
  • Loading branch information
turbolent authored May 13, 2024
2 parents 850c2db + b1700d5 commit f02a00f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2788,3 +2788,54 @@ func TestContractUpgradeIsRepresentable(t *testing.T) {
test(true)
test(false)
}

func TestContractUpgrade(t *testing.T) {

t.Parallel()

const oldCode = `
access(all)
contract Test {
access(all)
resource A {
access(self)
// NOTE: undefined type
let cap: Capability<&B{Undefined}>
}
access(all)
resource B {}
}
`

const newCode = `
access(all)
contract Test {
access(all)
entitlement E
access(all)
resource A {
access(self)
let cap: Capability<auth(E) &B>
init(cap: Capability<auth(E) &B>) {
self.cap = cap
}
}
access(all)
resource B {}
}
`

err := testContractUpdate(t, oldCode, newCode)
require.Error(t, err)

cause := getSingleContractUpdateErrorCause(t, err, "Test")
assertFieldAuthorizationMismatchError(t, cause, "A", "cap", "all", "E")
}
12 changes: 10 additions & 2 deletions runtime/stdlib/cadence_v0.42_to_v1_contract_upgrade_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,12 @@ func (validator *CadenceV042ToV1ContractUpdateValidator) getInterfaceType(intf *
func (validator *CadenceV042ToV1ContractUpdateValidator) getIntersectedInterfaces(
intersection []*ast.NominalType,
) (interfaceTypes []*sema.InterfaceType) {
for _, interfaceType := range intersection {
interfaceTypes = append(interfaceTypes, validator.getInterfaceType(interfaceType))
for _, astInterfaceType := range intersection {
interfaceType := validator.getInterfaceType(astInterfaceType)
if interfaceType == nil {
continue
}
interfaceTypes = append(interfaceTypes, interfaceType)
}
return
}
Expand Down Expand Up @@ -289,6 +293,10 @@ func (validator *CadenceV042ToV1ContractUpdateValidator) expectedAuthorizationOf
// been a restricted type with no legacy type
interfaces := validator.getIntersectedInterfaces(intersectionTypes)

if len(interfaces) == 0 {
return sema.UnauthorizedAccess
}

intersectionType := sema.NewIntersectionType(nil, nil, interfaces)

return intersectionType.SupportedEntitlements().Access()
Expand Down

0 comments on commit f02a00f

Please sign in to comment.