Skip to content

Commit

Permalink
Merge pull request #3524 from onflow/supun/improve-reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent authored Aug 13, 2024
2 parents 3625dbe + 0f12301 commit c0b6ebb
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 27 deletions.
4 changes: 2 additions & 2 deletions migrations/capcons/capabilitymigration.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type CapabilityMigrationReporter interface {
addressPath interpreter.AddressPath,
)
MissingBorrowType(
accountAddress common.Address,
addressPath interpreter.AddressPath,
targetPath interpreter.AddressPath,
storedPath interpreter.AddressPath,
)
}

Expand Down
66 changes: 47 additions & 19 deletions migrations/capcons/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ type testStorageCapConIssued struct {
}

type testStorageCapConsMissingBorrowType struct {
accountAddress common.Address
addressPath interpreter.AddressPath
targetPath interpreter.AddressPath
storedPath interpreter.AddressPath
}

type testStorageCapConsInferredBorrowType struct {
accountAddress common.Address
addressPath interpreter.AddressPath
borrowType *interpreter.ReferenceStaticType
targetPath interpreter.AddressPath
borrowType *interpreter.ReferenceStaticType
storedPath interpreter.AddressPath
}

type testMigration struct {
Expand Down Expand Up @@ -195,29 +195,29 @@ func (t *testMigrationReporter) MissingCapabilityID(
}

func (t *testMigrationReporter) MissingBorrowType(
accountAddress common.Address,
addressPath interpreter.AddressPath,
targetPath interpreter.AddressPath,
storedPath interpreter.AddressPath,
) {
t.missingStorageCapConBorrowTypes = append(
t.missingStorageCapConBorrowTypes,
testStorageCapConsMissingBorrowType{
accountAddress: accountAddress,
addressPath: addressPath,
targetPath: targetPath,
storedPath: storedPath,
},
)
}

func (t *testMigrationReporter) InferredMissingBorrowType(
accountAddress common.Address,
addressPath interpreter.AddressPath,
targetPath interpreter.AddressPath,
borrowType *interpreter.ReferenceStaticType,
storedPath interpreter.AddressPath,
) {
t.inferredStorageCapConBorrowTypes = append(
t.inferredStorageCapConBorrowTypes,
testStorageCapConsInferredBorrowType{
accountAddress: accountAddress,
addressPath: addressPath,
borrowType: borrowType,
targetPath: targetPath,
borrowType: borrowType,
storedPath: storedPath,
},
)
}
Expand Down Expand Up @@ -3390,7 +3390,23 @@ func TestUntypedStorageCapMigration(t *testing.T) {

require.Empty(t, reporter.errors)
require.Empty(t, reporter.missingCapabilityIDs)
require.Empty(t, reporter.missingStorageCapConBorrowTypes)

require.Equal(
t,
[]testStorageCapConsMissingBorrowType{
{
targetPath: testAddressPath,
storedPath: interpreter.AddressPath{
Address: testAddress,
Path: interpreter.PathValue{
Domain: common.PathDomainStorage,
Identifier: "cap",
},
},
},
},
reporter.missingStorageCapConBorrowTypes,
)

require.Equal(
t,
Expand All @@ -3413,13 +3429,19 @@ func TestUntypedStorageCapMigration(t *testing.T) {
t,
[]testStorageCapConsInferredBorrowType{
{
accountAddress: testAddress,
addressPath: testAddressPath,
targetPath: testAddressPath,
borrowType: interpreter.NewReferenceStaticType(
nil,
inferredAuth,
interpreter.PrimitiveStaticTypeString,
),
storedPath: interpreter.AddressPath{
Address: testAddress,
Path: interpreter.PathValue{
Identifier: "cap",
Domain: common.PathDomainStorage,
},
},
},
},
reporter.inferredStorageCapConBorrowTypes,
Expand Down Expand Up @@ -3632,11 +3654,17 @@ func TestUntypedStorageCapWithMissingTargetMigration(t *testing.T) {
t,
[]testStorageCapConsMissingBorrowType{
{
accountAddress: addressA,
addressPath: interpreter.AddressPath{
targetPath: interpreter.AddressPath{
Address: addressA,
Path: targetPath,
},
storedPath: interpreter.AddressPath{
Address: testAddress,
Path: interpreter.PathValue{
Identifier: "cap",
Domain: common.PathDomainStorage,
},
},
},
},
reporter.missingStorageCapConBorrowTypes,
Expand Down
26 changes: 20 additions & 6 deletions migrations/capcons/storagecapmigration.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (

type StorageCapabilityMigrationReporter interface {
MissingBorrowType(
accountAddress common.Address,
addressPath interpreter.AddressPath,
targetPath interpreter.AddressPath,
storedPath interpreter.AddressPath,
)
IssuedStorageCapabilityController(
accountAddress common.Address,
Expand All @@ -38,9 +38,9 @@ type StorageCapabilityMigrationReporter interface {
capabilityID interpreter.UInt64Value,
)
InferredMissingBorrowType(
accountAddress common.Address,
addressPath interpreter.AddressPath,
targetPath interpreter.AddressPath,
borrowType *interpreter.ReferenceStaticType,
storedPath interpreter.AddressPath,
)
}

Expand Down Expand Up @@ -129,6 +129,17 @@ func IssueAccountCapabilities(
borrowType = capabilityBorrowType.(*interpreter.ReferenceStaticType)

} else {
targetPath := interpreter.AddressPath{
Address: address,
Path: interpreter.PathValue{
Identifier: capability.StoredPath.Path,
Domain: common.PathDomainFromIdentifier(capability.StoredPath.Domain),
},
}

// Report for all caps with missing borrow type.
reporter.MissingBorrowType(addressPath, targetPath)

if _, _, ok := untypedCapabilityMapping.Get(addressPath); ok {
continue
}
Expand All @@ -140,7 +151,6 @@ func IssueAccountCapabilities(
// However, if there is no value at the target,
//it is not possible to migrate this cap.
if value == nil {
reporter.MissingBorrowType(address, addressPath)
continue
}

Expand All @@ -152,7 +162,11 @@ func IssueAccountCapabilities(
valueType,
)

reporter.InferredMissingBorrowType(address, addressPath, borrowType)
reporter.InferredMissingBorrowType(
addressPath,
borrowType,
targetPath,
)
}

capabilityID := stdlib.IssueStorageCapabilityController(
Expand Down

0 comments on commit c0b6ebb

Please sign in to comment.