Skip to content

Commit

Permalink
Overloaded method with different number of arguments can't be invoked (
Browse files Browse the repository at this point in the history
  • Loading branch information
tom2drum authored Nov 8, 2023
1 parent 9ebaacb commit 15cfad3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
24 changes: 23 additions & 1 deletion ui/address/contract/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
{
Expand All @@ -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]);
});
});
4 changes: 4 additions & 0 deletions ui/address/contract/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 15cfad3

Please sign in to comment.