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

Commit

Permalink
fix: hanging tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gagdiez committed Feb 29, 2024
1 parent 7ef8c10 commit c3095d2
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 24 deletions.
3 changes: 2 additions & 1 deletion bin/near
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node
const flaggedRespawn = require('flagged-respawn');

require('v8flags')((e, flags) => {
if (e) {
throw e;
Expand All @@ -14,4 +15,4 @@ require('v8flags')((e, flags) => {
require('./near-cli.js');
}
});
})
});
25 changes: 15 additions & 10 deletions commands/account/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,32 @@ 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',
type: 'boolean',
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',
Expand Down Expand Up @@ -82,23 +87,23 @@ 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');
}

if (options.useFaucet) {
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
const newAccountId = options.newAccountId;
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
Expand Down
2 changes: 1 addition & 1 deletion commands/account/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion commands/contract/call.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || ''})` +
Expand Down
2 changes: 1 addition & 1 deletion commands/contract/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion commands/keys/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ')}.`);
Expand Down
2 changes: 1 addition & 1 deletion commands/keys/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion commands/transactions/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion commands/validators/stake.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions ledger-test.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions utils/credentials.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit c3095d2

Please sign in to comment.