diff --git a/commands/call.js b/commands/call.js index 52afc760..904bb346 100644 --- a/commands/call.js +++ b/commands/call.js @@ -17,8 +17,13 @@ module.exports = { type: 'string', default: '0' }) + .option('base64', { + desc: 'Treat arguments as base64-encoded BLOB.', + type: 'boolean', + default: false + }) .option('args', { - desc: 'Arguments to the contract call, in JSON format (e.g. \'{"param_a": "value"}\')', + desc: 'Arguments to the contract call, in JSON format by default (e.g. \'{"param_a": "value"}\')', type: 'string', default: null }) @@ -35,10 +40,11 @@ async function scheduleFunctionCall(options) { (options.amount && options.amount != '0' ? ` with attached ${options.amount} NEAR` : '')); const near = await connect(options); const account = await near.account(options.accountId); + const parsedArgs = options.base64 ? Buffer.from(options.args, 'base64') : JSON.parse(options.args || '{}'); const functionCallResponse = await account.functionCall( options.contractName, options.methodName, - JSON.parse(options.args || '{}'), + parsedArgs, options.gas, utils.format.parseNearAmount(options.amount)); const result = providers.getTransactionLastResult(functionCallResponse); diff --git a/middleware/base64-args.js b/middleware/base64-args.js new file mode 100644 index 00000000..e69de29b diff --git a/test/test_contract.sh b/test/test_contract.sh index 924ed9db..9a5e3c90 100755 --- a/test/test_contract.sh +++ b/test/test_contract.sh @@ -28,9 +28,18 @@ RESULT=$(../bin/near view $testaccount getGreeting '{"accountId":"test.near"}' - TEXT=$RESULT EXPECTED='TEST' if [[ ! $TEXT =~ .*$EXPECTED.* ]]; then - cd .. echo FAILURE Unexpected output from near call: $RESULT exit 1 -else - cd .. fi + +# base64-encoded '{"message":"BASE64ROCKS"}' +../bin/near call $testaccount setGreeting --base64 'eyJtZXNzYWdlIjoiQkFTRTY0Uk9DS1MifQ==' --accountId=test.near + +RESULT=$(../bin/near view $testaccount getGreeting '{"accountId":"test.near"}' --accountId=test.near -v) +# TODO: Refactor asserts +TEXT=$RESULT +EXPECTED='BASE64ROCKS' +if [[ ! $TEXT =~ .*$EXPECTED.* ]]; then + echo FAILURE Unexpected output from near call: $RESULT + exit 1 +fi \ No newline at end of file