From 537f38f48b2d15db88f899e66562d6a7fee0257a Mon Sep 17 00:00:00 2001 From: Marcos Date: Thu, 19 Oct 2023 09:07:47 -0300 Subject: [PATCH 1/4] Refactor 02_00_06-2wp-new-minimum tests to compare values use the base unit --- tests/02_00_06-2wp-new-minimum.js | 48 ++++++++++++++++++------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/tests/02_00_06-2wp-new-minimum.js b/tests/02_00_06-2wp-new-minimum.js index 894877d6..3b26ad8a 100644 --- a/tests/02_00_06-2wp-new-minimum.js +++ b/tests/02_00_06-2wp-new-minimum.js @@ -1,11 +1,11 @@ const { expect } = require('chai'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBtcClient } = require('../lib/btc-client-provider'); -const rskUtils = require('../lib/rsk-utils'); +const { getLatestForkName, activateFork, triggerRelease } = require('../lib/rsk-utils'); const { sendPegin, ensurePeginIsRegistered, sendTxToBridge, BRIDGE_ADDRESS, MIN_PEGOUT_VALUE_IN_RBTC } = require('../lib/2wp-utils'); const { getDerivedRSKAddressInformation } = require('@rsksmart/btc-rsk-derivation'); const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); -const btcEthUnitConverter = require('btc-eth-unit-converter'); +const { btcToSatoshis, btcToWeis, satoshisToBtc } = require('btc-eth-unit-converter'); describe('2wp after iris300, using new minimum values', () => { let rskTxHelpers; @@ -16,8 +16,8 @@ describe('2wp after iris300, using new minimum values', () => { let federationAddress; const fulfillRequirementsToRunAsSingleTestFile = async () => { - const latestForkName = rskUtils.getLatestForkName() - await rskUtils.activateFork(latestForkName); + const latestForkName = getLatestForkName() + await activateFork(latestForkName); }; before(async () => { @@ -33,7 +33,7 @@ describe('2wp after iris300, using new minimum values', () => { const latestActiveForkName = await getLatestActiveForkName(); bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); const minimumPeginValueInSatoshi = await bridge.methods.getMinimumLockTxValue().call(); - minimumPeginValueInBTC = btcEthUnitConverter.satoshisToBtc(minimumPeginValueInSatoshi); + minimumPeginValueInBTC = satoshisToBtc(minimumPeginValueInSatoshi); //get federation address federationAddress = await bridge.methods.getFederationAddress().call(); @@ -53,7 +53,6 @@ describe('2wp after iris300, using new minimum values', () => { await btcTxHelper.fundAddress(senderAddressInfo.address, minimumPeginValueInBTC + btcTxHelper.getFee()); const federationAddressBalanceInitial = Number(await btcTxHelper.getAddressBalance(federationAddress)); - const bridgeAddressBalanceInitial = Number(await rskTxHelper.getBalance(BRIDGE_ADDRESS)); // Execute peg-in @@ -61,16 +60,18 @@ describe('2wp after iris300, using new minimum values', () => { await ensurePeginIsRegistered(rskTxHelper, btcPeginTxHash); const federationAddressBalanceAfterPegin = Number(await btcTxHelper.getAddressBalance(federationAddress)); - expect(federationAddressBalanceAfterPegin).to.be.equal(Number(federationAddressBalanceInitial + minimumPeginValueInBTC)); + const expectedFederationAddressBalanceAfterPegin = federationAddressBalanceInitial + minimumPeginValueInBTC; + expect(btcToSatoshis(federationAddressBalanceAfterPegin)).to.be.equal(btcToSatoshis(expectedFederationAddressBalanceAfterPegin)); const bridgeAddressBalanceAfterPegin = Number(await rskTxHelper.getBalance(BRIDGE_ADDRESS)); - expect(bridgeAddressBalanceAfterPegin).to.be.equal(bridgeAddressBalanceInitial - btcEthUnitConverter.btcToWeis(minimumPeginValueInBTC)) + const expectedBridgeAddressBalanceAfterPegin = bridgeAddressBalanceInitial - btcToWeis(minimumPeginValueInBTC); + expect(bridgeAddressBalanceAfterPegin).to.be.equal(expectedBridgeAddressBalanceAfterPegin) const senderAddressBalanceFinal = Number(await btcTxHelper.getAddressBalance(senderAddressInfo.address)); expect(senderAddressBalanceFinal).to.equal(0); const recipientRskAddressBalanceFinal = Number(await rskTxHelper.getBalance(recipientRskAddressInfo.address)); - expect(recipientRskAddressBalanceFinal).to.equal(btcEthUnitConverter.btcToWeis(minimumPeginValueInBTC)); + expect(recipientRskAddressBalanceFinal).to.equal(btcToWeis(minimumPeginValueInBTC)); }); it('should not peg-in and not refund when sending below minimum value', async () => { @@ -88,7 +89,8 @@ describe('2wp after iris300, using new minimum values', () => { await sendPegin(rskTxHelper, btcTxHelper, senderAddressInfo, BELOW_MIN_PEGIN_VALUE_IN_BTC); const federationAddressBalanceAfterPegin = Number(await btcTxHelper.getAddressBalance(federationAddress)); - expect(btcEthUnitConverter.btcToSatoshis(federationAddressBalanceAfterPegin)).to.be.equal(btcEthUnitConverter.btcToSatoshis(federationAddressBalanceInitial + BELOW_MIN_PEGIN_VALUE_IN_BTC)); + const expectedFederationAddressBalanceAfterPegin = federationAddressBalanceInitial + BELOW_MIN_PEGIN_VALUE_IN_BTC; + expect(btcToSatoshis(federationAddressBalanceAfterPegin)).to.be.equal(btcToSatoshis(expectedFederationAddressBalanceAfterPegin)); const bridgeAddressBalanceAfterPegin = Number(await rskTxHelper.getBalance(BRIDGE_ADDRESS)); expect(bridgeAddressBalanceAfterPegin).to.be.equal(bridgeAddressBalanceInitial); @@ -96,13 +98,14 @@ describe('2wp after iris300, using new minimum values', () => { const senderAddressBalanceAfterPegin = Number(await btcTxHelper.getAddressBalance(senderAddressInfo.address)); expect(senderAddressBalanceAfterPegin).to.be.equal(0); - await rskUtils.triggerRelease(rskTxHelpers, btcTxHelper); + await triggerRelease(rskTxHelpers, btcTxHelper); const senderAddressBalanceFinal = Number(await btcTxHelper.getAddressBalance(senderAddressInfo.address)); expect(senderAddressBalanceFinal).to.be.equal(0); const federationAddressBalanceFinal = Number(await btcTxHelper.getAddressBalance(federationAddress)); - expect(btcEthUnitConverter.btcToSatoshis(federationAddressBalanceFinal)).to.be.equal(btcEthUnitConverter.btcToSatoshis(federationAddressBalanceInitial + BELOW_MIN_PEGIN_VALUE_IN_BTC)); + const expectedFederationAddressBalanceFinal = federationAddressBalanceInitial + BELOW_MIN_PEGIN_VALUE_IN_BTC; + expect(btcToSatoshis(federationAddressBalanceFinal)).to.be.equal(btcToSatoshis(expectedFederationAddressBalanceFinal)); const bridgeAddressBalanceFinal = Number(await rskTxHelper.getBalance(BRIDGE_ADDRESS)); expect(bridgeAddressBalanceFinal).to.be.equal(bridgeAddressBalanceInitial) @@ -132,23 +135,28 @@ describe('2wp after iris300, using new minimum values', () => { await ensurePeginIsRegistered(rskTxHelper, btcPeginTxHash); const recipientRskAddressBalanceAfterPegin = Number(await rskTxHelper.getBalance(recipientRskAddressInfo.address)); - expect(recipientRskAddressBalanceAfterPegin).to.be.equal(btcEthUnitConverter.btcToWeis(minimumPeginValueInBTC)); + expect(recipientRskAddressBalanceAfterPegin).to.be.equal(btcToWeis(minimumPeginValueInBTC)); const federationAddressBalanceAfterPegin = Number(await btcTxHelper.getAddressBalance(federationAddress)); - expect(federationAddressBalanceAfterPegin).to.be.equal(Number(federationAddressBalanceInitial + minimumPeginValueInBTC)); + const expectedFederationAddressBalanceAfterPegin = federationAddressBalanceInitial + minimumPeginValueInBTC; + expect(btcToSatoshis(federationAddressBalanceAfterPegin)).to.be.equal(btcToSatoshis(expectedFederationAddressBalanceAfterPegin)); // Execute peg-out await sendTxToBridge(rskTxHelper, MIN_PEGOUT_VALUE_IN_RBTC, recipientRskAddressInfo.address); - await rskUtils.triggerRelease(rskTxHelpers, btcTxHelper); + await triggerRelease(rskTxHelpers, btcTxHelper); const senderAddressBalanceFinal = Number(await btcTxHelper.getAddressBalance(senderAddressInfo.address)); - expect(senderAddressBalanceFinal).to.be.above(MIN_PEGOUT_VALUE_IN_RBTC - TX_FEE_IN_RBTC).and.below(MIN_PEGOUT_VALUE_IN_RBTC); + const maxExpectedSenderAddressBalanceFinal = btcToSatoshis(MIN_PEGOUT_VALUE_IN_RBTC); + const minExpectedSenderAddressBalanceFinal = btcToSatoshis(MIN_PEGOUT_VALUE_IN_RBTC - TX_FEE_IN_RBTC); + expect(btcToSatoshis(senderAddressBalanceFinal)).to.be.above(minExpectedSenderAddressBalanceFinal).and.below(maxExpectedSenderAddressBalanceFinal); const federationAddressBalanceFinal = Number(await btcTxHelper.getAddressBalance(federationAddress)); - expect(federationAddressBalanceFinal).to.be.equal(Number(federationAddressBalanceAfterPegin - MIN_PEGOUT_VALUE_IN_RBTC)); - + const expectedFederationAddressBalanceFinal = federationAddressBalanceAfterPegin - MIN_PEGOUT_VALUE_IN_RBTC; + expect(btcToSatoshis(federationAddressBalanceFinal)).to.be.equal(btcToSatoshis(expectedFederationAddressBalanceFinal)); + const recipientRskAddressBalanceFinal = Number(await rskTxHelper.getBalance(recipientRskAddressInfo.address)); - expect(recipientRskAddressBalanceFinal).to.be.above(btcEthUnitConverter.btcToWeis(minimumPeginValueInBTC - MIN_PEGOUT_VALUE_IN_RBTC - TX_FEE_IN_RBTC)).and.below(btcEthUnitConverter.btcToWeis(minimumPeginValueInBTC - MIN_PEGOUT_VALUE_IN_RBTC)); + const maxExpectedRecipientRskAddressBalanceFinal = btcToWeis(minimumPeginValueInBTC - MIN_PEGOUT_VALUE_IN_RBTC); + const minExpectedRecipientRskAddressBalanceFinal = btcToWeis(minimumPeginValueInBTC - MIN_PEGOUT_VALUE_IN_RBTC - TX_FEE_IN_RBTC); + expect(recipientRskAddressBalanceFinal).to.be.above(minExpectedRecipientRskAddressBalanceFinal).and.below(maxExpectedRecipientRskAddressBalanceFinal); }); }); - From c227fd87290cc0fcea3c64b1740dbcc4ab98b679 Mon Sep 17 00:00:00 2001 From: Kelvin Isievwore Date: Fri, 13 Oct 2023 14:30:15 +0100 Subject: [PATCH 2/4] Added @rsksmart/btc-eth-unit-converter Dependency --- package-lock.json | 20 ++++++++++++++------ package.json | 12 ++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index 757f4e11..ac2da202 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,13 +10,13 @@ "license": "GPL3", "dependencies": { "@rsksmart/bridge-state-data-parser": "^1.1.0", + "@rsksmart/btc-eth-unit-converter": "^1.0.0", "@rsksmart/btc-rsk-derivation": "^0.0.2", "@rsksmart/pmt-builder": "^3.0.0", "@rsksmart/powpeg-redeemscript-parser": "^1.0.0", "bn.js": "^4.11.8", "bridge-transaction-parser-fingerroot500": "github:rsksmart/bridge-transaction-parser#v0.5.0-beta", "bridge-transaction-parser-hop400": "github:rsksmart/bridge-transaction-parser#v0.4.0-beta", - "btc-eth-unit-converter": "github:rsksmart/btc-eth-unit-converter#v0.3.0-beta", "btc-transaction-helper": "git+https://git@github.com/rsksmart/btc-transaction-helper#v3.4.0", "chai": "^4.1.2", "chai-as-promised": "^7.1.1", @@ -674,6 +674,14 @@ "web3": "^1.5.2" } }, + "node_modules/@rsksmart/btc-eth-unit-converter": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@rsksmart/btc-eth-unit-converter/-/btc-eth-unit-converter-1.0.0.tgz", + "integrity": "sha512-j5eyu+LkqPacbaNJShinS+sOC1PzcChCeenATuOSc7DoTT0+9wKYJxcuE5svuw+ZrjTzshn2Qxcdr9HAQv5spw==", + "dependencies": { + "decimal.js": "^10.4.3" + } + }, "node_modules/@rsksmart/btc-rsk-derivation": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/@rsksmart/btc-rsk-derivation/-/btc-rsk-derivation-0.0.2.tgz", @@ -1368,11 +1376,6 @@ "safe-buffer": "^5.1.2" } }, - "node_modules/btc-eth-unit-converter": { - "version": "0.3.0-beta", - "resolved": "git+ssh://git@github.com/rsksmart/btc-eth-unit-converter.git#e0049db653a839f87645560f71c93ebb37839d85", - "license": "MIT" - }, "node_modules/btc-transaction-helper": { "version": "3.4.0", "resolved": "git+https://git@github.com/rsksmart/btc-transaction-helper.git#7d17d5eb4a9bd6c446fbc470b253ec59267da975", @@ -1934,6 +1937,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/decimal.js": { + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.4.3.tgz", + "integrity": "sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA==" + }, "node_modules/decode-uri-component": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.2.tgz", diff --git a/package.json b/package.json index a6ce7995..3573da05 100644 --- a/package.json +++ b/package.json @@ -13,13 +13,13 @@ "license": "GPL3", "dependencies": { "@rsksmart/bridge-state-data-parser": "^1.1.0", + "@rsksmart/btc-eth-unit-converter": "^1.0.0", "@rsksmart/btc-rsk-derivation": "^0.0.2", "@rsksmart/pmt-builder": "^3.0.0", "@rsksmart/powpeg-redeemscript-parser": "^1.0.0", "bn.js": "^4.11.8", - "bridge-transaction-parser-hop400": "github:rsksmart/bridge-transaction-parser#v0.4.0-beta", "bridge-transaction-parser-fingerroot500": "github:rsksmart/bridge-transaction-parser#v0.5.0-beta", - "btc-eth-unit-converter": "github:rsksmart/btc-eth-unit-converter#v0.3.0-beta", + "bridge-transaction-parser-hop400": "github:rsksmart/bridge-transaction-parser#v0.4.0-beta", "btc-transaction-helper": "git+https://git@github.com/rsksmart/btc-transaction-helper#v3.4.0", "chai": "^4.1.2", "chai-as-promised": "^7.1.1", @@ -34,12 +34,12 @@ "mocha-junit-reporter": "^1.17.0", "pegin-address-verificator": "git+https://git@github.com/rsksmart/pegin-address-verifier#v0.2.1", "peglib": "git+https://github.com/rsksmart/rsk-peglib#v1.4.15", + "precompiled-fingerroot500": "npm:@rsksmart/rsk-precompiled-abis@^5.0.0-FINGERROOT", + "precompiled-hop400": "npm:@rsksmart/rsk-precompiled-abis@^5.0.0-HOP", + "precompiled-iris300": "npm:@rsksmart/rsk-precompiled-abis@^4.0.0-IRIS", "precompiled-orchid": "npm:@rsksmart/rsk-precompiled-abis@^1.0.0-ORCHID", - "precompiled-wasabi100": "npm:@rsksmart/rsk-precompiled-abis@^2.0.0-WASABI", "precompiled-papyrus200": "npm:@rsksmart/rsk-precompiled-abis@^3.0.0-PAPYRUS", - "precompiled-iris300": "npm:@rsksmart/rsk-precompiled-abis@^4.0.0-IRIS", - "precompiled-hop400": "npm:@rsksmart/rsk-precompiled-abis@^5.0.0-HOP", - "precompiled-fingerroot500": "npm:@rsksmart/rsk-precompiled-abis@^5.0.0-FINGERROOT", + "precompiled-wasabi100": "npm:@rsksmart/rsk-precompiled-abis@^2.0.0-WASABI", "rsk-transaction-helper": "git+https://github.com/rsksmart/rootstock-transaction-helper#v3.1.0", "solc": "^0.7.5", "stream-line-wrapper": "^0.1.1", From e7577c30e05f7620e58371b2df9eeea28ef15518 Mon Sep 17 00:00:00 2001 From: Kelvin Isievwore Date: Fri, 13 Oct 2023 16:57:53 +0100 Subject: [PATCH 3/4] Updated btcEthUnitConverter Usages --- lib/2wp-utils.js | 9 ++--- lib/liquidity-bridge-contract.js | 4 +-- lib/tests/2wp.js | 36 +++++++++---------- lib/tests/bridge-calls.js | 4 +-- tests/01_03_01-lock_whitelist_pre_papyrus.js | 14 ++++---- tests/01_03_04-2wp_segwit_not_compatible.js | 4 +-- tests/01_03_05-2wp_multisig_not_compatible.js | 4 +-- tests/01_03_06-2wp_no_locking_cap.js | 10 +++--- ...03_54-post-papyrus_coinbase_information.js | 4 +-- tests/01_04_01-pre_iris_2wp.js | 4 +-- ...t_iris_register_flyover_btc_transaction.js | 4 +-- ...ast_btc_transaction_surpass_locking_cap.js | 8 ++--- ...r_sending_same_tx_without_witness_twice.js | 6 ++-- ...over_sending_same_tx_with_witness_twice.js | 6 ++-- ...rroot500-release_request_received_bytes.js | 6 ++-- tests/02_00_02-2wp_segwit_compatible.js | 6 ++-- tests/02_00_03-2wp_multisig_compatible.js | 4 +-- tests/02_00_05-2wp_version1.js | 10 +++--- tests/02_00_06-2wp-new-minimum.js | 30 ++++++++-------- ..._05-fastbridge_operation_with_rejection.js | 8 ++--- 20 files changed, 91 insertions(+), 90 deletions(-) diff --git a/lib/2wp-utils.js b/lib/2wp-utils.js index 2496654c..189a2f1c 100644 --- a/lib/2wp-utils.js +++ b/lib/2wp-utils.js @@ -3,7 +3,8 @@ const { sendFromCow, mineAndSync, sendTxWithCheck } = require('./rsk-utils'); const { wait, retryWithCheck } = require('./utils'); const { getBridge, getLatestActiveForkName } = require('./precompiled-abi-forks-util'); const { getBridgeState } = require('@rsksmart/bridge-state-data-parser'); -const btcEthUnitConverter = require('btc-eth-unit-converter'); +const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); + const peginVerifier = require('pegin-address-verificator'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { WHITELIST_CHANGE_PK, WHITELIST_CHANGE_ADDR} = require('../lib/assertions/whitelisting') @@ -55,7 +56,7 @@ const sendTxToBridge = async (rskTxHelper, amountInRbtc, rskFromAddress, mine = const txPromise = rskTxHelper.sendTransaction({ from: rskFromAddress, to: BRIDGE_ADDRESS, - value: btcEthUnitConverter.btcToWeis(amountInRbtc), + value: Number(btcEthUnitConverter.btcToWeis(amountInRbtc)), gasPrice: TO_BRIDGE_GAS_PRICE, }); if(!mine) { @@ -76,8 +77,8 @@ const sendTxToBridge = async (rskTxHelper, amountInRbtc, rskFromAddress, mine = * @returns {Promise} the rsk tx hash that mined the pegout request */ const createPegoutRequest = async (rskTxHelper, amountInRBTC, requestSize = 1) => { - const AMOUNT_IN_WEIS = btcEthUnitConverter.btcToWeis(amountInRBTC); - const RSK_TX_FEE_IN_WEIS = btcEthUnitConverter.btcToWeis(1); + const AMOUNT_IN_WEIS = Number(btcEthUnitConverter.btcToWeis(amountInRBTC)); + const RSK_TX_FEE_IN_WEIS = Number(btcEthUnitConverter.btcToWeis(1)); const PEGOUT_AMOUNT_PLUS_FEE = (AMOUNT_IN_WEIS + RSK_TX_FEE_IN_WEIS) * requestSize; const rskAddress = await rskTxHelper.newAccountWithSeed('test'); await sendFromCow(rskTxHelper, rskAddress, PEGOUT_AMOUNT_PLUS_FEE); diff --git a/lib/liquidity-bridge-contract.js b/lib/liquidity-bridge-contract.js index 2d06aea7..2ce9f992 100644 --- a/lib/liquidity-bridge-contract.js +++ b/lib/liquidity-bridge-contract.js @@ -3,7 +3,7 @@ const { getRskTransactionHelper } = require('../lib/rsk-tx-helper-provider'); const solUtils = require('../lib/sol-utils'); const rskUtils = require('../lib/rsk-utils'); -const btcEthUnitConverter = require('btc-eth-unit-converter'); +const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); const INITIAL_RSK_BALANCE_IN_BTC = 1; const BRIDGE_ADDRESS = '0x0000000000000000000000000000000001000006'; @@ -16,7 +16,7 @@ let contractInstance; const deployLiquidityBridgeContract = async (host = null) => { const rskTransactionHelper = getRskTransactionHelper(host); const fromAddress = await rskTransactionHelper.newAccountWithSeed(''); - await rskUtils.sendFromCow(rskTransactionHelper, fromAddress, btcEthUnitConverter.btcToWeis(INITIAL_RSK_BALANCE_IN_BTC)); + await rskUtils.sendFromCow(rskTransactionHelper, fromAddress, Number(btcEthUnitConverter.btcToWeis(INITIAL_RSK_BALANCE_IN_BTC))); await rskTransactionHelper.unlockAccount(fromAddress, ''); try { diff --git a/lib/tests/2wp.js b/lib/tests/2wp.js index 90648e72..3808fd73 100644 --- a/lib/tests/2wp.js +++ b/lib/tests/2wp.js @@ -7,7 +7,7 @@ const { getBridge, getLatestActiveForkName } = require('../precompiled-abi-forks const { getBtcClient } = require('../btc-client-provider'); const { getRskTransactionHelpers, getRskTransactionHelper } = require('../rsk-tx-helper-provider'); const { getDerivedRSKAddressInformation } = require('@rsksmart/btc-rsk-derivation'); -const btcEthUnitConverter = require('btc-eth-unit-converter'); +const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); const { sendTxToBridge, sendPegin, ensurePeginIsRegistered, donateToBridge } = require('../2wp-utils'); const DONATION_AMOUNT = 250; @@ -31,7 +31,7 @@ const execute = (description, getRskHost) => { federationAddress = await bridge.methods.getFederationAddress().call(); const minimumPeginValueInSatoshis = await bridge.methods.getMinimumLockTxValue().call(); - minimumPeginValueInBtc = btcEthUnitConverter.satoshisToBtc(minimumPeginValueInSatoshis); + minimumPeginValueInBtc = Number(btcEthUnitConverter.satoshisToBtc(minimumPeginValueInSatoshis)); await btcTxHelper.importAddress(federationAddress, 'federations'); @@ -45,7 +45,7 @@ const execute = (description, getRskHost) => { // Those tests are not doing a pegin if needed, so we need to donate to the bridge to ensure it has enough balance. // This will be removed after all pegout tests are updated to do their own pegin if needed. const donatingBtcAddressInformation = await btcTxHelper.generateBtcAddress('legacy'); - await whitelistingAssertions.assertAddLimitedLockWhitelistAddress(rskTxHelper, donatingBtcAddressInformation.address, btcEthUnitConverter.btcToSatoshis(DONATION_AMOUNT)); + await whitelistingAssertions.assertAddLimitedLockWhitelistAddress(rskTxHelper, donatingBtcAddressInformation.address, Number(btcEthUnitConverter.btcToSatoshis(DONATION_AMOUNT))); await rskUtils.mineAndSync(rskTxHelpers); await btcTxHelper.fundAddress(donatingBtcAddressInformation.address, DONATION_AMOUNT + btcTxHelper.getFee()); @@ -58,7 +58,7 @@ const execute = (description, getRskHost) => { try { const peginSenderAddressInfo = await btcTxHelper.generateBtcAddress('legacy'); - await whitelistingAssertions.assertAddLimitedLockWhitelistAddress(rskTxHelper, peginSenderAddressInfo.address, btcEthUnitConverter.btcToSatoshis(minimumPeginValueInBtc)); + await whitelistingAssertions.assertAddLimitedLockWhitelistAddress(rskTxHelper, peginSenderAddressInfo.address, Number(btcEthUnitConverter.btcToSatoshis(minimumPeginValueInBtc))); await rskUtils.mineAndSync(rskTxHelpers); const recipientRskAddressInfo = getDerivedRSKAddressInformation(peginSenderAddressInfo.privateKey, btcTxHelper.btcConfig.network); @@ -72,7 +72,7 @@ const execute = (description, getRskHost) => { const finalRskAddressBalanceInWeis = Number(await rskTxHelper.getBalance(recipientRskAddressInfo.address)); // Asserting that the received pegin amount in rsk is as expected - const peginValueInWeis = btcEthUnitConverter.btcToWeis(minimumPeginValueInBtc); + const peginValueInWeis = Number(btcEthUnitConverter.btcToWeis(minimumPeginValueInBtc)); expect(finalRskAddressBalanceInWeis).to.equal(initialRskAddressBalanceInWeis + peginValueInWeis); } catch (err) { throw new CustomError('Transfer BTC to RBTC', err); @@ -87,7 +87,7 @@ const execute = (description, getRskHost) => { const peginSenderAddressInfo = await btcTxHelper.generateBtcAddress('legacy'); - await whitelistingAssertions.assertAddLimitedLockWhitelistAddress(rskTxHelper, peginSenderAddressInfo.address, btcEthUnitConverter.btcToSatoshis(EXPECTED_RSK_BALANCE_IN_RBTC)); + await whitelistingAssertions.assertAddLimitedLockWhitelistAddress(rskTxHelper, peginSenderAddressInfo.address, Number(btcEthUnitConverter.btcToSatoshis(EXPECTED_RSK_BALANCE_IN_RBTC))); await rskUtils.mineAndSync(rskTxHelpers); await btcTxHelper.fundAddress(peginSenderAddressInfo.address, INITIAL_BTC_BALANCE + btcTxHelper.getFee()); @@ -102,7 +102,7 @@ const execute = (description, getRskHost) => { const finalRskAddressBalanceInWeis = Number(await rskTxHelper.getBalance(recipientRskAddressInfo.address)); // Asserting that the received pegin amount in rsk is as expected - const peginValueInWeis = btcEthUnitConverter.btcToWeis(EXPECTED_RSK_BALANCE_IN_RBTC); + const peginValueInWeis = Number(btcEthUnitConverter.btcToWeis(EXPECTED_RSK_BALANCE_IN_RBTC)); expect(finalRskAddressBalanceInWeis).to.equal(initialRskAddressBalanceInWeis + peginValueInWeis); } @@ -116,10 +116,10 @@ const execute = (description, getRskHost) => { const INITIAL_RSK_BALANCE = 1; const PEGOUT_VALUE_IN_RBTC = 0.5; const MAX_EXPECTED_FEE = 0.001; - const pegoutValueInSatoshis = btcEthUnitConverter.btcToSatoshis(PEGOUT_VALUE_IN_RBTC); - const maxExpectedFeeInSatoshis = btcEthUnitConverter.btcToSatoshis(MAX_EXPECTED_FEE); + const pegoutValueInSatoshis = Number(btcEthUnitConverter.btcToSatoshis(PEGOUT_VALUE_IN_RBTC)); + const maxExpectedFeeInSatoshis = Number(btcEthUnitConverter.btcToSatoshis(MAX_EXPECTED_FEE)); - const initialFederationBalanceInSatoshis = btcEthUnitConverter.btcToSatoshis(await btcTxHelper.getAddressBalance(federationAddress)); + const initialFederationBalanceInSatoshis = Number(btcEthUnitConverter.btcToSatoshis(await btcTxHelper.getAddressBalance(federationAddress))); const btcAddressInformation = await btcTxHelper.generateBtcAddress('legacy'); @@ -129,7 +129,7 @@ const execute = (description, getRskHost) => { const unlocked = await rskTxHelper.unlockAccount(recipientRskAddressInfo.address); expect(unlocked, 'Account was not unlocked').to.be.true; - await rskUtils.sendFromCow(rskTxHelper, recipientRskAddressInfo.address, btcEthUnitConverter.btcToWeis(INITIAL_RSK_BALANCE)); + await rskUtils.sendFromCow(rskTxHelper, recipientRskAddressInfo.address, Number(btcEthUnitConverter.btcToWeis(INITIAL_RSK_BALANCE))); const pegoutTransaction = await sendTxToBridge(rskTxHelper, PEGOUT_VALUE_IN_RBTC, recipientRskAddressInfo.address); @@ -178,8 +178,8 @@ const execute = (description, getRskHost) => { }; await rskUtils.triggerRelease(rskTxHelpers, btcTxHelper, callbacks); - const finalFederationBalanceInSatoshis = btcEthUnitConverter.btcToSatoshis(await btcTxHelper.getAddressBalance(federationAddress)); - const finalDestinationAddressBalanceInSatoshis = btcEthUnitConverter.btcToSatoshis(await btcTxHelper.getAddressBalance(btcAddressInformation.address)); + const finalFederationBalanceInSatoshis = Number(btcEthUnitConverter.btcToSatoshis(await btcTxHelper.getAddressBalance(federationAddress))); + const finalDestinationAddressBalanceInSatoshis = Number(btcEthUnitConverter.btcToSatoshis(await btcTxHelper.getAddressBalance(btcAddressInformation.address))); const difference = pegoutValueInSatoshis - finalDestinationAddressBalanceInSatoshis; expect(difference).to.be.at.most(maxExpectedFeeInSatoshis); expect(finalFederationBalanceInSatoshis).to.equal(initialFederationBalanceInSatoshis - pegoutValueInSatoshis); @@ -191,13 +191,13 @@ const execute = (description, getRskHost) => { const INITIAL_RSK_BALANCE = 2; const PEGOUT_UNDER_MINIMUM_VALUE_IN_BTC = 0.002; - const initialFederationBalanceInSatoshis = btcEthUnitConverter.btcToSatoshis(await btcTxHelper.getAddressBalance(federationAddress)); + const initialFederationBalanceInSatoshis = Number(btcEthUnitConverter.btcToSatoshis(await btcTxHelper.getAddressBalance(federationAddress))); const btcAddressInformation = await btcTxHelper.generateBtcAddress('legacy'); const recipientRskAddressInfo = getDerivedRSKAddressInformation(btcAddressInformation.privateKey, btcTxHelper.btcConfig.network); await rskTxHelper.importAccount(recipientRskAddressInfo.privateKey); - await rskUtils.sendFromCow(rskTxHelper, recipientRskAddressInfo.address, btcEthUnitConverter.btcToWeis(INITIAL_RSK_BALANCE)); + await rskUtils.sendFromCow(rskTxHelper, recipientRskAddressInfo.address, Number(btcEthUnitConverter.btcToWeis(INITIAL_RSK_BALANCE))); const initialRskAddressBalance = Number(await rskTxHelper.getBalance(recipientRskAddressInfo.address)); const unlocked = await rskTxHelper.unlockAccount(recipientRskAddressInfo.address); expect(unlocked, 'Account was not unlocked').to.be.true; @@ -207,7 +207,7 @@ const execute = (description, getRskHost) => { if (isIris300AlreadyActive) { const pegoutRejectedEvent = await rskUtils.findEventInBlock(rskTxHelper, 'release_request_rejected'); expect(pegoutRejectedEvent).to.not.be.null; - const pegoutValueInSatoshis = btcEthUnitConverter.btcToSatoshis(PEGOUT_UNDER_MINIMUM_VALUE_IN_BTC); + const pegoutValueInSatoshis = Number(btcEthUnitConverter.btcToSatoshis(PEGOUT_UNDER_MINIMUM_VALUE_IN_BTC)); expect(Number(pegoutRejectedEvent.arguments.amount)).to.equal(pegoutValueInSatoshis); expect(pegoutRejectedEvent.arguments.sender.toLowerCase()).to.equal(ensure0x(recipientRskAddressInfo.address)); expect(Number(pegoutRejectedEvent.arguments.reason)).to.equal(REJECTED_REASON); @@ -216,9 +216,9 @@ const execute = (description, getRskHost) => { } else { const finalRskAddressBalance = Number(await rskTxHelper.getBalance(recipientRskAddressInfo.address)); // The transaction should have been rejected and the RBTC should be lost - expect(finalRskAddressBalance).to.be.at.most(initialRskAddressBalance - btcEthUnitConverter.btcToWeis(PEGOUT_UNDER_MINIMUM_VALUE_IN_BTC)); + expect(finalRskAddressBalance).to.be.at.most(initialRskAddressBalance - Number(btcEthUnitConverter.btcToWeis(PEGOUT_UNDER_MINIMUM_VALUE_IN_BTC))); } - const finalFederationBalanceInSatoshis = btcEthUnitConverter.btcToSatoshis(await btcTxHelper.getAddressBalance(federationAddress)); + const finalFederationBalanceInSatoshis = Number(btcEthUnitConverter.btcToSatoshis(await btcTxHelper.getAddressBalance(federationAddress))); expect(finalFederationBalanceInSatoshis).to.equal(initialFederationBalanceInSatoshis); } catch (err) { diff --git a/lib/tests/bridge-calls.js b/lib/tests/bridge-calls.js index 173c10e9..0051e5d2 100644 --- a/lib/tests/bridge-calls.js +++ b/lib/tests/bridge-calls.js @@ -6,7 +6,7 @@ const CustomError = require('../CustomError'); const { wait } = require('../utils'); const rskUtils = require('../rsk-utils'); const solUtils = require('../sol-utils'); -const btcEthUnitConverter = require('btc-eth-unit-converter'); +const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); const { getRskTransactionHelpers, getRskTransactionHelper } = require('../rsk-tx-helper-provider'); const { getBridge } = require('../precompiled-abi-forks-util'); @@ -28,7 +28,7 @@ const execute = (description, getRskHost, bridgeCallsAllowed) => { rskTransactionHelper = getRskTransactionHelper(getRskHost()); rskClient = rskTransactionHelper.getClient(); address = await rskClient.eth.personal.newAccount(''); - await rskUtils.sendFromCow(rskTransactionHelper, address, btcEthUnitConverter.btcToWeis(INITIAL_RSK_BALANCE_IN_BTC)); + await rskUtils.sendFromCow(rskTransactionHelper, address, Number(btcEthUnitConverter.btcToWeis(INITIAL_RSK_BALANCE_IN_BTC))); await rskClient.eth.personal.unlockAccount(address, ''); }); diff --git a/tests/01_03_01-lock_whitelist_pre_papyrus.js b/tests/01_03_01-lock_whitelist_pre_papyrus.js index 72ebf740..57ede0a1 100644 --- a/tests/01_03_01-lock_whitelist_pre_papyrus.js +++ b/tests/01_03_01-lock_whitelist_pre_papyrus.js @@ -13,7 +13,7 @@ const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBtcClient } = require('../lib/btc-client-provider'); const { sendPegin, ensurePeginIsRegistered } = require('../lib/2wp-utils'); const { getDerivedRSKAddressInformation } = require('@rsksmart/btc-rsk-derivation'); -const { btcToWeis, btcToSatoshis, satoshisToBtc } = require('btc-eth-unit-converter'); +const { btcToWeis, btcToSatoshis, satoshisToBtc } = require('@rsksmart/btc-eth-unit-converter'); const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); let rskTxHelpers; @@ -44,7 +44,7 @@ const fulfillRequirementsToRunAsSingleTestFile = async () => { const assertLockCreatingWhiteListAddress = async (rskTxHelper, btcTxHelper, useUnlimitedWhitelist) => { const minPeginValueInSatoshis = await bridge.methods.getMinimumLockTxValue().call(); - const minPeginValueInBtc = satoshisToBtc(minPeginValueInSatoshis); + const minPeginValueInBtc = Number(satoshisToBtc(minPeginValueInSatoshis)); const btcAddressInformation = await btcTxHelper.generateBtcAddress('legacy'); const recipientRskAddressInfo = getDerivedRSKAddressInformation(btcAddressInformation.privateKey, btcTxHelper.btcConfig.network); @@ -64,7 +64,7 @@ const assertLockCreatingWhiteListAddress = async (rskTxHelper, btcTxHelper, useU await assertWhitelistAddressPresence(rskTxHelper, btcAddressInformation.address, useUnlimitedWhitelist); const finalRskAddressBalanceInWeis = Number(await rskTxHelper.getBalance(recipientRskAddressInfo.address)); - const peginValueInWeis = btcToWeis(minPeginValueInBtc); + const peginValueInWeis = Number(btcToWeis(minPeginValueInBtc)); expect(finalRskAddressBalanceInWeis).to.equal(initialRskAddressBalanceInWeis + peginValueInWeis); }; @@ -159,10 +159,10 @@ describe('Lock whitelisting', () => { const peginBtcTxHash = await sendPegin(rskTxHelper, btcTxHelper, btcAddressInformation, testCaseAmounts); const peginBtcTx = await btcTxHelper.getTransaction(peginBtcTxHash); const btcBalanceAfterPegin = await btcTxHelper.getAddressBalance(btcAddressInformation.address); - expect(btcToSatoshis(btcBalanceAfterPegin)).to.equal(btcToSatoshis(INITIAL_PEGIN_BALANCE - AMOUNT_TO_TRY_TO_LOCK - MAX_EXPECTED_FEE), 'Lock BTC debit'); + expect(Number(btcToSatoshis(btcBalanceAfterPegin))).to.equal(Number(btcToSatoshis(INITIAL_PEGIN_BALANCE - AMOUNT_TO_TRY_TO_LOCK - MAX_EXPECTED_FEE)), 'Lock BTC debit'); const federationBalanceAfterPegin = await btcTxHelper.getAddressBalance(federationAddress); - expect(btcToSatoshis(federationBalanceAfterPegin)).to.equal(btcToSatoshis(initialFederationBalance + AMOUNT_TO_TRY_TO_LOCK), `Lock BTC federation ${federationAddress} credit`); + expect(Number(btcToSatoshis(federationBalanceAfterPegin))).to.equal(Number(btcToSatoshis(initialFederationBalance + AMOUNT_TO_TRY_TO_LOCK)), `Lock BTC federation ${federationAddress} credit`); await rskTxHelper.updateBridge(); await rskUtils.mineAndSync(rskTxHelpers); @@ -203,7 +203,7 @@ describe('Lock whitelisting', () => { const inputTxHash = txInput.hash.reverse().toString('hex'); expect(inputTxHash).to.equal(peginBtcTxHash); const spentUtxo = peginBtcTx.outs[txInput.index]; - const amountInBtc = satoshisToBtc(spentUtxo.value); + const amountInBtc = Number(satoshisToBtc(spentUtxo.value)); nonMatchedAmounts = nonMatchedAmounts.filter(a => a !== amountInBtc); }); @@ -221,7 +221,7 @@ describe('Lock whitelisting', () => { const initialFederationBalance = await btcTxHelper.getAddressBalance(federationAddress); - await assertAddOneOffWhitelistAddress(rskTxHelper, btcAddressInformation.address, btcToSatoshis(WHITELISTED_MAX_VALUE)); + await assertAddOneOffWhitelistAddress(rskTxHelper, btcAddressInformation.address, Number(btcToSatoshis(WHITELISTED_MAX_VALUE))); await sendPegin(rskTxHelper, btcTxHelper, btcAddressInformation, PEGIN_VALUE_IN_BTC); diff --git a/tests/01_03_04-2wp_segwit_not_compatible.js b/tests/01_03_04-2wp_segwit_not_compatible.js index 0334c8a7..5390b939 100644 --- a/tests/01_03_04-2wp_segwit_not_compatible.js +++ b/tests/01_03_04-2wp_segwit_not_compatible.js @@ -1,5 +1,5 @@ const expect = require('chai').expect -const { satoshisToBtc } = require('btc-eth-unit-converter'); +const { satoshisToBtc } = require('@rsksmart/btc-eth-unit-converter'); const rskUtils = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBtcClient } = require('../lib/btc-client-provider'); @@ -31,7 +31,7 @@ describe('Lock p2sh-p2wpkh address', () => { const bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); const minimumPeginValueInSatoshis = await bridge.methods.getMinimumLockTxValue().call(); - const minimumPeginValueInBtc = satoshisToBtc(minimumPeginValueInSatoshis); + const minimumPeginValueInBtc = Number(satoshisToBtc(minimumPeginValueInSatoshis)); const federationAddress = await bridge.methods.getFederationAddress().call(); const federationAddressBalanceInitial = Number(await btcTxHelper.getAddressBalance(federationAddress)); diff --git a/tests/01_03_05-2wp_multisig_not_compatible.js b/tests/01_03_05-2wp_multisig_not_compatible.js index cd771613..08f9d903 100644 --- a/tests/01_03_05-2wp_multisig_not_compatible.js +++ b/tests/01_03_05-2wp_multisig_not_compatible.js @@ -1,5 +1,5 @@ const expect = require('chai').expect -const { satoshisToBtc } = require('btc-eth-unit-converter'); +const { satoshisToBtc } = require('@rsksmart/btc-eth-unit-converter'); const rskUtils = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBtcClient } = require('../lib/btc-client-provider'); @@ -32,7 +32,7 @@ describe('Peg-in multisig address', () => { const bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); const minimumPeginValueInSatoshis = await bridge.methods.getMinimumLockTxValue().call(); - const minimumPeginValueInBtc = satoshisToBtc(minimumPeginValueInSatoshis); + const minimumPeginValueInBtc = Number(satoshisToBtc(minimumPeginValueInSatoshis)); const federationAddress = await bridge.methods.getFederationAddress().call(); const federationAddressBalanceInitial = Number(await btcTxHelper.getAddressBalance(federationAddress)); diff --git a/tests/01_03_06-2wp_no_locking_cap.js b/tests/01_03_06-2wp_no_locking_cap.js index 066ca88c..d8a95b91 100644 --- a/tests/01_03_06-2wp_no_locking_cap.js +++ b/tests/01_03_06-2wp_no_locking_cap.js @@ -5,7 +5,7 @@ const { getBtcClient } = require('../lib/btc-client-provider'); const { sendPegin, ensurePeginIsRegistered, sendTxToBridge } = require('../lib/2wp-utils'); const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); const { getDerivedRSKAddressInformation } = require('@rsksmart/btc-rsk-derivation'); -const btcEthUnitConverter = require('btc-eth-unit-converter'); +const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); const whitelistingAssertions = require('../lib/assertions/whitelisting'); describe('Transfer BTC to RBTC before papyrus200', function() { @@ -35,7 +35,7 @@ describe('Transfer BTC to RBTC before papyrus200', function() { it('should do a multiple pegouts from the same rsk address after making a pegin', async () => { const btcAddressInfo = await btcTxHelper.generateBtcAddress('legacy'); - await whitelistingAssertions.assertAddLimitedLockWhitelistAddress(rskTxHelper, btcAddressInfo.address, btcEthUnitConverter.btcToSatoshis(PEGIN_VALUE_IN_BTC)); + await whitelistingAssertions.assertAddLimitedLockWhitelistAddress(rskTxHelper, btcAddressInfo.address, Number(btcEthUnitConverter.btcToSatoshis(PEGIN_VALUE_IN_BTC))); await rskUtils.mineAndSync(rskTxHelpers); const recipientRskAddressInfo = getDerivedRSKAddressInformation(btcAddressInfo.privateKey, btcTxHelper.btcConfig.network); @@ -54,7 +54,7 @@ describe('Transfer BTC to RBTC before papyrus200', function() { const btcPeginTxHash = await sendPegin(rskTxHelper, btcTxHelper, btcAddressInfo, PEGIN_VALUE_IN_BTC); await ensurePeginIsRegistered(rskTxHelper, btcPeginTxHash); const recipientRskAddressBalanceAfterPegin = Number(await rskTxHelper.getBalance(recipientRskAddressInfo.address)); - expect(Number(recipientRskAddressBalanceAfterPegin)).to.be.equal(btcEthUnitConverter.btcToWeis(PEGIN_VALUE_IN_BTC)); + expect(Number(recipientRskAddressBalanceAfterPegin)).to.be.equal(Number(btcEthUnitConverter.btcToWeis(PEGIN_VALUE_IN_BTC))); await sendTxToBridge(rskTxHelper, PEGOUT_VALUE_IN_RBTC, recipientRskAddressInfo.address); await rskUtils.triggerRelease(rskTxHelpers, btcTxHelper); @@ -66,7 +66,7 @@ describe('Transfer BTC to RBTC before papyrus200', function() { expect(Number(senderAddressBalanceAfterFirstPegout)).to.be.above(PEGOUT_VALUE_IN_RBTC - btcTxHelper.getFee()).and.below(PEGOUT_VALUE_IN_RBTC); const recipientRskAddressBalanceAfterFirstPegout = Number(await rskTxHelper.getBalance(recipientRskAddressInfo.address)); - expect(Number(recipientRskAddressBalanceAfterFirstPegout)).to.be.above(btcEthUnitConverter.btcToWeis(PEGIN_VALUE_IN_BTC - PEGOUT_VALUE_IN_RBTC - RSK_TX_FEE_IN_RBTC)).and.below(btcEthUnitConverter.btcToWeis(PEGIN_VALUE_IN_BTC - PEGOUT_VALUE_IN_RBTC)); + expect(Number(recipientRskAddressBalanceAfterFirstPegout)).to.be.above(Number(btcEthUnitConverter.btcToWeis(PEGIN_VALUE_IN_BTC - PEGOUT_VALUE_IN_RBTC - RSK_TX_FEE_IN_RBTC))).and.below(Number(btcEthUnitConverter.btcToWeis(PEGIN_VALUE_IN_BTC - PEGOUT_VALUE_IN_RBTC))); await sendTxToBridge(rskTxHelper, PEGOUT_VALUE_IN_RBTC, recipientRskAddressInfo.address); await rskUtils.triggerRelease(rskTxHelpers, btcTxHelper); @@ -75,7 +75,7 @@ describe('Transfer BTC to RBTC before papyrus200', function() { expect(Number(senderAddressBalanceAfterSecondPegout)).to.be.above(senderAddressBalanceAfterFirstPegout + PEGOUT_VALUE_IN_RBTC - btcTxHelper.getFee()).and.below(senderAddressBalanceAfterFirstPegout + PEGOUT_VALUE_IN_RBTC); const recipientRskAddressBalanceAfterSecondPegout = Number(await rskTxHelper.getBalance(recipientRskAddressInfo.address)); - expect(Number(recipientRskAddressBalanceAfterSecondPegout)).to.be.above(recipientRskAddressBalanceAfterFirstPegout - btcEthUnitConverter.btcToWeis(PEGOUT_VALUE_IN_RBTC + RSK_TX_FEE_IN_RBTC)).and.below(recipientRskAddressBalanceAfterFirstPegout - btcEthUnitConverter.btcToWeis(PEGOUT_VALUE_IN_RBTC)); + expect(Number(recipientRskAddressBalanceAfterSecondPegout)).to.be.above(recipientRskAddressBalanceAfterFirstPegout - Number(btcEthUnitConverter.btcToWeis(PEGOUT_VALUE_IN_RBTC + RSK_TX_FEE_IN_RBTC))).and.below(recipientRskAddressBalanceAfterFirstPegout - Number(btcEthUnitConverter.btcToWeis(PEGOUT_VALUE_IN_RBTC))); }); }); diff --git a/tests/01_03_54-post-papyrus_coinbase_information.js b/tests/01_03_54-post-papyrus_coinbase_information.js index a875cd58..fe5856af 100644 --- a/tests/01_03_54-post-papyrus_coinbase_information.js +++ b/tests/01_03_54-post-papyrus_coinbase_information.js @@ -5,7 +5,7 @@ const { wait, ensure0x, retryWithCheck } = require('../lib/utils'); const CustomError = require('../lib/CustomError'); const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); const { getBtcClient } = require('../lib//btc-client-provider'); -const btcEthUnitConverter = require('btc-eth-unit-converter'); +const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); let rskTxHelpers; @@ -26,7 +26,7 @@ describe('Calling coinbase information methods after papyrus', () => { const rskTxSenderAddress = await rskTxHelper.newAccountWithSeed('test'); // Funding the `from` address to pay for fees - await rskUtils.sendFromCow(rskTxHelper, rskTxSenderAddress, btcEthUnitConverter.btcToWeis(0.1)); + await rskUtils.sendFromCow(rskTxHelper, rskTxSenderAddress, Number(btcEthUnitConverter.btcToWeis(0.1))); const blockHash = await btcClient.mine(1); await wait(1000); diff --git a/tests/01_04_01-pre_iris_2wp.js b/tests/01_04_01-pre_iris_2wp.js index 2b8a6f72..91bae9b1 100644 --- a/tests/01_04_01-pre_iris_2wp.js +++ b/tests/01_04_01-pre_iris_2wp.js @@ -1,7 +1,7 @@ const { expect } = require('chai'); const { createPeginV1TxData } = require('../lib/2wp-utils'); const { getRskTransactionHelper } = require('../lib/rsk-tx-helper-provider'); -const btcEthUnitConverter = require('btc-eth-unit-converter'); +const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); const { getBtcClient } = require('../lib/btc-client-provider'); const { getDerivedRSKAddressInformation } = require('@rsksmart/btc-rsk-derivation'); const { sendPegin, ensurePeginIsRegistered } = require('../lib/2wp-utils'); @@ -48,7 +48,7 @@ describe('Lock funds using peg-in protocol version 1 before iris300', () => { expect(Number(initialSenderBalance)).to.equal(0); expect(Number(finalSenderBalance)).to.equal(0); expect(Number(initialDerivedAddressBalance)).to.equal(0); - expect(Number(finalDerivedAddressBalance)).to.equal(btcEthUnitConverter.btcToWeis(AMOUNT_TO_LOCK_IN_BTC)); + expect(Number(finalDerivedAddressBalance)).to.equal(Number(btcEthUnitConverter.btcToWeis(AMOUNT_TO_LOCK_IN_BTC))); expect(Number(initialDestinationAddressBalance)).to.equal(0); expect(Number(finalDestinationAddressBalance)).to.equal(0); }); diff --git a/tests/01_04_51-post_iris_register_flyover_btc_transaction.js b/tests/01_04_51-post_iris_register_flyover_btc_transaction.js index 57eda85f..c69d4857 100644 --- a/tests/01_04_51-post_iris_register_flyover_btc_transaction.js +++ b/tests/01_04_51-post_iris_register_flyover_btc_transaction.js @@ -5,7 +5,7 @@ const lbc = require('../lib/liquidity-bridge-contract'); const { sendTxWithCheck, getFedsPubKeys, activateFork } = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBridge } = require('../lib/precompiled-abi-forks-util'); -const btcEthUnitConverter = require('btc-eth-unit-converter'); +const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); const { getBtcClient } = require('../lib/btc-client-provider'); const CustomError = require('../lib/CustomError'); const { mineForPeginRegistration } = require('../lib/2wp-utils'); @@ -58,7 +58,7 @@ describe('Calling registerFastBtcTransaction after iris', () => { const BTC_BALANCE_TO_TRANSFER_IN_BTC = 20; const AMOUNT_FOR_FUNDER_IN_BTC = 30; - const weisToTransfer = btcEthUnitConverter.btcToWeis(BTC_BALANCE_TO_TRANSFER_IN_BTC); + const weisToTransfer = Number(btcEthUnitConverter.btcToWeis(BTC_BALANCE_TO_TRANSFER_IN_BTC)); const powpegRedeemScript = redeemScriptParser.getPowpegRedeemScript(FEDS_PUBKEYS_LIST); const flyoverRedeemScript = redeemScriptParser.getFlyoverRedeemScript(powpegRedeemScript, derivationHash.substring(2)); const flyoverFedAddress = redeemScriptParser.getAddressFromRedeemScript('REGTEST', flyoverRedeemScript); diff --git a/tests/01_04_53-post_iris_register_fast_btc_transaction_surpass_locking_cap.js b/tests/01_04_53-post_iris_register_fast_btc_transaction_surpass_locking_cap.js index 4b671ddc..6ab39785 100644 --- a/tests/01_04_53-post_iris_register_fast_btc_transaction_surpass_locking_cap.js +++ b/tests/01_04_53-post_iris_register_fast_btc_transaction_surpass_locking_cap.js @@ -6,7 +6,7 @@ const { REFUNDED_USER_ERROR } = require("../lib/flyover-pegin-response-codes"); const { sendTxWithCheck, triggerRelease, getFedsPubKeys, activateFork } = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBtcClient } = require('../lib/btc-client-provider'); -const btcEthUnitConverter = require('btc-eth-unit-converter'); +const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); const { ensure0x, fundAddressAndGetData, wait } = require('../lib/utils'); const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); const { mineForPeginRegistration } = require('../lib/2wp-utils'); @@ -58,7 +58,7 @@ describe('Executing registerFastBtcTransaction after iris - with release', () => liquidityProviderBtcAddressBytes ).call(); - const amountForFlyoverInSatoshis = btcEthUnitConverter.btcToSatoshis(AMOUNT_TO_SEND_IN_BTC); + const amountForFlyoverInSatoshis = Number(btcEthUnitConverter.btcToSatoshis(AMOUNT_TO_SEND_IN_BTC)); const fundingAmountInBtc = AMOUNT_TO_SEND_IN_BTC + 1; @@ -99,9 +99,9 @@ describe('Executing registerFastBtcTransaction after iris - with release', () => await triggerRelease(rskTxHelpers, btcTxHelper); await wait(500); - const finalBalanceInSatoshis = btcEthUnitConverter.btcToSatoshis(await btcTxHelper.getAddressBalance(userBtcRefundAddress)); + const finalBalanceInSatoshis = Number(btcEthUnitConverter.btcToSatoshis(await btcTxHelper.getAddressBalance(userBtcRefundAddress))); const difference = amountForFlyoverInSatoshis - finalBalanceInSatoshis; - const FEE_IN_SATOSHIS = btcEthUnitConverter.btcToSatoshis(0.001); + const FEE_IN_SATOSHIS = Number(btcEthUnitConverter.btcToSatoshis(0.001)); expect(difference).to.be.at.most(FEE_IN_SATOSHIS * 2); diff --git a/tests/01_04_56-post_iris_flyover_sending_same_tx_without_witness_twice.js b/tests/01_04_56-post_iris_flyover_sending_same_tx_without_witness_twice.js index 74b0643b..cef62397 100644 --- a/tests/01_04_56-post_iris_flyover_sending_same_tx_without_witness_twice.js +++ b/tests/01_04_56-post_iris_flyover_sending_same_tx_without_witness_twice.js @@ -6,7 +6,7 @@ const lbc = require('../lib/liquidity-bridge-contract'); const { sendTxWithCheck, getFedsPubKeys, activateFork } = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBtcClient } = require('../lib/btc-client-provider'); -const btcEthUnitConverter = require('btc-eth-unit-converter'); +const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); const { ensure0x, fundAddressAndGetData } = require('../lib/utils'); const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); const { mineForPeginRegistration } = require('../lib/2wp-utils'); @@ -81,8 +81,8 @@ describe('Executing registerFastBtcTransaction post hop - sending same tx withou const checkFunction = result => { resultValueFromFirstTx = Number(result); - const expectedResultSatoshis = btcEthUnitConverter.btcToSatoshis(EXPECTED_AMOUNT_IN_BTC); - const expectedResultInWeis = btcEthUnitConverter.satoshisToWeis(expectedResultSatoshis); + const expectedResultSatoshis = Number(btcEthUnitConverter.btcToSatoshis(EXPECTED_AMOUNT_IN_BTC)); + const expectedResultInWeis = Number(btcEthUnitConverter.satoshisToWeis(expectedResultSatoshis)); expect(expectedResultInWeis).to.be.equals(resultValueFromFirstTx); }; diff --git a/tests/01_04_57-post_iris_flyover_sending_same_tx_with_witness_twice.js b/tests/01_04_57-post_iris_flyover_sending_same_tx_with_witness_twice.js index 59420bdf..bd6c79d4 100644 --- a/tests/01_04_57-post_iris_flyover_sending_same_tx_with_witness_twice.js +++ b/tests/01_04_57-post_iris_flyover_sending_same_tx_with_witness_twice.js @@ -6,7 +6,7 @@ const lbc = require('../lib/liquidity-bridge-contract'); const { sendTxWithCheck, getFedsPubKeys, activateFork } = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBtcClient } = require('../lib/btc-client-provider'); -const btcEthUnitConverter = require('btc-eth-unit-converter'); +const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); const { ensure0x, fundAddressAndGetData } = require('../lib/utils'); const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); const { mineForPeginRegistration } = require('../lib/2wp-utils'); @@ -99,8 +99,8 @@ describe('Executing registerFastBtcTransaction post hop - sending same tx with w const checkFunction = (result) => { resultValueFromFirstTx = Number(result); - const expectedResultSatoshis = btcEthUnitConverter.btcToSatoshis(EXPECTED_AMOUNT_IN_BTC); - const expectedResultInWeis = btcEthUnitConverter.satoshisToWeis(expectedResultSatoshis); + const expectedResultSatoshis = Number(btcEthUnitConverter.btcToSatoshis(EXPECTED_AMOUNT_IN_BTC)); + const expectedResultInWeis = Number(btcEthUnitConverter.satoshisToWeis(expectedResultSatoshis)); expect(expectedResultInWeis).to.be.equals(resultValueFromFirstTx) }; diff --git a/tests/01_06_02-pre-fingerroot500-release_request_received_bytes.js b/tests/01_06_02-pre-fingerroot500-release_request_received_bytes.js index 960cbf5b..d9e2eef9 100644 --- a/tests/01_06_02-pre-fingerroot500-release_request_received_bytes.js +++ b/tests/01_06_02-pre-fingerroot500-release_request_received_bytes.js @@ -4,7 +4,7 @@ const rskUtils = require('../lib/rsk-utils'); const { getBtcClient } = require('../lib/btc-client-provider'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getDerivedRSKAddressInformation } = require('@rsksmart/btc-rsk-derivation'); -const btcEthUnitConverter = require('btc-eth-unit-converter'); +const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); const { sendTxToBridge } = require('../lib/2wp-utils'); const { ensure0x } = require('../lib/utils'); @@ -25,7 +25,7 @@ describe('pegout events improvements - pre fingerroot', () => { const INITIAL_RSK_BALANCE = 0.01; const PEGOUT_AMOUNT_IN_RBTC = 0.005; - const PEGOUT_AMOUNT_IN_SATOSHIS = btcEthUnitConverter.btcToSatoshis(PEGOUT_AMOUNT_IN_RBTC); + const PEGOUT_AMOUNT_IN_SATOSHIS = Number(btcEthUnitConverter.btcToSatoshis(PEGOUT_AMOUNT_IN_RBTC)); const btcAddressInformation = await btcTxHelper.generateBtcAddress('legacy'); @@ -35,7 +35,7 @@ describe('pegout events improvements - pre fingerroot', () => { const unlocked = await rskTxHelper.unlockAccount(recipientRskAddressInfo.address); expect(unlocked, 'Account was not unlocked').to.be.true; - await rskUtils.sendFromCow(rskTxHelper, recipientRskAddressInfo.address, btcEthUnitConverter.btcToWeis(INITIAL_RSK_BALANCE)); + await rskUtils.sendFromCow(rskTxHelper, recipientRskAddressInfo.address, Number(btcEthUnitConverter.btcToWeis(INITIAL_RSK_BALANCE))); await sendTxToBridge(rskTxHelper, PEGOUT_AMOUNT_IN_RBTC, recipientRskAddressInfo.address); diff --git a/tests/02_00_02-2wp_segwit_compatible.js b/tests/02_00_02-2wp_segwit_compatible.js index 12a0670c..88d778cb 100644 --- a/tests/02_00_02-2wp_segwit_compatible.js +++ b/tests/02_00_02-2wp_segwit_compatible.js @@ -1,6 +1,6 @@ const expect = require('chai').expect const { getDerivedRSKAddressInformation } = require('@rsksmart/btc-rsk-derivation'); -const btcEthUnitConverter = require('btc-eth-unit-converter'); +const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); const rskUtils = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { sendPegin, ensurePeginIsRegistered, disableWhitelisting } = require('../lib/2wp-utils'); @@ -33,7 +33,7 @@ describe('Lock using p2sh-p2wpkh address', () => { const bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); const minimumPeginValueInSatoshis = await bridge.methods.getMinimumLockTxValue().call(); - const minimumPeginValueInBtc = btcEthUnitConverter.satoshisToBtc(minimumPeginValueInSatoshis); + const minimumPeginValueInBtc = Number(btcEthUnitConverter.satoshisToBtc(minimumPeginValueInSatoshis)); const federationAddress = await bridge.methods.getFederationAddress().call(); const federationAddressBalanceInitial = Number(await btcTxHelper.getAddressBalance(federationAddress)); @@ -56,6 +56,6 @@ describe('Lock using p2sh-p2wpkh address', () => { expect(senderAddressBalanceAfterPegin).to.be.equal(0); const recipientRskAddressBalanceAfterPegin = Number(await rskTxHelper.getBalance(recipientRskAddressInfo.address)); - expect(recipientRskAddressBalanceAfterPegin).to.be.equal(btcEthUnitConverter.btcToWeis(minimumPeginValueInBtc)); + expect(recipientRskAddressBalanceAfterPegin).to.be.equal(Number(btcEthUnitConverter.btcToWeis(minimumPeginValueInBtc))); }); }); diff --git a/tests/02_00_03-2wp_multisig_compatible.js b/tests/02_00_03-2wp_multisig_compatible.js index 20c17b3e..79513922 100644 --- a/tests/02_00_03-2wp_multisig_compatible.js +++ b/tests/02_00_03-2wp_multisig_compatible.js @@ -1,5 +1,5 @@ const expect = require('chai').expect -const { satoshisToBtc } = require('btc-eth-unit-converter'); +const { satoshisToBtc } = require('@rsksmart/btc-eth-unit-converter'); const rskUtils = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBtcClient } = require('../lib/btc-client-provider'); @@ -34,7 +34,7 @@ describe('Lock multisig address', () => { const bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); const minimumPeginValueInSatoshis = await bridge.methods.getMinimumLockTxValue().call(); - const minimumPeginValueInBtc = satoshisToBtc(minimumPeginValueInSatoshis); + const minimumPeginValueInBtc = Number(satoshisToBtc(minimumPeginValueInSatoshis)); const federationAddress = await bridge.methods.getFederationAddress().call(); const federationAddressBalanceInitial = Number(await btcTxHelper.getAddressBalance(federationAddress)); diff --git a/tests/02_00_05-2wp_version1.js b/tests/02_00_05-2wp_version1.js index 83836eae..f8168fcc 100644 --- a/tests/02_00_05-2wp_version1.js +++ b/tests/02_00_05-2wp_version1.js @@ -5,7 +5,7 @@ const { getBridge , getLatestActiveForkName} = require('../lib/precompiled-abi-f const { getBtcClient } = require('../lib/btc-client-provider'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getDerivedRSKAddressInformation } = require('@rsksmart/btc-rsk-derivation'); -const btcEthUnitConverter = require('btc-eth-unit-converter'); +const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); const { ensure0x } = require('../lib/utils'); const { PEGIN_REJECTION_REASONS: { PEGIN_CAP_SURPASSED_REASON, PEGIN_V1_INVALID_PAYLOAD_REASON } @@ -40,7 +40,7 @@ describe('Lock funds using peg-in protocol version 1', () => { const bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); // Get the current locking cap - lockingCapInBtc = btcEthUnitConverter.satoshisToBtc(Number(await bridge.methods.getLockingCap().call())); + lockingCapInBtc = Number(btcEthUnitConverter.satoshisToBtc(Number(await bridge.methods.getLockingCap().call()))); }); @@ -72,7 +72,7 @@ describe('Lock funds using peg-in protocol version 1', () => { expect(Number(initialSenderBalance)).to.equal(0); expect(Number(finalSenderBalance)).to.equal(0); expect(Number(initialDestinationAddressBalance)).to.equal(0); - expect(Number(finalDestinationAddressBalance)).to.equal(btcEthUnitConverter.btcToWeis(AMOUNT_TO_LOCK_IN_BTC)); + expect(Number(finalDestinationAddressBalance)).to.equal(Number(btcEthUnitConverter.btcToWeis(AMOUNT_TO_LOCK_IN_BTC))); }); it('should lock using bech32 sender', async () => { @@ -103,7 +103,7 @@ describe('Lock funds using peg-in protocol version 1', () => { expect(Number(initialSenderBalance)).to.equal(0); expect(Number(finalSenderBalance)).to.equal(0); expect(Number(initialDestinationAddressBalance)).to.equal(0); - expect(Number(finalDestinationAddressBalance)).to.equal(btcEthUnitConverter.btcToWeis(AMOUNT_TO_LOCK_IN_BTC)); + expect(Number(finalDestinationAddressBalance)).to.equal(Number(btcEthUnitConverter.btcToWeis(AMOUNT_TO_LOCK_IN_BTC))); }); it('should refund to indicated address when locking cap exceeded using bech32 sender', async () => { @@ -378,7 +378,7 @@ describe('Lock funds using peg-in protocol version 1', () => { expect(Number(initialSenderBalance)).to.equal(0); expect(Number(finalSenderBalance)).to.equal(0); expect(Number(initialDestinationAddressBalance)).to.equal(0); - expect(Number(finalDestinationAddressBalance)).to.equal(btcEthUnitConverter.btcToWeis(AMOUNT_TO_LOCK_IN_BTC)); + expect(Number(finalDestinationAddressBalance)).to.equal(Number(btcEthUnitConverter.btcToWeis(AMOUNT_TO_LOCK_IN_BTC))); }); it('should refund lock with OP_RETURN output for RSK with invalid payload', async () => { diff --git a/tests/02_00_06-2wp-new-minimum.js b/tests/02_00_06-2wp-new-minimum.js index 3b26ad8a..7a67d40e 100644 --- a/tests/02_00_06-2wp-new-minimum.js +++ b/tests/02_00_06-2wp-new-minimum.js @@ -5,7 +5,7 @@ const { getLatestForkName, activateFork, triggerRelease } = require('../lib/rsk- const { sendPegin, ensurePeginIsRegistered, sendTxToBridge, BRIDGE_ADDRESS, MIN_PEGOUT_VALUE_IN_RBTC } = require('../lib/2wp-utils'); const { getDerivedRSKAddressInformation } = require('@rsksmart/btc-rsk-derivation'); const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); -const { btcToSatoshis, btcToWeis, satoshisToBtc } = require('btc-eth-unit-converter'); +const { btcToSatoshis, btcToWeis, satoshisToBtc } = require('@rsksmart/btc-eth-unit-converter'); describe('2wp after iris300, using new minimum values', () => { let rskTxHelpers; @@ -33,7 +33,7 @@ describe('2wp after iris300, using new minimum values', () => { const latestActiveForkName = await getLatestActiveForkName(); bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); const minimumPeginValueInSatoshi = await bridge.methods.getMinimumLockTxValue().call(); - minimumPeginValueInBTC = satoshisToBtc(minimumPeginValueInSatoshi); + minimumPeginValueInBTC = Number(satoshisToBtc(minimumPeginValueInSatoshi)); //get federation address federationAddress = await bridge.methods.getFederationAddress().call(); @@ -61,17 +61,17 @@ describe('2wp after iris300, using new minimum values', () => { const federationAddressBalanceAfterPegin = Number(await btcTxHelper.getAddressBalance(federationAddress)); const expectedFederationAddressBalanceAfterPegin = federationAddressBalanceInitial + minimumPeginValueInBTC; - expect(btcToSatoshis(federationAddressBalanceAfterPegin)).to.be.equal(btcToSatoshis(expectedFederationAddressBalanceAfterPegin)); + expect(Number(btcToSatoshis(federationAddressBalanceAfterPegin))).to.be.equal(Number(btcToSatoshis(expectedFederationAddressBalanceAfterPegin))); const bridgeAddressBalanceAfterPegin = Number(await rskTxHelper.getBalance(BRIDGE_ADDRESS)); - const expectedBridgeAddressBalanceAfterPegin = bridgeAddressBalanceInitial - btcToWeis(minimumPeginValueInBTC); + const expectedBridgeAddressBalanceAfterPegin = bridgeAddressBalanceInitial - Number(btcToWeis(minimumPeginValueInBTC)); expect(bridgeAddressBalanceAfterPegin).to.be.equal(expectedBridgeAddressBalanceAfterPegin) const senderAddressBalanceFinal = Number(await btcTxHelper.getAddressBalance(senderAddressInfo.address)); expect(senderAddressBalanceFinal).to.equal(0); const recipientRskAddressBalanceFinal = Number(await rskTxHelper.getBalance(recipientRskAddressInfo.address)); - expect(recipientRskAddressBalanceFinal).to.equal(btcToWeis(minimumPeginValueInBTC)); + expect(recipientRskAddressBalanceFinal).to.equal(Number(btcToWeis(minimumPeginValueInBTC))); }); it('should not peg-in and not refund when sending below minimum value', async () => { @@ -90,7 +90,7 @@ describe('2wp after iris300, using new minimum values', () => { const federationAddressBalanceAfterPegin = Number(await btcTxHelper.getAddressBalance(federationAddress)); const expectedFederationAddressBalanceAfterPegin = federationAddressBalanceInitial + BELOW_MIN_PEGIN_VALUE_IN_BTC; - expect(btcToSatoshis(federationAddressBalanceAfterPegin)).to.be.equal(btcToSatoshis(expectedFederationAddressBalanceAfterPegin)); + expect(Number(btcToSatoshis(federationAddressBalanceAfterPegin))).to.be.equal(Number(btcToSatoshis(expectedFederationAddressBalanceAfterPegin))); const bridgeAddressBalanceAfterPegin = Number(await rskTxHelper.getBalance(BRIDGE_ADDRESS)); expect(bridgeAddressBalanceAfterPegin).to.be.equal(bridgeAddressBalanceInitial); @@ -105,7 +105,7 @@ describe('2wp after iris300, using new minimum values', () => { const federationAddressBalanceFinal = Number(await btcTxHelper.getAddressBalance(federationAddress)); const expectedFederationAddressBalanceFinal = federationAddressBalanceInitial + BELOW_MIN_PEGIN_VALUE_IN_BTC; - expect(btcToSatoshis(federationAddressBalanceFinal)).to.be.equal(btcToSatoshis(expectedFederationAddressBalanceFinal)); + expect(Number(btcToSatoshis(federationAddressBalanceFinal))).to.be.equal(Number(btcToSatoshis(expectedFederationAddressBalanceFinal))); const bridgeAddressBalanceFinal = Number(await rskTxHelper.getBalance(BRIDGE_ADDRESS)); expect(bridgeAddressBalanceFinal).to.be.equal(bridgeAddressBalanceInitial) @@ -135,28 +135,28 @@ describe('2wp after iris300, using new minimum values', () => { await ensurePeginIsRegistered(rskTxHelper, btcPeginTxHash); const recipientRskAddressBalanceAfterPegin = Number(await rskTxHelper.getBalance(recipientRskAddressInfo.address)); - expect(recipientRskAddressBalanceAfterPegin).to.be.equal(btcToWeis(minimumPeginValueInBTC)); + expect(recipientRskAddressBalanceAfterPegin).to.be.equal(Number(btcToWeis(minimumPeginValueInBTC))); const federationAddressBalanceAfterPegin = Number(await btcTxHelper.getAddressBalance(federationAddress)); const expectedFederationAddressBalanceAfterPegin = federationAddressBalanceInitial + minimumPeginValueInBTC; - expect(btcToSatoshis(federationAddressBalanceAfterPegin)).to.be.equal(btcToSatoshis(expectedFederationAddressBalanceAfterPegin)); + expect(Number(btcToSatoshis(federationAddressBalanceAfterPegin))).to.be.equal(Number(btcToSatoshis(expectedFederationAddressBalanceAfterPegin))); // Execute peg-out await sendTxToBridge(rskTxHelper, MIN_PEGOUT_VALUE_IN_RBTC, recipientRskAddressInfo.address); await triggerRelease(rskTxHelpers, btcTxHelper); const senderAddressBalanceFinal = Number(await btcTxHelper.getAddressBalance(senderAddressInfo.address)); - const maxExpectedSenderAddressBalanceFinal = btcToSatoshis(MIN_PEGOUT_VALUE_IN_RBTC); - const minExpectedSenderAddressBalanceFinal = btcToSatoshis(MIN_PEGOUT_VALUE_IN_RBTC - TX_FEE_IN_RBTC); - expect(btcToSatoshis(senderAddressBalanceFinal)).to.be.above(minExpectedSenderAddressBalanceFinal).and.below(maxExpectedSenderAddressBalanceFinal); + const maxExpectedSenderAddressBalanceFinal = Number(btcToSatoshis(MIN_PEGOUT_VALUE_IN_RBTC)); + const minExpectedSenderAddressBalanceFinal = Number(btcToSatoshis(MIN_PEGOUT_VALUE_IN_RBTC - TX_FEE_IN_RBTC)); + expect(Number(btcToSatoshis(senderAddressBalanceFinal))).to.be.above(minExpectedSenderAddressBalanceFinal).and.below(maxExpectedSenderAddressBalanceFinal); const federationAddressBalanceFinal = Number(await btcTxHelper.getAddressBalance(federationAddress)); const expectedFederationAddressBalanceFinal = federationAddressBalanceAfterPegin - MIN_PEGOUT_VALUE_IN_RBTC; - expect(btcToSatoshis(federationAddressBalanceFinal)).to.be.equal(btcToSatoshis(expectedFederationAddressBalanceFinal)); + expect(Number(btcToSatoshis(federationAddressBalanceFinal))).to.be.equal(Number(btcToSatoshis(expectedFederationAddressBalanceFinal))); const recipientRskAddressBalanceFinal = Number(await rskTxHelper.getBalance(recipientRskAddressInfo.address)); - const maxExpectedRecipientRskAddressBalanceFinal = btcToWeis(minimumPeginValueInBTC - MIN_PEGOUT_VALUE_IN_RBTC); - const minExpectedRecipientRskAddressBalanceFinal = btcToWeis(minimumPeginValueInBTC - MIN_PEGOUT_VALUE_IN_RBTC - TX_FEE_IN_RBTC); + const maxExpectedRecipientRskAddressBalanceFinal = Number(btcToWeis(minimumPeginValueInBTC - MIN_PEGOUT_VALUE_IN_RBTC)); + const minExpectedRecipientRskAddressBalanceFinal = Number(btcToWeis(minimumPeginValueInBTC - MIN_PEGOUT_VALUE_IN_RBTC - TX_FEE_IN_RBTC)); expect(recipientRskAddressBalanceFinal).to.be.above(minExpectedRecipientRskAddressBalanceFinal).and.below(maxExpectedRecipientRskAddressBalanceFinal); }); }); diff --git a/tests/04_00_05-fastbridge_operation_with_rejection.js b/tests/04_00_05-fastbridge_operation_with_rejection.js index 8fd03287..17499166 100644 --- a/tests/04_00_05-fastbridge_operation_with_rejection.js +++ b/tests/04_00_05-fastbridge_operation_with_rejection.js @@ -7,7 +7,7 @@ const { ERP_PUBKEYS, ERP_CSV_VALUE } = require("../lib/constants") const { sendTxWithCheck, triggerRelease, getFedsPubKeys } = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBtcClient } = require('../lib/btc-client-provider'); -const btcEthUnitConverter = require('btc-eth-unit-converter'); +const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); const { ensure0x, fundAddressAndGetData, wait } = require('../lib/utils'); const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); const { mineForPeginRegistration } = require('../lib/2wp-utils'); @@ -47,7 +47,7 @@ describe('Executing registerFastBtcTransaction after fed change - with release', liquidityProviderBtcAddressBytes ).call(); - const amountForFlyoverInSatoshis = btcEthUnitConverter.btcToSatoshis(AMOUNT_TO_SEND_IN_BTC); + const amountForFlyoverInSatoshis = Number(btcEthUnitConverter.btcToSatoshis(AMOUNT_TO_SEND_IN_BTC)); const fundingAmountInBtc = AMOUNT_TO_SEND_IN_BTC + 1; @@ -89,9 +89,9 @@ describe('Executing registerFastBtcTransaction after fed change - with release', await triggerRelease(rskTxHelpers, btcTxHelper); await wait(500); - const finalBalanceInSatoshis = btcEthUnitConverter.btcToSatoshis(await btcTxHelper.getAddressBalance(userBtcRefundAddress)); + const finalBalanceInSatoshis = Number(btcEthUnitConverter.btcToSatoshis(await btcTxHelper.getAddressBalance(userBtcRefundAddress))); const difference = amountForFlyoverInSatoshis - finalBalanceInSatoshis; - const FEE_IN_SATOSHIS = btcEthUnitConverter.btcToSatoshis(0.001); + const FEE_IN_SATOSHIS = Number(btcEthUnitConverter.btcToSatoshis(0.001)); expect(difference).to.be.at.most(FEE_IN_SATOSHIS * 2); From 300cdc997b3fce8f199451f60e9ac45f45b8d4a4 Mon Sep 17 00:00:00 2001 From: Kelvin Isievwore Date: Thu, 19 Oct 2023 20:48:37 +0100 Subject: [PATCH 4/4] Rearranged Precompiled abis Dependencies In Package.json --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 3573da05..3194ebbf 100644 --- a/package.json +++ b/package.json @@ -34,12 +34,12 @@ "mocha-junit-reporter": "^1.17.0", "pegin-address-verificator": "git+https://git@github.com/rsksmart/pegin-address-verifier#v0.2.1", "peglib": "git+https://github.com/rsksmart/rsk-peglib#v1.4.15", - "precompiled-fingerroot500": "npm:@rsksmart/rsk-precompiled-abis@^5.0.0-FINGERROOT", - "precompiled-hop400": "npm:@rsksmart/rsk-precompiled-abis@^5.0.0-HOP", - "precompiled-iris300": "npm:@rsksmart/rsk-precompiled-abis@^4.0.0-IRIS", "precompiled-orchid": "npm:@rsksmart/rsk-precompiled-abis@^1.0.0-ORCHID", - "precompiled-papyrus200": "npm:@rsksmart/rsk-precompiled-abis@^3.0.0-PAPYRUS", "precompiled-wasabi100": "npm:@rsksmart/rsk-precompiled-abis@^2.0.0-WASABI", + "precompiled-papyrus200": "npm:@rsksmart/rsk-precompiled-abis@^3.0.0-PAPYRUS", + "precompiled-iris300": "npm:@rsksmart/rsk-precompiled-abis@^4.0.0-IRIS", + "precompiled-hop400": "npm:@rsksmart/rsk-precompiled-abis@^5.0.0-HOP", + "precompiled-fingerroot500": "npm:@rsksmart/rsk-precompiled-abis@^5.0.0-FINGERROOT", "rsk-transaction-helper": "git+https://github.com/rsksmart/rootstock-transaction-helper#v3.1.0", "solc": "^0.7.5", "stream-line-wrapper": "^0.1.1",