mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-01-25 04:20:33 +00:00
9e1ed70d18
* Insert and remove a dummy BlockProgress from db. * Test to fetch a Token entity from pruned region. * Check if db is empty initially. * Test to fetch a Token entity from frothy region. * Test to fetch a Token from frothy region (same block num). * Test to fetch a Token entity from another branch. * Tests to fetch a Token entity (multiple tokens). * Test to fetch updated Token entity in pruned region. Co-authored-by: prathamesh0 <prathamesh.musale0@gmail.com>
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
//
|
|
// Copyright 2021 Vulcanize, Inc.
|
|
//
|
|
|
|
import { QueryRunner, FindConditions } from 'typeorm';
|
|
|
|
import { Database } from '../src/database';
|
|
import { BlockProgress } from '../src/entity/BlockProgress';
|
|
import { Token } from '../src/entity/Token';
|
|
|
|
export class TestDatabase extends Database {
|
|
async removeEntities<Entity> (queryRunner: QueryRunner, entity: new () => Entity, findConditions?: FindConditions<Entity>): Promise<void> {
|
|
const repo = queryRunner.manager.getRepository(entity);
|
|
|
|
const entities = await repo.find(findConditions);
|
|
await repo.remove(entities);
|
|
}
|
|
|
|
async isEmpty (): Promise<boolean> {
|
|
const dbTx = await this.createTransactionRunner();
|
|
try {
|
|
const dataBP = await this.getEntities(dbTx, BlockProgress, {}, {}, { limit: 1 });
|
|
const dataToken = await this.getEntities(dbTx, Token, {}, {}, { limit: 1 });
|
|
const dataSyncStatus = await this.getSyncStatus(dbTx);
|
|
if (dataBP.length > 0 || dataToken.length > 0 || dataSyncStatus) {
|
|
return false;
|
|
}
|
|
return true;
|
|
} catch (error) {
|
|
await dbTx.rollbackTransaction();
|
|
throw error;
|
|
} finally {
|
|
await dbTx.release();
|
|
}
|
|
}
|
|
}
|