fix: typegen supports vectors of slices (#4720)
* fix: typegen supports vectors of slices * fix linting * Update packages/typegen/src/util/derived.ts Co-authored-by: Jaco <jacogr@gmail.com>
This commit is contained in:
co-authored by
Jaco
parent
111540177f
commit
576efc0239
@@ -8,26 +8,37 @@ import { getSimilarTypes } from './derived';
|
||||
describe('getSimilarTypes', (): void => {
|
||||
let registry: TypeRegistry;
|
||||
|
||||
const mockImports = {
|
||||
codecTypes: {},
|
||||
definitions: {},
|
||||
extrinsicTypes: {},
|
||||
genericTypes: {},
|
||||
ignoredTypes: [],
|
||||
localTypes: {},
|
||||
lookupTypes: {},
|
||||
metadataTypes: {},
|
||||
primitiveTypes: {},
|
||||
typeToModule: {},
|
||||
typesTypes: {}
|
||||
};
|
||||
|
||||
beforeAll((): void => {
|
||||
registry = new TypeRegistry();
|
||||
});
|
||||
|
||||
it('handles nested Tuples', (): void => {
|
||||
expect(getSimilarTypes(registry, {}, '(AccountId, (Balance, u32), u64)', {
|
||||
codecTypes: {},
|
||||
definitions: {},
|
||||
extrinsicTypes: {},
|
||||
genericTypes: {},
|
||||
ignoredTypes: [],
|
||||
localTypes: {},
|
||||
lookupTypes: {},
|
||||
metadataTypes: {},
|
||||
primitiveTypes: {},
|
||||
typeToModule: {},
|
||||
typesTypes: {}
|
||||
})).toEqual([
|
||||
expect(getSimilarTypes(registry, {}, '(AccountId, (Balance, u32), u64)', mockImports)).toEqual([
|
||||
'ITuple<[AccountId, ITuple<[Balance, u32]>, u64]>',
|
||||
'[AccountId | string | Uint8Array, ITuple<[Balance, u32]> | [Balance | AnyNumber | Uint8Array, u32 | AnyNumber | Uint8Array], u64 | AnyNumber | Uint8Array]'
|
||||
]);
|
||||
});
|
||||
|
||||
it('handles vectors of slices', (): void => {
|
||||
expect(getSimilarTypes(registry, {}, 'Vec<[u8;4]>', mockImports)).toEqual([
|
||||
'Vec<U8aFixed>'
|
||||
]);
|
||||
expect(getSimilarTypes(registry, {}, 'Vec<[Balance;8]>', mockImports)).toEqual([
|
||||
'Vec<Vec<Balance>>'
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -58,6 +58,8 @@ export function getSimilarTypes (registry: Registry, definitions: Record<string,
|
||||
);
|
||||
|
||||
possibleTypes.push(`([${subs.join(', ')}])[]`);
|
||||
} else if (subDef.info === TypeDefInfo.VecFixed) {
|
||||
// TODO: Add possibleTypes so imports work
|
||||
} else {
|
||||
throw new Error(`Unhandled subtype in Vec, ${stringify(subDef)}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user