From 15cfad340d9ac16e7b4ba47090a191e435bdfbcd Mon Sep 17 00:00:00 2001 From: tom goriunov Date: Wed, 8 Nov 2023 10:12:04 -0300 Subject: [PATCH] Overloaded method with different number of arguments can't be invoked (#1332) Fixes #1327 --- ui/address/contract/utils.test.ts | 24 +++++++++++++++++++++++- ui/address/contract/utils.ts | 4 ++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ui/address/contract/utils.test.ts b/ui/address/contract/utils.test.ts index 89a5936f2a..135e765f88 100644 --- a/ui/address/contract/utils.test.ts +++ b/ui/address/contract/utils.test.ts @@ -53,7 +53,7 @@ describe('function prepareAbi()', () => { expect(abi).toHaveLength(commonAbi.length); }); - it('if there are two or more methods with the same name, filters out those which inputs are not matched', () => { + it('if there are two or more methods with the same name and inputs length, filters out those which input types are not matched', () => { const abi = prepareAbi([ ...commonAbi, { @@ -75,4 +75,26 @@ describe('function prepareAbi()', () => { const item = abi.find((item) => 'name' in item ? item.name === method.name : false); expect(item).toEqual(commonAbi[2]); }); + + it('if there are two or more methods with the same name and different inputs length, filters out those which inputs are not matched', () => { + const abi = prepareAbi([ + ...commonAbi, + { + inputs: [ + { internalType: 'address', name: '_fallbackUser', type: 'address' }, + ], + name: 'directNativeDeposit', + outputs: [ + { internalType: 'uint256', name: '', type: 'uint256' }, + ], + stateMutability: 'payable', + type: 'function', + }, + ], method); + + expect(abi).toHaveLength(commonAbi.length); + + const item = abi.find((item) => 'name' in item ? item.name === method.name : false); + expect(item).toEqual(commonAbi[2]); + }); }); diff --git a/ui/address/contract/utils.ts b/ui/address/contract/utils.ts index dccd568c90..aea8a17587 100644 --- a/ui/address/contract/utils.ts +++ b/ui/address/contract/utils.ts @@ -61,6 +61,10 @@ export function prepareAbi(abi: Abi, item: SmartContractWriteMethod): Abi { return true; } + if (abiItem.inputs.length !== item.inputs.length) { + return false; + } + return abiItem.inputs.every(({ name, type }) => { const itemInput = item.inputs.find((input) => input.name === name); return Boolean(itemInput) && itemInput?.type === type;