2022-08-09 09:43:11 +00:00
|
|
|
import { renderHook } from '@testing-library/react';
|
2022-06-10 13:55:14 +00:00
|
|
|
import { useSettlementAccount } from './use-settlement-account';
|
|
|
|
import type { PartyBalanceQuery_party_accounts } from '../components/deal-ticket/__generated__/PartyBalanceQuery';
|
2022-08-10 15:28:03 +00:00
|
|
|
import { AccountType } from '@vegaprotocol/types';
|
2022-06-10 13:55:14 +00:00
|
|
|
|
|
|
|
describe('useSettlementAccount Hook', () => {
|
|
|
|
it('should filter accounts by settlementAssetId', () => {
|
|
|
|
const accounts: PartyBalanceQuery_party_accounts[] = [
|
|
|
|
{
|
|
|
|
__typename: 'Account',
|
2022-08-22 22:50:13 +00:00
|
|
|
type: AccountType.ACCOUNT_TYPE_GENERAL,
|
2022-06-10 13:55:14 +00:00
|
|
|
balance: '2000000000000000000000',
|
|
|
|
asset: {
|
|
|
|
__typename: 'Asset',
|
|
|
|
id: '5cfa87844724df6069b94e4c8a6f03af21907d7bc251593d08e4251043ee9f7c',
|
|
|
|
symbol: 'tBTC',
|
|
|
|
name: 'tBTC TEST',
|
|
|
|
decimals: 5,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
__typename: 'Account',
|
2022-08-22 22:50:13 +00:00
|
|
|
type: AccountType.ACCOUNT_TYPE_GENERAL,
|
2022-06-10 13:55:14 +00:00
|
|
|
balance: '1000000000',
|
|
|
|
asset: {
|
|
|
|
__typename: 'Asset',
|
|
|
|
id: '6d9d35f657589e40ddfb448b7ad4a7463b66efb307527fedd2aa7df1bbd5ea61',
|
|
|
|
symbol: 'tDAI',
|
|
|
|
name: 'tDAI TEST',
|
|
|
|
decimals: 5,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
__typename: 'Account',
|
2022-08-22 22:50:13 +00:00
|
|
|
type: AccountType.ACCOUNT_TYPE_GENERAL,
|
2022-08-10 15:28:03 +00:00
|
|
|
balance: '5000000000000000000',
|
|
|
|
asset: {
|
|
|
|
__typename: 'Asset',
|
|
|
|
id: 'fc7fd956078fb1fc9db5c19b88f0874c4299b2a7639ad05a47a28c0aef291b55',
|
|
|
|
symbol: 'VEGA',
|
|
|
|
name: 'Vega (testnet)',
|
|
|
|
decimals: 18,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
__typename: 'Account',
|
2022-08-22 22:50:13 +00:00
|
|
|
type: AccountType.ACCOUNT_TYPE_MARGIN,
|
2022-06-10 13:55:14 +00:00
|
|
|
balance: '5000000000000000000',
|
|
|
|
asset: {
|
|
|
|
__typename: 'Asset',
|
|
|
|
id: 'fc7fd956078fb1fc9db5c19b88f0874c4299b2a7639ad05a47a28c0aef291b55',
|
|
|
|
symbol: 'VEGA',
|
|
|
|
name: 'Vega (testnet)',
|
|
|
|
decimals: 18,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
2022-08-10 15:28:03 +00:00
|
|
|
const tDAI =
|
2022-06-10 13:55:14 +00:00
|
|
|
'6d9d35f657589e40ddfb448b7ad4a7463b66efb307527fedd2aa7df1bbd5ea61';
|
2022-08-10 15:28:03 +00:00
|
|
|
const vega =
|
|
|
|
'fc7fd956078fb1fc9db5c19b88f0874c4299b2a7639ad05a47a28c0aef291b55';
|
2022-06-10 13:55:14 +00:00
|
|
|
|
2022-08-10 15:28:03 +00:00
|
|
|
const { result: resultDai } = renderHook(() =>
|
|
|
|
useSettlementAccount(tDAI, accounts)
|
|
|
|
);
|
|
|
|
expect(resultDai.current?.balance).toBe(accounts[1].balance);
|
|
|
|
expect(resultDai.current?.asset).toEqual(accounts[1].asset);
|
|
|
|
|
|
|
|
const { result: resultVega } = renderHook(() =>
|
2022-08-22 22:50:13 +00:00
|
|
|
useSettlementAccount(vega, accounts, AccountType.ACCOUNT_TYPE_MARGIN)
|
2022-06-10 13:55:14 +00:00
|
|
|
);
|
2022-08-10 15:28:03 +00:00
|
|
|
|
|
|
|
expect(resultVega.current?.balance).toBe(accounts[3].balance);
|
|
|
|
expect(resultVega.current?.asset).toEqual(accounts[3].asset);
|
2022-06-10 13:55:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return null if no accounts', () => {
|
|
|
|
const accounts: PartyBalanceQuery_party_accounts[] = [];
|
|
|
|
const settlementAssetId =
|
|
|
|
'6d9d35f657589e40ddfb448b7ad4a7463b66efb307527fedd2aa7df1bbd5ea61';
|
|
|
|
const { result } = renderHook(() =>
|
|
|
|
useSettlementAccount(settlementAssetId, accounts)
|
|
|
|
);
|
|
|
|
expect(result.current).toBe(undefined);
|
|
|
|
});
|
|
|
|
});
|