-
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: handle tx with no inputs (#181)
* tests: added tests for the voidTransaction method * chore: re-add test_images_down * fix: markUtxosAsVoided should not throw when inputs are empty * fix: returning empty object on db utils and added test for services including db * tests: fix invalid order of calls
- Loading branch information
1 parent
ec8755b
commit 9e8959d
Showing
4 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
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
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(); | ||
await expect(handleVoidedTx(context as any)).resolves.not.toThrow(); | ||
|
||
const lastEvent = await db.getLastSyncedEvent(mysql); | ||
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