Skip to content

Commit

Permalink
remove bch-js
Browse files Browse the repository at this point in the history
  • Loading branch information
vinarmani committed Dec 17, 2021
1 parent ed1d3b9 commit 0aea859
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 805 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@
"@ant-design/dark-theme": "^1.0.3",
"@babel/core": "^7.6.0",
"@babel/node": "^7.12.6",
"@psf/bch-js": "^4.16.1",
"@svgr/webpack": "^5.5.0",
"@testing-library/react": "^11.2.2",
"@testing-library/react-hooks": "^3.7.0",
Expand Down
1 change: 0 additions & 1 deletion src/components/Send/__tests__/Send.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import renderer from 'react-test-renderer';
import { ThemeProvider } from 'styled-components';
import { theme } from '@assets/styles/theme';
import Send from '@components/Send/Send';
import BCHJS from '@psf/bch-js';
import {
walletWithBalancesAndTokensWithCorrectState,
} from '../../Wallet/__mocks__/walletAndBalancesMock';
Expand Down
2 changes: 0 additions & 2 deletions src/components/Tokens/__tests__/CreateTokenForm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import renderer from 'react-test-renderer';
import { ThemeProvider } from 'styled-components';
import { theme } from '@assets/styles/theme';
import CreateTokenForm from '@components/Tokens/CreateTokenForm';
import BCHJS from '@psf/bch-js';
import useBCH from '@hooks/useBCH';
import { walletWithBalancesAndTokensWithCorrectState } from '../../Wallet/__mocks__/walletAndBalancesMock';

Expand Down Expand Up @@ -38,7 +37,6 @@ afterEach(() => {
test('Wallet with BCH balances and tokens and state field', () => {
useContextMock.mockReturnValue(walletWithBalancesAndTokensWithCorrectState);

const testBCH = new BCHJS();
const { getRestUrl, createToken } = useBCH();
const component = renderer.create(
<ThemeProvider theme={theme}>
Expand Down
2 changes: 0 additions & 2 deletions src/components/Tokens/__tests__/Tokens.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import renderer from 'react-test-renderer';
import { ThemeProvider } from 'styled-components';
import { theme } from '@assets/styles/theme';
import Tokens from '@components/Tokens/Tokens';
import BCHJS from '@psf/bch-js';
import {
walletWithBalancesAndTokens,
walletWithBalancesMock,
Expand Down Expand Up @@ -42,7 +41,6 @@ afterEach(() => {

test('Wallet with BCH balances and tokens and state field', () => {
useContextMock.mockReturnValue(walletWithBalancesAndTokensWithCorrectState);
const testBCH = new BCHJS();
const component = renderer.create(
<ThemeProvider theme={theme}>
<Router>
Expand Down
34 changes: 12 additions & 22 deletions src/hooks/__tests__/migrations.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { currency } from '../../components/Common/Ticker';
import BigNumber from 'bignumber.js';
import BCHJS from '@psf/bch-js';
import {
fromSmallestDenomination,
toSmallestDenomination,
Expand All @@ -17,28 +16,23 @@ describe('Testing functions for upgrading Cashtab', () => {
).toBe(0.0000055);
});
it('Replicate 8-decimal return value from instance of toSatoshi in TransactionBuilder with toSmallestDenomination', () => {
const BCH = new BCHJS();
const testSendAmount = '0.12345678';
const resultAmount = 12345678;
expect(
parseInt(toSmallestDenomination(new BigNumber(testSendAmount), 8)),
).toBe(BCH.BitcoinCash.toSatoshi(Number(testSendAmount).toFixed(8)));
).toBe(resultAmount);
});
it('Replicate 2-decimal return value from instance of toSatoshi in TransactionBuilder with toSmallestDenomination', () => {
const BCH = new BCHJS();
const testSendAmount = '0.12';
const resultAmount = 12000000;
expect(
parseInt(toSmallestDenomination(new BigNumber(testSendAmount), 8)),
).toBe(BCH.BitcoinCash.toSatoshi(Number(testSendAmount).toFixed(8)));
).toBe(resultAmount);
});
it('Replicate 8-decimal return value from instance of toSatoshi in remainder comparison with toSmallestDenomination', () => {
const BCH = new BCHJS();
expect(
parseFloat(toSmallestDenomination(new BigNumber('0.00000546'), 8)),
).toBe(
BCH.BitcoinCash.toSatoshi(
parseFloat(new BigNumber('0.00000546').toFixed(8)),
),
);
).toBe(546);
});
it('toSmallestDenomination() returns false if input is not a BigNumber', () => {
const testInput = 132.12345678;
Expand Down Expand Up @@ -67,13 +61,9 @@ describe('Testing functions for upgrading Cashtab', () => {
);
});
it('toSmallestDenomination() returns exact result as toSatoshi but in BigNumber format', () => {
const BCH = new BCHJS();
const testAmount = new BigNumber('0.12345678');

// Match legacy implementation, inputting a BigNumber converted to a string by .toFixed(8)
const testAmountInSatoshis = BCH.BitcoinCash.toSatoshi(
testAmount.toFixed(8),
);
const testAmountInSatoshis = 12345678;

const testAmountInCashDecimals = toSmallestDenomination(testAmount, 8);

Expand Down Expand Up @@ -108,25 +98,25 @@ describe('Testing functions for upgrading Cashtab', () => {
expect(parseInt(remainder)).toStrictEqual(12345678);
});
it('Replicates return value from instance of toBitcoinCash with fromSmallestDenomination and cashDecimals = 8', () => {
const BCH = new BCHJS();
const testSendAmount = '12345678';
const resultAmount = .12345678
expect(fromSmallestDenomination(testSendAmount, 8)).toBe(
BCH.BitcoinCash.toBitcoinCash(testSendAmount),
resultAmount,
);
});
it('Replicates largest possible digits return value from instance of toBitcoinCash with fromSmallestDenomination and cashDecimals = 8', () => {
const BCH = new BCHJS();
const testSendAmount = '1000000012345678';
const resultAmount = 10000000.12345678;
expect(fromSmallestDenomination(testSendAmount, 8)).toBe(
BCH.BitcoinCash.toBitcoinCash(testSendAmount),
resultAmount,
);
});

it('Replicates smallest unit value return value from instance of toBitcoinCash with fromSmallestDenomination and cashDecimals = 8', () => {
const BCH = new BCHJS();
const testSendAmount = '1';
const resultAmount = .00000001
expect(fromSmallestDenomination(testSendAmount, 8)).toBe(
BCH.BitcoinCash.toBitcoinCash(testSendAmount),
resultAmount,
);
});

Expand Down
Loading

0 comments on commit 0aea859

Please sign in to comment.