diff --git a/lib/2wp-utils.js b/lib/2wp-utils.js index 1ad2fb93..ff82310a 100644 --- a/lib/2wp-utils.js +++ b/lib/2wp-utils.js @@ -1,5 +1,5 @@ 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'); @@ -15,6 +15,8 @@ const ADDRESS_TYPES_CODES = { const BTC_TO_RSK_MINIMUM_CONFIRMATIONS = 3; const TO_BRIDGE_GAS_PRICE = 2; const BRIDGE_ADDRESS = '0x0000000000000000000000000000000001000006'; +const WHITELIST_CHANGE_PK = '3890187a3071327cee08467ba1b44ed4c13adb2da0d5ffcc0563c371fa88259c'; +const WHITELIST_CHANGE_ADDR = '87d2a0f33744929da08b65fd62b627ea52b25f8e'; /** * @@ -238,6 +240,25 @@ const donateToBridge = async (rskTxHelper, btcTxHelper, donatingBtcAddressInform return peginBtcTxHash; }; +const disableWhitelisting = async (rskTxHelper) => { + const latestActiveForkName = await getLatestActiveForkName(); + console.log(`latestActiveForkName - disableWhitelisting: ${latestActiveForkName}`) + const bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); + + const addr = await rskTxHelper.importAccount(WHITELIST_CHANGE_PK) + expect(addr.slice(2)).to.equal(WHITELIST_CHANGE_ADDR); + const unclock = await rskTxHelper.unlockAccount(addr); + console.log(`unlock: ${unclock}`) + + await sendTxWithCheck( + rskTxHelper, + bridge.methods.setLockWhitelistDisableBlockDelay(1), + WHITELIST_CHANGE_ADDR), + (disableResult) => expect(Number(disableResult)).to.equal(1)(); + + rskTxHelper.mine(1); +} + module.exports = { sendTxToBridge, assertRefundUtxosSameAsPeginUtxos, @@ -250,4 +271,5 @@ module.exports = { BRIDGE_ADDRESS, createPeginV1TxData, mineForPeginRegistration, + disableWhitelisting }; diff --git a/tests/02_00_02-2wp_segwit_compatible.js b/tests/02_00_02-2wp_segwit_compatible.js index 636e5a5d..f36b44b6 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,11 @@ let rskTxHelpers; let rskTxHelper; let btcTxHelper; -const fulfillRequirementsToRunAsSingleTestFile = async () => { +const fulfillRequirementsToRunAsSingleTestFile = async (rskTxHelper) => { const latestForkName = rskUtils.getLatestForkName() + console.log(`latestForkName: ${JSON.stringify(latestForkName)}`) await rskUtils.activateFork(latestForkName); + disableWhitelisting(rskTxHelper) }; describe('Lock using p2sh-p2wpkh address', () => { @@ -23,12 +25,29 @@ describe('Lock using p2sh-p2wpkh address', () => { btcTxHelper = getBtcClient(); if(process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(); + await fulfillRequirementsToRunAsSingleTestFile(rskTxHelper); + // const latestActiveForkName = await getLatestActiveForkName(); + // console.log(`latestActiveForkName: ${latestActiveForkName}`) + // bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); + + // const addr = await rskTxHelper.importAccount(WHITELIST_CHANGE_PK) + // console.log(`addr: ${addr}`) + // expect(addr.slice(2)).to.equal(WHITELIST_CHANGE_ADDR); + // await rskTxHelper.unlockAccount(addr); + + // await rskUtils.sendTxWithCheck( + // rskTxHelper, + // bridge.methods.setLockWhitelistDisableBlockDelay(1), + // WHITELIST_CHANGE_ADDR), + // (disableResult) => expect(Number(disableResult)).to.equal(1)(); + + // rskTxHelper.mine(1); } }); it('should do a legacy pegin using p2sh-p2wpkh address', async () => { const latestActiveForkName = await getLatestActiveForkName(); + console.log(`latestActiveForkName: ${latestActiveForkName}`) const bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); const minimumPeginValueInSatoshis = await bridge.methods.getMinimumLockTxValue().call(); @@ -36,6 +55,7 @@ describe('Lock using p2sh-p2wpkh address', () => { const federationAddress = await bridge.methods.getFederationAddress().call(); const federationAddressBalanceInitial = Number(await btcTxHelper.getAddressBalance(federationAddress)); + console.log(`federationAddressBalanceInitial: ${federationAddressBalanceInitial}`) const senderAddressInfo = await btcTxHelper.generateBtcAddress('p2sh-segwit'); const recipientRskAddressInfo = getDerivedRSKAddressInformation(senderAddressInfo.privateKey, btcTxHelper.btcConfig.network); @@ -49,6 +69,7 @@ describe('Lock using p2sh-p2wpkh address', () => { await ensurePeginIsRegistered(rskTxHelper, btcPeginTxHash); const federationAddressBalanceAfterPegin = Number(await btcTxHelper.getAddressBalance(federationAddress)); + console.log(`federationAddressBalanceAfterPegin: ${federationAddressBalanceAfterPegin}`) expect(federationAddressBalanceAfterPegin).to.be.equal(Number(federationAddressBalanceInitial + minimumPeginValueInBtc)); const senderAddressBalanceAfterPegin = Number(await btcTxHelper.getAddressBalance(senderAddressInfo.address));