Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Blockchain:hash returns incorrect hash (#9150)
Browse files Browse the repository at this point in the history
* Fix data stream

* Update unit test

* Close db upon finish

* Fix unit test per update
  • Loading branch information
Incede authored Nov 24, 2023
1 parent f825978 commit c610d8c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions commander/src/bootstrapping/commands/blockchain/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export class HashCommand extends Command {
const dbHash = crypto.createHash('sha256');

const hash: Buffer = await new Promise((resolve, reject) => {
stream.on('data', (chunk: Buffer) => {
dbHash.update(chunk);
stream.on('data', ({ value }: { key: Buffer; value: Buffer }) => {
dbHash.update(value);
});

stream.on('error', error => {
Expand All @@ -68,7 +68,7 @@ export class HashCommand extends Command {
});

this.debug('Hash generation completed.');

this.log(hash.toString('hex'));
db.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ describe('blockchain:hash', () => {
};
jest.spyOn(crypto, 'createHash').mockReturnValue(hashStub as never);
jest.spyOn(dbUtils, 'getBlockchainDB').mockReturnValue({
createReadStream: jest.fn().mockReturnValue(Readable.from([hashBuffer])),
createReadStream: jest.fn().mockReturnValue(
Readable.from([
{
value: hashBuffer,
},
]),
),
close: jest.fn(),
} as never);
jest.spyOn(appUtils, 'getPid').mockReturnValue(pid);
});
Expand Down

0 comments on commit c610d8c

Please sign in to comment.