Skip to content

Commit

Permalink
Always honor the name parameter passed to importAccount
Browse files Browse the repository at this point in the history
When calling `importAccount` with an `RpcAccountImport` and a
non-undefined `name`, the `name` parameter used to be ignored. This is
no longer the case: passing a non-undefined `name` now overrides the
name of the `RpcAccountImport`.
  • Loading branch information
andiflabs committed Apr 18, 2024
1 parent 0fcacc9 commit 1735b1f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ironfish/src/rpc/routes/wallet/importAccount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,34 @@ describe('Route wallet/importAccount', () => {
})
})

it('should import a spending account with the specified name', async () => {
const key = generateKey()

const accountName = 'bar'
const overriddenAccountName = 'not-bar'
const response = await routeTest.client.wallet.importAccount({
account: {
name: accountName,
viewKey: key.viewKey,
spendingKey: key.spendingKey,
publicAddress: key.publicAddress,
incomingViewKey: key.incomingViewKey,
outgoingViewKey: key.outgoingViewKey,
proofAuthorizingKey: null,
version: 1,
createdAt: null,
},
name: overriddenAccountName,
rescan: false,
})

expect(response.status).toBe(200)
expect(response.content).toMatchObject({
name: overriddenAccountName,
isDefaultAccount: false, // This is false because the default account is already imported in a previous test
})
})

describe('import rescanning', () => {
let nodeClient: RpcClient | null = null

Expand Down
3 changes: 3 additions & 0 deletions ironfish/src/rpc/routes/wallet/importAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ routes.register<typeof ImportAccountRequestSchema, ImportResponse>(
}
} else {
accountImport = deserializeRpcAccountImport(request.data.account)
if (request.data.name) {
accountImport.name = request.data.name
}
}

account = await context.wallet.importAccount(accountImport)
Expand Down

0 comments on commit 1735b1f

Please sign in to comment.