35 lines
1.6 KiB
TypeScript
35 lines
1.6 KiB
TypeScript
import { parseChainDetail } from './chain-detail';
|
|
|
|
const info = {
|
|
data: {
|
|
gasTxUsed: '3388899',
|
|
fromAddress: '0x85aa7cdeba55cb08427018d066a26719b956ceff',
|
|
toAddress: '0x8c7df15858ee7c2f51ce74899a6d097ed163443f',
|
|
timeStamp: 1786261526886,
|
|
blockHeight: 39944998,
|
|
inputDataBin: '0xsecret',
|
|
inputDataDetail: { method: 'mint(address to, string author, string productId, string feature, string initPrice)', methodId: '0xa40d1b10' },
|
|
inputInfo: [{ name: 'author', type: 'string', data: '黄志伟' }],
|
|
transactionDetail: [{ fromAddress: '0x0000000000000000000000000000000000000000', toAddress: '0xae3ecbac36b5874b0372686e5b88894c22be4296', contractAddress: '0x8c7df15858ee7c2f51ce74899a6d097ed163443f', tokenId: '3051' }],
|
|
},
|
|
};
|
|
const receipt = {
|
|
data: [{ logInfo: { address: '0x8c7df15858ee7c2f51ce74899a6d097ed163443f', name: 'Transfer(address from, address to, uint256 tokenId)', data: '0x', topics: ['0xabc'] } }],
|
|
};
|
|
|
|
describe('parseChainDetail', () => {
|
|
it('keeps gas, sender and logs and drops the raw input binary', () => {
|
|
const detail = parseChainDetail(info, receipt);
|
|
expect(detail?.gasUsed).toBe('3388899');
|
|
expect(detail?.fromAddress).toBe('0x85aa7cdeba55cb08427018d066a26719b956ceff');
|
|
expect(detail?.logs).toHaveLength(1);
|
|
expect(detail?.action?.tokenId).toBe('3051');
|
|
expect(JSON.stringify(detail)).not.toContain('secret');
|
|
});
|
|
|
|
it('stays empty when gas, sender or logs are missing', () => {
|
|
expect(parseChainDetail({ data: { gasTxUsed: '', fromAddress: info.data.fromAddress } }, receipt)).toBeNull();
|
|
expect(parseChainDetail(info, { data: [] })).toBeNull();
|
|
});
|
|
});
|