|
| 1 | +import BigNumber from 'bignumber.js'; |
| 2 | +import { hasAssetsAfterTransaction } from './helpers'; |
| 3 | + |
| 4 | +const assetWithOneQuantity = { |
| 5 | + policyId: 'policyId1', |
| 6 | + assetName: '54657374636f696e', |
| 7 | + quantity: new BigNumber(1), |
| 8 | + fingerprint: 'policyId154657374636f696e', |
| 9 | + metadata: { |
| 10 | + name: 'Testcoin', |
| 11 | + description: 'Test coin', |
| 12 | + }, |
| 13 | + uniqueId: 'uniqueId1', |
| 14 | + decimals: 1, |
| 15 | + recommendedDecimals: null, |
| 16 | +}; |
| 17 | + |
| 18 | +const assetWithTenQuantity = { |
| 19 | + policyId: 'policyId2', |
| 20 | + assetName: '436f696e74657374', |
| 21 | + quantity: new BigNumber(10), |
| 22 | + fingerprint: 'policyId2436f696e74657374', |
| 23 | + uniqueId: 'uniqueId2', |
| 24 | + decimals: 1, |
| 25 | + recommendedDecimals: null, |
| 26 | +}; |
| 27 | + |
| 28 | +describe('hasAssetsAfterTransaction', () => { |
| 29 | + test('Should be true when wallet has assets and tx sending no assets', () => { |
| 30 | + expect( |
| 31 | + hasAssetsAfterTransaction({ |
| 32 | + assetTokens: [assetWithOneQuantity, assetWithTenQuantity], |
| 33 | + selectedAssets: [], |
| 34 | + assetsAmounts: [], |
| 35 | + }) |
| 36 | + ).toEqual(true); |
| 37 | + }); |
| 38 | + |
| 39 | + test('Should be true when wallet has assets and tx is not sending all asset types', () => { |
| 40 | + expect( |
| 41 | + hasAssetsAfterTransaction({ |
| 42 | + assetTokens: [assetWithOneQuantity, assetWithTenQuantity], |
| 43 | + selectedAssets: [assetWithTenQuantity], |
| 44 | + assetsAmounts: ['5'], |
| 45 | + }) |
| 46 | + ).toEqual(true); |
| 47 | + }); |
| 48 | + |
| 49 | + test('Should be true when wallet has assets and tx is not sending all assets', () => { |
| 50 | + expect( |
| 51 | + hasAssetsAfterTransaction({ |
| 52 | + assetTokens: [assetWithOneQuantity, assetWithTenQuantity], |
| 53 | + selectedAssets: [assetWithOneQuantity, assetWithTenQuantity], |
| 54 | + assetsAmounts: ['1', '5'], |
| 55 | + }) |
| 56 | + ).toEqual(true); |
| 57 | + }); |
| 58 | + |
| 59 | + test('Should be false when wallet has no assets', () => { |
| 60 | + expect( |
| 61 | + hasAssetsAfterTransaction({ |
| 62 | + assetTokens: [], |
| 63 | + selectedAssets: [], |
| 64 | + assetsAmounts: [], |
| 65 | + }) |
| 66 | + ).toEqual(false); |
| 67 | + }); |
| 68 | + |
| 69 | + test('Should be false when tx is sending all assets (1 asset)', () => { |
| 70 | + expect( |
| 71 | + hasAssetsAfterTransaction({ |
| 72 | + assetTokens: [assetWithOneQuantity], |
| 73 | + selectedAssets: [assetWithOneQuantity], |
| 74 | + assetsAmounts: ['1'], |
| 75 | + }) |
| 76 | + ).toEqual(false); |
| 77 | + }); |
| 78 | + |
| 79 | + test('Should be false when tx is sending all assets (2 assets)', () => { |
| 80 | + expect( |
| 81 | + hasAssetsAfterTransaction({ |
| 82 | + assetTokens: [assetWithOneQuantity, assetWithTenQuantity], |
| 83 | + selectedAssets: [assetWithOneQuantity, assetWithTenQuantity], |
| 84 | + assetsAmounts: ['1', '10'], |
| 85 | + }) |
| 86 | + ).toEqual(false); |
| 87 | + }); |
| 88 | +}); |
0 commit comments