From 14b2b5ada89bdfa1276b10f00da4264b82d07f5a Mon Sep 17 00:00:00 2001 From: Ben <89335033+bz888@users.noreply.github.com> Date: Wed, 17 Apr 2024 10:46:59 +0000 Subject: [PATCH] fix test cases, update logic in removal --- packages/node/src/utils/kyve/kyve.spec.ts | 1 - packages/node/src/utils/kyve/kyve.ts | 22 ++++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/node/src/utils/kyve/kyve.spec.ts b/packages/node/src/utils/kyve/kyve.spec.ts index df06ea8d8..0fd558b6b 100644 --- a/packages/node/src/utils/kyve/kyve.spec.ts +++ b/packages/node/src/utils/kyve/kyve.spec.ts @@ -275,7 +275,6 @@ describe('KyveApi', () => { const files = await fs.promises.readdir(tmpPath); expect(files).not.toContain('bundle_0.json'); - expect(files).not.toContain('bundle_1.json'); }); it('Should increment bundleId when height exceeds cache', async () => { const bundle = await (kyveApi as any).getBundleById(0); diff --git a/packages/node/src/utils/kyve/kyve.ts b/packages/node/src/utils/kyve/kyve.ts index ddcfa59c2..b08c815d3 100644 --- a/packages/node/src/utils/kyve/kyve.ts +++ b/packages/node/src/utils/kyve/kyve.ts @@ -306,16 +306,18 @@ export class KyveApi { const currentBundle = this.getBundleFromCache(height); - return cachedBundles.filter((b) => { - const isNotCurrentBundleAndLower = - currentBundle.id !== b.id && - parseDecimal(currentBundle.id) > parseDecimal(b.id); - const isOutsiderBuffer = - height < parseDecimal(b.from_key) - bufferSize || - height > parseDecimal(b.to_key) + bufferSize; - - return isNotCurrentBundleAndLower && isOutsiderBuffer; - }); + return currentBundle + ? cachedBundles.filter((b) => { + const isNotCurrentBundleAndLower = + currentBundle.id !== b.id && + parseDecimal(currentBundle.id) > parseDecimal(b.id); + const isOutsiderBuffer = + height < parseDecimal(b.from_key) - bufferSize || + height > parseDecimal(b.to_key) + bufferSize; + + return isNotCurrentBundleAndLower && isOutsiderBuffer; + }) + : []; } async clearFileCache(