Skip to content

Commit

Permalink
feat(cli): Check the wallet is unlocked before prompting for name (#5395
Browse files Browse the repository at this point in the history
)

* feat(cli): Check the wallet is unlocked before prompting for name

* feat(cli): Add this.exit(0)

* update message

* update tests
  • Loading branch information
rohanjadvani committed Sep 19, 2024
1 parent 9319ca0 commit b27366f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions ironfish-cli/src/commands/wallet/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ export class CreateCommand extends IronfishCommand {

async start(): Promise<void> {
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 })

Expand All @@ -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)
}
}
2 changes: 1 addition & 1 deletion ironfish/src/rpc/routes/wallet/decrypt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ironfish/src/rpc/routes/wallet/unlock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ironfish/src/wallet/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ export class AccountDecryptionFailedError extends Error {

constructor() {
super()
this.message = 'Failed to decrypt account'
this.message = 'Failed to decrypt wallet'
}
}

0 comments on commit b27366f

Please sign in to comment.