Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable whitelisting #12

Merged
merged 6 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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