This commit is contained in:
hailin 2025-11-24 02:54:27 -08:00
parent 3aaac6af6f
commit 0b1defb78b
2 changed files with 19 additions and 16 deletions

View File

@ -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 {

View File

@ -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',
});