diff --git a/packages/core/src/utils/set-storage.ts b/packages/core/src/utils/set-storage.ts index 2f1315d5..635e4fdf 100644 --- a/packages/core/src/utils/set-storage.ts +++ b/packages/core/src/utils/set-storage.ts @@ -38,13 +38,25 @@ function objectToStorageItems(meta: DecoratedMeta, storage: StorageConfig): RawS if (storageEntry.meta.type.isPlain) { const key = new StorageKey(meta.registry, [storageEntry]) - const type = storageEntry.meta.modifier.isOptional ? `Option<${key.outputType}>` : key.outputType - storageItems.push([key.toHex(), storage ? meta.registry.createType(type, storage).toHex() : null]) + if (storageEntry.meta.modifier.isOptional && storage === '0x') { + storageItems.push([key.toHex(), '0x']) + } else { + storageItems.push([ + key.toHex(), + storage ? u8aToHex(meta.registry.createType(key.outputType, storage).toU8a()) : null, + ]) + } } else { for (const [keys, value] of storage) { const key = new StorageKey(meta.registry, [storageEntry, keys]) - const type = storageEntry.meta.modifier.isOptional ? `Option<${key.outputType}>` : key.outputType - storageItems.push([key.toHex(), value ? meta.registry.createType(type, value).toHex() : null]) + if (storageEntry.meta.modifier.isOptional && value === '0x') { + storageItems.push([key.toHex(), '0x']) + } else { + storageItems.push([ + key.toHex(), + value ? u8aToHex(meta.registry.createType(key.outputType, value).toU8a()) : null, + ]) + } } } } diff --git a/packages/e2e/src/import-storage/index.test.ts b/packages/e2e/src/import-storage/index.test.ts index baa31583..84879de7 100644 --- a/packages/e2e/src/import-storage/index.test.ts +++ b/packages/e2e/src/import-storage/index.test.ts @@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest' import path from 'path' import { api, chain, setupApi } from '../helper.js' +import { compactHex } from '@acala-network/chopsticks' import { overrideStorage, overrideWasm } from '@acala-network/chopsticks/utils/override.js' setupApi({ @@ -14,12 +15,21 @@ const sudoKey = '0x5c0d1176a568c1f92944340dbfed9e9c530ebca703c85910e7164cb7d1c9e describe('import-storage', () => { it('works', async () => { const block = await chain.getBlock() + if (!block) throw new Error('block not found') - expect(await block?.get(sudoKey)).toBe('0x6d6f646c6163612f747273790000000000000000000000000000000000000000') + expect(await block.get(sudoKey)).toBe('0x6d6f646c6163612f747273790000000000000000000000000000000000000000') await overrideStorage(chain, path.join(__dirname, './storage.ok.yml')) - expect(await block?.get(sudoKey)).toBeUndefined() + expect(await block.get(sudoKey)).toBe('0x') // None + + { + const key = compactHex((await block.meta).query.stableAsset.pools(0)) + expect(await block.get(key)).toBe('0x') // None + } + + const key = compactHex((await block.meta).query.timestamp.now()) + expect(await block.get(key)).toBe('0x0100000000000000') }) it('handle errors', async () => { diff --git a/packages/e2e/src/import-storage/storage.ok.yml b/packages/e2e/src/import-storage/storage.ok.yml index 71e81d87..ad5f3e38 100644 --- a/packages/e2e/src/import-storage/storage.ok.yml +++ b/packages/e2e/src/import-storage/storage.ok.yml @@ -1,5 +1,15 @@ Sudo: - Key: null + Key: 0x + +Timestamp: + Now: 1 + +StableAsset: + Pools: + - + - + - 0 + - 0x TechnicalCommittee: Members: