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

Commit c610d8c

Browse files
authored
Blockchain:hash returns incorrect hash (#9150)
* Fix data stream * Update unit test * Close db upon finish * Fix unit test per update
1 parent f825978 commit c610d8c

File tree

2 files changed

+11
-4
lines changed
  • commander

2 files changed

+11
-4
lines changed

Diff for: commander/src/bootstrapping/commands/blockchain/hash.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ export class HashCommand extends Command {
5454
const dbHash = crypto.createHash('sha256');
5555

5656
const hash: Buffer = await new Promise((resolve, reject) => {
57-
stream.on('data', (chunk: Buffer) => {
58-
dbHash.update(chunk);
57+
stream.on('data', ({ value }: { key: Buffer; value: Buffer }) => {
58+
dbHash.update(value);
5959
});
6060

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

7070
this.debug('Hash generation completed.');
71-
7271
this.log(hash.toString('hex'));
72+
db.close();
7373
}
7474
}

Diff for: commander/test/bootstrapping/commands/blockchain/hash.spec.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ describe('blockchain:hash', () => {
4646
};
4747
jest.spyOn(crypto, 'createHash').mockReturnValue(hashStub as never);
4848
jest.spyOn(dbUtils, 'getBlockchainDB').mockReturnValue({
49-
createReadStream: jest.fn().mockReturnValue(Readable.from([hashBuffer])),
49+
createReadStream: jest.fn().mockReturnValue(
50+
Readable.from([
51+
{
52+
value: hashBuffer,
53+
},
54+
]),
55+
),
56+
close: jest.fn(),
5057
} as never);
5158
jest.spyOn(appUtils, 'getPid').mockReturnValue(pid);
5259
});

0 commit comments

Comments
 (0)