diff --git a/migrations/statictypes/account_type_migration_test.go b/migrations/statictypes/account_type_migration_test.go index f1d74bdb0..62cb9e075 100644 --- a/migrations/statictypes/account_type_migration_test.go +++ b/migrations/statictypes/account_type_migration_test.go @@ -880,6 +880,46 @@ func TestMigratingValuesWithAccountStaticType(t *testing.T) { require.NoError(t, err) testCases := map[string]testCase{ + "dictionary_value": { + storedValue: interpreter.NewDictionaryValue( + inter, + interpreter.EmptyLocationRange, + interpreter.NewDictionaryStaticType( + nil, + interpreter.PrimitiveStaticTypeString, + interpreter.PrimitiveStaticTypePublicAccount, + ), + ), + expectedValue: interpreter.NewDictionaryValue( + inter, + interpreter.EmptyLocationRange, + interpreter.NewDictionaryStaticType( + nil, + interpreter.PrimitiveStaticTypeString, + unauthorizedAccountReferenceType, + ), + ), + }, + "array_value": { + storedValue: interpreter.NewArrayValue( + inter, + interpreter.EmptyLocationRange, + interpreter.NewVariableSizedStaticType( + nil, + interpreter.PrimitiveStaticTypePublicAccount, + ), + common.Address{}, + ), + expectedValue: interpreter.NewArrayValue( + inter, + interpreter.EmptyLocationRange, + interpreter.NewVariableSizedStaticType( + nil, + unauthorizedAccountReferenceType, + ), + common.Address{}, + ), + }, "account_capability_value": { storedValue: interpreter.NewUnmeteredCapabilityValue( 123, @@ -955,6 +995,26 @@ func TestMigratingValuesWithAccountStaticType(t *testing.T) { BorrowType: unauthorizedAccountReferenceType, }, }, + "capability_dictionary": { + storedValue: interpreter.NewDictionaryValue( + inter, + interpreter.EmptyLocationRange, + interpreter.NewDictionaryStaticType( + nil, + interpreter.PrimitiveStaticTypeString, + interpreter.NewCapabilityStaticType(nil, interpreter.PrimitiveStaticTypePublicAccount), + ), + ), + expectedValue: interpreter.NewDictionaryValue( + inter, + interpreter.EmptyLocationRange, + interpreter.NewDictionaryStaticType( + nil, + interpreter.PrimitiveStaticTypeString, + interpreter.NewCapabilityStaticType(nil, unauthorizedAccountReferenceType), + ), + ), + }, } // Store values diff --git a/migrations/statictypes/statictype_migration.go b/migrations/statictypes/statictype_migration.go index 038e49a89..a0b7c7132 100644 --- a/migrations/statictypes/statictype_migration.go +++ b/migrations/statictypes/statictype_migration.go @@ -62,7 +62,7 @@ func (m *StaticTypeMigration) Migrate( _ interpreter.StorageKey, _ interpreter.StorageMapKey, value interpreter.Value, - _ *interpreter.Interpreter, + inter *interpreter.Interpreter, ) (newValue interpreter.Value, err error) { switch value := value.(type) { case interpreter.TypeValue: @@ -129,6 +129,51 @@ func (m *StaticTypeMigration) Migrate( value.CapabilityID, value.TargetPath, ), nil + + case *interpreter.ArrayValue: + convertedElementType := m.maybeConvertStaticType(value.Type, nil) + if convertedElementType == nil { + return + } + + iterator := value.Iterator(inter, interpreter.EmptyLocationRange) + + return interpreter.NewArrayValueWithIterator( + inter, + convertedElementType.(interpreter.ArrayStaticType), + value.GetOwner(), + uint64(value.Count()), + func() interpreter.Value { + return iterator.Next(inter, interpreter.EmptyLocationRange) + }, + ), nil + + case *interpreter.DictionaryValue: + convertedElementType := m.maybeConvertStaticType(value.Type, nil) + if convertedElementType == nil { + return + } + + var keysAndValues []interpreter.Value + + iterator := value.Iterator() + for { + keyValue, value := iterator.Next(inter) + if keyValue == nil { + break + } + + keysAndValues = append(keysAndValues, keyValue) + keysAndValues = append(keysAndValues, value) + } + + return interpreter.NewDictionaryValueWithAddress( + inter, + interpreter.EmptyLocationRange, + convertedElementType.(*interpreter.DictionaryStaticType), + value.GetOwner(), + keysAndValues..., + ), nil } return