Skip to content

Commit 8280bed

Browse files
committed
fix tests
1 parent c030c1a commit 8280bed

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

packages/api-contract/src/Abi/index.ts

+22-13
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,25 @@ function getLatestMeta (registry: Registry, json: Record<string, unknown>): Cont
5353
return converter[1](registry, metadata[`as${converter[0]}`]);
5454
}
5555

56-
function getEnvTypes (env: ContractEnvironment, lookup: PortableRegistry) {
57-
const keys = Object.keys(env);
56+
function getEnvTypes (env: ContractEnvironment | undefined, lookup: PortableRegistry) {
57+
if (env) {
58+
const keys = Object.keys(env);
5859

59-
return Object.values(env).map((t: unknown, i) => {
60-
if (typeof t === 'object' && t !== null && 'type' in t) {
61-
return { [keys[i]]: lookup.getTypeDef(t.type as number) };
62-
}
60+
return Object.values(env).map((t: unknown, i) => {
61+
if (typeof t === 'object' && t !== null && 'type' in t) {
62+
return { [keys[i]]: lookup.getTypeDef(t.type as number) };
63+
}
64+
65+
return { [keys[i]]: t };
66+
});
67+
}
6368

64-
return { [keys[i]]: t };
65-
});
69+
return [];
6670
}
6771

6872
function parseJson (json: Record<string, unknown>, chainProperties?: ChainProperties): [Record<string, unknown>, Registry, ContractMetadataLatest, ContractProjectInfo, { [x: string]: unknown }[]] {
6973
const registry = new TypeRegistry();
7074
const info = registry.createType('ContractProjectInfo', json) as unknown as ContractProjectInfo;
71-
const { spec: { environment } } = json as {spec: {environment?: ContractEnvironment}};
7275
const latest = getLatestMeta(registry, json);
7376
const lookup = registry.createType('PortableRegistry', { types: latest.types }, true);
7477

@@ -84,9 +87,15 @@ function parseJson (json: Record<string, unknown>, chainProperties?: ChainProper
8487
lookup.getTypeDef(id)
8588
);
8689

87-
const env = environment
88-
? getEnvTypes(environment, lookup)
89-
: [];
90+
let env: { [x: string]: unknown }[] = [];
91+
92+
try {
93+
const { spec: { environment } } = json as unknown as ContractMetadataLatest;
94+
95+
env = getEnvTypes(environment, lookup);
96+
} catch (e) {
97+
console.error(e);
98+
}
9099

91100
return [json, registry, latest, info, env];
92101
}
@@ -110,7 +119,7 @@ export class Abi {
110119
);
111120
this.constructors = this.metadata.spec.constructors.map((spec: ContractConstructorSpecLatest, index) => {
112121
const isDefault = 'default' in spec ? spec.default.isTrue : undefined;
113-
const typeSpec = spec.returnType.unwrapOr(null);
122+
const typeSpec = 'returnType' in spec ? spec.returnType.unwrapOr(null) : null;
114123

115124
return this.#createMessage(spec, index, {
116125
isConstructor: true,

0 commit comments

Comments
 (0)