diff --git a/artifacts/ts/MapTest.ts b/artifacts/ts/MapTest.ts index c3dc0befa..4620a2837 100644 --- a/artifacts/ts/MapTest.ts +++ b/artifacts/ts/MapTest.ts @@ -107,6 +107,12 @@ export namespace MapTestTypes { SignExecuteMethodTable[T]["params"]; export type SignExecuteMethodResult = SignExecuteMethodTable[T]["result"]; + + export type Maps = { + map0?: Map; + map1?: Map; + map2?: Map; + }; } class Factory extends ContractFactory { @@ -124,99 +130,35 @@ class Factory extends ContractFactory { TestContractParams< never, { key: Address; value: MapValue }, - { - map0?: Map; - map1?: Map; - map2?: Map; - } + MapTestTypes.Maps >, "initialFields" > - ): Promise< - TestContractResult< - null, - { - map0?: Map; - map1?: Map; - map2?: Map; - } - > - > => { + ): Promise> => { return testMethod(this, "insert", params, getContractByCodeHash); }, update: async ( params: Omit< - TestContractParams< - never, - { key: Address }, - { - map0?: Map; - map1?: Map; - map2?: Map; - } - >, + TestContractParams, "initialFields" > - ): Promise< - TestContractResult< - null, - { - map0?: Map; - map1?: Map; - map2?: Map; - } - > - > => { + ): Promise> => { return testMethod(this, "update", params, getContractByCodeHash); }, remove: async ( params: Omit< - TestContractParams< - never, - { key: Address }, - { - map0?: Map; - map1?: Map; - map2?: Map; - } - >, + TestContractParams, "initialFields" > - ): Promise< - TestContractResult< - null, - { - map0?: Map; - map1?: Map; - map2?: Map; - } - > - > => { + ): Promise> => { return testMethod(this, "remove", params, getContractByCodeHash); }, getValue: async ( params: Omit< - TestContractParams< - never, - { key: Address }, - { - map0?: Map; - map1?: Map; - map2?: Map; - } - >, + TestContractParams, "initialFields" > - ): Promise< - TestContractResult< - MapValue, - { - map0?: Map; - map1?: Map; - map2?: Map; - } - > - > => { + ): Promise> => { return testMethod(this, "getValue", params, getContractByCodeHash); }, }; @@ -225,11 +167,7 @@ class Factory extends ContractFactory { initFields: {}, asset?: Asset, address?: string, - maps?: { - map0?: Map; - map1?: Map; - map2?: Map; - } + maps?: MapTestTypes.Maps ) { return this.stateForTest_(initFields, asset, address, maps); } diff --git a/packages/cli/src/codegen.ts b/packages/cli/src/codegen.ts index 33b4f9b02..59d0000dd 100644 --- a/packages/cli/src/codegen.ts +++ b/packages/cli/src/codegen.ts @@ -328,7 +328,11 @@ function genMapsType(contract: Contract): string { const [key, value] = parseMapType(mapType) return `${name}?: Map<${toTsType(key)}, ${toTsType(value)}>` }) - return `{ ${mapFields.join(', ')} }` + return `export type Maps = { ${mapFields.join(', ')} }` +} + +function getMapsType(contract: Contract): string { + return `${contractTypes(contract.name)}.Maps` } function genTestMethod(contract: Contract, functionSig: FunctionSig): string { @@ -340,7 +344,7 @@ function genTestMethod(contract: Contract, functionSig: FunctionSig): string { : 'never' const fieldsType = contractHasFields ? contractFieldType(contract.name, fieldsSig) : 'never' const hasMapVars: boolean = contract.mapsSig !== undefined - const mapsType = genMapsType(contract) + const mapsType = getMapsType(contract) const baseParamsType = hasMapVars ? `TestContractParams<${fieldsType}, ${argsType}, ${mapsType}>` : `TestContractParamsWithoutMaps<${fieldsType}, ${argsType}>` @@ -380,7 +384,7 @@ function genTestMethods(contract: Contract): string { function genStateForTest(contract: Contract, fieldType: string): string { const hasMap = contract.mapsSig !== undefined - const mapsParam = hasMap ? `, maps?: ${genMapsType(contract)}` : '' + const mapsParam = hasMap ? `, maps?: ${getMapsType(contract)}` : '' const mapsValue = hasMap ? 'maps' : 'undefined' return ` stateForTest(initFields: ${fieldType}, asset?: Asset, address?: string${mapsParam}) { @@ -521,6 +525,7 @@ function genContract(contract: Contract, artifactRelativePath: string): string { ${contract.eventsSig.map((e) => genEventType(e)).join('\n')} ${genCallMethodTypes(contract)} ${genSignExecuteMethodTypes(contract)} + ${genMapsType(contract)} } class Factory extends ContractFactory<${contract.name}Instance, ${fieldType}> {