Skip to content

Commit

Permalink
Add capability stored path info to the report
Browse files Browse the repository at this point in the history
  • Loading branch information
SupunS committed Aug 13, 2024
1 parent 7f0f77b commit 0544c67
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
3 changes: 2 additions & 1 deletion migrations/capcons/capabilitymigration.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ type CapabilityMigrationReporter interface {
)
MissingBorrowType(
accountAddress common.Address,
addressPath interpreter.AddressPath,
targetPath interpreter.AddressPath,
storedPath Path,
)
}

Expand Down
30 changes: 22 additions & 8 deletions migrations/capcons/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,15 @@ type testStorageCapConIssued struct {

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

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

type testMigration struct {
Expand Down Expand Up @@ -196,28 +198,32 @@ func (t *testMigrationReporter) MissingCapabilityID(

func (t *testMigrationReporter) MissingBorrowType(
accountAddress common.Address,
addressPath interpreter.AddressPath,
targetPath interpreter.AddressPath,
storedPath Path,
) {
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 Path,
) {
t.inferredStorageCapConBorrowTypes = append(
t.inferredStorageCapConBorrowTypes,
testStorageCapConsInferredBorrowType{
accountAddress: accountAddress,
addressPath: addressPath,
targetPath: targetPath,
borrowType: borrowType,
storedPath: storedPath,
},
)
}
Expand Down Expand Up @@ -3414,12 +3420,16 @@ func TestUntypedStorageCapMigration(t *testing.T) {
[]testStorageCapConsInferredBorrowType{
{
accountAddress: testAddress,
addressPath: testAddressPath,
targetPath: testAddressPath,
borrowType: interpreter.NewReferenceStaticType(
nil,
inferredAuth,
interpreter.PrimitiveStaticTypeString,
),
storedPath: Path{
Domain: "storage",
Path: "cap",
},
},
},
reporter.inferredStorageCapConBorrowTypes,
Expand Down Expand Up @@ -3633,10 +3643,14 @@ func TestUntypedStorageCapWithMissingTargetMigration(t *testing.T) {
[]testStorageCapConsMissingBorrowType{
{
accountAddress: addressA,
addressPath: interpreter.AddressPath{
targetPath: interpreter.AddressPath{
Address: addressA,
Path: targetPath,
},
storedPath: Path{
Domain: "storage",
Path: "cap",
},
},
},
reporter.missingStorageCapConBorrowTypes,
Expand Down
15 changes: 11 additions & 4 deletions migrations/capcons/storagecapmigration.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import (
type StorageCapabilityMigrationReporter interface {
MissingBorrowType(
accountAddress common.Address,
addressPath interpreter.AddressPath,
targetPath interpreter.AddressPath,
storedPath Path,
)
IssuedStorageCapabilityController(
accountAddress common.Address,
Expand All @@ -39,8 +40,9 @@ type StorageCapabilityMigrationReporter interface {
)
InferredMissingBorrowType(
accountAddress common.Address,
addressPath interpreter.AddressPath,
targetPath interpreter.AddressPath,
borrowType *interpreter.ReferenceStaticType,
storedPath Path,
)
}

Expand Down Expand Up @@ -140,7 +142,7 @@ 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)
reporter.MissingBorrowType(address, addressPath, capability.StoredPath)
continue
}

Expand All @@ -152,7 +154,12 @@ func IssueAccountCapabilities(
valueType,
)

reporter.InferredMissingBorrowType(address, addressPath, borrowType)
reporter.InferredMissingBorrowType(
address,
addressPath,
borrowType,
capability.StoredPath,
)
}

capabilityID := stdlib.IssueStorageCapabilityController(
Expand Down

0 comments on commit 0544c67

Please sign in to comment.