diff --git a/lib/2wp-utils.js b/lib/2wp-utils.js index d0bf1be1..2496654c 100644 --- a/lib/2wp-utils.js +++ b/lib/2wp-utils.js @@ -1,11 +1,12 @@ const expect = require('chai').expect; -const { sendFromCow, mineAndSync } = require('./rsk-utils'); +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 peginVerifier = require('pegin-address-verificator'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); +const { WHITELIST_CHANGE_PK, WHITELIST_CHANGE_ADDR} = require('../lib/assertions/whitelisting') const ADDRESS_TYPES_CODES = { p2pkh: '01', @@ -239,6 +240,30 @@ const donateToBridge = async (rskTxHelper, btcTxHelper, donatingBtcAddressInform return peginBtcTxHash; }; +/** + * Disabling whitelisting + * @param {RskTransactionHelper} rskTxHelper + * @param {BtcTransactionHelper} btcTxHelper + */ +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); +} + module.exports = { sendTxToBridge, assertRefundUtxosSameAsPeginUtxos, @@ -251,5 +276,6 @@ module.exports = { BRIDGE_ADDRESS, createPeginV1TxData, mineForPeginRegistration, - MIN_PEGOUT_VALUE_IN_RBTC + MIN_PEGOUT_VALUE_IN_RBTC, + disableWhitelisting }; diff --git a/tests/02_00_02-2wp_segwit_compatible.js b/tests/02_00_02-2wp_segwit_compatible.js index 636e5a5d..12a0670c 100644 --- a/tests/02_00_02-2wp_segwit_compatible.js +++ b/tests/02_00_02-2wp_segwit_compatible.js @@ -3,7 +3,7 @@ const { getDerivedRSKAddressInformation } = require('@rsksmart/btc-rsk-derivatio const btcEthUnitConverter = require('btc-eth-unit-converter'); const rskUtils = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); -const { sendPegin, ensurePeginIsRegistered } = require('../lib/2wp-utils'); +const { sendPegin, ensurePeginIsRegistered, disableWhitelisting } = require('../lib/2wp-utils'); const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); const { getBtcClient } = require('../lib/btc-client-provider'); @@ -11,9 +11,10 @@ let rskTxHelpers; let rskTxHelper; let btcTxHelper; -const fulfillRequirementsToRunAsSingleTestFile = async () => { - const latestForkName = rskUtils.getLatestForkName() +const fulfillRequirementsToRunAsSingleTestFile = async (rskTxHelper, btcTxHelper) => { + const latestForkName = rskUtils.getLatestForkName(); await rskUtils.activateFork(latestForkName); + await disableWhitelisting(rskTxHelper, btcTxHelper); }; describe('Lock using p2sh-p2wpkh address', () => { @@ -23,7 +24,7 @@ describe('Lock using p2sh-p2wpkh address', () => { btcTxHelper = getBtcClient(); if(process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(); + await fulfillRequirementsToRunAsSingleTestFile(rskTxHelper, btcTxHelper); } }); diff --git a/tests/02_00_06-2wp-new-minimum.js b/tests/02_00_06-2wp-new-minimum.js index 844d1180..894877d6 100644 --- a/tests/02_00_06-2wp-new-minimum.js +++ b/tests/02_00_06-2wp-new-minimum.js @@ -102,7 +102,7 @@ describe('2wp after iris300, using new minimum values', () => { expect(senderAddressBalanceFinal).to.be.equal(0); const federationAddressBalanceFinal = Number(await btcTxHelper.getAddressBalance(federationAddress)); - expect(federationAddressBalanceFinal).to.be.equal(Number(federationAddressBalanceInitial + BELOW_MIN_PEGIN_VALUE_IN_BTC)); + expect(btcEthUnitConverter.btcToSatoshis(federationAddressBalanceFinal)).to.be.equal(btcEthUnitConverter.btcToSatoshis(federationAddressBalanceInitial + BELOW_MIN_PEGIN_VALUE_IN_BTC)); const bridgeAddressBalanceFinal = Number(await rskTxHelper.getBalance(BRIDGE_ADDRESS)); expect(bridgeAddressBalanceFinal).to.be.equal(bridgeAddressBalanceInitial)