Skip to content

Commit 83d4c60

Browse files
committed
refactor(cardano): fix unit tests
1 parent cea23ef commit 83d4c60

File tree

7 files changed

+35
-32
lines changed

7 files changed

+35
-32
lines changed

packages/cardano/src/ui/components/StakePoolNameBrowser/__tests__/StakePoolNameBrowser.test.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ import { StakePoolNameBrowser, StakePoolNameBrowserProps } from '../StakePoolNam
55
import '@testing-library/jest-dom';
66

77
describe('Testing StakePoolNameBrowser component', () => {
8+
const name = 'name';
9+
const ticker = 'ticker';
810
const props: StakePoolNameBrowserProps = {
9-
name: 'name',
10-
ticker: 'ticker',
11+
name,
12+
ticker,
1113
isDelegated: true,
1214
translations: { retiring: 'retiring', retired: 'retired', delegating: 'delegating', saturated: 'saturated' }
1315
};
1416
test('should display all stake pool metrics with icons', async () => {
1517
const { findByText, findByTestId } = render(<StakePoolNameBrowser {...props} />);
1618
const roiLabel = await findByTestId('stake-pool-item-logo');
17-
const nameValue = await findByText(props.name);
18-
const tickerValue = await findByText(props.ticker);
19+
const nameValue = await findByText(name);
20+
const tickerValue = await findByText(ticker);
1921

2022
expect(roiLabel).toBeVisible();
2123
expect(nameValue).toBeVisible();

packages/cardano/src/wallet/lib/__tests__/build-transaction.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe.skip('Testing build-transaction', () => {
2727

2828
expect(transaction).toBeDefined();
2929
expect(minimumCoinQuantities).toBeDefined();
30-
expect(minimumCoinQuantities.get(output).coinMissing).toBe(BigInt(0));
30+
expect(minimumCoinQuantities.get(output)?.coinMissing).toBe(BigInt(0));
3131
});
3232

3333
test('should validate and build a transaction successfully with coins missing', async () => {
@@ -39,7 +39,7 @@ describe.skip('Testing build-transaction', () => {
3939

4040
expect(transaction).toBeDefined();
4141
expect(minimumCoinQuantities).toBeDefined();
42-
expect(minimumCoinQuantities.get(output).coinMissing).toBeGreaterThan(BigInt(0));
42+
expect(minimumCoinQuantities.get(output)?.coinMissing).toBeGreaterThan(BigInt(0));
4343
});
4444

4545
test('should throw an error if tx initialization fails', async () => {

packages/cardano/src/wallet/lib/__tests__/get-inputs-value.test.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('Testing getTxInputsValueAndAddress function', () => {
4949
signed$: of([])
5050
}
5151
}
52-
} as ObservableWallet;
52+
} as unknown as ObservableWallet;
5353

5454
const multiDelegationTransactionMock: Cardano.HydratedTx = {
5555
inputSource: Cardano.InputSource.inputs,
@@ -194,11 +194,11 @@ describe('Testing getTxInputsValueAndAddress function', () => {
194194
'addr_test1qrmavlv5c7za68rq6n6r0hrcqd604j9zsr6tycwtjf3lef0wc4p9nt0e0wwytcy30mxar65892w3k77e5g2uyhx29lhqjt267p'
195195
);
196196
// From matched output in mocked transaction
197-
expect(inputs[0].value.coins.toString()).toBe('3000000');
197+
expect(inputs[0].value?.coins.toString()).toBe('3000000');
198198
expect(
199-
inputs[0].value.assets
200-
.get(Cardano.AssetId('6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7'))
201-
.toString()
199+
inputs[0].value?.assets
200+
?.get(Cardano.AssetId('6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7'))
201+
?.toString()
202202
).toBe('30');
203203
});
204204
});
@@ -225,11 +225,11 @@ describe('Testing getTxInputsValueAndAddress function', () => {
225225
'addr_test1qrmavlv5c7za68rq6n6r0hrcqd604j9zsr6tycwtjf3lef0wc4p9nt0e0wwytcy30mxar65892w3k77e5g2uyhx29lhqjt267p'
226226
);
227227
// From matched output in mocked transaction
228-
expect(inputs[0].value.coins.toString()).toBe('3000000');
228+
expect(inputs[0].value?.coins.toString()).toBe('3000000');
229229
expect(
230-
inputs[0].value.assets
231-
.get(Cardano.AssetId('6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7'))
232-
.toString()
230+
inputs[0].value?.assets
231+
?.get(Cardano.AssetId('6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7'))
232+
?.toString()
233233
).toBe('30');
234234
});
235235
});
@@ -250,7 +250,7 @@ describe('Testing getTxInputsValueAndAddress function', () => {
250250
]);
251251

252252
const result = getTxInputsValueAndAddress(
253-
Array.from({ length: 30 }).map((_, index) => ({ index, txId: 'txId1' } as unknown as Cardano.TxIn)),
253+
Array.from({ length: 30 }).map((_, index) => ({ index, txId: 'txId1' }) as unknown as Cardano.TxIn),
254254
{
255255
transactionsByHashes
256256
} as unknown as ChainHistoryProvider,
@@ -261,7 +261,7 @@ describe('Testing getTxInputsValueAndAddress function', () => {
261261
const inputs = await result;
262262
expect(transactionsByHashes).toBeCalledTimes(1);
263263
expect(inputs[0].address).toBe('address');
264-
expect(inputs[0].value.coins.toString()).toBe('3000000');
264+
expect(inputs[0].value?.coins.toString()).toBe('3000000');
265265
});
266266
});
267267

