From b27366f058fb8b662cdbd2705257f13e19a4328c Mon Sep 17 00:00:00 2001 From: Rohan Jadvani <5459049+rohanjadvani@users.noreply.github.com> Date: Thu, 19 Sep 2024 17:11:03 -0400 Subject: [PATCH] feat(cli): Check the wallet is unlocked before prompting for name (#5395) * feat(cli): Check the wallet is unlocked before prompting for name * feat(cli): Add this.exit(0) * update message * update tests --- ironfish-cli/src/commands/wallet/create.ts | 9 +++++---- ironfish/src/rpc/routes/wallet/decrypt.test.ts | 2 +- ironfish/src/rpc/routes/wallet/unlock.test.ts | 2 +- ironfish/src/wallet/errors.ts | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ironfish-cli/src/commands/wallet/create.ts b/ironfish-cli/src/commands/wallet/create.ts index db1c1a40c0..56238c933e 100644 --- a/ironfish-cli/src/commands/wallet/create.ts +++ b/ironfish-cli/src/commands/wallet/create.ts @@ -23,15 +23,14 @@ export class CreateCommand extends IronfishCommand { async start(): Promise { const { args } = await this.parse(CreateCommand) - let name = args.name + const client = await this.connectRpc() + await checkWalletUnlocked(client) + let name = args.name if (!name) { name = await inputPrompt('Enter the name of the account', true) } - const client = await this.connectRpc() - await checkWalletUnlocked(client) - this.log(`Creating account ${name}`) const result = await client.wallet.createAccount({ name }) @@ -44,5 +43,7 @@ export class CreateCommand extends IronfishCommand { } else { this.log(`Run "ironfish wallet:use ${name}" to set the account as default`) } + + this.exit(0) } } diff --git a/ironfish/src/rpc/routes/wallet/decrypt.test.ts b/ironfish/src/rpc/routes/wallet/decrypt.test.ts index 17628ef3a5..e347ebecb9 100644 --- a/ironfish/src/rpc/routes/wallet/decrypt.test.ts +++ b/ironfish/src/rpc/routes/wallet/decrypt.test.ts @@ -55,7 +55,7 @@ describe('Route wallet/encrypt', () => { await expect( routeTest.client.wallet.decrypt({ passphrase: invalidPassphrase }), - ).rejects.toThrow('Request failed (400) error: Failed to decrypt account') + ).rejects.toThrow('Request failed (400) error: Failed to decrypt wallet') status = await routeTest.client.wallet.getAccountsStatus() expect(status.content.encrypted).toBe(true) diff --git a/ironfish/src/rpc/routes/wallet/unlock.test.ts b/ironfish/src/rpc/routes/wallet/unlock.test.ts index 33c2f14145..9e2ddf9e6d 100644 --- a/ironfish/src/rpc/routes/wallet/unlock.test.ts +++ b/ironfish/src/rpc/routes/wallet/unlock.test.ts @@ -42,7 +42,7 @@ describe('Route wallet/unlock', () => { await expect( routeTest.client.wallet.unlock({ passphrase: invalidPassphrase }), - ).rejects.toThrow('Request failed (400) error: Failed to decrypt account') + ).rejects.toThrow('Request failed (400) error: Failed to decrypt wallet') status = await routeTest.client.wallet.getAccountsStatus() expect(status.content.encrypted).toBe(true) diff --git a/ironfish/src/wallet/errors.ts b/ironfish/src/wallet/errors.ts index dd1e4f9d1d..e0d9c0c16e 100644 --- a/ironfish/src/wallet/errors.ts +++ b/ironfish/src/wallet/errors.ts @@ -84,6 +84,6 @@ export class AccountDecryptionFailedError extends Error { constructor() { super() - this.message = 'Failed to decrypt account' + this.message = 'Failed to decrypt wallet' } }