fix: 校准天河链返回字段映射

This commit is contained in:
Nixevol
2026-07-06 19:20:33 +08:00
parent e6961ef1ae
commit e6caed498f
4 changed files with 393 additions and 3 deletions
@@ -0,0 +1,41 @@
import { TianheProvider } from './tianhe.provider';
describe('TianheProvider', () => {
const provider = new TianheProvider({
baseUrl: 'https://test.api.tichain.tianhecloud.com',
appId: 'app-id',
appKey: 'app-key',
userId: 'user-id',
userKey: 'user-key',
});
afterEach(() => {
jest.restoreAllMocks();
});
it('按天河链 upload 文档映射交易哈希、存证链接和文件哈希', async () => {
const response = {
code: 0,
message: 'success',
data: {
digest: 'file-digest-001',
url: 'https://test.explorer.tianhecloud.com/proof/001',
transactionHash: '0x1234567890abcdef',
},
};
jest.spyOn(globalThis, 'fetch').mockResolvedValue({
ok: true,
text: async () => JSON.stringify(response),
} as Response);
const result = await provider.attest({
dataHash: '0xlocaldatahash',
meta: { traceCode: 'TRACE-001' },
});
expect(result.txHash).toBe(response.data.transactionHash);
expect(result.explorerUrl).toBe(response.data.url);
expect(result.raw.digest).toBe(response.data.digest);
expect(result.raw.transactionStatus).toBe('submitted');
});
});