From a99a443edeaaf3ae75fa5eb115504d0737bffbb6 Mon Sep 17 00:00:00 2001
From: cgeek <cem.moreau@gmail.com>
Date: Sat, 10 Jun 2023 23:16:52 +0200
Subject: [PATCH] fix(1447): show that the issue is about indexForTrimming only

---
 app/lib/dal/indexDAL/leveldb/LevelDBSindex.ts | 11 ++++++++++-
 test/dal/triming-dal.ts                       | 18 ++++++++++--------
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/app/lib/dal/indexDAL/leveldb/LevelDBSindex.ts b/app/lib/dal/indexDAL/leveldb/LevelDBSindex.ts
index dfb026f42..7c9117cdb 100644
--- a/app/lib/dal/indexDAL/leveldb/LevelDBSindex.ts
+++ b/app/lib/dal/indexDAL/leveldb/LevelDBSindex.ts
@@ -345,7 +345,16 @@ export class LevelDBSindex extends LevelDBTable<SindexEntry>
    * Allow to get internal index, for unit test (see test triming-dal.ts)
    */
   getInternalIndexes(): LevelDBTable<any>[] {
-    return [this.indexForTrimming, this.indexForConditions, this.indexForConditions, this.indexOfComplexeConditionForPubkeys];
+    return [this.indexForTrimming, this.indexForConditions, this.indexForConsumed, this.indexOfComplexeConditionForPubkeys];
+  }
+  getIndexForTrimming(): LevelDBTable<any> {
+    return this.indexForTrimming
+  }
+  getIndexForConditions(): LevelDBTable<any> {
+    return this.indexForConditions
+  }
+  getIndexForConsumed(): LevelDBTable<any> {
+    return this.indexForConsumed
   }
 
   private async trimConditions(condition: string, id: string) {
diff --git a/test/dal/triming-dal.ts b/test/dal/triming-dal.ts
index 535dcff85..eafe4f0b6 100644
--- a/test/dal/triming-dal.ts
+++ b/test/dal/triming-dal.ts
@@ -120,8 +120,8 @@ describe("Triming", function(){
     await dal.sindexDAL.insertBatch([
       { op: 'CREATE', identifier: 'SOURCE_1', pos: 4, written_on: '126-H', writtenOn: 126, written_time: 2000, consumed: false, conditions: 'COND(SOURCE_1)'},
       { op: 'UPDATE', identifier: 'SOURCE_1', pos: 4, written_on: '139-H', writtenOn: 139, written_time: 4500, consumed: true, conditions: 'COND(SOURCE_1)'},
-      { op: 'CREATE', identifier: 'SOURCE_2', pos: 4, written_on: '127-H', writtenOn: 127, written_time: 2500, consumed: false, conditions: 'COND(SOURCE_2)'},
-      { op: 'CREATE', identifier: 'SOURCE_3', pos: 4, written_on: '127-H', writtenOn: 127, written_time: 2500, consumed: false, conditions: 'SIG(PUB_1)'}
+      { op: 'CREATE', identifier: 'SOURCE_2', pos: 4, written_on: '126-H', writtenOn: 126, written_time: 2500, consumed: false, conditions: 'COND(SOURCE_2)'},
+      { op: 'CREATE', identifier: 'SOURCE_3', pos: 4, written_on: '126-H', writtenOn: 126, written_time: 2500, consumed: false, conditions: 'SIG(PUB_1)'}
     ] as any);
     (await dal.sindexDAL.findByIdentifier('SOURCE_1')).should.have.length(2);
     (await dal.sindexDAL.getAvailableForConditions('COND(SOURCE_2)')).should.have.length(1);
@@ -141,13 +141,15 @@ describe("Triming", function(){
     (await dal.sindexDAL.findByPos(4)).should.have.length(2);
 
     // Check internal index
+    should.not.exist(await sindexDAL.getIndexForConditions().getOrNull("COND(SOURCE_1)")); // The only source at this condition was trimmed
+    should.not.exist(await sindexDAL.getIndexForConsumed().getOrNull("0000000139")); // The only consumption at this block was trimmed
+    let entriesAt0000000126 = await sindexDAL.getIndexForTrimming().getOrNull("0000000126");
+
     // FIXME another issue here
-    for (let index of sindexDAL.getInternalIndexes()) {
-      const keys = await index.findAllKeys();
-      keys.should.not.containEql("COND(SOURCE_1)");
-      keys.should.not.containEql("0000000126");
-      keys.should.not.containEql("0000000139");
-    }
+    entriesAt0000000126.should.not.containEql('SOURCE_1-0000000004'); // This CREATE entry should have been trimmed
+
+    let entriesAt0000000139 = await sindexDAL.getIndexForTrimming().getOrNull("0000000139");
+    should.not.exist(entriesAt0000000139);
 
     // Now we consume all sources
     await dal.sindexDAL.insertBatch([
-- 
GitLab