From adc370471f098a5e01f1f23042e512d4659a6e8c Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Sun, 13 Nov 2022 20:33:17 -0500 Subject: [PATCH 01/13] call special output type --- packages/web3-eth-contract/src/types.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/web3-eth-contract/src/types.ts b/packages/web3-eth-contract/src/types.ts index 3a02e622b51..4be53c7b181 100644 --- a/packages/web3-eth-contract/src/types.ts +++ b/packages/web3-eth-contract/src/types.ts @@ -227,7 +227,11 @@ export interface NonPayableMethodObject * @param block - If you pass this parameter it will not use the default block set with contract.defaultBlock. Pre-defined block numbers as `earliest`, `latest`, and `pending` can also be used. Useful for requesting data from or replaying transactions in past blocks. * @returns - The return value(s) of the smart contract method. If it returns a single value, it’s returned as is. If it has multiple return values they are returned as an object with properties and indices. */ - call(tx?: NonPayableCallOptions, block?: BlockNumberOrTag): Promise; + + call( + tx?: NonPayableCallOptions, + block?: BlockNumberOrTag, + ): Promise; /** * This will send a transaction to the smart contract and execute its method. Note this can alter the smart contract state. @@ -384,7 +388,10 @@ export interface PayableMethodObject { * @param block - If you pass this parameter it will not use the default block set with contract.defaultBlock. Pre-defined block numbers as `earliest`, `latest`, and `pending` can also be used. Useful for requesting data from or replaying transactions in past blocks. * @returns - The return value(s) of the smart contract method. If it returns a single value, it’s returned as is. If it has multiple return values they are returned as an object with properties and indices. */ - call(tx?: PayableCallOptions, block?: BlockNumberOrTag): Promise; + call( + tx?: PayableCallOptions, + block?: BlockNumberOrTag, + ): Promise; /** * Will send a transaction to the smart contract and execute its method. Note this can alter the smart contract state. From c91e51899a342608d846eb0126a67a5e67f018c0 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Mon, 14 Nov 2022 12:12:37 -0500 Subject: [PATCH 02/13] fix --- packages/web3-eth-contract/src/types.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/web3-eth-contract/src/types.ts b/packages/web3-eth-contract/src/types.ts index 4be53c7b181..438b8e9708f 100644 --- a/packages/web3-eth-contract/src/types.ts +++ b/packages/web3-eth-contract/src/types.ts @@ -228,10 +228,10 @@ export interface NonPayableMethodObject * @returns - The return value(s) of the smart contract method. If it returns a single value, it’s returned as is. If it has multiple return values they are returned as an object with properties and indices. */ - call( + call( tx?: NonPayableCallOptions, block?: BlockNumberOrTag, - ): Promise; + ): Promise; /** * This will send a transaction to the smart contract and execute its method. Note this can alter the smart contract state. @@ -388,10 +388,10 @@ export interface PayableMethodObject { * @param block - If you pass this parameter it will not use the default block set with contract.defaultBlock. Pre-defined block numbers as `earliest`, `latest`, and `pending` can also be used. Useful for requesting data from or replaying transactions in past blocks. * @returns - The return value(s) of the smart contract method. If it returns a single value, it’s returned as is. If it has multiple return values they are returned as an object with properties and indices. */ - call( + call( tx?: PayableCallOptions, block?: BlockNumberOrTag, - ): Promise; + ): Promise; /** * Will send a transaction to the smart contract and execute its method. Note this can alter the smart contract state. From a22f2a25cef1138ae82c44440270f13ee7911a97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marin=20Petruni=C4=87?= Date: Thu, 17 Nov 2022 17:43:39 +0100 Subject: [PATCH 03/13] fix: enable outputs to have param names (#5624) --- packages/web3-eth-abi/src/types.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/web3-eth-abi/src/types.ts b/packages/web3-eth-abi/src/types.ts index 926fdc66402..fc6014ed78e 100644 --- a/packages/web3-eth-abi/src/types.ts +++ b/packages/web3-eth-abi/src/types.ts @@ -186,14 +186,21 @@ export type MatchPrimitiveType< | never; export type ContractMethodOutputParameters | undefined> = + // check if params are empty array Params extends readonly [] - ? [] - : Params extends readonly [infer H, ...infer R] + ? void // if yes outputs is void + : Params extends readonly [infer H, ...infer R] // check if Params is array ? H extends AbiParameter - ? // TODO: Find a way to set name for tuple item - [MatchPrimitiveType, ...ContractMethodOutputParameters] + ? [ + MatchPrimitiveType, + ...ContractMethodOutputParameters, + ] & + H['name'] extends '' // check if output param name is empty string + ? [] + : Record> & // sets key-value pair of output param name and type + ContractMethodOutputParameters : ContractMethodOutputParameters - : Params extends undefined | unknown + : Params extends undefined | unknown // param is not array, check if undefined ? [] : Params; From a338132fcddbe9d0c0bbc6ace7954e16989a531d Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Mon, 21 Nov 2022 19:11:15 -0500 Subject: [PATCH 04/13] hot fix --- packages/web3-eth-abi/src/types.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/web3-eth-abi/src/types.ts b/packages/web3-eth-abi/src/types.ts index fc6014ed78e..43cf2c3023e 100644 --- a/packages/web3-eth-abi/src/types.ts +++ b/packages/web3-eth-abi/src/types.ts @@ -188,8 +188,8 @@ export type MatchPrimitiveType< export type ContractMethodOutputParameters | undefined> = // check if params are empty array Params extends readonly [] - ? void // if yes outputs is void - : Params extends readonly [infer H, ...infer R] // check if Params is array + ? [] + : Params extends readonly [infer H, ...infer R] // check if Params is an array ? H extends AbiParameter ? [ MatchPrimitiveType, From 09283a7d60f38f65323faedcecb1cc142ce6eb42 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Mon, 21 Nov 2022 22:11:05 -0500 Subject: [PATCH 05/13] add type if only one param --- packages/web3-eth-abi/src/types.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/web3-eth-abi/src/types.ts b/packages/web3-eth-abi/src/types.ts index 43cf2c3023e..85526c3bece 100644 --- a/packages/web3-eth-abi/src/types.ts +++ b/packages/web3-eth-abi/src/types.ts @@ -190,7 +190,11 @@ export type ContractMethodOutputParameters Params extends readonly [] ? [] : Params extends readonly [infer H, ...infer R] // check if Params is an array - ? H extends AbiParameter + ? R extends [] // if only one output in array + ? H extends AbiParameter + ? MatchPrimitiveType + : [] + : H extends AbiParameter // if more than 1 outputs ? [ MatchPrimitiveType, ...ContractMethodOutputParameters, From 0f81c970d97b4c5da315db342aae1abef7ea0c4b Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Mon, 21 Nov 2022 22:43:14 -0500 Subject: [PATCH 06/13] overloaded inputs types --- packages/web3-eth-contract/src/contract.ts | 61 ++++++++++++++-------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/packages/web3-eth-contract/src/contract.ts b/packages/web3-eth-contract/src/contract.ts index ebbee98b4c7..8e5d727dcc1 100644 --- a/packages/web3-eth-contract/src/contract.ts +++ b/packages/web3-eth-contract/src/contract.ts @@ -36,6 +36,8 @@ import { ContractEvent, ContractEvents, ContractMethod, + ContractMethodInputParameters, + ContractMethodOutputParameters, encodeEventSignature, encodeFunctionSignature, FilterAbis, @@ -102,7 +104,6 @@ import { isWeb3ContractContext, } from './utils'; -// eslint-disable-next-line @typescript-eslint/no-explicit-any type ContractBoundMethod< Abi extends AbiFunctionFragment, Method extends ContractMethod = ContractMethod, @@ -112,6 +113,26 @@ type ContractBoundMethod< ? PayableMethodObject : NonPayableMethodObject; +export type ContractOverloadedMethodInputs> = NonNullable< + AbiArr extends readonly [] + ? undefined + : AbiArr extends readonly [infer A, ...infer R] + ? A extends AbiFunctionFragment + ? ContractMethodInputParameters | ContractOverloadedMethodInputs + : undefined + : undefined +>; + +export type ContractOverloadedMethodOutputs> = NonNullable< + AbiArr extends readonly [] + ? undefined + : AbiArr extends readonly [infer A, ...infer R] + ? A extends AbiFunctionFragment + ? ContractMethodOutputParameters | ContractOverloadedMethodOutputs + : undefined + : undefined +>; + // To avoid circular dependency between types and encoding, declared these types here. export type ContractMethodsInterface = { [MethodAbi in FilterAbis< @@ -912,25 +933,20 @@ export class Contract abi.constant; abi.payable = abi.stateMutability === 'payable' ?? abi.payable; - - const contractMethod = this._createContractMethod(abi, errorsAbi); - this._overloadedMethodAbis.set(abi.name, [ ...(this._overloadedMethodAbis.get(abi.name) ?? []), abi, ]); - if (methodName in this._functions) { - this._functions[methodName] = { - signature: methodSignature, - method: contractMethod, - }; - } else { - this._functions[methodName] = { - signature: methodSignature, - method: contractMethod, - }; - } + const contractMethod = this._createContractMethod( + this._overloadedMethodAbis.get(abi.name) ?? [], + errorsAbi, + ); + + this._functions[methodName] = { + signature: methodSignature, + method: contractMethod, + }; // We don't know a particular type of the Abi method so can't type check this._methods[abi.name as keyof ContractMethodsInterface] = this._functions[ @@ -979,10 +995,11 @@ export class Contract ); } } - private _createContractMethod( - abi: T, + private _createContractMethod( + abiArr: T, errorsAbis: E[], - ): ContractBoundMethod { + ): ContractBoundMethod { + const abi = abiArr[abiArr.length - 1]; return (...params: unknown[]) => { let abiParams!: Array; const abis = this._overloadedMethodAbis.get(abi.name) ?? []; @@ -1036,8 +1053,8 @@ export class Contract }), encodeABI: () => encodeMethodABI(methodAbi, abiParams), } as unknown as PayableMethodObject< - ContractMethod['Inputs'], - ContractMethod['Outputs'] + ContractOverloadedMethodInputs, + ContractOverloadedMethodOutputs >; } return { @@ -1058,8 +1075,8 @@ export class Contract }), encodeABI: () => encodeMethodABI(methodAbi, abiParams), } as unknown as NonPayableMethodObject< - ContractMethod['Inputs'], - ContractMethod['Outputs'] + ContractOverloadedMethodInputs, + ContractOverloadedMethodOutputs >; }; } From d69c0e5cab7132e39f0e95354b92b587b58c8c60 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Tue, 22 Nov 2022 20:31:13 -0500 Subject: [PATCH 07/13] fix resolver tests --- packages/web3-eth-abi/src/types.ts | 27 ++++++++++++++++--- .../test/integration/resolver.test.ts | 4 +-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/packages/web3-eth-abi/src/types.ts b/packages/web3-eth-abi/src/types.ts index 85526c3bece..cc0020255c9 100644 --- a/packages/web3-eth-abi/src/types.ts +++ b/packages/web3-eth-abi/src/types.ts @@ -185,25 +185,44 @@ export type MatchPrimitiveType< | PrimitiveTupleType | never; +type ContractMethodOutputParametersRecursive | undefined> = + // check if params are empty array + Params extends readonly [] + ? [] + : Params extends readonly [infer H, ...infer R] // check if Params is an array + ? H extends AbiParameter // if more than 1 outputs + ? [ + MatchPrimitiveType, + ...ContractMethodOutputParametersRecursive, + ] & + H['name'] extends '' // check if output param name is empty string + ? [] + : Record> & // sets key-value pair of output param name and type + ContractMethodOutputParametersRecursive + : ContractMethodOutputParametersRecursive + : Params extends undefined | unknown // param is not array, check if undefined + ? [] + : Params; + export type ContractMethodOutputParameters | undefined> = // check if params are empty array Params extends readonly [] ? [] : Params extends readonly [infer H, ...infer R] // check if Params is an array - ? R extends [] // if only one output in array + ? R extends readonly [] // if only one output in array ? H extends AbiParameter ? MatchPrimitiveType : [] : H extends AbiParameter // if more than 1 outputs ? [ MatchPrimitiveType, - ...ContractMethodOutputParameters, + ...ContractMethodOutputParametersRecursive, ] & H['name'] extends '' // check if output param name is empty string ? [] : Record> & // sets key-value pair of output param name and type - ContractMethodOutputParameters - : ContractMethodOutputParameters + ContractMethodOutputParametersRecursive + : ContractMethodOutputParametersRecursive : Params extends undefined | unknown // param is not array, check if undefined ? [] : Params; diff --git a/packages/web3-eth-ens/test/integration/resolver.test.ts b/packages/web3-eth-ens/test/integration/resolver.test.ts index de46cc38c99..63b494458db 100644 --- a/packages/web3-eth-ens/test/integration/resolver.test.ts +++ b/packages/web3-eth-ens/test/integration/resolver.test.ts @@ -172,8 +172,8 @@ describe('ens', () => { const res = await ens.getPubkey(domain); - expect(res[0]).toBe('0x0000000000000000000000000000000000000000000000000000000000000000'); - expect(res[1]).toBe('0x0000000000000000000000000000000000000000000000000000000000000000'); + expect(res.x).toBe('0x0000000000000000000000000000000000000000000000000000000000000000'); + expect(res.y).toBe('0x0000000000000000000000000000000000000000000000000000000000000000'); }); it('permits setting public key by owner', async () => { From d88fd45166c38a70202f043fe42c8c551cc03316 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Thu, 24 Nov 2022 17:36:07 -0500 Subject: [PATCH 08/13] add type tests --- packages/web3-eth-abi/src/types.ts | 56 +++++++---- packages/web3-eth-abi/test/unit/types.test.ts | 99 ++++++++++++++++++- .../web3-eth-ens/test/unit/registry.test.ts | 6 +- 3 files changed, 140 insertions(+), 21 deletions(-) diff --git a/packages/web3-eth-abi/src/types.ts b/packages/web3-eth-abi/src/types.ts index cc0020255c9..4b4512d9120 100644 --- a/packages/web3-eth-abi/src/types.ts +++ b/packages/web3-eth-abi/src/types.ts @@ -173,6 +173,11 @@ export type PrimitiveTupleType< : never : never; +type ObjectToArray = T extends [...infer R, infer A] + ? Record & ObjectToArray + : T; +type ArrToObjectWithFunctions = Array & ObjectToArray; + export type MatchPrimitiveType< Type extends string, Components extends ReadonlyArray | undefined, @@ -185,44 +190,61 @@ export type MatchPrimitiveType< | PrimitiveTupleType | never; -type ContractMethodOutputParametersRecursive | undefined> = +type ContractMethodOutputParametersRecursiveArray< + Params extends ReadonlyArray | undefined, +> = // check if params are empty array Params extends readonly [] ? [] : Params extends readonly [infer H, ...infer R] // check if Params is an array - ? H extends AbiParameter // if more than 1 outputs + ? H extends AbiParameter ? [ MatchPrimitiveType, - ...ContractMethodOutputParametersRecursive, - ] & - H['name'] extends '' // check if output param name is empty string - ? [] - : Record> & // sets key-value pair of output param name and type - ContractMethodOutputParametersRecursive - : ContractMethodOutputParametersRecursive + ...ContractMethodOutputParametersRecursiveArray, + ] + : [] : Params extends undefined | unknown // param is not array, check if undefined ? [] : Params; +type ContractMethodOutputParametersRecursiveRecord< + Params extends ReadonlyArray | undefined, +> = + // check if params are empty array + Params extends readonly [] + ? undefined + : Params extends readonly [infer H, ...infer R] // check if Params is an array + ? H extends AbiParameter + ? H['name'] extends '' // check if output param name is empty string + ? ContractMethodOutputParametersRecursiveRecord + : Record> & // sets key-value pair of output param name and type + ContractMethodOutputParametersRecursiveRecord + : ContractMethodOutputParametersRecursiveRecord + : Params extends undefined | unknown // param is not array, check if undefined + ? undefined + : Params; + export type ContractMethodOutputParameters | undefined> = // check if params are empty array Params extends readonly [] - ? [] + ? void : Params extends readonly [infer H, ...infer R] // check if Params is an array ? R extends readonly [] // if only one output in array ? H extends AbiParameter ? MatchPrimitiveType : [] : H extends AbiParameter // if more than 1 outputs - ? [ - MatchPrimitiveType, - ...ContractMethodOutputParametersRecursive, - ] & + ? ArrToObjectWithFunctions< + [ + MatchPrimitiveType, + ...ContractMethodOutputParametersRecursiveArray, + ] + > & H['name'] extends '' // check if output param name is empty string - ? [] + ? NonNullable> : Record> & // sets key-value pair of output param name and type - ContractMethodOutputParametersRecursive - : ContractMethodOutputParametersRecursive + NonNullable> + : [] : Params extends undefined | unknown // param is not array, check if undefined ? [] : Params; diff --git a/packages/web3-eth-abi/test/unit/types.test.ts b/packages/web3-eth-abi/test/unit/types.test.ts index 773ab6e7ede..5bdce305c69 100644 --- a/packages/web3-eth-abi/test/unit/types.test.ts +++ b/packages/web3-eth-abi/test/unit/types.test.ts @@ -17,7 +17,7 @@ along with web3.js. If not, see . import { Address, Bytes, Numbers } from 'web3-types'; import { expectTypeOf, typecheck } from '@humeris/espresso-shot'; -import { MatchPrimitiveType } from '../../src/types'; +import { ContractMethodOutputParameters, MatchPrimitiveType } from '../../src'; describe('types', () => { describe('primitive types', () => { @@ -157,4 +157,101 @@ describe('types', () => { ); }); }); + + describe('contract', () => { + describe('outputs', () => { + typecheck('empty outputs should result in []', () => + expectTypeOf>().toExtend(), + ); + + typecheck('single outputs should result in that type', () => { + const abi = [ + { + name: '', + type: 'string', + }, + ] as const; + return expectTypeOf< + ContractMethodOutputParameters + >().toExtend(); + }); + + typecheck('multiple outputs should result in object indexed by numbers', () => { + const abi = [ + { + name: '', + type: 'string', + }, + { + name: '', + type: 'int', + }, + ] as const; + + return expectTypeOf< + ContractMethodOutputParameters[0] + >().toExtend(); + }); + + typecheck('multiple outputs should result in object indexed by numbers', () => { + const abi = [ + { + name: '', + type: 'string', + }, + { + name: '', + type: 'int', + }, + ] as const; + return expectTypeOf< + ContractMethodOutputParameters[1] + >().toExtend(); + }); + + typecheck('multiple outputs should result in object indexed by name', () => { + const abi = [ + { + name: 'first', + type: 'string', + }, + { + name: 'second', + type: 'int', + }, + ] as const; + return expectTypeOf< + ContractMethodOutputParameters['first'] + >().toExtend(); + }); + + typecheck('multiple outputs should result in object indexed by name', () => { + const abi = [ + { + name: 'first', + type: 'string', + }, + { + name: 'second', + type: 'int', + }, + ] as const; + return expectTypeOf< + ContractMethodOutputParameters['second'] + >().toExtend(); + }); + + typecheck('single output should result as in exactly one type', () => { + const abi = [ + { + name: 'first', + type: 'string', + }, + ] as const; + return expectTypeOf< + ContractMethodOutputParameters + >().toExtend(); + }); + }); + }); }); diff --git a/packages/web3-eth-ens/test/unit/registry.test.ts b/packages/web3-eth-ens/test/unit/registry.test.ts index f0cdec2448f..fb1d9983f7f 100644 --- a/packages/web3-eth-ens/test/unit/registry.test.ts +++ b/packages/web3-eth-ens/test/unit/registry.test.ts @@ -38,7 +38,7 @@ describe('registry', () => { jest.clearAllMocks(); }); - it('constructor with custom address', async () => { + it('constructor with custom address', () => { const tempRegistry = new Registry(object, mockAddress); expect(tempRegistry).toBeInstanceOf(Registry); @@ -531,7 +531,7 @@ describe('registry', () => { const call = jest .spyOn( { - call: async () => { + call: () => { return mockAddress; }, }, @@ -555,7 +555,7 @@ describe('registry', () => { const call = jest .spyOn( { - call: async () => { + call: () => { return 5; // something that is not string }, }, From 294d7b6b5da88e981c9482ebfadc69d2a81c1a4f Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Thu, 24 Nov 2022 18:04:07 -0500 Subject: [PATCH 09/13] simplify types --- packages/web3-eth-abi/src/types.ts | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/packages/web3-eth-abi/src/types.ts b/packages/web3-eth-abi/src/types.ts index 4b4512d9120..7e443862310 100644 --- a/packages/web3-eth-abi/src/types.ts +++ b/packages/web3-eth-abi/src/types.ts @@ -203,16 +203,14 @@ type ContractMethodOutputParametersRecursiveArray< ...ContractMethodOutputParametersRecursiveArray, ] : [] - : Params extends undefined | unknown // param is not array, check if undefined - ? [] - : Params; + : []; type ContractMethodOutputParametersRecursiveRecord< Params extends ReadonlyArray | undefined, > = // check if params are empty array Params extends readonly [] - ? undefined + ? [] : Params extends readonly [infer H, ...infer R] // check if Params is an array ? H extends AbiParameter ? H['name'] extends '' // check if output param name is empty string @@ -221,7 +219,7 @@ type ContractMethodOutputParametersRecursiveRecord< ContractMethodOutputParametersRecursiveRecord : ContractMethodOutputParametersRecursiveRecord : Params extends undefined | unknown // param is not array, check if undefined - ? undefined + ? [] : Params; export type ContractMethodOutputParameters | undefined> = @@ -233,21 +231,10 @@ export type ContractMethodOutputParameters ? H extends AbiParameter ? MatchPrimitiveType : [] - : H extends AbiParameter // if more than 1 outputs - ? ArrToObjectWithFunctions< - [ - MatchPrimitiveType, - ...ContractMethodOutputParametersRecursiveArray, - ] - > & - H['name'] extends '' // check if output param name is empty string - ? NonNullable> - : Record> & // sets key-value pair of output param name and type - NonNullable> - : [] - : Params extends undefined | unknown // param is not array, check if undefined - ? [] - : Params; + : // if more than one output + ArrToObjectWithFunctions<[...ContractMethodOutputParametersRecursiveArray]> & + ContractMethodOutputParametersRecursiveRecord + : []; export type ContractMethodInputParameters | undefined> = Params extends readonly [] From 9c28a4b961c62e4112c568ebc34fc5b2b6114f53 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Thu, 24 Nov 2022 18:17:36 -0500 Subject: [PATCH 10/13] revert registry unit test --- packages/web3-eth-ens/test/unit/registry.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/web3-eth-ens/test/unit/registry.test.ts b/packages/web3-eth-ens/test/unit/registry.test.ts index fb1d9983f7f..f0cdec2448f 100644 --- a/packages/web3-eth-ens/test/unit/registry.test.ts +++ b/packages/web3-eth-ens/test/unit/registry.test.ts @@ -38,7 +38,7 @@ describe('registry', () => { jest.clearAllMocks(); }); - it('constructor with custom address', () => { + it('constructor with custom address', async () => { const tempRegistry = new Registry(object, mockAddress); expect(tempRegistry).toBeInstanceOf(Registry); @@ -531,7 +531,7 @@ describe('registry', () => { const call = jest .spyOn( { - call: () => { + call: async () => { return mockAddress; }, }, @@ -555,7 +555,7 @@ describe('registry', () => { const call = jest .spyOn( { - call: () => { + call: async () => { return 5; // something that is not string }, }, From fb0051471952d6fcc52554806968ca5f26ea28a8 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Thu, 24 Nov 2022 19:21:47 -0500 Subject: [PATCH 11/13] test firefox --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a4ddf0ebd06..e9e11b17e58 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -135,6 +135,7 @@ jobs: - name: Cypress run uses: cypress-io/github-action@v4 with: + browser: ${{ matrix.browser }} install: false command: yarn test:e2e:ganache:ws:${{ matrix.browser }} cache-key: node-v${{ matrix.node }}-on-${{ matrix.browser }}-hash-${{ hashFiles('yarn.lock') }} From 924da4c67da9fd21feef04522498adccde043af4 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Fri, 25 Nov 2022 10:18:53 -0500 Subject: [PATCH 12/13] revert firefox test --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e9e11b17e58..a4ddf0ebd06 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -135,7 +135,6 @@ jobs: - name: Cypress run uses: cypress-io/github-action@v4 with: - browser: ${{ matrix.browser }} install: false command: yarn test:e2e:ganache:ws:${{ matrix.browser }} cache-key: node-v${{ matrix.node }}-on-${{ matrix.browser }}-hash-${{ hashFiles('yarn.lock') }} From d1dd37a831b7acd5f744f3ab3321f52d71c03c95 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Tue, 29 Nov 2022 21:30:54 -0500 Subject: [PATCH 13/13] update changelogs --- CHANGELOG.md | 9 +++++++++ packages/web3-eth-abi/CHANGELOG.md | 4 ++++ packages/web3-eth-contract/CHANGELOG.md | 4 ++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c133c7462d..56745bfb868 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -903,6 +903,11 @@ should use 4.0.1-alpha.0 for testing. - Export a new function `uuidV4` that generates a random v4 Uuid (#5373). +#### web3-eth-contract + +- `SpecialOutput` type was added as a generic type into the call function to support reassigning output types (#5631) +- Overloaded functions types (`ContractOverloadedMethodInputs`, `ContractOverloadedMethodOutputs`) was added (#5631) + ### Fixed #### web3-eth-contract @@ -917,6 +922,10 @@ should use 4.0.1-alpha.0 for testing. - Use Uuid for the response id, to fix the issue "Responses get mixed up due to conflicting payload IDs" (#5373). +#### web3-eth-abi + +- Fix ContractMethodOutputParameters type to support output object types by index and string key. Also, it returns void if ABI doesn't have outputs and returns exactly one type if the output array has only one element. (#5631) + ### Removed #### web3-eth-accounts diff --git a/packages/web3-eth-abi/CHANGELOG.md b/packages/web3-eth-abi/CHANGELOG.md index deed4f9e417..4a58fa0cda4 100644 --- a/packages/web3-eth-abi/CHANGELOG.md +++ b/packages/web3-eth-abi/CHANGELOG.md @@ -47,3 +47,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Return `BigInt` instead of `string` when decoding function parameters for large numbers, such as `uint256`. (#5435) ## [Unreleased] + +### Fixed + +- Fix ContractMethodOutputParameters type to support output object types by index and string key. Also, it returns void if ABI doesn't have outputs and returns exactly one type if the output array has only one element. (5631) diff --git a/packages/web3-eth-contract/CHANGELOG.md b/packages/web3-eth-contract/CHANGELOG.md index 15a675364ce..beeec0bf709 100644 --- a/packages/web3-eth-contract/CHANGELOG.md +++ b/packages/web3-eth-contract/CHANGELOG.md @@ -177,6 +177,8 @@ const transactionHash = receipt.transactionHash; - Decoding error data, using Error ABI if available, according to EIP-838. (#5434) - The class `Web3ContractError` is moved from this package to `web3-error`. (#5434) +- `SpecialOutput` type was added as a generic type into the call function to support reassigning output types (#5631) +- Overloaded functions types (`ContractOverloadedMethodInputs`, `ContractOverloadedMethodOutputs`) was added (#5631) ### Fixed @@ -186,6 +188,4 @@ const transactionHash = receipt.transactionHash; ### Fixed -#### web3-eth-contract - - Emit past contract events based on `fromBlock` when passed to `contract.events.someEventName` (#5201)