|
| 1 | +import { describe, test } from '@jest/globals'; |
| 2 | +import { TxId } from '@vechain/sdk-core'; |
| 3 | +import { |
| 4 | + type FetchHttpClient, |
| 5 | + type GetTxResponseJSON, |
| 6 | + RetrieveTransactionByID |
| 7 | +} from '../../../src'; |
| 8 | + |
| 9 | +const mockHttpClient = <T>(response: T): FetchHttpClient => { |
| 10 | + return { |
| 11 | + get: jest.fn().mockImplementation(() => { |
| 12 | + return { |
| 13 | + json: jest.fn().mockImplementation(() => { |
| 14 | + return response; |
| 15 | + }) |
| 16 | + }; |
| 17 | + }) |
| 18 | + } as unknown as FetchHttpClient; |
| 19 | +}; |
| 20 | + |
| 21 | +/** |
| 22 | + * VeChain transaction - unit |
| 23 | + * |
| 24 | + * @group unit/transaction |
| 25 | + */ |
| 26 | +describe('RetrieveTransactionByID unit tests', () => { |
| 27 | + test('ok <- askTo', async () => { |
| 28 | + const txId = TxId.of( |
| 29 | + '0xb6b5b47a5eee8b14e5222ac1bb957c0bbdc3d489850b033e3e544d9ca0cef934' |
| 30 | + ); |
| 31 | + |
| 32 | + const mockResponse = { |
| 33 | + id: '0xb6b5b47a5eee8b14e5222ac1bb957c0bbdc3d489850b033e3e544d9ca0cef934', |
| 34 | + chainTag: 39, |
| 35 | + blockRef: |
| 36 | + '0x0000000000000000000000000000000000000000000000000000000000000000', |
| 37 | + expiration: 32, |
| 38 | + clauses: [ |
| 39 | + { |
| 40 | + to: '0x7d8Bf18C7ce84B3e175B339C4cA93Aed1dD488Aa', |
| 41 | + // We are adding a leading zero to the value because of how VCDM's |
| 42 | + // Hex is parsing and because we need an even number of hex-digits in other places |
| 43 | + value: '0x05ec3db77eba739400', |
| 44 | + data: '0x' |
| 45 | + } |
| 46 | + ], |
| 47 | + gasPriceCoef: 0, |
| 48 | + gas: 21000, |
| 49 | + origin: '0x7d8Bf18C7ce84B3e175B339C4cA93Aed1dD488Aa', |
| 50 | + nonce: '0x12345678', |
| 51 | + dependsOn: undefined, |
| 52 | + delegator: null, |
| 53 | + size: 128, |
| 54 | + meta: { |
| 55 | + blockID: |
| 56 | + '0x0000000000000000000000000000000000000000000000000000000000000000', |
| 57 | + blockNumber: 1, |
| 58 | + blockTimestamp: 1000000 |
| 59 | + } |
| 60 | + } satisfies GetTxResponseJSON; |
| 61 | + |
| 62 | + const mockClient = mockHttpClient(mockResponse); |
| 63 | + const response = |
| 64 | + await RetrieveTransactionByID.of(txId).askTo(mockClient); |
| 65 | + expect(response.response.toJSON()).toEqual(mockResponse); |
| 66 | + }); |
| 67 | +}); |
0 commit comments