-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: returning empty object on db utils and added test for services i…
…ncluding db
- Loading branch information
1 parent
b67edfc
commit 402ee17
Showing
3 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
packages/daemon/__tests__/services/services_with_db.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Copyright (c) Hathor Labs and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import * as db from '../../src/db'; | ||
import { handleVoidedTx } from '../../src/services'; | ||
import { LRU } from '../../src/utils'; | ||
|
||
/** | ||
* @jest-environment node | ||
*/ | ||
|
||
describe('handleVoidedTx (db)', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should handle transactions with an empty list of inputs', async () => { | ||
const voidTxSpy = jest.spyOn(db, 'voidTransaction'); | ||
voidTxSpy.mockResolvedValue(); | ||
|
||
const context = { | ||
socket: expect.any(Object), | ||
healthcheck: expect.any(Object), | ||
retryAttempt: expect.any(Number), | ||
initialEventId: expect.any(Number), | ||
txCache: expect.any(LRU), | ||
event: { | ||
stream_id: 'stream-id', | ||
peer_id: 'peer_id', | ||
network: 'testnet', | ||
type: 'FULLNODE_EVENT', | ||
latest_event_id: 4, | ||
event: { | ||
id: 5, | ||
data: { | ||
hash: 'random-hash', | ||
outputs: [], | ||
inputs: [], | ||
tokens: [], | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const mysql = await db.getDbConnection(); | ||
const lastEvent = await db.getLastSyncedEvent(mysql); | ||
|
||
await expect(handleVoidedTx(context as any)).resolves.not.toThrow(); | ||
expect(db.voidTransaction).toHaveBeenCalledWith( | ||
expect.any(Object), | ||
'random-hash', | ||
expect.any(Object), | ||
); | ||
expect(lastEvent).toStrictEqual({ | ||
id: expect.any(Number), | ||
last_event_id: 5, | ||
updated_at: expect.any(String), | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters