diff --git a/migrations/migration.go b/migrations/migration.go index c998dfc371..ab1b88426b 100644 --- a/migrations/migration.go +++ b/migrations/migration.go @@ -127,6 +127,18 @@ func (m *StorageMigration) Migrate(migrator StorageMapKeyMigrator) { stdlib.CapabilityControllerStorageDomain, migrator, ) + + accountStorage.MigrateStringKeys( + m.interpreter, + stdlib.PathCapabilityStorageDomain, + migrator, + ) + + accountStorage.MigrateUint64Keys( + m.interpreter, + stdlib.AccountCapabilityStorageDomain, + migrator, + ) } func (m *StorageMigration) NewValueMigrationsPathMigrator( diff --git a/migrations/migration_test.go b/migrations/migration_test.go index 00b6fa332d..8cf592af51 100644 --- a/migrations/migration_test.go +++ b/migrations/migration_test.go @@ -242,6 +242,12 @@ func (testCapConMigration) Migrate( value.BorrowType, value.CapabilityID+10, ), nil + + case interpreter.UInt64Value: + return value + 10, nil + + case interpreter.NilValue: + return value, nil } return nil, nil @@ -798,28 +804,49 @@ func TestCapConMigration(t *testing.T) { }) require.NoError(t, err) - storageMap := storage.GetStorageMap( + capConStorageMap := storage.GetStorageMap( testAddress, stdlib.CapabilityControllerStorageDomain, false, ) - assert.Equal(t, uint64(2), storageMap.Count()) + assert.Equal(t, uint64(2), capConStorageMap.Count()) - controller1 := storageMap.ReadValue(nil, interpreter.Uint64StorageMapKey(1)) + controller1 := capConStorageMap.ReadValue(nil, interpreter.Uint64StorageMapKey(1)) require.IsType(t, &interpreter.StorageCapabilityControllerValue{}, controller1) assert.Equal(t, interpreter.UInt64Value(1), controller1.(*interpreter.StorageCapabilityControllerValue).CapabilityID, ) - controller2 := storageMap.ReadValue(nil, interpreter.Uint64StorageMapKey(2)) + controller2 := capConStorageMap.ReadValue(nil, interpreter.Uint64StorageMapKey(2)) require.IsType(t, &interpreter.AccountCapabilityControllerValue{}, controller2) assert.Equal(t, interpreter.UInt64Value(2), controller2.(*interpreter.AccountCapabilityControllerValue).CapabilityID, ) + pathCapStorageMap := storage.GetStorageMap( + testAddress, + stdlib.PathCapabilityStorageDomain, + false, + ) + + pathCapSet := pathCapStorageMap.ReadValue(nil, interpreter.StringStorageMapKey("foo")) + require.IsType(t, &interpreter.DictionaryValue{}, pathCapSet) + capSetDict := pathCapSet.(*interpreter.DictionaryValue) + assert.Equal(t, 1, capSetDict.Count()) + assert.True(t, bool(capSetDict.ContainsKey(inter, emptyLocationRange, interpreter.UInt64Value(1)))) + + accountCapStorageMap := storage.GetStorageMap( + testAddress, + stdlib.AccountCapabilityStorageDomain, + false, + ) + + accountCapEntry := accountCapStorageMap.ReadValue(nil, interpreter.Uint64StorageMapKey(2)) + assert.NotNil(t, accountCapEntry) + // Migrate migration, err := NewStorageMigration(inter, storage, "test", testAddress) @@ -839,34 +866,89 @@ func TestCapConMigration(t *testing.T) { // Assert - assert.Len(t, reporter.migrated, 2) - require.Empty(t, reporter.errors) + assert.Equal(t, + map[struct { + interpreter.StorageKey + interpreter.StorageMapKey + }][]string{ + { + StorageKey: interpreter.StorageKey{ + Address: testAddress, + Key: stdlib.CapabilityControllerStorageDomain, + }, + StorageMapKey: interpreter.Uint64StorageMapKey(1), + }: {"testCapConMigration"}, + { + StorageKey: interpreter.StorageKey{ + Address: testAddress, + Key: stdlib.CapabilityControllerStorageDomain, + }, + StorageMapKey: interpreter.Uint64StorageMapKey(2), + }: {"testCapConMigration"}, + { + StorageKey: interpreter.StorageKey{ + Address: testAddress, + Key: stdlib.PathCapabilityStorageDomain, + }, + StorageMapKey: interpreter.StringStorageMapKey("foo"), + }: {"testCapConMigration", "testCapConMigration"}, + { + StorageKey: interpreter.StorageKey{ + Address: testAddress, + Key: stdlib.AccountCapabilityStorageDomain, + }, + StorageMapKey: interpreter.Uint64StorageMapKey(2), + }: {"testCapConMigration"}, + }, + reporter.migrated, + ) err = storage.CheckHealth() require.NoError(t, err) - storageMap = storage.GetStorageMap( + capConStorageMap = storage.GetStorageMap( testAddress, stdlib.CapabilityControllerStorageDomain, false, ) - assert.Equal(t, uint64(2), storageMap.Count()) + assert.Equal(t, uint64(2), capConStorageMap.Count()) - controller1 = storageMap.ReadValue(nil, interpreter.Uint64StorageMapKey(1)) + controller1 = capConStorageMap.ReadValue(nil, interpreter.Uint64StorageMapKey(1)) require.IsType(t, &interpreter.StorageCapabilityControllerValue{}, controller1) assert.Equal(t, interpreter.UInt64Value(11), controller1.(*interpreter.StorageCapabilityControllerValue).CapabilityID, ) - controller2 = storageMap.ReadValue(nil, interpreter.Uint64StorageMapKey(2)) + controller2 = capConStorageMap.ReadValue(nil, interpreter.Uint64StorageMapKey(2)) require.IsType(t, &interpreter.AccountCapabilityControllerValue{}, controller2) assert.Equal(t, interpreter.UInt64Value(12), controller2.(*interpreter.AccountCapabilityControllerValue).CapabilityID, ) + + pathCapStorageMap = storage.GetStorageMap( + testAddress, + stdlib.PathCapabilityStorageDomain, + false, + ) + + pathCapSet = pathCapStorageMap.ReadValue(nil, interpreter.StringStorageMapKey("foo")) + require.IsType(t, &interpreter.DictionaryValue{}, pathCapSet) + capSetDict = pathCapSet.(*interpreter.DictionaryValue) + assert.Equal(t, 1, capSetDict.Count()) + assert.True(t, bool(capSetDict.ContainsKey(inter, emptyLocationRange, interpreter.UInt64Value(11)))) + + accountCapStorageMap = storage.GetStorageMap( + testAddress, + stdlib.AccountCapabilityStorageDomain, + false, + ) + + accountCapEntry = accountCapStorageMap.ReadValue(nil, interpreter.Uint64StorageMapKey(2)) + assert.NotNil(t, accountCapEntry) } func TestContractMigration(t *testing.T) {