diff --git a/migrations/capcons/capabilitymigration.go b/migrations/capcons/capabilitymigration.go index b664e4b58a..f2b2f76f63 100644 --- a/migrations/capcons/capabilitymigration.go +++ b/migrations/capcons/capabilitymigration.go @@ -38,8 +38,8 @@ type CapabilityMigrationReporter interface { addressPath interpreter.AddressPath, ) MissingBorrowType( - accountAddress common.Address, - addressPath interpreter.AddressPath, + targetPath interpreter.AddressPath, + storedPath interpreter.AddressPath, ) } diff --git a/migrations/capcons/migration_test.go b/migrations/capcons/migration_test.go index 9834cbb1e3..ed35a720c9 100644 --- a/migrations/capcons/migration_test.go +++ b/migrations/capcons/migration_test.go @@ -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 { @@ -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, }, ) } @@ -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, @@ -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, @@ -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, diff --git a/migrations/capcons/storagecapmigration.go b/migrations/capcons/storagecapmigration.go index 73787112fa..ba95c1dd16 100644 --- a/migrations/capcons/storagecapmigration.go +++ b/migrations/capcons/storagecapmigration.go @@ -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, @@ -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, ) } @@ -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 } @@ -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 } @@ -152,7 +162,11 @@ func IssueAccountCapabilities( valueType, ) - reporter.InferredMissingBorrowType(address, addressPath, borrowType) + reporter.InferredMissingBorrowType( + addressPath, + borrowType, + targetPath, + ) } capabilityID := stdlib.IssueStorageCapabilityController(