From 8b66166d4343d9aa21ec634ea150d86863f6533d Mon Sep 17 00:00:00 2001 From: Incede <33103370+Incede@users.noreply.github.com> Date: Thu, 23 Nov 2023 13:09:46 +0100 Subject: [PATCH 1/4] Fix data stream --- commander/src/bootstrapping/commands/blockchain/hash.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commander/src/bootstrapping/commands/blockchain/hash.ts b/commander/src/bootstrapping/commands/blockchain/hash.ts index 3b792b848b9..8425a34326e 100644 --- a/commander/src/bootstrapping/commands/blockchain/hash.ts +++ b/commander/src/bootstrapping/commands/blockchain/hash.ts @@ -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 => { From 4ae0dbe41736b524879e268aeda634e330044b3a Mon Sep 17 00:00:00 2001 From: Incede <33103370+Incede@users.noreply.github.com> Date: Thu, 23 Nov 2023 15:14:38 +0100 Subject: [PATCH 2/4] Update unit test --- .../test/bootstrapping/commands/blockchain/hash.spec.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/commander/test/bootstrapping/commands/blockchain/hash.spec.ts b/commander/test/bootstrapping/commands/blockchain/hash.spec.ts index ee3d6f9fb01..d87bd016465 100644 --- a/commander/test/bootstrapping/commands/blockchain/hash.spec.ts +++ b/commander/test/bootstrapping/commands/blockchain/hash.spec.ts @@ -46,7 +46,13 @@ 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, + }, + ]), + ), } as never); jest.spyOn(appUtils, 'getPid').mockReturnValue(pid); }); From 524f260ef2034b89b3cdb9b94739fa128ce496d8 Mon Sep 17 00:00:00 2001 From: Incede <33103370+Incede@users.noreply.github.com> Date: Fri, 24 Nov 2023 09:29:07 +0100 Subject: [PATCH 3/4] Close db upon finish --- commander/src/bootstrapping/commands/blockchain/hash.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commander/src/bootstrapping/commands/blockchain/hash.ts b/commander/src/bootstrapping/commands/blockchain/hash.ts index 8425a34326e..f5c1578caec 100644 --- a/commander/src/bootstrapping/commands/blockchain/hash.ts +++ b/commander/src/bootstrapping/commands/blockchain/hash.ts @@ -68,7 +68,7 @@ export class HashCommand extends Command { }); this.debug('Hash generation completed.'); - this.log(hash.toString('hex')); + db.close(); } } From 5c025f0fb8b5a00ceb768117d22e893b6efbcc90 Mon Sep 17 00:00:00 2001 From: Incede <33103370+Incede@users.noreply.github.com> Date: Fri, 24 Nov 2023 10:18:45 +0100 Subject: [PATCH 4/4] Fix unit test per update --- commander/test/bootstrapping/commands/blockchain/hash.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/commander/test/bootstrapping/commands/blockchain/hash.spec.ts b/commander/test/bootstrapping/commands/blockchain/hash.spec.ts index d87bd016465..a63b506b82f 100644 --- a/commander/test/bootstrapping/commands/blockchain/hash.spec.ts +++ b/commander/test/bootstrapping/commands/blockchain/hash.spec.ts @@ -53,6 +53,7 @@ describe('blockchain:hash', () => { }, ]), ), + close: jest.fn(), } as never); jest.spyOn(appUtils, 'getPid').mockReturnValue(pid); });