From c3095d2c1f1027ad01dd0528105d3278b3b8f052 Mon Sep 17 00:00:00 2001 From: gagdiez Date: Thu, 29 Feb 2024 13:35:14 +0100 Subject: [PATCH] fix: hanging tests --- bin/near | 3 ++- commands/account/create.js | 25 +++++++++++++++---------- commands/account/delete.js | 2 +- commands/contract/call.js | 2 +- commands/contract/deploy.js | 2 +- commands/keys/add.js | 2 +- commands/keys/delete.js | 2 +- commands/transactions/send.js | 2 +- commands/validators/stake.js | 2 +- ledger-test.sh | 9 +++++---- utils/credentials.js | 4 ++-- 11 files changed, 31 insertions(+), 24 deletions(-) diff --git a/bin/near b/bin/near index 813848f5..f2b0d401 100755 --- a/bin/near +++ b/bin/near @@ -1,5 +1,6 @@ #!/usr/bin/env node const flaggedRespawn = require('flagged-respawn'); + require('v8flags')((e, flags) => { if (e) { throw e; @@ -14,4 +15,4 @@ require('v8flags')((e, flags) => { require('./near-cli.js'); } }); -}) +}); \ No newline at end of file diff --git a/commands/account/create.js b/commands/account/create.js index f7849119..7c9259b0 100644 --- a/commands/account/create.js +++ b/commands/account/create.js @@ -29,6 +29,11 @@ module.exports = { type: 'string', default: '1' }) + .option('publicKey', { + desc: 'Public key to initialize the account with', + type: 'string', + required: false + }) .option('signWithLedger', { alias: ['useLedgerKey'], desc: 'Use Ledger for signing', @@ -36,20 +41,20 @@ module.exports = { default: false }) .option('ledgerPath', { - desc: 'HD key path', + desc: 'Path to the Ledger key', type: 'string', default: "44'/397'/0'/0'/1'" }) - .option('ledgerPK', { + .option('useLedgerPK', { alias: ['newLedgerKey'], desc: 'Initialize the account using the public key from the Ledger', - type: 'string', - default: "44'/397'/0'/0'/1'" + type: 'boolean', + default: false }) - .option('publicKey', { - desc: 'Public key to initialize the account with', + .option('PkLedgerPath', { + desc: 'Path to the Ledger key that will be added to the account', type: 'string', - required: false + default: "44'/397'/0'/0'/1'" }) .option('networkId', { desc: 'Which network to use. Supports: mainnet, testnet, custom', @@ -82,7 +87,7 @@ async function create(options) { throw new Error(chalk`Please specify if you want the account to be fund by a faucet (--useFaucet) or through an existing --accountId)`); } - if (options.ledgerPK && options.publicKey) { + if (options.useLedgerPK && options.publicKey) { throw new Error('Please specify only one of --publicKeyFromLedger or --publicKey'); } @@ -90,7 +95,7 @@ async function create(options) { if (options.networkId === 'mainnet') throw new Error('Pre-funding accounts is not possible on mainnet'); } else { if (!options.useAccount) throw new Error('Please specify an account to sign the transaction (--useAccount)'); - await assertCredentials(options); + await assertCredentials(options.useAccount, options.networkId, options.keyStore, options.useLedgerKey); } // assert account being created does not exist @@ -98,7 +103,7 @@ async function create(options) { await assertAccountDoesNotExist(newAccountId, near); let keyPair; - let publicKey = options.ledgerPK ? await getPublicKeyForPath(options.ledgerPK) : options.publicKey; + let publicKey = options.useLedgerPK ? await getPublicKeyForPath(options.PkLedgerPath) : options.publicKey; if (!publicKey) { // If no public key is specified, create a random one diff --git a/commands/account/delete.js b/commands/account/delete.js index 1cf0d91b..38c1202b 100644 --- a/commands/account/delete.js +++ b/commands/account/delete.js @@ -41,7 +41,7 @@ const confirmDelete = function (accountId, beneficiaryId) { }; async function deleteAccount(options) { - await assertCredentials(options); + await assertCredentials(options.accountId, options.networkId, options.keyStore, options.useLedgerKey); const near = await connect(options); const beneficiaryAccount = await near.account(options.beneficiaryId); diff --git a/commands/contract/call.js b/commands/contract/call.js index abdf4dd6..859b2aac 100644 --- a/commands/contract/call.js +++ b/commands/contract/call.js @@ -69,7 +69,7 @@ async function scheduleFunctionCall(options) { options.keyStore.setKey(options.networkId, options.accountId, keyPair); } - await assertCredentials(options); + await assertCredentials(options.accountId, options.networkId, options.keyStore, options.useLedgerKey); const deposit = options.depositYocto != null ? options.depositYocto : utils.format.parseNearAmount(options.deposit); console.log(`Scheduling a call: ${options.contractName}.${options.methodName}(${options.args || ''})` + diff --git a/commands/contract/deploy.js b/commands/contract/deploy.js index 567f3581..3c8c4654 100644 --- a/commands/contract/deploy.js +++ b/commands/contract/deploy.js @@ -58,7 +58,7 @@ const checkExistingContract = async function (prevCodeHash) { }; async function deploy(options) { - await assertCredentials(options); + await assertCredentials(options.accountId, options.networkId, options.keyStore, options.useLedgerKey); const near = await connect(options); const account = await near.account(options.accountId); diff --git a/commands/keys/add.js b/commands/keys/add.js index 1cbb8c9b..e031ca2c 100644 --- a/commands/keys/add.js +++ b/commands/keys/add.js @@ -44,7 +44,7 @@ module.exports = { }; async function addAccessKey(options) { - await assertCredentials(options); + await assertCredentials(options.accountId, options.networkId, options.keyStore, options.useLedgerKey); console.log(`Adding ${options.contractId ? 'function call access' : 'full access'} key ${options.publicKey} to ${options.accountId}.`); if (options.contractId) console.log(`Limited to: ${options.allowance} $NEAR and methods: ${options.methodNames.join(' ')}.`); diff --git a/commands/keys/delete.js b/commands/keys/delete.js index beee4588..d65b1316 100644 --- a/commands/keys/delete.js +++ b/commands/keys/delete.js @@ -34,7 +34,7 @@ module.exports = { }; async function deleteAccessKey(options) { - await assertCredentials(options); + await assertCredentials(options.accountId, options.networkId, options.keyStore, options.useLedgerKey); const near = await connect(options); const account = await near.account(options.accountId); const approval = await isAllApprovalsGranted(account, options.accessKey); diff --git a/commands/transactions/send.js b/commands/transactions/send.js index 5816e0ff..25137383 100644 --- a/commands/transactions/send.js +++ b/commands/transactions/send.js @@ -34,7 +34,7 @@ module.exports = { }; async function sendMoney(options) { - await assertCredentials(options); + await assertCredentials(options.sender, options.networkId, options.keyStore, options.useLedgerKey); const near = await connect(options); const account = await near.account(options.sender); diff --git a/commands/validators/stake.js b/commands/validators/stake.js index 98b54a08..24134372 100644 --- a/commands/validators/stake.js +++ b/commands/validators/stake.js @@ -47,7 +47,7 @@ module.exports = { async function stake(options) { - await assertCredentials(options); + await assertCredentials(options.accountId, options.networkId, options.keyStore, options.useLedgerKey); console.log(`Staking ${options.amount} (${utils.format.parseNearAmount(options.amount)}N) on ${options.accountId} with public key = ${qs.unescape(options.stakingKey)}.`); const near = await connect(options); const account = await near.account(options.accountId); diff --git a/ledger-test.sh b/ledger-test.sh index 70c1fc39..d0c45bb0 100644 --- a/ledger-test.sh +++ b/ledger-test.sh @@ -1,17 +1,18 @@ # CREATE WITH FAUCET -yarn start create-account miralos-como-sonrien.testnet --ledgerPK --useFaucet +yarn start create-account miralos-como-sonrien.testnet --useLedgerPK --useFaucet # CREATE WITH ACCOUNT -yarn start create-account ya.miralos-como-sonrien.testnet --ledgerPK --useAccount miralos-como-sonrien.testnet --useLedgerKey +yarn start create-account ya.miralos-como-sonrien.testnet --useLedgerPK --useAccount miralos-como-sonrien.testnet --useLedgerKey # SEND-NEAR yarn start send-near miralos-como-sonrien.testnet influencer.testnet 0.01 --useLedgerKey +yarn start send-near ya.miralos-como-sonrien.testnet influencer.testnet 0.01 --useLedgerKey # CALL yarn start call hello.near-examples.testnet set_greeting '{"greeting":"Hola"}' --accountId miralos-como-sonrien.testnet --useLedgerKey -# DEPLOY -yarn start deploy miralos-como-sonrien.testnet ./contract.wasm --signWithLedger +# DEPLOY (not available yet, maybe in the future with the Ledger App update?) +# yarn start deploy miralos-como-sonrien.testnet ./contract.wasm --signWithLedger ## ADD KEY yarn start add-key miralos-como-sonrien.testnet ed25519:GnsdHdSrhe8v3MMAQi2bnXR59xMDwdkSRAFZ961ydxWZ --signWithLedger diff --git a/utils/credentials.js b/utils/credentials.js index 9cb3d2ac..5d449a47 100644 --- a/utils/credentials.js +++ b/utils/credentials.js @@ -1,7 +1,7 @@ const chalk = require('chalk'); -async function assertCredentials({ accountId, networkId, keyStore, signWithLedger }) { - if (signWithLedger) return; +async function assertCredentials(accountId, networkId, keyStore, usingLedger) { + if (usingLedger) return; const key = await keyStore.getKey(networkId, accountId); if (key) return;