Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/__tests__/useBCH.test.js
/* eslint-disable no-native-reassign */ | /* eslint-disable no-native-reassign */ | ||||
import useBCH from '../useBCH'; | import useBCH from '../useBCH'; | ||||
import mockReturnGetUtxos from '../__mocks__/mockReturnGetUtxos'; | import mockReturnGetUtxos from '../__mocks__/mockReturnGetUtxos'; | ||||
import mockReturnGetSlpBalancesAndUtxos from '../__mocks__/mockReturnGetSlpBalancesAndUtxos'; | import mockReturnGetSlpBalancesAndUtxos from '../__mocks__/mockReturnGetSlpBalancesAndUtxos'; | ||||
import sendBCHMock from '../__mocks__/sendBCH'; | import sendBCHMock from '../__mocks__/sendBCH'; | ||||
import BCHJS from '@psf/bch-js'; // TODO: should be removed when external lib not needed anymore | import BCHJS from '@psf/bch-js'; // TODO: should be removed when external lib not needed anymore | ||||
import { currency } from '../../components/Common/Ticker'; | import { currency } from '../../components/Common/Ticker'; | ||||
import sendBCH from '../__mocks__/sendBCH'; | import sendBCH from '../__mocks__/sendBCH'; | ||||
describe('useBCH hook', () => { | describe('useBCH hook', () => { | ||||
it('gets Rest Api Url on testnet', () => { | it('gets Rest Api Url on testnet', () => { | ||||
process = { | process = { | ||||
env: { | env: { | ||||
REACT_APP_NETWORK: `testnet`, | REACT_APP_NETWORK: `testnet`, | ||||
REACT_APP_API_TEST: `https://free-test.fullstack.cash/v3/`, | REACT_APP_BCHA_APIS: | ||||
REACT_APP_API: `https://free-main.fullstack.cash/v3/`, | 'https://rest.kingbch.com/v3/,https://wallet-service-prod.bitframe.org/v3/,notevenaurl,https://rest.kingbch.com/v3/', | ||||
REACT_APP_BCHA_APIS_TEST: | |||||
'https://free-test.fullstack.cash/v3/', | |||||
}, | }, | ||||
}; | }; | ||||
const { getRestUrl } = useBCH(); | const { getRestUrl } = useBCH(); | ||||
const expectedApiUrl = `https://free-test.fullstack.cash/v3/`; | const expectedApiUrl = `https://free-test.fullstack.cash/v3/`; | ||||
expect(getRestUrl()).toBe(expectedApiUrl); | expect(getRestUrl(0)).toBe(expectedApiUrl); | ||||
}); | }); | ||||
it('gets Rest Api Url on mainnet', () => { | it('gets primary Rest API URL on mainnet', () => { | ||||
process = { | process = { | ||||
env: { | env: { | ||||
REACT_APP_NETWORK: `mainnet`, | REACT_APP_BCHA_APIS: | ||||
REACT_APP_API_TEST: `https://free-test.fullstack.cash/v3/`, | 'https://rest.kingbch.com/v3/,https://wallet-service-prod.bitframe.org/v3/,notevenaurl,https://rest.kingbch.com/v3/', | ||||
REACT_APP_API: `https://free-main.fullstack.cash/v3/`, | REACT_APP_NETWORK: 'mainnet', | ||||
}, | }, | ||||
}; | }; | ||||
const { getRestUrl } = useBCH(); | const { getRestUrl } = useBCH(); | ||||
const expectedApiUrl = `https://free-main.fullstack.cash/v3/`; | const expectedApiUrl = `https://rest.kingbch.com/v3/`; | ||||
expect(getRestUrl()).toBe(expectedApiUrl); | expect(getRestUrl(0)).toBe(expectedApiUrl); | ||||
}); | }); | ||||
it('calculates fee correctly for 2 P2PKH outputs', () => { | it('calculates fee correctly for 2 P2PKH outputs', () => { | ||||
const { calcFee } = useBCH(); | const { calcFee } = useBCH(); | ||||
const BCH = new BCHJS(); | const BCH = new BCHJS(); | ||||
const utxosMock = [{}, {}]; | const utxosMock = [{}, {}]; | ||||
// For 1.01 sat/byte fee | // For 1.01 sat/byte fee | ||||
let expectedTxFee = 378; | let expectedTxFee = 378; | ||||
▲ Show 20 Lines • Show All 178 Lines • Show Last 20 Lines |