@@ -285,7 +285,7 @@ describe('Testing getTxInputsValueAndAddress function', () => {
285285
);
286286

287287
const result = getTxInputsValueAndAddress(
288-
Array.from({ length: 30 }).map((_, index) => ({ index: 0, txId: `txId${index}` } as Cardano.TxIn)),
288+
Array.from({ length: 30 }).map((_, index) => ({ index: 0, txId: `txId${index}` }) as Cardano.TxIn),
289289
{
290290
transactionsByHashes
291291
} as unknown as ChainHistoryProvider,
@@ -329,11 +329,11 @@ describe('Testing getTxInputsValueAndAddress function', () => {
329329
expect(inputs[0].address).toBe(
330330
'addr_test1qrmavlv5c7za68rq6n6r0hrcqd604j9zsr6tycwtjf3lef0wc4p9nt0e0wwytcy30mxar65892w3k77e5g2uyhx29lhqjt267p'
331331
);
332-
expect(inputs[0].value.coins.toString()).toBe('3000000');
332+
expect(inputs[0].value?.coins.toString()).toBe('3000000');
333333
expect(
334-
inputs[0].value.assets
335-
.get(Cardano.AssetId('6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7'))
336-
.toString()
334+
inputs[0].value?.assets
335+
?.get(Cardano.AssetId('6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7'))
336+
?.toString()
337337
).toBe('30');
338338

339339
// Assert the properties for the second input
@@ -342,12 +342,12 @@ describe('Testing getTxInputsValueAndAddress function', () => {
342342
);
343343

344344
expect(
345-
inputs[1].value.assets
346-
.get(Cardano.AssetId('6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7'))
347-
.toString()
345+
inputs[1].value?.assets
346+
?.get(Cardano.AssetId('6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7'))
347+
?.toString()
348348
).toBe('10');
349349

350-
expect(inputs[1].value.coins.toString()).toBe('100000');
350+
expect(inputs[1].value?.coins.toString()).toBe('100000');
351351

352352
expect(inputs[2].address).toBe(
353353
'addr_test1qrrx8s34r6m0w835qe9tj8mqa4ugkwhllw5l4hwpmhakpy8hukqufzmfnrvvr24tschssxw96z8dq9dz09xkg9eghtkqe07423'

packages/cardano/src/wallet/test/mocks/mock.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ export const stakePoolMock: Cardano.StakePool = {
4747
relays: undefined
4848
} as unknown as Cardano.StakePool;
4949

50-
export const rewardAcountMock: Partial<Cardano.RewardAccountInfo> = {
50+
export const rewardAcountMock: Cardano.RewardAccountInfo = {
5151
address: Cardano.RewardAccount('stake_test1urm7tqwy3d5e3kxp424cvtcgr8zaprkszk38jntyzu5t4mqalgvfg'),
5252
credentialStatus: Cardano.StakeCredentialStatus.Registered,
5353

5454
delegatee: {
5555
nextNextEpoch: stakePoolMock
5656
},
5757
rewardBalance: BigInt('0')
58-
};
58+
} as unknown as Cardano.RewardAccountInfo;

packages/cardano/src/wallet/util/__tests__/asset-balance.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable unicorn/no-useless-undefined */
12
/* eslint-disable no-magic-numbers */
23
import { Asset } from '@cardano-sdk/core';
34
import { calculateAssetBalance, assetBalanceToBigInt } from '../asset-balance';
@@ -17,7 +18,7 @@ describe('asset-balance', () => {
1718
});
1819

1920
test('with no decimals', () => {
20-
expect(calculateAssetBalance(BigInt(15), undefined as Asset.AssetInfo)).toEqual('15');
21+
expect(calculateAssetBalance(BigInt(15), undefined)).toEqual('15');
2122
expect(calculateAssetBalance(BigInt(15), {} as Asset.AssetInfo)).toEqual('15');
2223
expect(calculateAssetBalance(BigInt(15), { tokenMetadata: undefined } as Asset.AssetInfo)).toEqual('15');
2324
expect(calculateAssetBalance(BigInt(15), { tokenMetadata: { decimals: undefined } } as Asset.AssetInfo)).toEqual(
@@ -41,7 +42,7 @@ describe('asset-balance', () => {
4142
});
4243

4344
test('with no decimals in metadata', () => {
44-
expect(assetBalanceToBigInt('15', undefined as Asset.AssetInfo)).toEqual(BigInt(15));
45+
expect(assetBalanceToBigInt('15', undefined)).toEqual(BigInt(15));
4546
expect(assetBalanceToBigInt('15', {} as Asset.AssetInfo)).toEqual(BigInt(15));
4647
expect(assetBalanceToBigInt('15', { tokenMetadata: undefined } as Asset.AssetInfo)).toEqual(BigInt(15));
4748
expect(assetBalanceToBigInt('15', { tokenMetadata: { decimals: undefined } } as Asset.AssetInfo)).toEqual(

packages/cardano/src/wallet/util/__tests__/stake-pool-transformer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const cardanoStakePoolMock: StakePoolSearchResults = {
6161
}
6262
],
6363
totalResultCount: 1
64-
};
64+
} as unknown as StakePoolSearchResults;
6565

6666
const transformedStakePool = {
6767
ros: '69.00',

packages/cardano/src/wallet/util/asset-balance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const getPlaceholderDecimal = (value: string) => {
1313
return decimals ? decimals : 0;
1414
};
1515

16-
export const calculateAssetBalance = (balance: bigint | string, assetInfo: Asset.AssetInfo): string => {
16+
export const calculateAssetBalance = (balance: bigint | string, assetInfo?: Asset.AssetInfo): string => {
1717
const decimals = assetInfo?.tokenMetadata?.decimals;
1818
if (!decimals) return balance.toString();
1919

0 commit comments

Comments
 (0)