Skip to content

Commit

Permalink
Prototype base64-support
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrichina committed Nov 27, 2020
1 parent 80d5d66 commit 0c3989e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
10 changes: 8 additions & 2 deletions commands/call.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand All @@ -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);
Expand Down
Empty file added middleware/base64-args.js
Empty file.
15 changes: 12 additions & 3 deletions test/test_contract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0c3989e

Please sign in to comment.