From d9f2b13d75a3d8c912b0f78cbd621c5eedcb58d4 Mon Sep 17 00:00:00 2001 From: "tan.hoang" Date: Tue, 15 Oct 2024 13:57:25 +0700 Subject: [PATCH] feat: update api get config fee --- .../common-configuration.repository.ts | 4 +--- src/modules/crawler/sender.evmbridge.ts | 8 +++---- src/modules/crawler/tests/evm-sender.spec.ts | 24 +------------------ 3 files changed, 5 insertions(+), 31 deletions(-) diff --git a/src/database/repositories/common-configuration.repository.ts b/src/database/repositories/common-configuration.repository.ts index f6afac1..ee6e5bb 100644 --- a/src/database/repositories/common-configuration.repository.ts +++ b/src/database/repositories/common-configuration.repository.ts @@ -10,9 +10,7 @@ export class CommonConfigRepository extends BaseRepository { protected alias: ETableName = ETableName.COMMON_CONFIGURATION; public getCommonConfig() { - return this.createQueryBuilder(`${this.alias}`) - .select([`${this.alias}.id`, `${this.alias}.tip`, `${this.alias}.dailyQuota`, `${this.alias}.asset`]) - .getOne(); + return this.createQueryBuilder(`${this.alias}`).select().getOne(); } public updateCommonConfig(id: number, updateConfig: UpdateCommonConfigBodyDto) { diff --git a/src/modules/crawler/sender.evmbridge.ts b/src/modules/crawler/sender.evmbridge.ts index 152cb05..a6293bc 100644 --- a/src/modules/crawler/sender.evmbridge.ts +++ b/src/modules/crawler/sender.evmbridge.ts @@ -74,10 +74,8 @@ export class SenderEVMBridge { async validateUnlockEVMTransaction(txId: number): Promise<{ error: Error | null; success: boolean }> { const wallet = this.getWallet(); - const [dataLock] = await Promise.all([ - this.eventLogRepository.findOneBy({ id: txId, networkReceived: ENetworkName.ETH }), - this.commonConfigRepository.getCommonConfig(), - ]); + const dataLock = await this.eventLogRepository.findOneBy({ id: txId, networkReceived: ENetworkName.ETH }); + if (!dataLock) { this.logger.warn('no data found tx', txId); return { error: null, success: false }; @@ -117,7 +115,7 @@ export class SenderEVMBridge { }, value, ); - + this.logger.info(`params ${value}`); return { success: true, signature, payload: { data: value } }; } diff --git a/src/modules/crawler/tests/evm-sender.spec.ts b/src/modules/crawler/tests/evm-sender.spec.ts index 01000f7..6a3aa1f 100644 --- a/src/modules/crawler/tests/evm-sender.spec.ts +++ b/src/modules/crawler/tests/evm-sender.spec.ts @@ -14,14 +14,12 @@ import { TokenPairRepository } from '../../../database/repositories/token-pair.r import { LoggerService } from '../../../shared/modules/logger/logger.service.js'; import { Web3Module } from '../../../shared/modules/web3/web3.module.js'; import { ETHBridgeContract } from '../../../shared/modules/web3/web3.service.js'; -import { CommonConfig } from '../entities/common-config.entity.js'; import { EventLog } from '../entities/index.js'; import { MultiSignature } from '../entities/multi-signature.entity.js'; import { SenderEVMBridge } from '../sender.evmbridge.js'; let senderEVMBridge: SenderEVMBridge; let eventLogRepository: EventLogRepository; -let commonConfigRepository: CommonConfigRepository; let multiSignatureRepository: MultiSignatureRepository; // Mock objects const mockJwtService = { @@ -99,18 +97,10 @@ beforeEach(async () => { senderEVMBridge = module.get(SenderEVMBridge); eventLogRepository = module.get(EventLogRepository); - commonConfigRepository = module.get(CommonConfigRepository); multiSignatureRepository = module.get(MultiSignatureRepository); }); describe('handleValidateUnlockTxEVM', () => { - const commonConfig = { - id: 1, - dailyQuota: 500, - tip: 0.5, - asset: 'ETH', - } as CommonConfig; - const data: Partial = { id: 18, deletedAt: undefined, @@ -138,26 +128,14 @@ describe('handleValidateUnlockTxEVM', () => { gasFee: '0.00001', }; it('should handle validator signature generation', async () => { - const wallet = senderEVMBridge.getWallet(); - - data.validator!.push({ - validator: wallet.address, - txId: 18, - retry: 2, - signature: - '0xc096d8abb2af534fa09b62ca3825a202172239ee0ab3d8438680faca0f0e59153fef0bdc0681162d94cad9fe77b05d4c1945be9c46cb89f9b2821d8576fb28d31b', - } as MultiSignature); jest.spyOn(eventLogRepository, 'findOneBy').mockResolvedValue(data as EventLog); - jest.spyOn(commonConfigRepository, 'getCommonConfig').mockResolvedValue(commonConfig); jest.spyOn(multiSignatureRepository, 'findOneBy').mockResolvedValue(data.validator![0]!); - jest.spyOn(multiSignatureRepository, 'update').mockResolvedValue(true as any); - + jest.spyOn(multiSignatureRepository, 'save').mockResolvedValue({} as any); const result = await senderEVMBridge.validateUnlockEVMTransaction(data.id!); expect(result.success).toBeTruthy(); }); it('should handle Unlock EVM and send to blockchain', async () => { - jest.spyOn(commonConfigRepository, 'getCommonConfig').mockResolvedValue(commonConfig); jest.spyOn(eventLogRepository, 'findOne').mockResolvedValue(data as EventLog); jest.spyOn(eventLogRepository, 'updateLockEvenLog').mockResolvedValue(true as any); jest.spyOn(eventLogRepository, 'updateStatusAndRetryEvenLog').mockResolvedValue(true as any);