Skip to content

Commit

Permalink
starts scanTransactions after account creation (#3659)
Browse files Browse the repository at this point in the history
* starts scanTransactions after account creation

if a node is online and syncing at the time of account creation it's possible to
for an account head to be set to a block that is behind the wallet's
chainProcessor.

if the account's head is behind the chain processor then the wallet will not
scan any transactions for the account until the node is restarted.

runs scanTransactions after creating an account in the 'create' RPC so that a
newly created account will be synced with the chainProcessor if it is behind.
this matches the logic in the 'importAccount' RPC.

* mocks scanTransactions in beforeEach
  • Loading branch information
hughy authored Mar 20, 2023
1 parent 2770943 commit c57ade0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions ironfish/src/rpc/routes/wallet/create.test.slow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import { RpcRequestError } from '../../clients/errors'
describe('Route wallet/create', () => {
jest.setTimeout(15000)
const routeTest = createRouteTest()

beforeEach(() => {
jest.spyOn(routeTest.node.wallet, 'scanTransactions').mockReturnValue(Promise.resolve())
})

it('should create an account', async () => {
await routeTest.node.wallet.createAccount('existingAccount', true)

Expand Down Expand Up @@ -63,4 +68,24 @@ describe('Route wallet/create', () => {
expect(e.code).toBe(ERROR_CODES.ACCOUNT_EXISTS)
}
})

it('should start scanning transactions for the new account', async () => {
const scanTransactions = jest
.spyOn(routeTest.node.wallet, 'scanTransactions')
.mockReturnValue(Promise.resolve())

await routeTest.node.wallet.createAccount('existingAccount', true)

const name = uuid()

const response = await routeTest.client.createAccount({ name })
expect(response.status).toBe(200)
expect(response.content).toMatchObject({
name: name,
publicAddress: expect.any(String),
isDefaultAccount: false,
})

expect(scanTransactions).toHaveBeenCalled()
})
})
1 change: 1 addition & 0 deletions ironfish/src/rpc/routes/wallet/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ router.register<typeof CreateAccountRequestSchema, CreateAccountResponse>(
}

const account = await node.wallet.createAccount(name)
void node.wallet.scanTransactions()

let isDefaultAccount = false
if (!node.wallet.hasDefaultAccount || request.data.default) {
Expand Down

0 comments on commit c57ade0

Please sign in to comment.