Skip to content

Commit

Permalink
Merge pull request #175 from sotatek-dev/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Sotatek-TanHoang authored Oct 15, 2024
2 parents cca7fa6 + 5e7ed8a commit 6d54253
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 31 deletions.
4 changes: 1 addition & 3 deletions src/database/repositories/common-configuration.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ export class CommonConfigRepository extends BaseRepository<CommonConfig> {
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) {
Expand Down
8 changes: 3 additions & 5 deletions src/modules/crawler/sender.evmbridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -117,7 +115,7 @@ export class SenderEVMBridge {
},
value,
);

this.logger.info(`params ${value}`);
return { success: true, signature, payload: { data: value } };
}

Expand Down
24 changes: 1 addition & 23 deletions src/modules/crawler/tests/evm-sender.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -99,18 +97,10 @@ beforeEach(async () => {

senderEVMBridge = module.get<SenderEVMBridge>(SenderEVMBridge);
eventLogRepository = module.get<EventLogRepository>(EventLogRepository);
commonConfigRepository = module.get<CommonConfigRepository>(CommonConfigRepository);
multiSignatureRepository = module.get<MultiSignatureRepository>(MultiSignatureRepository);
});

describe('handleValidateUnlockTxEVM', () => {
const commonConfig = {
id: 1,
dailyQuota: 500,
tip: 0.5,
asset: 'ETH',
} as CommonConfig;

const data: Partial<EventLog> = {
id: 18,
deletedAt: undefined,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6d54253

Please sign in to comment.