diff --git a/lib/2wp-utils.js b/lib/2wp-utils.js index 189a2f1c..ce50f05b 100644 --- a/lib/2wp-utils.js +++ b/lib/2wp-utils.js @@ -242,28 +242,24 @@ const donateToBridge = async (rskTxHelper, btcTxHelper, donatingBtcAddressInform }; /** - * Disabling whitelisting + * Disable the whitelisting in the bridge and mine the required blocks specified in the blockDelay parameter if mineDelayBlocks is true * @param {RskTransactionHelper} rskTxHelper * @param {BtcTransactionHelper} btcTxHelper + * @param {number} blockDelay default 1 + * @param {boolean} mineDelayBlocks default true + * @returns {Promise} */ -const disableWhitelisting = async (rskTxHelper, btcTxHelper) => { - const btcBlocksToMine = 1; - const latestActiveForkName = await getLatestActiveForkName(); - const bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); - - const whitelistChangeAddress = await rskTxHelper.importAccount(WHITELIST_CHANGE_PK); - expect(whitelistChangeAddress.slice(2)).to.equal(WHITELIST_CHANGE_ADDR); - await rskTxHelper.unlockAccount(whitelistChangeAddress); - - await sendTxWithCheck( - rskTxHelper, - bridge.methods.setLockWhitelistDisableBlockDelay(btcBlocksToMine), - WHITELIST_CHANGE_ADDR, - (disableResult) => expect(Number(disableResult)).to.equal(1) - ); - - btcTxHelper.mine(btcBlocksToMine); -} +const disableWhitelisting = async (rskTxHelper, btcTxHelper, blockDelay = 1, mineDelayBlocks = true) => { + const bridge = getBridge(rskTxHelper.getClient()); + const unlocked = await rskUtils.getUnlockedAddress(rskTxHelper, WHITELIST_CHANGE_PK, WHITELIST_CHANGE_ADDR); + expect(unlocked).to.be.true; + const disableLockWhitelistMethod = bridge.methods.setLockWhitelistDisableBlockDelay(blockDelay); + const disableResultCallback = (disableResult) => expect(Number(disableResult)).to.equal(1); + await rskUtils.sendTxWithCheck(rskTxHelper, disableLockWhitelistMethod, WHITELIST_CHANGE_ADDR, disableResultCallback); + if(mineDelayBlocks) { + await btcTxHelper.mine(blockDelay); + } +}; module.exports = { sendTxToBridge, diff --git a/lib/assertions/whitelisting.js b/lib/assertions/whitelisting.js index f0d39495..96557858 100644 --- a/lib/assertions/whitelisting.js +++ b/lib/assertions/whitelisting.js @@ -171,23 +171,6 @@ const assertWhitelistAddressPresence = async (rskTxHelper, btcAddress, present) }; -/** - * - * @param {RskTransactionHelper} rskTxHelper - * @param {BtcTransactionHelper} btcTxHelper - */ -const disableWhitelisting = async (rskTxHelper, btcTxHelper, blockDelay = 1, mineDelayBlocks = true) => { - const bridge = getBridge(rskTxHelper.getClient()); - const unlocked = await rskUtils.getUnlockedAddress(rskTxHelper, WHITELIST_CHANGE_PK, WHITELIST_CHANGE_ADDR); - expect(unlocked).to.be.true; - const disableLockWhitelistMethod = bridge.methods.setLockWhitelistDisableBlockDelay(blockDelay); - const disableResultCallback = (disableResult) => expect(Number(disableResult)).to.equal(1); - await rskUtils.sendTxWithCheck(rskTxHelper, disableLockWhitelistMethod, WHITELIST_CHANGE_ADDR, disableResultCallback); - if(mineDelayBlocks) { - await btcTxHelper.mine(blockDelay); - } -} - module.exports = { assertAddOneOffWhitelistAddress, assertAddUnlimitedWhitelistAddress, @@ -195,7 +178,6 @@ module.exports = { assertWhitelistAddressPresence, assertAddLockWhitelistAddress, assertAddLimitedLockWhitelistAddress, - disableWhitelisting, WHITELIST_CHANGE_PK, WHITELIST_CHANGE_ADDR, }; diff --git a/tests/04_00_02-fedchange.js b/tests/04_00_02-fedchange.js index 228c065a..d26b359b 100644 --- a/tests/04_00_02-fedchange.js +++ b/tests/04_00_02-fedchange.js @@ -9,7 +9,6 @@ const bitcoin = peglib.bitcoin; const rsk = peglib.rsk; const pegUtils = peglib.pegUtils; const pegAssertions = require('../lib/assertions/2wp'); -const whitelistingAssertions = require('../lib/assertions/whitelisting'); const whitelistingAssertionsLegacy = require('../lib/assertions/whitelisting-legacy'); const rskUtilsLegacy = require('../lib/rsk-utils-legacy'); const rskUtils = require('../lib/rsk-utils'); @@ -19,7 +18,7 @@ const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBtcClient } = require('../lib/btc-client-provider'); const removePrefix0x = require("../lib/utils").removePrefix0x; const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); -const { sendPegin, ensurePeginIsRegistered } = require('../lib/2wp-utils'); +const { sendPegin, ensurePeginIsRegistered, disableWhitelisting } = require('../lib/2wp-utils'); const { KEY_TYPE_BTC, KEY_TYPE_RSK, @@ -84,8 +83,8 @@ let rskTxHelper; * Takes the blockchain to the required state for this test file to run in isolation. */ const fulfillRequirementsToRunAsSingleTestFile = async (rskTxHelper, btcTxHelper) => { - await rskUtils.activateFork(Runners.common.forks.fingerroot500); - await whitelistingAssertions.disableWhitelisting(rskTxHelper, btcTxHelper); + await rskUtils.activateFork(rskUtils.getLatestForkName()); + await disableWhitelisting(rskTxHelper, btcTxHelper); }; describe('RSK Federation change', function() { @@ -339,7 +338,8 @@ describe('RSK Federation change', function() { const utxosToGenerate = UTXOS_TO_TRANSFER + UTXOS_TO_PAY_FEES; const utxoValueInSatoshis = bitcoin.btcToSatoshis(1); const peginSenderAddressInfo = await btcTxHelper.generateBtcAddress('legacy'); - const totalAmountToSendInSatoshis = (utxoValueInSatoshis * utxosToGenerate) + (utxosToGenerate * btcEthUnitConverter.btcToSatoshis(btcTxHelper.getFee())); + const totalFeesInSatoshis = (utxosToGenerate * btcEthUnitConverter.btcToSatoshis(btcTxHelper.getFee())); + const totalAmountToSendInSatoshis = (utxoValueInSatoshis * utxosToGenerate) + totalFeesInSatoshis; await btcTxHelper.fundAddress(peginSenderAddressInfo.address, btcEthUnitConverter.satoshisToBtc(totalAmountToSendInSatoshis));