Skip to content

Commit 9c52206

Browse files
test: add coverage for getAccountTransactionHistory
1 parent ac95554 commit 9c52206

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`getAccountTransactionHistory > returns transactions formatted 1`] = `
4+
{
5+
"count": 2,
6+
"transactions": [
7+
{
8+
"accountAddress": "0x3d759121234cd36F8124C21aFe1c6852d2bEd848",
9+
"amountCents": "2406931.018168454893468167206",
10+
"amountTokens": "24066181578079398.612862",
11+
"blockNumber": "41604851",
12+
"blockTimestamp": 2024-08-23T04:17:09.000Z,
13+
"chainId": 97,
14+
"contractAddress": "0xb7526572ffe56ab9d7489838bf2e18e3323b441a",
15+
"hash": "0xda13a0f45b10dabd21b863b6b602c6d8776edd4c6b10fe65a0881d491f468f35",
16+
"poolName": "Metaverse",
17+
"token": {
18+
"address": "0xA11c8D9DC9b66E209Ef60F0C8D969D3CD988782c",
19+
"asset": "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='24'%20height='24'%20fill='none'%20xmlns:v='https://vecta.io/nano'%3e%3cg%20clip-path='url(%23A)'%3e%3cpath%20d='M24%2012c0%206.628-5.372%2012-12%2012S0%2018.628%200%2012%205.373%200%2012%200s12%205.373%2012%2012z'%20fill='%231ba27a'/%3e%3cg%20fill='%23fff'%3e%3cpath%20d='M17.629%206.051H6.267v2.743h4.31v4.032h2.743V8.794h4.31V6.051z'/%3e%3cpath%20d='M11.973%2013.256c-3.565%200-6.456-.564-6.456-1.26s2.89-1.26%206.456-1.26%206.455.564%206.455%201.26-2.89%201.26-6.455%201.26zm7.249-1.05c0-.898-3.245-1.625-7.249-1.625s-7.249.727-7.249%201.625c0%20.79%202.517%201.449%205.851%201.595v5.788h2.743v-5.786c3.36-.141%205.903-.803%205.903-1.597z'/%3e%3c/g%3e%3c/g%3e%3cdefs%3e%3cclipPath%20id='A'%3e%3cpath%20fill='%23fff'%20d='M0%200h24v24H0z'/%3e%3c/clipPath%3e%3c/defs%3e%3c/svg%3e",
20+
"decimals": 6,
21+
"symbol": "USDT",
22+
},
23+
"txType": "redeem",
24+
},
25+
{
26+
"accountAddress": "0x3d759121234cd36F8124C21aFe1c6852d2bEd848",
27+
"amountCents": "2401121.576132434220587935367386",
28+
"amountTokens": "24001813290985731.455439",
29+
"blockNumber": "41114058",
30+
"blockTimestamp": 2024-08-06T02:18:03.000Z,
31+
"chainId": 97,
32+
"contractAddress": "0xb7526572ffe56ab9d7489838bf2e18e3323b441a",
33+
"hash": "0xb0435b135762a7ca2ad7dccb9aa6c7f50237c6139b16a76348d6c64dfece110e",
34+
"poolName": "Metaverse",
35+
"token": {
36+
"address": "0xA11c8D9DC9b66E209Ef60F0C8D969D3CD988782c",
37+
"asset": "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='24'%20height='24'%20fill='none'%20xmlns:v='https://vecta.io/nano'%3e%3cg%20clip-path='url(%23A)'%3e%3cpath%20d='M24%2012c0%206.628-5.372%2012-12%2012S0%2018.628%200%2012%205.373%200%2012%200s12%205.373%2012%2012z'%20fill='%231ba27a'/%3e%3cg%20fill='%23fff'%3e%3cpath%20d='M17.629%206.051H6.267v2.743h4.31v4.032h2.743V8.794h4.31V6.051z'/%3e%3cpath%20d='M11.973%2013.256c-3.565%200-6.456-.564-6.456-1.26s2.89-1.26%206.456-1.26%206.455.564%206.455%201.26-2.89%201.26-6.455%201.26zm7.249-1.05c0-.898-3.245-1.625-7.249-1.625s-7.249.727-7.249%201.625c0%20.79%202.517%201.449%205.851%201.595v5.788h2.743v-5.786c3.36-.141%205.903-.803%205.903-1.597z'/%3e%3c/g%3e%3c/g%3e%3cdefs%3e%3cclipPath%20id='A'%3e%3cpath%20fill='%23fff'%20d='M0%200h24v24H0z'/%3e%3c/clipPath%3e%3c/defs%3e%3c/svg%3e",
38+
"decimals": 6,
39+
"symbol": "USDT",
40+
},
41+
"txType": "mint",
42+
},
43+
],
44+
}
45+
`;
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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

Comments
 (0)