Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

splitArgsAndOptions with single argument containing options #1252

Open
Skanislav opened this issue Oct 29, 2024 · 2 comments · May be fixed by #1255
Open

splitArgsAndOptions with single argument containing options #1252

Skanislav opened this issue Oct 29, 2024 · 2 comments · May be fixed by #1255
Labels
Type: bug Something isn't working

Comments

@Skanislav
Copy link

Skanislav commented Oct 29, 2024

Describe the bug

export const splitArgsAndOptions = (args: ArgsOrCalldataWithOptions) => {
  const options = [
    'blockIdentifier',
    'parseRequest',
    'parseResponse',
    'formatResponse',
    'maxFee',
    'nonce',
    'signature',
    'addressSalt',
  ];
  const lastArg = args[args.length - 1];
  if (typeof lastArg === 'object' && options.some((x) => x in lastArg)) {
    return { args: args as ArgsOrCalldata, options: args.pop() as ContractOptions };
  }
  return { args: args as ArgsOrCalldata };
};

When it's called during buildCall, and the contract expects a single argument which is struct with a property that overlaps this list of hardcoded options. Resulting in this:

Error: Invalid number of arguments, expected 1 arguments, but got 0
    at _CallData.validate (index.ts:95:13)
    at default.ts:236:23
    at getCalldata (default.ts:115:10)
    at Contract.call (default.ts:234:22)
    at Contract.get_proposal_hash (default.ts:61:21)

To Reproduce

I exported ABIs using abi-wan-kanabi for this contracts and tried to call the get_proposal_hash. I spotted the error because the similar call worked for the function encode_proposal_data that accepts two arguments and works just fine.

Expected behavior

Desktop (please complete the following information):

  • Browser & version Chrome Version 124.0.6367.208
  • Node version v20.14.0
  • Starknet.js version 6.17.0
  • Network devnet
@Skanislav Skanislav added the Type: bug Something isn't working label Oct 29, 2024
@penovicp
Copy link
Collaborator

It looks like it should be doable to refactor splitArgsAndOptions to accept and use the corresponding ABI information to discern if the options object is used rather than through duck typing. The only snag is that the possible inputs are fairly flexible with allowing both structured and precompiled values so extra care needs to be taken to cover all the scenarios.

If this is a major blocker for you there is a silver lining in the aforementioned flexibility in that using the output of CallData.compile(...) for the method input or some other approach from the docs can be used as a workaround.

@poolcleaner6
Copy link

Perhaps splitArgsAndOptions could include a check for the expected argument type from the ABI. This could help avoid errors when the contract expects a single struct with properties that overlap with options

@tabaktoni tabaktoni linked a pull request Nov 1, 2024 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants