From 0b1defb78b6ef969cec878bfbb75859ce7e152c7 Mon Sep 17 00:00:00 2001 From: hailin Date: Mon, 24 Nov 2025 02:54:27 -0800 Subject: [PATCH] . --- .../src/domain/value-objects/index.ts | 5 +++- .../wallet-generator.service.spec.ts | 30 +++++++++---------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/backend/services/identity-service/src/domain/value-objects/index.ts b/backend/services/identity-service/src/domain/value-objects/index.ts index c078980e..822fb2f6 100644 --- a/backend/services/identity-service/src/domain/value-objects/index.ts +++ b/backend/services/identity-service/src/domain/value-objects/index.ts @@ -6,7 +6,10 @@ import { wordlist } from '@scure/bip39/wordlists/english'; // ============ UserId ============ export class UserId { constructor(public readonly value: bigint) { - if (!value) throw new DomainError('UserId不能为空'); + // 允许 0 作为临时值(表示未持久化的新账户) + if (value === null || value === undefined) { + throw new DomainError('UserId不能为空'); + } } static create(value: bigint | string | number): UserId { diff --git a/backend/services/identity-service/src/infrastructure/external/blockchain/wallet-generator.service.spec.ts b/backend/services/identity-service/src/infrastructure/external/blockchain/wallet-generator.service.spec.ts index 3f6e0d13..56d6a608 100644 --- a/backend/services/identity-service/src/infrastructure/external/blockchain/wallet-generator.service.spec.ts +++ b/backend/services/identity-service/src/infrastructure/external/blockchain/wallet-generator.service.spec.ts @@ -31,7 +31,7 @@ describe('WalletGeneratorService', () => { describe('generateWalletSystem', () => { it('应该生成完整的钱包系统', () => { const result = service.generateWalletSystem({ - userId: 'test-user-id', + userId: '12345', deviceId: 'test-device-id', }); @@ -44,7 +44,7 @@ describe('WalletGeneratorService', () => { it('应该为所有链生成钱包地址', () => { const result = service.generateWalletSystem({ - userId: 'test-user-id', + userId: '12345', deviceId: 'test-device-id', }); @@ -55,7 +55,7 @@ describe('WalletGeneratorService', () => { it('生成的 KAVA 地址应该有正确的格式', () => { const result = service.generateWalletSystem({ - userId: 'test-user-id', + userId: '12345', deviceId: 'test-device-id', }); @@ -66,7 +66,7 @@ describe('WalletGeneratorService', () => { it('生成的 DST 地址应该有正确的格式', () => { const result = service.generateWalletSystem({ - userId: 'test-user-id', + userId: '12345', deviceId: 'test-device-id', }); @@ -77,7 +77,7 @@ describe('WalletGeneratorService', () => { it('生成的 BSC 地址应该有正确的格式', () => { const result = service.generateWalletSystem({ - userId: 'test-user-id', + userId: '12345', deviceId: 'test-device-id', }); @@ -88,12 +88,12 @@ describe('WalletGeneratorService', () => { it('每次生成的钱包应该不同', () => { const result1 = service.generateWalletSystem({ - userId: 'test-user-id-1', + userId: '11111', deviceId: 'test-device-id-1', }); const result2 = service.generateWalletSystem({ - userId: 'test-user-id-2', + userId: '22222', deviceId: 'test-device-id-2', }); @@ -108,13 +108,13 @@ describe('WalletGeneratorService', () => { it('应该使用助记词恢复钱包系统', () => { // 先生成一个钱包系统 const original = service.generateWalletSystem({ - userId: 'test-user-id', + userId: '12345', deviceId: 'test-device-id', }); // 使用助记词恢复 const recovered = service.recoverWalletSystem({ - userId: 'test-user-id', + userId: '12345', mnemonic: original.mnemonic, deviceId: 'new-device-id', }); @@ -135,18 +135,18 @@ describe('WalletGeneratorService', () => { it('不同设备应该生成相同的地址(相同助记词)', () => { const original = service.generateWalletSystem({ - userId: 'test-user-id', + userId: '12345', deviceId: 'device-1', }); const recovered1 = service.recoverWalletSystem({ - userId: 'test-user-id', + userId: '12345', mnemonic: original.mnemonic, deviceId: 'device-2', }); const recovered2 = service.recoverWalletSystem({ - userId: 'test-user-id', + userId: '12345', mnemonic: original.mnemonic, deviceId: 'device-3', }); @@ -193,7 +193,7 @@ describe('WalletGeneratorService', () => { describe('verifyMnemonic', () => { it('应该验证正确的助记词', () => { const result = service.generateWalletSystem({ - userId: 'test-user-id', + userId: '12345', deviceId: 'test-device-id', }); @@ -209,12 +209,12 @@ describe('WalletGeneratorService', () => { it('应该拒绝错误的助记词', () => { const result1 = service.generateWalletSystem({ - userId: 'test-user-id-1', + userId: '11111', deviceId: 'test-device-id-1', }); const result2 = service.generateWalletSystem({ - userId: 'test-user-id-2', + userId: '22222', deviceId: 'test-device-id-2', });