From 836346909f29f55ea4d59d6546ff2dcc5d064f19 Mon Sep 17 00:00:00 2001 From: Jaco Date: Sat, 13 Aug 2022 09:10:51 +0200 Subject: [PATCH] Adjust definitions check test (ensure failures via raw) (#5157) * Adjust definitions check test (ensure failures via raw) * Adjust * Chain error path --- .../types/src/interfaces/definitions.spec.ts | 39 ++++++------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/packages/types/src/interfaces/definitions.spec.ts b/packages/types/src/interfaces/definitions.spec.ts index 147664d540..5c24e54631 100644 --- a/packages/types/src/interfaces/definitions.spec.ts +++ b/packages/types/src/interfaces/definitions.spec.ts @@ -28,36 +28,21 @@ registry.register(types as RegistryTypes); registry.setMetadata(new Metadata(registry, rpcMetadata)); function inspectType (type: string): void { - console.error(type); + try { + // get the definition + const { sub } = getTypeDef(registry.createType(type).toRawType()); - // get the definition - const td = registry.isLookupType(type) - ? registry.lookup.getTypeDef(type) - : getTypeDef(type); - - console.error(td); - - // inspect the subs - if (Array.isArray(td.sub)) { - for (let i = 0; i < td.sub.length; i++) { - inspectType(td.sub[i].type); + // inspect the subs + if (Array.isArray(sub)) { + for (let i = 0; i < sub.length; i++) { + inspectType(sub[i].type); + } + } else if (sub) { + inspectType(sub.type); } - } else if (td.sub) { - inspectType(td.sub.type); - } else if (!['Vec'].includes(type)) { - // see if we have it - registry.getOrThrow(type); + } catch (error) { + throw new Error(`${type}:: ${(error as Error).message}`); } - - // create a class - const Clazz = registry.createClass(type); - - // construct the class - // eslint-disable-next-line no-new - new Clazz(registry); - - // create it - registry.createType(type); } describe('type definitions', (): void => {