Skip to content

Commit

Permalink
Updates disableWhitelisting function
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-then committed Oct 30, 2023
1 parent dfb8815 commit ee66d16
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 42 deletions.
34 changes: 15 additions & 19 deletions lib/2wp-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>}
*/
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,
Expand Down
18 changes: 0 additions & 18 deletions lib/assertions/whitelisting.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,31 +171,13 @@ 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,
assertRemoveWhitelistAddress,
assertWhitelistAddressPresence,
assertAddLockWhitelistAddress,
assertAddLimitedLockWhitelistAddress,
disableWhitelisting,
WHITELIST_CHANGE_PK,
WHITELIST_CHANGE_ADDR,
};
10 changes: 5 additions & 5 deletions tests/04_00_02-fedchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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));

Expand Down

0 comments on commit ee66d16

Please sign in to comment.