From c7fdd0bff33e9468733451ac44dde6b1867b3df6 Mon Sep 17 00:00:00 2001 From: Serhii Volovyk Date: Thu, 2 Jun 2022 21:52:41 +0300 Subject: [PATCH] near-bindgen-exporter modified to allow dict params --- src/build-tools/near-bindgen-exporter.js | 4 ++-- src/near-contract.js | 2 +- tests/__tests__/function-params.ava.js | 11 ----------- tests/src/function-params.js | 2 +- 4 files changed, 4 insertions(+), 15 deletions(-) diff --git a/src/build-tools/near-bindgen-exporter.js b/src/build-tools/near-bindgen-exporter.js index 7f8926b70..bd4d9df3b 100644 --- a/src/build-tools/near-bindgen-exporter.js +++ b/src/build-tools/near-bindgen-exporter.js @@ -34,9 +34,9 @@ export default function () { // let args = _contract.constructor.deserializeArgs() t.variableDeclaration('let', [t.variableDeclarator(t.identifier('args'), t.callExpression(t.memberExpression(t.memberExpression(t.identifier('_contract'), t.identifier('constructor')), t.identifier('deserializeArgs')), []))]), - // let ret = _contract.method(...args) + // let ret = _contract.method(args) t.variableDeclaration('let', [t.variableDeclarator(t.identifier('ret'), - t.callExpression(t.memberExpression(t.identifier('_contract'), t.identifier(method)), [t.spreadElement(t.identifier('args'))]))]), + t.callExpression(t.memberExpression(t.identifier('_contract'), t.identifier(method)), [t.identifier('args')]))]), contractMethods[method] == 'call' ? // _contract.serialize() t.expressionStatement( diff --git a/src/near-contract.js b/src/near-contract.js index d763bf6f0..352d134cb 100644 --- a/src/near-contract.js +++ b/src/near-contract.js @@ -16,7 +16,7 @@ export class NearContract { static deserializeArgs() { let args = near.jsvmArgs(); - return JSON.parse(args || '[]') + return JSON.parse(args || '{}') } static serializeReturn(ret) { diff --git a/tests/__tests__/function-params.ava.js b/tests/__tests__/function-params.ava.js index 49a9720ee..87baee634 100644 --- a/tests/__tests__/function-params.ava.js +++ b/tests/__tests__/function-params.ava.js @@ -52,14 +52,3 @@ test('Developer can pass parameters as dictionary', async t => { { val3: 'newVal3', val2: 'newVal2', val1: 'newVal1' } ); }); - -test('Developer can pass parameters as array', async t => { - const { ali, jsvm, testContract } = t.context.accounts; - - await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'set_values', ['newVal1', 'newVal2', 'newVal3']), { attachedDeposit: '100000000000000000000000' }); - - t.deepEqual( - await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'get_values', [])), - { val3: 'newVal3', val2: 'newVal2', val1: 'newVal1' } - ); -}); \ No newline at end of file diff --git a/tests/src/function-params.js b/tests/src/function-params.js index ab64d5248..305f26e02 100644 --- a/tests/src/function-params.js +++ b/tests/src/function-params.js @@ -19,7 +19,7 @@ class FunctionParamsTestContract extends NearContract { } @call - set_values(param1, param2, param3) { + set_values({ param1, param2, param3 }) { near.log(JSON.stringify({ param1, param2, param3 })); this.val1 = param1; this.val2 = param2;