From ade51c96d8253e6bb0835611768e311ec7141603 Mon Sep 17 00:00:00 2001 From: Dennis <10233439+idea404@users.noreply.github.com> Date: Wed, 3 Aug 2022 13:41:06 +0000 Subject: [PATCH 1/9] initial commit --- index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index a93465a3..d04dfb16 100644 --- a/index.js +++ b/index.js @@ -224,9 +224,15 @@ exports.deleteAccount = async function (options) { const near = await connect(options); const beneficiaryAccount = await near.account(options.beneficiaryId); // beneficiary account does not exist if there are no access keys - if (!(await beneficiaryAccount.getAccessKeys()).length) { - console.log('Beneficiary account does not exist, please create the account to transfer Near tokens.'); - return; + try { + await beneficiaryAccount.state(); + } catch (e) { + if (e.type === 'AccountDoesNotExist') { + console.error(`Beneficiary account ${options.beneficiaryId} does not exist. Please create the account to transfer Near tokens.`); + return; + } else { + throw e; + } } if (await confirmDelete()) { From d4f2f78107e15cb0b45efaccc80e89b51bb0f983 Mon Sep 17 00:00:00 2001 From: Dennis <10233439+idea404@users.noreply.github.com> Date: Wed, 3 Aug 2022 13:49:00 +0000 Subject: [PATCH 2/9] add another random elem to test acc name --- test/test_deploy_init_contract.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_deploy_init_contract.sh b/test/test_deploy_init_contract.sh index d46c8956..013779d7 100755 --- a/test/test_deploy_init_contract.sh +++ b/test/test_deploy_init_contract.sh @@ -2,7 +2,7 @@ set -e timestamp=$(date +%s) -testaccount=testaccount$timestamp$RANDOM.test.near +testaccount=testaccount$timestamp$RANDOM$RANDOM.test.near echo Creating account ./bin/near create-account $testaccount > /dev/null From b64265e076321a131add1668c96b7c4fe0cd6a51 Mon Sep 17 00:00:00 2001 From: Dennis <10233439+idea404@users.noreply.github.com> Date: Wed, 3 Aug 2022 13:56:55 +0000 Subject: [PATCH 3/9] undo random addiiton --- test/test_deploy_init_contract.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_deploy_init_contract.sh b/test/test_deploy_init_contract.sh index 013779d7..d46c8956 100755 --- a/test/test_deploy_init_contract.sh +++ b/test/test_deploy_init_contract.sh @@ -2,7 +2,7 @@ set -e timestamp=$(date +%s) -testaccount=testaccount$timestamp$RANDOM$RANDOM.test.near +testaccount=testaccount$timestamp$RANDOM.test.near echo Creating account ./bin/near create-account $testaccount > /dev/null From 4f18e2ad3fc87f7bfc66dc160ec7d3e581bd19e6 Mon Sep 17 00:00:00 2001 From: Dennis <10233439+idea404@users.noreply.github.com> Date: Wed, 3 Aug 2022 14:21:43 +0000 Subject: [PATCH 4/9] add sleep after account deletion --- test/test_deploy_init_contract.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_deploy_init_contract.sh b/test/test_deploy_init_contract.sh index d46c8956..7d491b92 100755 --- a/test/test_deploy_init_contract.sh +++ b/test/test_deploy_init_contract.sh @@ -20,6 +20,7 @@ fi # Delete account, remake, redeploy ./bin/near delete $testaccount test.near > /dev/null +sleep 5 ./bin/near create-account $testaccount > /dev/null ./bin/near deploy --accountId $testaccount --wasmFile ./test/res/fungible_token.wasm --initFunction new --initArgs '{"owner_id": "test.near", "total_supply": "1000000"}' > /dev/null RESULT=$(./bin/near view $testaccount get_balance '{"owner_id": "test.near"}' -v | ./node_modules/.bin/strip-ansi) From 18c6718e48dc8d623bc2a58e233ce2cc8c437db0 Mon Sep 17 00:00:00 2001 From: Dennis <10233439+idea404@users.noreply.github.com> Date: Wed, 3 Aug 2022 16:59:57 +0000 Subject: [PATCH 5/9] add echo lines --- test/test_deploy_init_contract.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_deploy_init_contract.sh b/test/test_deploy_init_contract.sh index 7d491b92..d74d0296 100755 --- a/test/test_deploy_init_contract.sh +++ b/test/test_deploy_init_contract.sh @@ -19,8 +19,10 @@ else fi # Delete account, remake, redeploy +echo Deleting account: $testaccount ./bin/near delete $testaccount test.near > /dev/null sleep 5 +echo Recreating account: $testaccount ./bin/near create-account $testaccount > /dev/null ./bin/near deploy --accountId $testaccount --wasmFile ./test/res/fungible_token.wasm --initFunction new --initArgs '{"owner_id": "test.near", "total_supply": "1000000"}' > /dev/null RESULT=$(./bin/near view $testaccount get_balance '{"owner_id": "test.near"}' -v | ./node_modules/.bin/strip-ansi) From e423bdb7a47823738267392aef354d7e109b9b76 Mon Sep 17 00:00:00 2001 From: Dennis <10233439+idea404@users.noreply.github.com> Date: Wed, 3 Aug 2022 17:00:35 +0000 Subject: [PATCH 6/9] categorize tests in package.json --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 67388653..8b5dda9d 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,9 @@ "main": "index.js", "scripts": { "pretest": "rm -rf tmp-project", - "test": "jest && ./test/index.sh", + "test": "npm run test:unit && npm run test:integration", + "test:unit": "jest", + "test:integration": "./test/index.sh", "lint": "eslint .", "fix": "eslint . --fix" }, From 244702a17a9817094389c73df59d6305788f58f1 Mon Sep 17 00:00:00 2001 From: Dennis <10233439+idea404@users.noreply.github.com> Date: Wed, 3 Aug 2022 17:18:45 +0000 Subject: [PATCH 7/9] use yes bash command --- test/test_deploy_init_contract.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/test_deploy_init_contract.sh b/test/test_deploy_init_contract.sh index d74d0296..05bea241 100755 --- a/test/test_deploy_init_contract.sh +++ b/test/test_deploy_init_contract.sh @@ -20,8 +20,7 @@ fi # Delete account, remake, redeploy echo Deleting account: $testaccount -./bin/near delete $testaccount test.near > /dev/null -sleep 5 +yes | ./bin/near delete $testaccount test.near > /dev/null echo Recreating account: $testaccount ./bin/near create-account $testaccount > /dev/null ./bin/near deploy --accountId $testaccount --wasmFile ./test/res/fungible_token.wasm --initFunction new --initArgs '{"owner_id": "test.near", "total_supply": "1000000"}' > /dev/null From a094be4fdf9cb0a68f9d94d4e6aa1d91d4d8aded Mon Sep 17 00:00:00 2001 From: Dennis <10233439+idea404@users.noreply.github.com> Date: Wed, 3 Aug 2022 17:23:49 +0000 Subject: [PATCH 8/9] run index.sh with bash in package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8b5dda9d..94443ee8 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "pretest": "rm -rf tmp-project", "test": "npm run test:unit && npm run test:integration", "test:unit": "jest", - "test:integration": "./test/index.sh", + "test:integration": "bash ./test/index.sh", "lint": "eslint .", "fix": "eslint . --fix" }, From c0874762a0c3748e56856a217b4f51d6ec73dd7a Mon Sep 17 00:00:00 2001 From: Dennis <10233439+idea404@users.noreply.github.com> Date: Wed, 3 Aug 2022 17:39:51 +0000 Subject: [PATCH 9/9] use printf instead of yes, more intentional --- index.js | 2 +- test/test_deploy_init_contract.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index d04dfb16..b4869bcd 100644 --- a/index.js +++ b/index.js @@ -244,7 +244,7 @@ exports.deleteAccount = async function (options) { console.log(`Account ${options.accountId} for network "${options.networkId}" was deleted.`); } else { - console.log(chalk`{bold.white Deletion of account with account id: {bold.blue ${options.accountId} } was {bold.red canceled}}`); + console.log(chalk`{bold.white Deletion of account with account id: {bold.blue ${options.accountId} } was {bold.red cancelled}}`); } }; diff --git a/test/test_deploy_init_contract.sh b/test/test_deploy_init_contract.sh index 05bea241..7b7adee9 100755 --- a/test/test_deploy_init_contract.sh +++ b/test/test_deploy_init_contract.sh @@ -20,7 +20,7 @@ fi # Delete account, remake, redeploy echo Deleting account: $testaccount -yes | ./bin/near delete $testaccount test.near > /dev/null +printf 'y\n' | ./bin/near delete $testaccount test.near > /dev/null echo Recreating account: $testaccount ./bin/near create-account $testaccount > /dev/null ./bin/near deploy --accountId $testaccount --wasmFile ./test/res/fungible_token.wasm --initFunction new --initArgs '{"owner_id": "test.near", "total_supply": "1000000"}' > /dev/null