Skip to content

Commit

Permalink
Merge pull request #12 from rsksmart/disable-whitelist
Browse files Browse the repository at this point in the history
disable whitelisting
  • Loading branch information
jeremy-then authored Sep 29, 2023
2 parents fa353d8 + dc14c76 commit 8ac1bb3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
30 changes: 28 additions & 2 deletions lib/2wp-utils.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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,
Expand All @@ -251,5 +276,6 @@ module.exports = {
BRIDGE_ADDRESS,
createPeginV1TxData,
mineForPeginRegistration,
MIN_PEGOUT_VALUE_IN_RBTC
MIN_PEGOUT_VALUE_IN_RBTC,
disableWhitelisting
};
9 changes: 5 additions & 4 deletions tests/02_00_02-2wp_segwit_compatible.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ 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');

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', () => {
Expand All @@ -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);
}
});

Expand Down
2 changes: 1 addition & 1 deletion tests/02_00_06-2wp-new-minimum.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8ac1bb3

Please sign in to comment.