import { prepareToSendTx } from '../send'; import { getGasFee } from '../send/fee/getGasFee'; import { ITxData } from '../types'; import { BSC_TESTNET_NETWORK, BSC_ACCOUNT, BNB_ASSET, BBC_ACCOUNT, BUSD_ASSET, ETH_TESTNET_NETWORK, ETH_ACCOUNT, } from './mock'; import { ETH_ASSET, DAI_ASSET } from './mock'; const knownTxRegExp = /(already known)|(known transaction)/; export const prepareForBscOrEth = () => describe('prepareForBscOrEth', () => { // eth it('ETH -> ETH: Transfer ETH', async () => { try { const data: ITxData = { network: ETH_TESTNET_NETWORK, from: ETH_ACCOUNT.address, to: ETH_ACCOUNT.address, value: '0.001', asset: ETH_ASSET, type: '2', gas: { maxFeePerGas: '65632824640', maxPriorityFeePerGas: '1500000000', }, }; const { gasPrice, gasLimit, fee } = await getGasFee(data); console.log('gas: ', gasPrice, gasLimit, fee); const { sign, send } = await prepareToSendTx(data); const result = await send(sign(ETH_ACCOUNT.privateKey)); expect(result).toHaveProperty('transactionHash'); } catch (error) { expect(error.message).toMatch(knownTxRegExp); } }); it('ETH -> ETH: Transfer DAI', async () => { try { const data = { network: ETH_TESTNET_NETWORK, from: ETH_ACCOUNT.address, to: ETH_ACCOUNT.address, value: '0.1', asset: DAI_ASSET, }; const { gasPrice, gasLimit, fee } = await getGasFee(data); console.log('gas: ', gasPrice, gasLimit, fee); const { sign, send } = await prepareToSendTx(data); const result = await send(sign(ETH_ACCOUNT.privateKey)); console.log('transactionHash: ', result.transactionHash); expect(result).toHaveProperty('transactionHash'); } catch (error) { expect(error.message).toMatch(knownTxRegExp); } }); it('BSC -> BSC: Transfer BNB', async () => { try { const data = { network: BSC_TESTNET_NETWORK, from: BSC_ACCOUNT.address, to: BSC_ACCOUNT.address, value: '0.001', asset: BNB_ASSET, }; const { gasPrice, gasLimit, fee } = await getGasFee(data); console.log('gas: ', gasPrice, gasLimit, fee); const { sign, send } = await prepareToSendTx(data); const result = await send(sign(BSC_ACCOUNT.privateKey)); expect(result).toHaveProperty('transactionHash'); } catch (error) { expect(error.message).toMatch(knownTxRegExp); } }); it('BSC -> BSC: Transfer BUSD', async () => { try { const { sign, send } = await prepareToSendTx({ network: BSC_TESTNET_NETWORK, from: BSC_ACCOUNT.address, to: BSC_ACCOUNT.address, value: '0.001', asset: BUSD_ASSET, }); const result = await send(sign(BSC_ACCOUNT.privateKey)); expect(result).toHaveProperty('transactionHash'); } catch (error) { expect(error.message).toMatch(knownTxRegExp); } }); it('BSC -> BSC: Use custom gas, Transfer BNB', async () => { try { const { sign, send } = await prepareToSendTx({ network: BSC_TESTNET_NETWORK, from: BSC_ACCOUNT.address, to: BSC_ACCOUNT.address, value: '0.001', asset: BNB_ASSET, gas: { gasPrice: '15000000000', gasLimit: '42000', }, }); const result = await send(sign(BSC_ACCOUNT.privateKey)); expect(result).toHaveProperty('transactionHash'); } catch (error) { expect(error.message).toMatch(knownTxRegExp); } }); }); export const prepareForBscToBbc = () => describe('prepareForBscToBbc', () => { // BSC network it('BSC -> BBC: Transfer BNB', async () => { const data = { network: BSC_TESTNET_NETWORK, from: BSC_ACCOUNT.address, to: BBC_ACCOUNT.address, value: '0.00038024', asset: BNB_ASSET, }; const { gasLimit, gasPrice, fee } = await getGasFee(data); console.log('gas: ', gasPrice, gasLimit, fee); const { sign, send } = await prepareToSendTx(data); const result = await send(sign(BSC_ACCOUNT.privateKey)); expect(result).toHaveProperty('transactionHash'); }); it('BSC -> BBC: Transfer BUSD', async () => { const data = { network: BSC_TESTNET_NETWORK, from: BSC_ACCOUNT.address, to: BBC_ACCOUNT.address, value: '0.001', asset: BUSD_ASSET, }; const { gasLimit, gasPrice, fee } = await getGasFee(data); console.log('gas: ', gasPrice, gasLimit, fee); const { sign, send } = await prepareToSendTx(data); const result = await send(sign(BSC_ACCOUNT.privateKey)); expect(result).toHaveProperty('transactionHash'); }); it('BSC -> BBC: Use custom gas, Transfer BNB', async () => { try { const data = { network: BSC_TESTNET_NETWORK, from: BSC_ACCOUNT.address, to: BBC_ACCOUNT.address, value: '0.001', asset: BNB_ASSET, gas: { gasPrice: '15000000000', gasLimit: '120000', }, }; const { gasLimit, gasPrice, fee } = await getGasFee(data); console.log('gas: ', gasPrice, gasLimit, fee); const { sign, send } = await prepareToSendTx(data); const result = await send(sign(BSC_ACCOUNT.privateKey)); expect(result).toHaveProperty('transactionHash'); } catch (error) { expect(error.message).toMatch(knownTxRegExp); } }); });