Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #139 from nearprotocol/inspect-response
Browse files Browse the repository at this point in the history
Use inspectResponse to display nearcore responses
  • Loading branch information
vgrichina authored Sep 21, 2019
2 parents 8caace3 + 4281155 commit 69af793
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 14 deletions.
12 changes: 6 additions & 6 deletions index.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ exports.viewAccount = async function(options) {
let account = await near.account(options.accountId);
let state = await account.state();
console.log(`Account ${options.accountId}`);
console.log(state);
console.log(inspectResponse(state));
}

exports.deleteAccount = async function(options) {
Expand All @@ -95,7 +95,7 @@ exports.txStatus = async function(options) {
let near = await connect(options);
let status = await near.connection.provider.txStatus(bs58.decode(options.hash));
console.log(`Transaction ${options.hash}`);
console.log(status);
console.log(inspectResponse(status));
}

exports.deploy = async function(options) {
Expand All @@ -114,30 +114,30 @@ exports.scheduleFunctionCall = async function(options) {
const account = await near.account(options.accountId);
const functionCallResponse = await account.functionCall(options.contractName, options.methodName, JSON.parse(options.args || '{}'), options.amount);
const result = nearjs.providers.getTransactionLastResult(functionCallResponse);
console.log('Result:', result);
console.log(inspectResponse(result));
};

exports.sendMoney = async function(options) {
console.log(`Sending ${options.amount} NEAR to ${options.receiver} from ${options.sender}`);
const near = await connect(options);
const account = await near.account(options.sender);
await account.sendMoney(options.receiver, options.amount);
console.log(inspectResponse(await account.sendMoney(options.receiver, options.amount)));
};

exports.callViewFunction = async function(options) {
console.log(`View call: ${options.contractName}.${options.methodName}(${options.args || ''})`);
const near = await connect(options);
// TODO: Figure out how to run readonly calls without account
const account = await near.account(options.accountId || options.masterAccount || 'register.near');
console.log('Result:', await account.viewFunction(options.contractName, options.methodName, JSON.parse(options.args || '{}')));
console.log(inspectResponse(await account.viewFunction(options.contractName, options.methodName, JSON.parse(options.args || '{}'))));
};

exports.stake = async function(options) {
console.log(`Staking ${options.amount} on ${options.accountId} with public key = ${options.publicKey}.`);
const near = await connect(options);
const account = await near.account(options.accountId);
const result = await account.stake(options.publicKey, BigInt(options.amount));
console.log('Result: ', JSON.stringify(result));
console.log(inspectResponse(result));
}

exports.login = async function(options) {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"bin": {
"near": "./bin/near"
},
"devDependencies": {},
"devDependencies": {
"strip-ansi-cli": "^2.0.0"
},
"dependencies": {
"assemblyscript": "github:nearprotocol/assemblyscript",
"bs58": "^4.0.1",
Expand Down
18 changes: 14 additions & 4 deletions test/index.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/bin/bash
set -ex
./test/new_project.sh
./test/account_operations.sh
#./test/contract_tests.sh
OVERALL_RESULT=0
for test in ./test/test_*; do
echo ""
echo "Running $test"
"$test"
if [ $? -ne 0 ]; then
echo "$test FAIL"
OVERALL_RESULT=1
else
echo "$test SUCCESS"
fi
done

exit $OVERALL_RESULT
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#!/bin/bash
set -ex
rm -rf tmp-project
./bin/near new_project 'tmp-project'
cd tmp-project
timestamp=$(date +%s)
testaccount=testaccount$timestamp
echo Create account
../bin/near create_account $testaccount

echo Get account state
RESULT=$(../bin/near state $testaccount)
if [[ $RESULT != *"Account $testaccount"*"amount: '100000000'"* ]]; then
RESULT=$(../bin/near state $testaccount | strip-ansi)
echo $RESULT
EXPECTED=".+Account $testaccount.+amount:.+'100000000'.+ "
if [[ ! "$RESULT" =~ $EXPECTED ]]; then
echo FAILURE Unexpected output from near state
exit 1
fi
Expand Down
2 changes: 2 additions & 0 deletions test/contract_tests.sh → test/test_contract.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash
set -ex
rm -rf tmp-project
./bin/near new_project 'tmp-project'
cd tmp-project
rm -rf assembly
mkdir assembly
Expand Down
2 changes: 1 addition & 1 deletion test/new_project.sh → test/test_new_project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ yarn remove near-shell
yarn add ../
yarn test
cd ..
rm -rf tmp-project

# test generating new project in new dir
rm -rf tmp-project
./bin/near new_project 'tmp-project'
cd tmp-project
FILE=package.json
Expand Down

0 comments on commit 69af793

Please sign in to comment.