|
| 1 | +import { ChainId } from '@venusprotocol/chains'; |
| 2 | +import fakeAddress from '__mocks__/models/address'; |
| 3 | +import { poolData } from '__mocks__/models/pools'; |
| 4 | +import { restService } from 'utilities'; |
| 5 | +import { type Mock, vi } from 'vitest'; |
| 6 | +import { type ApiAccountHistoricalTransaction, TxType, getAccountTransactionHistory } from '..'; |
| 7 | + |
| 8 | +vi.mock('utilities/restService'); |
| 9 | + |
| 10 | +const fakeInput = { |
| 11 | + accountAddress: fakeAddress, |
| 12 | + chainId: ChainId.BSC_TESTNET, |
| 13 | + getPoolsData: { pools: poolData }, |
| 14 | + contractAddress: 'all', |
| 15 | + page: 1, |
| 16 | +}; |
| 17 | + |
| 18 | +describe('getAccountTransactionHistory', () => { |
| 19 | + it('returns transactions formatted', async () => { |
| 20 | + (restService as Mock).mockImplementation(() => { |
| 21 | + const txs: ApiAccountHistoricalTransaction[] = [ |
| 22 | + { |
| 23 | + id: 'da13a0f45b10dabd21b863b6b602c6d8776edd4c6b10fe65a0881d491f468f35-207-56', |
| 24 | + txHash: '0xda13a0f45b10dabd21b863b6b602c6d8776edd4c6b10fe65a0881d491f468f35', |
| 25 | + txIndex: 207, |
| 26 | + txTimestamp: new Date('2024-08-23T04:17:09.000Z'), |
| 27 | + blockNumber: '41604851', |
| 28 | + txType: TxType.Redeem, |
| 29 | + accountAddress: fakeAddress, |
| 30 | + contractAddress: '0xb7526572ffe56ab9d7489838bf2e18e3323b441a', |
| 31 | + amountVTokenMantissa: '99319379197734', |
| 32 | + amountUnderlyingMantissa: '24066181578079398612862', |
| 33 | + chainId: ChainId.BSC_TESTNET, |
| 34 | + underlyingAddress: '0xa11c8d9dc9b66e209ef60f0c8d969d3Cd988782c', |
| 35 | + underlyingTokenPriceMantissa: '1000130000000000000', |
| 36 | + }, |
| 37 | + { |
| 38 | + id: 'b0435b135762a7ca2ad7dccb9aa6c7f50237c6139b16a76348d6c64dfece110e-119-56', |
| 39 | + txHash: '0xb0435b135762a7ca2ad7dccb9aa6c7f50237c6139b16a76348d6c64dfece110e', |
| 40 | + txIndex: 119, |
| 41 | + txTimestamp: new Date('2024-08-06T02:18:03.000Z'), |
| 42 | + blockNumber: '41114058', |
| 43 | + txType: TxType.Mint, |
| 44 | + accountAddress: fakeAddress, |
| 45 | + contractAddress: '0xb7526572ffe56ab9d7489838bf2e18e3323b441a', |
| 46 | + amountVTokenMantissa: '99319377752025', |
| 47 | + amountUnderlyingMantissa: '24001813290985731455439', |
| 48 | + chainId: ChainId.BSC_TESTNET, |
| 49 | + underlyingAddress: '0xa11c8d9dc9b66e209ef60f0c8d969d3Cd988782c', |
| 50 | + underlyingTokenPriceMantissa: '1000391740000000000', |
| 51 | + }, |
| 52 | + ]; |
| 53 | + |
| 54 | + return { |
| 55 | + data: { |
| 56 | + count: '2', |
| 57 | + results: txs, |
| 58 | + }}; |
| 59 | + }); |
| 60 | + |
| 61 | + const response = await getAccountTransactionHistory(fakeInput); |
| 62 | + expect(response).toMatchSnapshot(); |
| 63 | + }); |
| 64 | + |
| 65 | + it('throws on error in payload', async () => { |
| 66 | + (restService as Mock).mockResolvedValue({ data: { error: 'Some error' } }); |
| 67 | + |
| 68 | + await expect(getAccountTransactionHistory(fakeInput)).rejects.toMatchObject({ |
| 69 | + code: 'somethingWentWrong', |
| 70 | + }); |
| 71 | + }); |
| 72 | + |
| 73 | + it('throws on undefined payload', async () => { |
| 74 | + (restService as Mock).mockResolvedValue({ data: undefined }); |
| 75 | + |
| 76 | + await expect(getAccountTransactionHistory(fakeInput)).rejects.toMatchObject({ |
| 77 | + code: 'somethingWentWrong', |
| 78 | + }); |
| 79 | + }); |
| 80 | +}); |
0 commit comments