Skip to content

Commit

Permalink
also migrate account capability storage maps
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed Jun 11, 2024
1 parent 10c9308 commit a97d108
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 8 deletions.
6 changes: 6 additions & 0 deletions migrations/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ func (m *StorageMigration) Migrate(migrator StorageMapKeyMigrator) {
stdlib.PathCapabilityStorageDomain,
migrator,
)

accountStorage.MigrateUint64Keys(
m.interpreter,
stdlib.AccountCapabilityStorageDomain,
migrator,
)
}

func (m *StorageMigration) NewValueMigrationsPathMigrator(
Expand Down
70 changes: 62 additions & 8 deletions migrations/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ func (testCapConMigration) Migrate(

case interpreter.UInt64Value:
return value + 10, nil

case interpreter.NilValue:
return value, nil
}

return nil, nil
Expand Down Expand Up @@ -829,12 +832,21 @@ func TestCapConMigration(t *testing.T) {
false,
)

capSet := pathCapStorageMap.ReadValue(nil, interpreter.StringStorageMapKey("foo"))
require.IsType(t, &interpreter.DictionaryValue{}, capSet)
capSetDict := capSet.(*interpreter.DictionaryValue)
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)
Expand All @@ -854,9 +866,43 @@ func TestCapConMigration(t *testing.T) {

// Assert

assert.Len(t, reporter.migrated, 3)

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)
Expand Down Expand Up @@ -889,12 +935,20 @@ func TestCapConMigration(t *testing.T) {
false,
)

capSet = pathCapStorageMap.ReadValue(nil, interpreter.StringStorageMapKey("foo"))
require.IsType(t, &interpreter.DictionaryValue{}, capSet)
capSetDict = capSet.(*interpreter.DictionaryValue)
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) {
Expand Down

0 comments on commit a97d108

Please sign in to comment.