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(