typegen: keep array and null inputs for types that contain an account

getSimilarTypes widened lookup types by name before its class checks, with
type.includes('AccountId32') and type.includes('MultiAddress'). Those also
match every type that only contains one: Vec<AccountId32>,
Option<AccountId32>, ITuple<[AccountId32, u32]>, Vec<MultiAddress>. They
were widened like a bare account and returned before reaching the Vec,
Option or Tuple branch, so the generated augment typed
multisig.asMulti(otherSignatories) as `Vec<AccountId32> | string |
Uint8Array` (no string[]), an Option<AccountId32> argument without null,
and a tuple key without its tuple form.

The names are now matched whole. The augment is regenerated
(yarn build:metadata); for these types it now matches what upstream
generates, e.g. `Vec<AccountId32> | (AccountId32 | string | Uint8Array)[]`.
This commit is contained in:
Satoshi Qazi Muhammed authored and SatoshiQaziMuhammed committed 2026-10-08 23:02:46 +04:00
1 parent 2a358917c7
commit a0b19f4916
12 files changed
+157 -138

No files matched your search

+16
View File
@@ -55,4 +55,20 @@ describe('getSimilarTypes', (): void => {
} & Struct>`
]);
});
it('keeps the array input for vectors of accounts and addresses', (): void => {
expect(getSimilarTypes(registry, {}, 'Vec<AccountId32>', mockImports)).toEqual([
'Vec<AccountId32>',
'(AccountId32 | string | Uint8Array)[]'
]);
expect(getSimilarTypes(registry, {}, 'Vec<MultiAddress>', mockImports)).toEqual([
'Vec<MultiAddress>',
'(MultiAddress | AccountId | AccountIndex | Address | LookupSource | string | Uint8Array)[]'
]);
});
it('still widens the account and address lookup types themselves', (): void => {
expect(getSimilarTypes(registry, {}, 'PezspCoreCryptoAccountId32', mockImports)).toEqual(['PezspCoreCryptoAccountId32', 'string', 'Uint8Array']);
expect(getSimilarTypes(registry, {}, 'PezspRuntimeMultiAddress', mockImports)).toEqual(['PezspRuntimeMultiAddress', 'AccountId', 'AccountIndex', 'Address', 'LookupSource', 'string', 'Uint8Array']);
});
});
+7 -4
View File
@@ -44,13 +44,16 @@ export function getSimilarTypes (registry: Registry, definitions: Record<string,
return ['null'];
}
// Handle lookup types by name pattern before class-based checks
// Lookup types like PezspRuntimeMultiAddress may not be properly registered as children of GenericMultiAddress
if (type.includes('MultiAddress') || type.endsWith('RuntimeMultiAddress')) {
// Handle lookup types by name before class-based checks: lookup types like
// PezspRuntimeMultiAddress may not be registered as children of
// GenericMultiAddress. Match the whole name; a type that only contains one,
// such as Vec<AccountId32>, has to reach the Vec branch below, or it loses
// its array input.
if (/^\w*MultiAddress$/.test(type)) {
possibleTypes.push('AccountId', 'AccountIndex', 'Address', 'LookupSource', 'string', 'Uint8Array');
return possibleTypes;
} else if (type.includes('AccountId32') || type.endsWith('CryptoAccountId32')) {
} else if (/^\w*AccountId32$/.test(type)) {
possibleTypes.push('string', 'Uint8Array');
return possibleTypes;