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

Invalid FunctionCall Arguments Type Declaration #1432

Open
1 of 4 tasks
bh2smith opened this issue Nov 20, 2024 · 3 comments
Open
1 of 4 tasks

Invalid FunctionCall Arguments Type Declaration #1432

bh2smith opened this issue Nov 20, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@bh2smith
Copy link

Prerequisites

  • I'm using the latest version of near-api-js.
  • I have tried to start with a fresh project and reproduce the defect with minimal code changes.
  • I have read the console error messages carefully (if applicable).

Description

This cast in the constructor is misleading and wrong:

function functionCall(
methodName: string,
args: Uint8Array | object,
gas = 0n,
deposit = 0n,
stringify = stringifyJsonOrBytes,
jsContract = false
): Action {
if (jsContract) {
return new Action({
functionCall: new FunctionCall({ methodName, args: args as Uint8Array, gas, deposit }),
});
}
return new Action({
functionCall: new FunctionCall({
methodName,
args: stringify(args),
gas,
deposit,
}),
});
}

The unit tests call this constructor with arguments defined via Buffer.from which is an "object"

The constructor takes object OR Unit8Array and casts to Uint8Array while the actual contents are never Uint8Array.

Reproducible demo

No response

Steps to reproduce

Try and construct an example in the tests that are actually Uint8Array to demonstrate to end users how its expected to look.

Expected behavior

Expect that the Type declaration for these arguments is actually something people use.

Actual behavior

This form is dumb.

Your environment

  • NEAR JavaScript API version used:
  • Frontend framework (if applicable):
  • Relevant dependencies (if applicable):

Self-service

  • I'd be willing to fix this bug myself.
@bh2smith bh2smith added the bug Something isn't working label Nov 20, 2024
@github-project-automation github-project-automation bot moved this to NEW❗ in DevTools Nov 20, 2024
@AlexKushnir1
Copy link

Sorry, I am not sure that get your problem. It seems that user can pass args either an object or a bytes array. Do you mean the Uint8Array in constructor is unnecessary for the users?

Regarding unit tests there are tests that take both a simple object

const action = functionCall('methodName', {}, 1n, 2n);
and a bytes array
const serializedArgs = Buffer.from('{}');
const action = functionCall('methodName', serializedArgs, 1n, 2n);

@bh2smith
Copy link
Author

bh2smith commented Jan 6, 2025

At this point I no longer remember how I dug up this issue, but both of these unit tests have trivial arguments. It would be better if there were non trivial arguments given to the test so people could use them as an example.

@AlexKushnir1
Copy link

Yeap, it makes more sense to show the real argument.
Thanks for the answer, if you"ll have some extra time and will remind about this issue, I"ll be glad to delve into it and work on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: NEW❗
Development

No branches or pull requests

2 participants