Skip to content

Commit

Permalink
test: test
Browse files Browse the repository at this point in the history
  • Loading branch information
phamphong9981 committed Oct 10, 2024
1 parent 339be48 commit c746468
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions test/unit/services/evm/erc20_reindex.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import { getViemClient } from '../../../../src/common/utils/etherjs_client';
import {
Account,
AccountBalance,
BlockCheckpoint,
Erc20Activity,
Erc20Contract,
EvmEvent,
EVMSmartContract,
EVMTransaction,
} from '../../../../src/models';
import { BULL_JOB_NAME } from '../../../../src/services/evm/constant';
import { ABI_TRANSFER_PARAMS } from '../../../../src/services/evm/erc20_handler';
import { Erc20Reindexer } from '../../../../src/services/evm/erc20_reindex';

Expand Down Expand Up @@ -121,6 +123,16 @@ const evmTransaction = EVMTransaction.fromJson({
index: 0,
from: hexToBytes('0x51aeade652867f342ddc012e15c27d0cd6220398'),
});
const blockCheckpoints = [
BlockCheckpoint.fromJson({
job_name: BULL_JOB_NAME.HANDLE_ERC20_BALANCE,
height: 123456,
}),
BlockCheckpoint.fromJson({
job_name: BULL_JOB_NAME.HANDLE_ERC20_ACTIVITY,
height: 123457,
}),
];

@Describe('Test erc20 reindex')
export default class Erc20ReindexTest {
Expand All @@ -130,12 +142,13 @@ export default class Erc20ReindexTest {
async initSuite() {
await this.broker.start();
await knex.raw(
'TRUNCATE TABLE evm_transaction, evm_smart_contract, erc20_contract, account, erc20_activity, account_balance, evm_event RESTART IDENTITY CASCADE'
'TRUNCATE TABLE evm_transaction, evm_smart_contract, erc20_contract, account, erc20_activity, account_balance, evm_event, block_checkpoint RESTART IDENTITY CASCADE'
);
await EVMTransaction.query().insert(evmTransaction);
await EVMSmartContract.query().insert(evmSmartContract);
await Erc20Contract.query().insertGraph(erc20Contract);
await Account.query().insertGraph(accounts);
await BlockCheckpoint.query().insert(blockCheckpoints);
}

@AfterAll()
Expand All @@ -148,7 +161,6 @@ export default class Erc20ReindexTest {
@Test('test reindex')
async testReindex() {
const viemClient = getViemClient();
jest.spyOn(viemClient, 'getBlockNumber').mockResolvedValue(BigInt(123456));
// Instantiate Erc20Reindexer with the mock
const reindexer = new Erc20Reindexer(viemClient, this.broker.logger);
const event = EvmEvent.fromJson({
Expand Down

0 comments on commit c746468

Please sign in to comment.