Skip to content

Commit

Permalink
near-bindgen-exporter modified to allow dict params
Browse files Browse the repository at this point in the history
  • Loading branch information
volovyks committed Jun 2, 2022
1 parent b67676a commit c7fdd0b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/build-tools/near-bindgen-exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/near-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class NearContract {

static deserializeArgs() {
let args = near.jsvmArgs();
return JSON.parse(args || '[]')
return JSON.parse(args || '{}')
}

static serializeReturn(ret) {
Expand Down
11 changes: 0 additions & 11 deletions tests/__tests__/function-params.ava.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
);
});
2 changes: 1 addition & 1 deletion tests/src/function-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c7fdd0b

Please sign in to comment.