Skip to content

Commit

Permalink
ensure working tests on cache file removal
Browse files Browse the repository at this point in the history
  • Loading branch information
bz888 committed Apr 16, 2024
1 parent 6d0f85a commit 0178985
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
6 changes: 1 addition & 5 deletions packages/node/src/utils/kyve/kyve.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,10 @@ describe('KyveApi', () => {
});
it('remove cached bundle files when past height', async () => {
await kyveApi.fetchBlocksBatches(registry, [1, 151, 301, 501], 300);
const files = await fs.promises.readdir(tmpPath);

await kyveApi.fetchBlocksBatches(registry, [502, 504, 600, 800], 300);

console.log(files);
const files = await fs.promises.readdir(tmpPath);
expect(files).not.toContain('bundle_0.json');
expect(files).not.toContain('bundle_1.json');
expect(files).not.toContain('bundle_2.json');
});
it('ensure to remove logic', () => {
const cachedBundleDetails = [
Expand Down
7 changes: 2 additions & 5 deletions packages/node/src/utils/kyve/kyve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,7 @@ export class KyveApi {
bufferSize,
);

if (toRemoveBundles.length) {
console.log('bundle not found', height);
console.log('bundle not found cache', this.cachedBundleDetails.length);
if (!toRemoveBundles.length) {
return;
}

Expand All @@ -327,7 +325,6 @@ export class KyveApi {
try {
await fs.promises.unlink(bundlePath);
remove(this.cachedBundleDetails, (b) => b.id === bundle.id);
console.log('cache after removal', this.cachedBundleDetails.length);
} catch (e) {
if (e.code === 'ENOENT') {
console.error(e);
Expand Down Expand Up @@ -361,7 +358,7 @@ export class KyveApi {
(b.log as any) = JSON.stringify(this.reconstructLogs(kyveBlockResult));
});
} catch (e) {
throw new Error(`Failed to inject kyveBlock`);
throw new Error(`Failed to inject kyveBlock, ${e}`);
}
return kyveBlockResult;
}
Expand Down

0 comments on commit 0178985

Please sign in to comment.