123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- /**
- * Jest测试环境设置
- *
- * 配置全局测试设置,包括超时、模拟和通用工具函数
- */
- // 扩展Jest超时时间,适应性能测试需求
- jest.setTimeout(30000);
- // 全局测试工具函数
- global.testUtils = {
- /**
- * 创建测试用的私钥(Ed25519格式)
- */
- createTestPrivateKey(): string {
- return 'abcd1234567890abcdef1234567890abcdef1234567890abcdef1234567890ab';
- },
- /**
- * 创建测试用的消息
- */
- createTestMessage(): Uint8Array {
- return new TextEncoder().encode('Test message for signing');
- },
- /**
- * 验证签名格式
- */
- isValidSignatureFormat(signature: string): boolean {
- return /^[A-Za-z0-9+/]+=*$/.test(signature) && signature.length > 0;
- },
- /**
- * 模拟延迟函数
- */
- async delay(ms: number): Promise<void> {
- return new Promise(resolve => setTimeout(resolve, ms));
- },
- /**
- * 创建测试账户配置
- */
- createTestAccountConfig() {
- return {
- version: '1.0',
- accounts: [
- {
- id: 'test-pacifica-001',
- platform: 'pacifica',
- credentials: {
- type: 'pacifica',
- privateKey: this.createTestPrivateKey(),
- },
- metadata: {
- alias: '测试Pacifica账户',
- description: '用于单元测试',
- },
- },
- {
- id: 'test-binance-001',
- platform: 'binance',
- credentials: {
- type: 'binance',
- apiKey: 'test_api_key',
- secretKey: 'test_secret_key',
- },
- metadata: {
- alias: '测试Binance账户',
- },
- },
- ],
- };
- },
- };
- // 类型声明
- declare global {
- var testUtils: {
- createTestPrivateKey(): string;
- createTestMessage(): Uint8Array;
- isValidSignatureFormat(signature: string): boolean;
- delay(ms: number): Promise<void>;
- createTestAccountConfig(): any;
- };
- }
- export {};
|