From 4114ab6b274ae55091fcd3a7d54f8c5957b90841 Mon Sep 17 00:00:00 2001 From: gagdiez Date: Thu, 8 Feb 2024 16:09:40 +0100 Subject: [PATCH] fix: TLA accounts from 1.37 --- commands/account/create.js | 14 +++++++------- commands/transactions/send.js | 1 - test/test_account_creation.sh | 15 +++++++++++---- utils/credentials.js | 1 - 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/commands/account/create.js b/commands/account/create.js index 95030dbe..7fca52a3 100644 --- a/commands/account/create.js +++ b/commands/account/create.js @@ -66,8 +66,8 @@ async function create(options) { if (options.useFaucet) { if (options.networkId !== 'testnet') throw new Error('Pre-funding accounts is only possible on testnet'); - }else{ - if(!options.useAccount) throw new Error('Please specify an account to sign the transaction (--useAccount)'); + } else { + if (!options.useAccount) throw new Error('Please specify an account to sign the transaction (--useAccount)'); await assertCredentials(options.useAccount, options.networkId, options.keyStore); } @@ -93,7 +93,7 @@ async function create(options) { // Use an existing account const account = await near.account(options.useAccount); try { await account.state(); } catch (e) { - throw new Error(`Account ${options.useAccount} does not exist in ${options.networkId}. Are you using the right network?`); + throw new Error(`Account ${options.useAccount} does not exist in ${options.networkId}. Are you using the right network?`); } const initialBalance = utils.format.parseNearAmount(options.initialBalance); @@ -117,7 +117,7 @@ async function create(options) { try { // Handle response const response = await promise; - if (keyPair){ + if (keyPair) { storeCredentials(newAccountId, options.networkId, options.keyStore, keyPair, true); } else { console.log(chalk`{bold.white ${newAccountId}} created successfully, please add its credentials manually.`); @@ -127,13 +127,13 @@ async function create(options) { // Handle errors switch (error.type) { case 'CreateAccountNotAllowed': - console.error(chalk`\n{red.bold Error:} ${options.useFaucet? 'the faucet service' : options.useAccount} cannot create ${newAccountId} (networkId: ${options.networkId}).`); + console.error(chalk`\n{red.bold Error:} ${options.useFaucet ? 'the faucet service' : options.useAccount} cannot create ${newAccountId} (networkId: ${options.networkId}).`); options.useAccount && console.error(chalk`${options.useAccount} can only create sub-accounts of itself, or .${network2TLA[options.networkId]} accounts.\n`); options.useFaucet && console.error(chalk`Try using an account to fund it (--useAccount).`); process.exit(1); break; case 'NotEnoughBalance': - console.error(chalk`\n{red.bold Error:} ${options.useFaucet? 'The faucet service' : options.useAccount} does not have enough balance.`); + console.error(chalk`\n{red.bold Error:} ${options.useFaucet ? 'The faucet service' : options.useAccount} does not have enough balance.`); console.error(`Transaction hash: ${error.context.transactionHash}\n`); console.error(`Signer: ${error.kind.signer_id}`); console.error(`Balance: ${utils.format.formatNearAmount(error.kind.balance)}`); @@ -141,7 +141,7 @@ async function create(options) { process.exit(1); break; case 'CreateAccountOnlyByRegistrar': - console.error(chalk`\nYou cannot create Top Level Accounts with less than 32 chars (${newAccountId} has ${newAccountId.length} chars).`); + console.error(chalk`\nYou cannot create Top Level Accounts.`); process.exit(1); break; default: diff --git a/commands/transactions/send.js b/commands/transactions/send.js index 0606bf80..f2cf6119 100644 --- a/commands/transactions/send.js +++ b/commands/transactions/send.js @@ -27,7 +27,6 @@ async function sendMoney(options) { const near = await connect(options); const account = await near.account(options.sender); - try { console.log(`Sending ${options.amount} NEAR to ${options.receiver} from ${options.sender}`); const result = await account.sendMoney(options.receiver, utils.format.parseNearAmount(options.amount)); diff --git a/test/test_account_creation.sh b/test/test_account_creation.sh index 2b07b542..0424cd50 100755 --- a/test/test_account_creation.sh +++ b/test/test_account_creation.sh @@ -41,9 +41,6 @@ fi # An account can create zero-balance accounts ./bin/near create-account $zerobalance --accountId $testaccount1 --initialBalance 0 -# An account can create a TLA -./bin/near create-account $tla --accountId $testaccount1 - set +e # Cannot create sub-accounts of other accounts @@ -68,7 +65,7 @@ fi # Cannot create a TLA with a short name ERROR=$(./bin/near create-account tooshortfortla --accountId $testaccount1 2>&1) -EXPECTED_ERROR=".+cannot create Top Level Accounts with less than 32 chars.+" +EXPECTED_ERROR=".+cannot create Top Level Accounts.+" if [[ ! "$ERROR" =~ $EXPECTED_ERROR ]]; then echo FAILURE Unexpected output when creating a short top-level account echo Got: $ERROR @@ -76,6 +73,16 @@ if [[ ! "$ERROR" =~ $EXPECTED_ERROR ]]; then exit 1 fi +# Cannot create a TLA with a long name +ERROR=$(./bin/near create-account $tla --accountId $testaccount1 2>&1) +EXPECTED_ERROR=".+cannot create Top Level Accounts.+" +if [[ ! "$ERROR" =~ $EXPECTED_ERROR ]]; then + echo FAILURE Unexpected output when creating a long top-level account + echo Got: $ERROR + echo Expected: $EXPECTED_ERROR + exit 1 +fi + # Cannot create a useFaucet account in mainnet ERROR=$(./bin/near create-account $testaccount4 --useFaucet --networkId mainnet 2>&1) EXPECTED_ERROR=".+Pre-funding accounts is only possible on testnet.+" diff --git a/utils/credentials.js b/utils/credentials.js index 10ba9a59..4d3fdceb 100644 --- a/utils/credentials.js +++ b/utils/credentials.js @@ -1,7 +1,6 @@ const chalk = require('chalk'); async function assertCredentials(accountId, networkId, keyStore) { - const key = await keyStore.getKey(networkId, accountId); if(key) return;