|
| 1 | +import { AddressTransactionsWithTransfersListResponse } from '@stacks/stacks-blockchain-api-types'; |
| 2 | +import { describe, expect, it } from 'vitest'; |
| 3 | + |
| 4 | +import { filterVerboseUnusedTransactionWithTransferData } from './transactions-with-transfers.query'; |
| 5 | + |
| 6 | +describe('filterVerboseUnusedTransactionWithTransferData', () => { |
| 7 | + it('should redact the source_code for smart_contract transactions', () => { |
| 8 | + const input = { |
| 9 | + results: [ |
| 10 | + { |
| 11 | + tx: { |
| 12 | + tx_type: 'smart_contract', |
| 13 | + smart_contract: { |
| 14 | + source_code: 'some_source_code', |
| 15 | + }, |
| 16 | + }, |
| 17 | + }, |
| 18 | + ], |
| 19 | + } as AddressTransactionsWithTransfersListResponse; |
| 20 | + |
| 21 | + const result = filterVerboseUnusedTransactionWithTransferData(input as any) as any; |
| 22 | + expect(result.results[0].tx?.smart_contract?.source_code).toBe('redacted'); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should redact function_args and tx_result for contract_call transactions', () => { |
| 26 | + const input = { |
| 27 | + results: [ |
| 28 | + { |
| 29 | + tx: { |
| 30 | + tx_type: 'contract_call', |
| 31 | + contract_call: { |
| 32 | + function_args: [ |
| 33 | + { hex: '0x123', repr: 'arg1' }, |
| 34 | + { hex: '0x456', repr: 'arg2' }, |
| 35 | + ], |
| 36 | + }, |
| 37 | + tx_result: { hex: '0xresult', repr: 'result_repr' }, |
| 38 | + }, |
| 39 | + }, |
| 40 | + ], |
| 41 | + } as AddressTransactionsWithTransfersListResponse; |
| 42 | + |
| 43 | + const result = filterVerboseUnusedTransactionWithTransferData(input) as any; |
| 44 | + |
| 45 | + expect(result.results[0].tx.contract_call?.function_args).toEqual([ |
| 46 | + { hex: 'redacted', repr: 'redacted' }, |
| 47 | + { hex: 'redacted', repr: 'redacted' }, |
| 48 | + ]); |
| 49 | + expect(result.results[0].tx.tx_result).toEqual({ hex: 'redacted', repr: 'redacted' }); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should handle contract_call transactions without function_args', () => { |
| 53 | + const input = { |
| 54 | + results: [ |
| 55 | + { |
| 56 | + tx: { |
| 57 | + tx_type: 'contract_call', |
| 58 | + contract_call: { |
| 59 | + function_args: [], |
| 60 | + contract_id: '', |
| 61 | + function_name: '', |
| 62 | + function_signature: '', |
| 63 | + }, |
| 64 | + tx_result: { hex: '0xresult', repr: 'result_repr' }, |
| 65 | + }, |
| 66 | + }, |
| 67 | + ], |
| 68 | + } as unknown as AddressTransactionsWithTransfersListResponse; |
| 69 | + |
| 70 | + const result = filterVerboseUnusedTransactionWithTransferData(input); |
| 71 | + |
| 72 | + // function_args should remain undefined and tx_result should be redacted |
| 73 | + expect(result.results[0].tx.tx_result).toEqual({ hex: 'redacted', repr: 'redacted' }); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should not modify transactions that are not smart_contract or contract_call type', () => { |
| 77 | + const input = { |
| 78 | + results: [{ tx: { tx_type: 'transfer' } }], |
| 79 | + } as unknown as AddressTransactionsWithTransfersListResponse; |
| 80 | + |
| 81 | + const result = filterVerboseUnusedTransactionWithTransferData(input); |
| 82 | + |
| 83 | + expect(result.results[0].tx).toEqual({ tx_type: 'transfer' }); |
| 84 | + }); |
| 85 | +}); |
0 commit comments