Skip to content

Commit

Permalink
fix: make sure that the flow works when params/result are missing
Browse files Browse the repository at this point in the history
  • Loading branch information
itegulov committed Jan 25, 2023
1 parent 38ac5bc commit 7c7370d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/near-api-js/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ function nameFunction(name: string, body: (args?: any[]) => any) {
function validateArguments(args: object, abiFunction: AbiFunction, ajv: Ajv, abiRoot: AbiRoot) {
if (!isObject(args)) return;

if (abiFunction.params?.serialization_type !== AbiSerializationType.Json) {
if (abiFunction.params && abiFunction.params.serialization_type !== AbiSerializationType.Json) {
throw new UnsupportedSerializationError(abiFunction.name, abiFunction.params.serialization_type);
}

if (abiFunction.result?.serialization_type !== AbiSerializationType.Json) {
throw new UnsupportedSerializationError(abiFunction.name, abiFunction.params.serialization_type);
if (abiFunction.result && abiFunction.result.serialization_type !== AbiSerializationType.Json) {
throw new UnsupportedSerializationError(abiFunction.name, abiFunction.result.serialization_type);
}

const params = abiFunction.params.args;
const params = abiFunction.params?.args || [];
for (const p of params) {
const arg = args[p.name];
const typeSchema = p.type_schema;
Expand Down
10 changes: 10 additions & 0 deletions packages/near-api-js/test/contract_abi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ let rawAbi = `{
"$ref": "#/definitions/Pair"
}
}
},
{
"name": "empty_call",
"kind": "call"
}
],
"root_schema": {
Expand Down Expand Up @@ -141,6 +145,12 @@ describe('add_call', () => {
});
});

describe('empty_call', () => {
test('can be called successfully', async () => {
await contract.empty_call({});
});
});

describe('Contract constructor', () => {
test('throws UnsupportedSerializationError when ABI has borsh serialization', async () => {
let rawAbi = `{
Expand Down

0 comments on commit 7c7370d

Please sign in to comment.