feat: 新增示例种子数据与核心单元测试

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Nixevol
2026-06-28 16:33:35 +08:00
co-authored by Cursor
parent 23cbf37aa1
commit fa61840cfb
7 changed files with 291 additions and 21 deletions
@@ -0,0 +1,37 @@
import { ConfigService } from '@nestjs/config';
import { BlockchainService } from './blockchain.service';
function makeService(): BlockchainService {
const config = {
get: (key: string) => (key === 'blockchain.driver' ? 'mock' : undefined),
} as unknown as ConfigService;
return new BlockchainService(config);
}
describe('BlockchainService.hashData', () => {
const svc = makeService();
it('相同输入产生相同哈希', () => {
const a = svc.hashData({ title: '青花瓷', n: 1 });
const b = svc.hashData({ title: '青花瓷', n: 1 });
expect(a).toBe(b);
expect(a).toMatch(/^0x[0-9a-f]{64}$/);
});
it('不同输入产生不同哈希', () => {
const a = svc.hashData({ title: '青花瓷' });
const b = svc.hashData({ title: '霁红釉' });
expect(a).not.toBe(b);
});
});
describe('BlockchainService.attest (mock)', () => {
it('返回完整链上字段', async () => {
const svc = makeService();
const result = await svc.attest({ dataHash: '0xabc' });
expect(result.txHash).toMatch(/^0x[0-9a-f]{64}$/);
expect(result.blockHash).toMatch(/^0x[0-9a-f]{64}$/);
expect(result.blockHeight).toBeGreaterThan(0);
expect(result.explorerUrl).toContain(result.txHash);
});
});