From 95c40d0d9ca8aadee5d2d2db77db3bbd7d74755d Mon Sep 17 00:00:00 2001 From: jeremy-then Date: Mon, 9 Sep 2024 22:10:24 -0400 Subject: [PATCH] Removes forks activation and checks related code Rebases --- README.md | 10 -- lib/2wp-utils.js | 6 +- lib/assertions/fed.js | 4 +- lib/assertions/whitelisting-legacy.js | 7 +- lib/assertions/whitelisting.js | 9 +- lib/federate-starter.js | 10 +- lib/hsm-runner.js | 6 +- lib/precompiled-abi-forks-util.js | 137 ++---------------- lib/rsk-utils-legacy.js | 13 +- lib/rsk-utils.js | 55 ++----- lib/tests/2wp.js | 98 ++++--------- lib/tests/activate-fork.js | 29 ---- lib/tests/call_receive_header.js | 15 +- lib/tests/call_receive_headers.js | 17 +-- singleTestFileRunner.js | 9 -- test.js | 54 ++----- ...01_01_03-pre_orchid_lock_whitelist_fork.js | 4 +- tests/01_01_50-activate_orchid_fork.js | 6 - ...1_01_52-post_orchid_lock_whitelist_fork.js | 4 +- tests/01_02_01-pre_wasabi_fed_pubkeys_fork.js | 6 +- tests/01_02_50-activate_wasabi_fork.js | 6 - .../01_02_51-post_wasabi_fed_pubkeys_fork.js | 15 +- tests/01_03_01-lock_whitelist_pre_papyrus.js | 15 +- tests/01_03_04-2wp_segwit_not_compatible.js | 13 +- tests/01_03_05-2wp_multisig_not_compatible.js | 14 +- tests/01_03_06-2wp_no_locking_cap.js | 13 +- tests/01_03_50-activate_papyrus_fork.js | 6 - tests/01_03_52-disable_lock_whitelist.js | 99 +++++++++++++ ...03_54-post-papyrus_coinbase_information.js | 4 +- tests/01_04_50-activate_iris_fork.js | 6 - ...t_iris_register_flyover_btc_transaction.js | 12 +- ...ast_btc_transaction_surpass_locking_cap.js | 19 +-- ...r_sending_same_tx_without_witness_twice.js | 19 +-- ...over_sending_same_tx_with_witness_twice.js | 19 +-- ..._cap_sending_same_tx_with_witness_twice.js | 19 +-- ...p_sending_same_tx_without_witness_twice.js | 18 +-- tests/01_05_49-activate_hop_fork.js | 6 - tests/01_05_50-activate_hop401_fork.js | 6 - ...57-post_hop_active_powpeg_redeem_script.js | 15 +- ..._register_fast_bridge_btc_below_minimum.js | 15 +- ...ated-fees-for-next-pegout_returned_zero.js | 6 +- tests/01_06_50-activate_fingerroot500_fork.js | 6 - ...egout_should_returned_correct_estimated.js | 6 +- ...06_53-2wp_version1_exceeding-lockingCap.js | 16 +- tests/01_07_50-activate-arrowhead600.js | 6 - tests/01_08_50-activate-lovell700.js | 6 - tests/02_00_02-2wp_segwit_compatible.js | 9 +- tests/02_00_03-2wp_multisig_compatible.js | 16 +- tests/02_00_05-2wp_version1.js | 10 -- tests/02_00_06-2wp-new-minimum.js | 16 +- tests/03_00_01-powpeg_redeem_script.js | 13 +- tests/04_00_02-fedchange.js | 11 -- ..._05-fastbridge_operation_with_rejection.js | 5 +- tests/04_00_06-fastbridge_after_fed_change.js | 5 +- tests/05_00_01-powpeg_redeem_script.js | 4 +- 55 files changed, 252 insertions(+), 721 deletions(-) delete mode 100644 lib/tests/activate-fork.js delete mode 100644 tests/01_01_50-activate_orchid_fork.js delete mode 100644 tests/01_02_50-activate_wasabi_fork.js delete mode 100644 tests/01_03_50-activate_papyrus_fork.js create mode 100644 tests/01_03_52-disable_lock_whitelist.js delete mode 100644 tests/01_04_50-activate_iris_fork.js delete mode 100644 tests/01_05_49-activate_hop_fork.js delete mode 100644 tests/01_05_50-activate_hop401_fork.js delete mode 100644 tests/01_06_50-activate_fingerroot500_fork.js delete mode 100644 tests/01_07_50-activate-arrowhead600.js delete mode 100644 tests/01_08_50-activate-lovell700.js diff --git a/README.md b/README.md index 3598309e..a3cf3ba4 100644 --- a/README.md +++ b/README.md @@ -326,13 +326,3 @@ The command `run-single-test-file` will execute the file `singleTestFileRunner.j 1 - It will assign the `01_02_51-post_wasabi_fed_pubkeys_fork.js` test file name to the `process.env.INCLUDE_CASES` variable. Since it will be the one in that `INCLUDE_CASES` variable, then only that test file will be run. 2 - It will setup a boolean `process.env.RUNNING_SINGLE_TEST_FILE` variable to `true` so the `fulfillRequirementsToRunAsSingleTestFile` function can check if it needs to manually take the blockchain to a state where the test file can run or not. - -The test file should have a `fulfillRequirementsToRunAsSingleTestFile` function to be called in the `before` function because each test file has different requirements to be able to run. Some will need to mine blocks, fund the bridge, activate 1 or more forks, etc. Some will be able to run without any prior preparation. - -Another advantage of this is that it will allow us to understand exactly what each test really needs in order to run, reducing uncertainties. - -To indicate a fork name to be used in the `fulfillRequirementsToRunAsSingleTestFile` function, you can specify it as the last argument of the command like this, passing the fork name `fingerroot500`: - -> npm run run-single-test-file 02_00_01-2wp.js fingerroot500 - -This is when the `fulfillRequirementsToRunAsSingleTestFile` function needs a fork name that needs to be dynamically passed. For example, the `2wp.js` file is run multiple times with different forks. We cannot simply hardcode which fork to use or to use the latest, because sometimes we will need to run it with a fork passed dynamically. diff --git a/lib/2wp-utils.js b/lib/2wp-utils.js index 0db45a40..9a915188 100644 --- a/lib/2wp-utils.js +++ b/lib/2wp-utils.js @@ -9,7 +9,7 @@ const { } = require('./rsk-utils'); const { retryWithCheck } = require('./utils'); const { waitForBitcoinTxToBeInMempool, waitForBitcoinMempoolToGetTxs } = require('./btc-utils'); -const { getBridge, getLatestActiveForkName } = require('./precompiled-abi-forks-util'); +const { getBridge } = require('./precompiled-abi-forks-util'); const { getBridgeState } = require('@rsksmart/bridge-state-data-parser'); const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); @@ -33,7 +33,7 @@ const logger = getLogger(); * @param {string} refundAddress */ const assertRefundUtxosSameAsPeginUtxos = async(rskTxHelper, btcTxHelper, peginTxHash, refundAddress) => { - const bridge = getBridge(rskTxHelper.getClient(), await getLatestActiveForkName()); + const bridge = getBridge(rskTxHelper.getClient()); const federationAddress = await bridge.methods.getFederationAddress().call(); const peginTx = await btcTxHelper.getTransaction(peginTxHash); const outputsForFederation = peginTx.outs.filter(output => btcTxHelper.getOutputAddress(output.script) === federationAddress); @@ -138,7 +138,7 @@ const sendPegin = async (rskTxHelper, btcTxHelper, btcSenderAddressInformation, outputAmountsInBtc = Array.of(outputAmountsInBtc); } - const bridge = getBridge(rskTxHelper.getClient(), await getLatestActiveForkName()); + const bridge = getBridge(rskTxHelper.getClient()); const federationAddress = await bridge.methods.getFederationAddress().call(); const recipientsTransferInformation = outputAmountsInBtc.map(amount => ({ recipientAddress: federationAddress, amountInBtc: amount })); diff --git a/lib/assertions/fed.js b/lib/assertions/fed.js index dab0fb6f..d0a53403 100644 --- a/lib/assertions/fed.js +++ b/lib/assertions/fed.js @@ -3,7 +3,7 @@ var { wait } = require('../utils'); var bitcoin = require('peglib').bitcoin; var rsk = require('peglib').rsk; const rskUtilsLegacy = require('../rsk-utils-legacy'); -const { getBridge, getLatestActiveForkName } = require('../precompiled-abi-forks-util'); +const { getBridge } = require('../precompiled-abi-forks-util'); const rskUtils = require('../rsk-utils'); const { getRskTransactionHelpers } = require('../rsk-tx-helper-provider'); @@ -57,7 +57,7 @@ var checkUpdateBridge = async (rskClients, federateAddresses, fedIndex) => { var client = rskClients[fedIndex]; var address = federateAddresses[fedIndex].toLowerCase(); - const bridge = getBridge(client, await getLatestActiveForkName()); + const bridge = getBridge(client); var updateCollectionsData = bridge.methods.updateCollections().encodeABI(); diff --git a/lib/assertions/whitelisting-legacy.js b/lib/assertions/whitelisting-legacy.js index 75f3625f..bac33136 100644 --- a/lib/assertions/whitelisting-legacy.js +++ b/lib/assertions/whitelisting-legacy.js @@ -11,12 +11,7 @@ const getUnlockedAddress = async (rskClient, privateKey, address) => { }; const assertAddLimitedLockWhitelistAddress = (btcClient, rskClient) => (address, maxTransferValue) => async () => { - const isOrchidAlreadyActive = await Runners.common.forks.orchid.isAlreadyActive(); - if (isOrchidAlreadyActive) { - return assertAddOneOffWhitelistAddress(btcClient, rskClient)(address, maxTransferValue)(); - } else { - return assertAddLockWhitelistAddress(btcClient, rskClient)(address, maxTransferValue)(); - } + return assertAddOneOffWhitelistAddress(btcClient, rskClient)(address, maxTransferValue)(); }; const assertAddOneOffWhitelistAddress = (btcClient, rskClient) => (address, maxTransferValue) => async () => { diff --git a/lib/assertions/whitelisting.js b/lib/assertions/whitelisting.js index 96557858..0d9b14ff 100644 --- a/lib/assertions/whitelisting.js +++ b/lib/assertions/whitelisting.js @@ -6,19 +6,14 @@ const WHITELIST_CHANGE_PK = '3890187a3071327cee08467ba1b44ed4c13adb2da0d5ffcc056 const WHITELIST_CHANGE_ADDR = '87d2a0f33744929da08b65fd62b627ea52b25f8e'; /** - * If orchid is already active, then this method will call assertAddOneOffWhitelistAddress. Otherwise, it will call assertAddLockWhitelistAddress. + * * @param {RskTransactionHelper} rskTxHelper * @param {string} btcAddress to be added to the bridge whitelist. * @param {number} maxTransferValueInSatoshis max transfer value in satoshis that the `btcAddress` is allowed to transfer in a pegin transaction. * @returns {Promise} */ const assertAddLimitedLockWhitelistAddress = async (rskTxHelper, btcAddress, maxTransferValueInSatoshis) => { - const isOrchidAlreadyActive = await Runners.common.forks.orchid.isAlreadyActive(); - if (isOrchidAlreadyActive) { - return await assertAddOneOffWhitelistAddress(rskTxHelper, btcAddress, maxTransferValueInSatoshis); - } else { - return await assertAddLockWhitelistAddress(rskTxHelper, btcAddress, maxTransferValueInSatoshis); - } + return await assertAddOneOffWhitelistAddress(rskTxHelper, btcAddress, maxTransferValueInSatoshis); }; /** diff --git a/lib/federate-starter.js b/lib/federate-starter.js index eb2fc3bb..b78592d5 100644 --- a/lib/federate-starter.js +++ b/lib/federate-starter.js @@ -82,18 +82,10 @@ const startFederate = async (index, config, stderr, stdout, runners, logbackFile var fedStderr = new LineWrapper({ prefix: federateOutputPrefix }); fedStderr.pipe(stderr); - let parseActivations = (forks) => { - activations = { activationHeights: {} }; - for (fork in forks) { - activations.activationHeights[fork] = forks[fork].activationHeight; - } - return activations; - }; - var federateConfig = Object.assign({}, config, { stderr: fedStderr, logbackFile: config.logbackFile ? config.logbackFile : logbackFile, - forks: parseActivations(Runners.common.forks) + forks: { activationHeights: { ...Runners.common.forks } } }); federateConfig.customConfig['miner.client.enabled'] = false; diff --git a/lib/hsm-runner.js b/lib/hsm-runner.js index 23de3f61..29fe5412 100644 --- a/lib/hsm-runner.js +++ b/lib/hsm-runner.js @@ -144,7 +144,11 @@ const spawnProcessVersion2NoDocker = ( let parseNetworkUpgrades = (forks) => { let upgrades = {}; - Object.values(forks).map(f => upgrades[f.name] = f.activationHeight); + Object.entries(forks).forEach(entry => { + const forkName = entry[0]; + const forkHeight = entry[1]; + upgrades[forkName] = forkHeight; + }); let networkUpgrades = {network_upgrades:upgrades} return JSON.stringify(networkUpgrades); }; diff --git a/lib/precompiled-abi-forks-util.js b/lib/precompiled-abi-forks-util.js index c9793fda..fc008d2b 100644 --- a/lib/precompiled-abi-forks-util.js +++ b/lib/precompiled-abi-forks-util.js @@ -1,147 +1,32 @@ - -const orchidPrecompiled = require("precompiled-orchid"); -const wasabi100Precompiled = require("precompiled-wasabi100"); -const papyrus200Precompiled = require("precompiled-papyrus200"); -const iris300Precompiled = require("precompiled-iris300"); -const hop400Precompiled = require("precompiled-hop400"); -const precompiledFingerroot500 = require("precompiled-fingerroot500"); const precompiledArrowhead600 = require("precompiled-arrowhead600"); -const precompiledLovell700 = require("precompiled-lovell700"); - -const ORCHID = 'orchid'; -const WASABI = 'wasabi'; -const PAPYRUS = 'papyrus'; -const IRIS = 'iris'; -const HOP = 'hop'; -const HOP401 = 'hop401'; -const FINGERROOT = 'fingerroot'; -const ARROWHEAD = 'arrowhead'; -const LOVELL = 'lovell'; -// Map to access the pre fork names of certain fork in constant time O(1) -const preForkMap = { - [ORCHID]: ORCHID, // orchid pre is itself - [WASABI]: ORCHID, - [PAPYRUS]: WASABI, - [IRIS]: PAPYRUS, - [HOP]: IRIS, - [HOP401]: HOP, - [FINGERROOT]: HOP401, - [ARROWHEAD]: FINGERROOT, - [LOVELL]: ARROWHEAD -} - -const cache = new Map(); +let bridgeCache; /** - * Creates a bridge instance for the given fork name. If no fork name is provided, then the latest bridge is returned. - * The bridge instance is cached using the forkname for future use. + * Returns a bridge instance and caches it. * @param {Web3} rskClient - * @param {string} forkName * @returns {Bridge} */ -const getBridge = (rskClient, forkName = '') => { +const getBridge = (rskClient) => { - const { orchid, wasabi100, papyrus200, iris300, hop400, hop401, fingerroot500, arrowhead600, lovell700 } = Runners.common.forks; - if(cache.has(forkName)) { - return cache.get(forkName); + if(bridgeCache) { + return bridgeCache; } - let bridge; - switch(forkName) { - case lovell700.name: - bridge = precompiledLovell700.bridge.build(rskClient); - break; - case arrowhead600.name: - bridge = precompiledArrowhead600.bridge.build(rskClient); - break; - case fingerroot500.name: - bridge = precompiledFingerroot500.bridge.build(rskClient); - break; - case hop400.name: - case hop401.name: - bridge = hop400Precompiled.bridge.build(rskClient); - break; - case iris300.name: - bridge = iris300Precompiled.bridge.build(rskClient); - break; - case papyrus200.name: - bridge = papyrus200Precompiled.bridge.build(rskClient); - break; - case wasabi100.name: - bridge = wasabi100Precompiled.bridge.build(rskClient); - break; - case orchid.name: - bridge = orchidPrecompiled.bridge.build(rskClient); - break; - default: - // return latest bridge - bridge = precompiledLovell700.bridge.build(rskClient); - } - cache.set(forkName, bridge); - return bridge; -} + bridgeCache = precompiledArrowhead600.bridge.build(rskClient); -/** - * Returns the abi of the bridge for the given fork name. If no fork name is provided, then the latest bridge abi is returned. - * @param {string} forkName - * @returns {json} The bridge abi in json format - */ -const getBridgeAbi = (forkName) => { - - const { orchid, wasabi100, papyrus200, iris300, hop400, hop401, fingerroot500, arrowhead600, lovell700 } = Runners.common.forks; - switch(forkName) { - case lovell700.name: - return precompiledLovell700.bridge.abi; - case arrowhead600.name: - return precompiledArrowhead600.bridge.abi; - case fingerroot500.name: - return precompiledFingerroot500.bridge.abi; - case hop400.name: - case hop401.name: - return hop400Precompiled.bridge.abi; - case iris300.name: - return iris300Precompiled.bridge.abi; - case papyrus200.name: - return papyrus200Precompiled.bridge.abi; - case wasabi100.name: - return wasabi100Precompiled.bridge.abi; - case orchid.name: - return orchidPrecompiled.bridge.abi; - default: - // return latest abi - return precompiledArrowhead600.bridge.abi; - } -}; - -/** - * Returns the name of the fork right before the given `currentForkName` - * @param {string} currentForkName - * @returns {string} The name of the fork right before the given `currentForkName` - */ -const getPreForkName = (currentForkName) => { - return preForkMap[currentForkName]; + return bridgeCache; } /** - * Returns the most recent activated fork name - * @returns {Promise} the most recent activated fork name + * Returns the abi of the bridge for the latest fork. + * @returns {json} The bridge abi in json format */ -const getLatestActiveForkName = async () => { - const forks = Object.values(Runners.common.forks); - for(let i = forks.length - 1; i > -1; i--) { - const fork = forks[i]; - const isForkAlreadyActive = await fork.isAlreadyActive(); - if(isForkAlreadyActive) { - return fork.name; - } - } - return Runners.common.forks.orchid.name; +const getBridgeAbi = () => { + return precompiledArrowhead600; }; module.exports = { getBridge, getBridgeAbi, - getLatestActiveForkName, - getPreForkName, }; diff --git a/lib/rsk-utils-legacy.js b/lib/rsk-utils-legacy.js index e10c323d..4fdd80cf 100644 --- a/lib/rsk-utils-legacy.js +++ b/lib/rsk-utils-legacy.js @@ -1,7 +1,7 @@ const expect = require('chai').expect; const btcClientProvider = require('./btc-client-provider'); const { sequentialPromise, wait, interval } = require('./utils'); -const { getBridgeAbi, getLatestActiveForkName } = require('./precompiled-abi-forks-util'); +const { getBridgeAbi } = require('./precompiled-abi-forks-util'); const waitForBlockAttemptTimeMillis = process.env.WAIT_FOR_BLOCK_ATTEMPT_TIME_MILLIS || 200; const waitForBlockMaxAttempts = process.env. WAIT_FOR_BLOCK_MAX_ATTEMPTS || 600; @@ -102,10 +102,7 @@ let triggerRelease2 = async(rskClients, releaseCreatedCallback, releaseConfirmed }; let triggerPegoutEvent = async(rskClients, releaseCreatedCallback, releaseConfirmedCallback) => { - const isHop400AlreadyActive = await Runners.common.forks.hop400.isAlreadyActive(); - if (isHop400AlreadyActive) { - await increaseBlockToNextPegoutHeight(rskClients[0]); - } + await increaseBlockToNextPegoutHeight(rskClients[0]); await triggerRelease2(rskClients, releaseCreatedCallback, releaseConfirmedCallback); }; @@ -206,12 +203,12 @@ const waitForBtcToReturn = (btcClient, rskClient) => async (btcAddress) => { }; const getBridgeEventInBlockAndRunAssertions = async(block, eventName, eventAssertions, rsk, rskClient) => { - const latestActiveForkName = await getLatestActiveForkName(); - const abi = getBridgeAbi(latestActiveForkName); + + const abi = getBridgeAbi(); let txs = block.transactions; let eventJson = abi.find((methods) => methods.name == eventName && methods.type == 'event'); - expect(eventJson, `Event with name "${eventName}" was not found in the "${latestActiveForkName}" abi`).to.not.be.undefined; + expect(eventJson, `Event with name "${eventName}" was not found in the abi`).to.not.be.undefined; let signature = rskClient.eth.abi.encodeEventSignature(eventJson); for (tx of txs) { let txReceipt = await rskClient.eth.getTransactionReceipt(tx); diff --git a/lib/rsk-utils.js b/lib/rsk-utils.js index 99fc1d73..c6e03055 100644 --- a/lib/rsk-utils.js +++ b/lib/rsk-utils.js @@ -1,6 +1,6 @@ const expect = require('chai').expect; const { getBridgeState } = require('@rsksmart/bridge-state-data-parser'); -const { getBridge, getLatestActiveForkName } = require('./precompiled-abi-forks-util'); +const { getBridge } = require('./precompiled-abi-forks-util'); const hopBridgeTxParser = require('bridge-transaction-parser-hop400'); const fingerrootBridgeTxParser = require('bridge-transaction-parser-fingerroot500'); const BridgeTransactionParser = require('bridge-transaction-parser-lovell700'); @@ -135,7 +135,7 @@ const sendFromCow = async (rskTxHelper, recipientAddress, amountInWeis) => { */ const increaseBlockToNextPegoutHeight = async (rskTransactionHelpers) => { const rskTransactionHelper = rskTransactionHelpers[0]; - const bridge = getBridge(rskTransactionHelper.getClient(), await getLatestActiveForkName()); + const bridge = getBridge(rskTransactionHelper.getClient()); const nextPegoutCreationBlockNumber = await bridge.methods.getNextPegoutCreationBlockNumber().call(); const currentBlockNumber = await getMaxBlockNumber(rskTransactionHelpers); const blocksNeededToReachHeight = nextPegoutCreationBlockNumber - currentBlockNumber; @@ -263,11 +263,9 @@ const waitForRskMempoolToGetNewTxs = async (rskTxHelper, maxAttempts = 3, checkE const triggerRelease = async (rskTransactionHelpers, btcClient, callbacks = {}) => { const rskTxHelper = rskTransactionHelpers[rskTransactionHelpers.length - 1]; - const isHop400AlreadyActive = await Runners.common.forks.hop400.isAlreadyActive(); - if (isHop400AlreadyActive) { - await increaseBlockToNextPegoutHeight(rskTransactionHelpers); - } - + + await increaseBlockToNextPegoutHeight(rskTransactionHelpers); + // Adds the pegout to the pegoutsWaitingForConfirmations structure with this 1 confirmation // release_request_received and batch_pegout_created triggered here (if appropriate fork, RSKIP185 and RSKIP271, is/are active) await waitAndUpdateBridge(rskTxHelper); @@ -415,16 +413,12 @@ const findEventInBlock = async (rskTxHelper, eventName, fromBlockHashOrBlockNumb }; const findBridgeTransactionsInThisBlock = async (web3Client, blockHashOrBlockNumber) => { - const isLovell700AlreadyActive = await Runners.common.forks.lovell700.isAlreadyActive() - if (isLovell700AlreadyActive){ - const bridgeTransactionParser = new BridgeTransactionParser(web3Client); - return bridgeTransactionParser.getBridgeTransactionsInThisBlock(blockHashOrBlockNumber); - } + // TODO: uncomment this when lovell700 is active. + // const bridgeTransactionParser = new BridgeTransactionParser(web3Client); + // return bridgeTransactionParser.getBridgeTransactionsInThisBlock(blockHashOrBlockNumber); - const isFingerroot500AlreadyActive = await Runners.common.forks.fingerroot500.isAlreadyActive(); - const bridgeTxParser = isFingerroot500AlreadyActive ? fingerrootBridgeTxParser : hopBridgeTxParser; - return bridgeTxParser.getBridgeTransactionsInThisBlock(web3Client, blockHashOrBlockNumber); + return fingerrootBridgeTxParser.getBridgeTransactionsInThisBlock(web3Client, blockHashOrBlockNumber); } /** @@ -455,35 +449,6 @@ const getFedsPubKeys = async (bridge) => { return FEDS_PUBKEYS_LIST; } -/** Activates the given fork if it's not already active by mining blocks until reach the activation block - * @param {Runners.common.forks[fork]} fork - * @returns {Promise} - */ -const activateFork = async (fork) => { - - const initialForkActivationState = await fork.isAlreadyActive(); - expect(initialForkActivationState, `Fork ${fork.name} already active`).to.be.false; - - const rskTxHelpers = getRskTransactionHelpers(); - const blockNum = await rskTxHelpers[0].getBlockNumber(); - const activationBlock = fork.activationHeight; - - const differenceBlockNumbers = activationBlock - blockNum + 1; // + 1 to be above the activation block - await mineAndSync(rskTxHelpers, differenceBlockNumbers); - const finalForkActivationState = await fork.isAlreadyActive(); - expect(finalForkActivationState, `Fork ${fork.name} is not yet active`).to.be.true; - -}; - -/** - * Get the name of latest fork - * @returns {string} The name of the latest fork - */ -const getLatestForkName = () => { - const forks = Object.values(Runners.common.forks); - return forks[forks.length - 1]; -}; - module.exports = { mineAndSync, waitForBlock, @@ -496,8 +461,6 @@ module.exports = { findEventInBlock, getUnlockedAddress, getFedsPubKeys, - activateFork, - getLatestForkName, getRskMempoolTransactionHashes, waitForRskTxToBeInTheMempool, waitForRskMempoolToGetNewTxs, diff --git a/lib/tests/2wp.js b/lib/tests/2wp.js index 2de59ed7..50333f87 100644 --- a/lib/tests/2wp.js +++ b/lib/tests/2wp.js @@ -3,7 +3,7 @@ const { ensure0x, removePrefix0x} = require('../utils'); const whitelistingAssertions = require('../assertions/whitelisting'); const rskUtils = require('../rsk-utils'); const CustomError = require('../CustomError'); -const { getBridge, getLatestActiveForkName } = require('../precompiled-abi-forks-util'); +const { getBridge } = require('../precompiled-abi-forks-util'); const { getBtcClient } = require('../btc-client-provider'); const { getRskTransactionHelpers, getRskTransactionHelper } = require('../rsk-tx-helper-provider'); const { getDerivedRSKAddressInformation } = require('@rsksmart/btc-rsk-derivation'); @@ -23,14 +23,6 @@ let rskTxHelpers; let federationAddress; let minimumPeginValueInBtc; -/** - * Takes the blockchain to the required state for this test file to run in isolation. - */ -const fulfillRequirementsToRunAsSingleTestFile = async () => { - const forkName = process.env.FORK_NAME || rskUtils.getLatestForkName().name; - await rskUtils.activateFork(Runners.common.forks[forkName]); -}; - const assertPegoutTransactionCreatedEventIsEmitted = async (localRskTxHelper, activeFederationUtxosBeforePegout) => { const pegoutTransactionCreatedEvent = await rskUtils.findEventInBlock(localRskTxHelper, PEGOUT_EVENTS.PEGOUT_TRANSACTION_CREATED); expect(pegoutTransactionCreatedEvent).to.not.be.null; @@ -50,12 +42,8 @@ const execute = (description, getRskHost) => { btcTxHelper = getBtcClient(); rskTxHelper = getRskTransactionHelper(getRskHost()); - if(process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(); - } - // Grab the federation address - const bridge = getBridge(rskTxHelper.getClient(), await getLatestActiveForkName()); + const bridge = getBridge(rskTxHelper.getClient()); federationAddress = await bridge.methods.getFederationAddress().call(); const minimumPeginValueInSatoshis = await bridge.methods.getMinimumLockTxValue().call(); @@ -162,48 +150,31 @@ const execute = (description, getRskHost) => { const activeFederationUtxosBeforePegout = bridgeStateBeforePegout.activeFederationUtxos; const pegoutTransaction = await sendTxToBridge(rskTxHelper, PEGOUT_VALUE_IN_RBTC, recipientRskAddressInfo.address); - const isFingerroot500AlreadyActive = await Runners.common.forks.fingerroot500.isAlreadyActive(); - - const isIris300AlreadyActive = await Runners.common.forks.iris300.isAlreadyActive(); - if (isIris300AlreadyActive) { - const pegoutRequestReceivedEvent = await rskUtils.findEventInBlock(rskTxHelper, PEGOUT_EVENTS.RELEASE_REQUEST_RECEIVED); - expect(pegoutRequestReceivedEvent).to.not.be.null; - const btcDestinationAddress = pegoutRequestReceivedEvent.arguments.btcDestinationAddress; - expect(pegoutRequestReceivedEvent.arguments.sender.toLowerCase()).to.equal(ensure0x(recipientRskAddressInfo.address)); - expect(Number(pegoutRequestReceivedEvent.arguments.amount)).to.equal(pegoutValueInSatoshis); - if(isFingerroot500AlreadyActive) { - // After fingerroot, the btcDestinationAddress is in base58 format - expect(btcAddressInformation.address).to.equal(btcDestinationAddress); - } else { - expect(btcAddressInformation.address).to.equal(ensure0x(btcTxHelper.decodeBase58Address(btcAddressInformation.address))); - } - } + const pegoutRequestReceivedEvent = await rskUtils.findEventInBlock(rskTxHelper, PEGOUT_EVENTS.RELEASE_REQUEST_RECEIVED); + expect(pegoutRequestReceivedEvent).to.not.be.null; + const btcDestinationAddress = pegoutRequestReceivedEvent.arguments.btcDestinationAddress; + expect(pegoutRequestReceivedEvent.arguments.sender.toLowerCase()).to.equal(ensure0x(recipientRskAddressInfo.address)); + expect(Number(pegoutRequestReceivedEvent.arguments.amount)).to.equal(pegoutValueInSatoshis); + expect(btcAddressInformation.address).to.equal(btcDestinationAddress); const pegoutCreatedValidations = async (localRskTxHelper) => { - const isPapyrus200AlreadyActive = await Runners.common.forks.papyrus200.isAlreadyActive(); - if (isPapyrus200AlreadyActive) { - const pegoutRequestedEvent = await rskUtils.findEventInBlock(localRskTxHelper, PEGOUT_EVENTS.RELEASE_REQUESTED); - expect(pegoutRequestedEvent).to.not.be.null; - expect(Number(pegoutRequestedEvent.arguments.amount)).to.equal(pegoutValueInSatoshis); - } - const isHop400AlreadyActive = await Runners.common.forks.hop400.isAlreadyActive(); - if (isHop400AlreadyActive) { - const batchPegoutCreatedEvent = await rskUtils.findEventInBlock(localRskTxHelper, PEGOUT_EVENTS.BATCH_PEGOUT_CREATED); - expect(batchPegoutCreatedEvent).to.not.be.null; - expect(batchPegoutCreatedEvent.arguments.releaseRskTxHashes.includes(pegoutTransaction.transactionHash)).to.be.true; - } - - const isLovell700AlreadyActive = await Runners.common.forks.lovell700.isAlreadyActive(); - if (isLovell700AlreadyActive) { - await assertPegoutTransactionCreatedEventIsEmitted(localRskTxHelper, activeFederationUtxosBeforePegout); - } + + const pegoutRequestedEvent = await rskUtils.findEventInBlock(localRskTxHelper, PEGOUT_EVENTS.RELEASE_REQUESTED); + expect(pegoutRequestedEvent).to.not.be.null; + expect(Number(pegoutRequestedEvent.arguments.amount)).to.equal(pegoutValueInSatoshis); + + const batchPegoutCreatedEvent = await rskUtils.findEventInBlock(localRskTxHelper, PEGOUT_EVENTS.BATCH_PEGOUT_CREATED); + expect(batchPegoutCreatedEvent).to.not.be.null; + expect(batchPegoutCreatedEvent.arguments.releaseRskTxHashes.includes(pegoutTransaction.transactionHash)).to.be.true; + + // TODO: Uncomment this line when lovell700 is active. + // await assertPegoutTransactionCreatedEventIsEmitted(localRskTxHelper, activeFederationUtxosBeforePegout); + }; const pegoutConfirmedValidations = async (localRskTxHelper) => { - if (isFingerroot500AlreadyActive) { - const pegoutConfirmedEvent = await rskUtils.findEventInBlock(localRskTxHelper, PEGOUT_EVENTS.PEGOUT_CONFIRMED); - expect(pegoutConfirmedEvent).to.not.be.null; - } + const pegoutConfirmedEvent = await rskUtils.findEventInBlock(localRskTxHelper, PEGOUT_EVENTS.PEGOUT_CONFIRMED); + expect(pegoutConfirmedEvent).to.not.be.null; }; const callbacks = { @@ -237,21 +208,16 @@ const execute = (description, getRskHost) => { expect(unlocked, 'Account was not unlocked').to.be.true; const pegoutTransaction = await sendTxToBridge(rskTxHelper, PEGOUT_UNDER_MINIMUM_VALUE_IN_BTC, recipientRskAddressInfo.address); - const isIris300AlreadyActive = await Runners.common.forks.iris300.isAlreadyActive(); - if (isIris300AlreadyActive) { - const pegoutRejectedEvent = await rskUtils.findEventInBlock(rskTxHelper, PEGOUT_EVENTS.RELEASE_REQUEST_REJECTED); - expect(pegoutRejectedEvent).to.not.be.null; - const pegoutValueInSatoshis = Number(btcEthUnitConverter.btcToSatoshis(PEGOUT_UNDER_MINIMUM_VALUE_IN_BTC)); - expect(Number(pegoutRejectedEvent.arguments.amount)).to.equal(pegoutValueInSatoshis); - expect(pegoutRejectedEvent.arguments.sender.toLowerCase()).to.equal(ensure0x(recipientRskAddressInfo.address)); - expect(Number(pegoutRejectedEvent.arguments.reason)).to.equal(REJECTED_REASON); - const finalRskAddressBalance = Number(await rskTxHelper.getBalance(recipientRskAddressInfo.address)); - expect(finalRskAddressBalance + pegoutTransaction.gasUsed * 2).to.equal(initialRskAddressBalance); - } else { - const finalRskAddressBalance = Number(await rskTxHelper.getBalance(recipientRskAddressInfo.address)); - // The transaction should have been rejected and the RBTC should be lost - expect(finalRskAddressBalance).to.be.at.most(initialRskAddressBalance - Number(btcEthUnitConverter.btcToWeis(PEGOUT_UNDER_MINIMUM_VALUE_IN_BTC))); - } + + const pegoutRejectedEvent = await rskUtils.findEventInBlock(rskTxHelper, PEGOUT_EVENTS.RELEASE_REQUEST_REJECTED); + expect(pegoutRejectedEvent).to.not.be.null; + const pegoutValueInSatoshis = Number(btcEthUnitConverter.btcToSatoshis(PEGOUT_UNDER_MINIMUM_VALUE_IN_BTC)); + expect(Number(pegoutRejectedEvent.arguments.amount)).to.equal(pegoutValueInSatoshis); + expect(pegoutRejectedEvent.arguments.sender.toLowerCase()).to.equal(ensure0x(recipientRskAddressInfo.address)); + expect(Number(pegoutRejectedEvent.arguments.reason)).to.equal(REJECTED_REASON); + const finalRskAddressBalance = Number(await rskTxHelper.getBalance(recipientRskAddressInfo.address)); + expect(finalRskAddressBalance + pegoutTransaction.gasUsed * 2).to.equal(initialRskAddressBalance); + const finalFederationBalanceInSatoshis = Number(btcEthUnitConverter.btcToSatoshis(await btcTxHelper.getAddressBalance(federationAddress))); expect(finalFederationBalanceInSatoshis).to.equal(initialFederationBalanceInSatoshis); } diff --git a/lib/tests/activate-fork.js b/lib/tests/activate-fork.js deleted file mode 100644 index a6924462..00000000 --- a/lib/tests/activate-fork.js +++ /dev/null @@ -1,29 +0,0 @@ -const { expect } = require('chai'); -const rskUtils = require('../rsk-utils'); -const CustomError = require('../CustomError'); -const { getRskTransactionHelpers } = require('../rsk-tx-helper-provider'); - -const execute = (fork, getFederates) => { - - describe(`Activate ${fork.name} fork`, () => { - - it(`should mine blocks until reach ${fork.activationHeight}th block in order to activate the fork`, async () => { - try { - const rskTransactionHelpers = getRskTransactionHelpers(getFederates()); - const currentBlockNumber = await rskTransactionHelpers[0].getBlockNumber(); - expect(currentBlockNumber).to.be.below(fork.activationHeight); - - // Mine until activation block plus one - const expectedHeight = fork.activationHeight + 1; - const blocksToMine = expectedHeight - currentBlockNumber; - await rskUtils.mineAndSync(rskTransactionHelpers, blocksToMine); - const isForkAlreadyActive = await fork.isAlreadyActive(); - expect(isForkAlreadyActive, `Fork ${fork.name} not yet active`).to.be.true; - } catch (err) { - throw new CustomError('Block mining until reach height to activate fork failure', err); - } - }); - }); -} - -module.exports = { execute }; diff --git a/lib/tests/call_receive_header.js b/lib/tests/call_receive_header.js index 6bcff0c0..391efc10 100644 --- a/lib/tests/call_receive_header.js +++ b/lib/tests/call_receive_header.js @@ -1,8 +1,8 @@ const expect = require('chai').expect; const { getRskTransactionHelper } = require('../rsk-tx-helper-provider'); const { getBtcClient } = require('../btc-client-provider'); -const { getBridge, getLatestActiveForkName } = require('../precompiled-abi-forks-util'); -const { activateFork, sendTxWithCheck, getLatestForkName, waitAndUpdateBridge } = require('../rsk-utils'); +const { getBridge } = require('../precompiled-abi-forks-util'); +const { sendTxWithCheck, waitAndUpdateBridge } = require('../rsk-utils'); const { ensure0x } = require('../utils'); let rskTxHelper; @@ -12,22 +12,13 @@ let bridge; const HEADER_RECEIVED_OK = 0; const RECEIVE_HEADER_CALLED_TOO_SOON = -1; -const fulfillRequirementsToRunAsSingleTestFile = async () => { - const forkName = process.env.FORK_NAME || getLatestForkName().name; - await activateFork(Runners.common.forks[forkName]); -}; - const execute = (description, getRskHost) => { describe(description, function() { before(async () => { rskTxHelper = getRskTransactionHelper(getRskHost()); btcTxHelper = getBtcClient(); - - if(process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(); - } - bridge = getBridge(rskTxHelper.getClient(), await getLatestActiveForkName()); + bridge = getBridge(rskTxHelper.getClient()); }); it('should return 0 and increment BTC blockchain size when calling receiveHeader method', async () => { diff --git a/lib/tests/call_receive_headers.js b/lib/tests/call_receive_headers.js index b9e437bc..18e10fe1 100644 --- a/lib/tests/call_receive_headers.js +++ b/lib/tests/call_receive_headers.js @@ -1,21 +1,13 @@ const expect = require('chai').expect; const { getRskTransactionHelper } = require('../rsk-tx-helper-provider'); const { getBtcClient } = require('../btc-client-provider'); -const { getBridge, getLatestActiveForkName } = require('../precompiled-abi-forks-util'); -const { activateFork, sendTxWithCheck, getLatestForkName, waitAndUpdateBridge } = require('../rsk-utils'); +const { getBridge } = require('../precompiled-abi-forks-util'); +const { sendTxWithCheck, waitAndUpdateBridge } = require('../rsk-utils'); const { ensure0x } = require('../utils'); let rskTxHelper; let btcTxHelper; -/** - * Takes the blockchain to the required state for this test file to run in isolation. - */ -const fulfillRequirementsToRunAsSingleTestFile = async () => { - const forkName = process.env.FORK_NAME || getLatestForkName().name; - await activateFork(Runners.common.forks[forkName]); -}; - const execute = (description, getRskHost) => { describe(description, function() { @@ -23,13 +15,10 @@ const execute = (description, getRskHost) => { rskTxHelper = getRskTransactionHelper(getRskHost()); btcTxHelper = getBtcClient(); - if(process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(); - } }); it('Calling receiveHeaders method with regular user should not increment BTC blockchain size', async () => { - const bridge = getBridge(rskTxHelper.getClient(), await getLatestActiveForkName()); + const bridge = getBridge(rskTxHelper.getClient()); await waitAndUpdateBridge(rskTxHelper); const blockNumberInitial = await bridge.methods.getBtcBlockchainBestChainHeight().call(); diff --git a/singleTestFileRunner.js b/singleTestFileRunner.js index 13fa5e6f..f95fab0f 100644 --- a/singleTestFileRunner.js +++ b/singleTestFileRunner.js @@ -4,22 +4,14 @@ const shell = require('shelljs'); const testFileNameWithJsExtension = process.argv[2]; -const forkName = process.argv[3] || ''; - console.log(`Executing test file '${testFileNameWithJsExtension}' in isolation.`); -if(forkName) { - console.log(`Using fork '${forkName}'.`); -} - // Including this test file to be the only one to be executed process.env.INCLUDE_CASES = testFileNameWithJsExtension; // Setting this flag to make the test file know it is being run in isolation and do the necessary adjustments process.env.RUNNING_SINGLE_TEST_FILE = true; -process.env.FORK_NAME = forkName; - if (shell.exec('npm run test-fail-fast').code !== 0) { console.error(`Test file '${testFileNameWithJsExtension}' failed to run.`); } else { @@ -29,4 +21,3 @@ if (shell.exec('npm run test-fail-fast').code !== 0) { // Just to make sure we leave everything as we found it process.env.RUNNING_SINGLE_TEST_FILE = false; -process.env.FORK_NAME = ''; diff --git a/test.js b/test.js index f2b26e61..848736a3 100644 --- a/test.js +++ b/test.js @@ -42,54 +42,22 @@ const bookkeepingConfigurations = { blockHeadersToSend: 27 }; -/** - * Creates a fork object with the provided name and activation height. - * The fork object will have a method called `isAlreadyActive` to check if the fork is already active, - * which will get the latest block number and compare it with the `activationHeight` and cache the result to avoid calling the blockchain again - * if the fork is already active because a fork is activated only once. - * @param {string} name - * @param {number} activationHeight - * @returns {{name: string, activationHeight: number, isAlreadyActive: function(RskTransactionHelper): Promise}} - */ -const createForkObject = (name, activationHeight) => { - // 'Private' variable to hold if the fork is already active - let isActive = false; - - async function isAlreadyActive(rskTxHelper) { - // If the fork is already active, then return the cached result - if(isActive) { - return isActive; - } - rskTxHelper = rskTxHelper || getRskTransactionHelper(); - // Cache the result to avoid calling the network again if the fork is already active - const latestBlockNumber = await rskTxHelper.getBlockNumber(); - isActive = latestBlockNumber >= this.activationHeight; - return isActive; - } - - return { - name, - activationHeight, - isAlreadyActive, - }; - -}; - // ***** GLOBALS ***** // +// If this is updated and more forks are added, remember to update './lib/precompiled-abi-forks-util.js' accordingly. global.Runners = { hosts: {}, common: { forks: { - orchid: createForkObject('orchid', 1), - wasabi100: createForkObject('wasabi', 1), - papyrus200: createForkObject('papyrus', 1), - iris300: createForkObject('iris', 1), - hop400: createForkObject('hop', 1), - hop401: createForkObject('hop401', 1), - fingerroot500: createForkObject('fingerroot', 1), - arrowhead600: createForkObject('arrowhead', 1), - arrowhead631: createForkObject('arrowhead631', 1), - lovell700: createForkObject('lovell', -1), + orchid: 1, + wasabi100: 1, + papyrus200: 1, + iris300: 1, + hop400: 1, + hop401: 1, + fingerroot500: 1, + arrowhead600: 1, + arrowhead631: 1, + lovell700: -1, }, additionalFederationAddresses: [] } diff --git a/tests/01_01_03-pre_orchid_lock_whitelist_fork.js b/tests/01_01_03-pre_orchid_lock_whitelist_fork.js index 02e65a26..07d56746 100644 --- a/tests/01_01_03-pre_orchid_lock_whitelist_fork.js +++ b/tests/01_01_03-pre_orchid_lock_whitelist_fork.js @@ -1,5 +1,5 @@ const whitelistingAssertions = require('../lib/assertions/whitelisting'); -const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); const contractMethodAssertions = require('../lib/assertions/contractMethods'); const expect = require('chai').expect; const CustomError = require('../lib/CustomError'); @@ -20,7 +20,7 @@ describe('RFS-170 test before fork', () => { before(async () => { rskTxHelper = getRskTransactionHelper(); - bridge = getBridge(rskTxHelper.getClient(), await getLatestActiveForkName()); + bridge = getBridge(rskTxHelper.getClient()); }); it(`should be at a height lower than ${RFS_170_ACTIVATION_BLOCK}`, async () => { diff --git a/tests/01_01_50-activate_orchid_fork.js b/tests/01_01_50-activate_orchid_fork.js deleted file mode 100644 index f1380e45..00000000 --- a/tests/01_01_50-activate_orchid_fork.js +++ /dev/null @@ -1,6 +0,0 @@ -const activateForkTest = require('../lib/tests/activate-fork'); - -activateForkTest.execute( - Runners.common.forks.orchid, - () => Runners.hosts.federates -); \ No newline at end of file diff --git a/tests/01_01_52-post_orchid_lock_whitelist_fork.js b/tests/01_01_52-post_orchid_lock_whitelist_fork.js index ebebdfc0..72347102 100644 --- a/tests/01_01_52-post_orchid_lock_whitelist_fork.js +++ b/tests/01_01_52-post_orchid_lock_whitelist_fork.js @@ -2,7 +2,7 @@ const whitelistingAssertions = require('../lib/assertions/whitelisting'); const contractMethodAssertions = require('../lib/assertions/contractMethods'); const { getBtcClient } = require('../lib/btc-client-provider'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); -const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); const WHITELIST_ADDRESSES = { 'mq4w7mWwCtCURdbB3m3EVXqtJiVBdXcEaK' : 100000000000, @@ -22,7 +22,7 @@ describe('RFS-170 test after fork', () => { btcTxHelper = getBtcClient(); rskTxHelpers = getRskTransactionHelpers(); rskTxHelper = rskTxHelpers[0]; - bridge = getBridge(await getLatestActiveForkName()); + bridge = getBridge(rskTxHelper.getClient()); }); diff --git a/tests/01_02_01-pre_wasabi_fed_pubkeys_fork.js b/tests/01_02_01-pre_wasabi_fed_pubkeys_fork.js index f417f859..67f68df6 100644 --- a/tests/01_02_01-pre_wasabi_fed_pubkeys_fork.js +++ b/tests/01_02_01-pre_wasabi_fed_pubkeys_fork.js @@ -3,7 +3,7 @@ const expect = require('chai').expect; const { assertIsPublicKey } = require('../lib/assertions/misc'); const { KEY_TYPE_BTC } = require('../lib/constants'); const CustomError = require('../lib/CustomError'); -const { getBridge, getPreForkName } = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); const { getRskTransactionHelper } = require('../lib/rsk-tx-helper-provider'); const RANDOM_PUBLIC_KEY = '0x02f9284f96eb093918a9da825111aec70a51152800e60249ac156ac35d2fa771ba'; @@ -21,8 +21,8 @@ describe('Multiple federation member keys test before fork', () => { before(async () => { rskTxHelper = getRskTransactionHelper(); fedChangeAddress = await rskTxHelper.importAccount(FEDERATION_CHANGE_PK, ''); - preWasabiBridge = getBridge(rskTxHelper.getClient(), getPreForkName(Runners.common.forks.wasabi100.name)); - postWasabiBridge = getBridge(rskTxHelper.getClient(), Runners.common.forks.wasabi100.name); + preWasabiBridge = getBridge(rskTxHelper.getClient()); + postWasabiBridge = getBridge(rskTxHelper.getClient()); }); it(`should be at a height lower than ${ACTIVATION_BLOCK}`, async () => { diff --git a/tests/01_02_50-activate_wasabi_fork.js b/tests/01_02_50-activate_wasabi_fork.js deleted file mode 100644 index 6d8547d7..00000000 --- a/tests/01_02_50-activate_wasabi_fork.js +++ /dev/null @@ -1,6 +0,0 @@ -const activateForkTest = require('../lib/tests/activate-fork'); - -activateForkTest.execute( - Runners.common.forks.wasabi100, - () => Runners.hosts.federates -); \ No newline at end of file diff --git a/tests/01_02_51-post_wasabi_fed_pubkeys_fork.js b/tests/01_02_51-post_wasabi_fed_pubkeys_fork.js index 5aab0a17..e0f90508 100644 --- a/tests/01_02_51-post_wasabi_fed_pubkeys_fork.js +++ b/tests/01_02_51-post_wasabi_fed_pubkeys_fork.js @@ -3,9 +3,8 @@ const expect = require('chai').expect; const { assertIsPublicKey } = require('../lib/assertions/misc'); const { KEY_TYPE_BTC } = require('../lib/constants'); const CustomError = require('../lib/CustomError'); -const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); const { getRskTransactionHelper } = require('../lib/rsk-tx-helper-provider'); -const { activateFork } = require('../lib/rsk-utils'); const RANDOM_PUBLIC_KEY = '0x02f9284f96eb093918a9da825111aec70a51152800e60249ac156ac35d2fa771ba'; const FEDERATION_CHANGE_PK = 'c14991a187e185ca1442e75eb8f60a6a5efd4ca57ce31e50d6e841d9381e996b'; @@ -14,13 +13,6 @@ let rskTxHelper; let fedChangeAddress; let bridge; -/** - * Takes the blockchain to the required state for this test file to run in isolation. - */ -const fulfillRequirementsToRunAsSingleTestFile = async () => { - await activateFork(Runners.common.forks.wasabi100); -}; - describe('Multiple federation member keys test after fork', () => { const ACTIVATION_BLOCK = Runners.common.forks.wasabi100.activationHeight; @@ -28,10 +20,7 @@ describe('Multiple federation member keys test after fork', () => { before(async () => { rskTxHelper = getRskTransactionHelper(); fedChangeAddress = await rskTxHelper.importAccount(FEDERATION_CHANGE_PK); - if(process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(); - } - bridge = getBridge(rskTxHelper.getClient(), await getLatestActiveForkName()); + bridge = getBridge(rskTxHelper.getClient()); }); it(`should be at a height higher than ${ACTIVATION_BLOCK}`, async () => { diff --git a/tests/01_03_01-lock_whitelist_pre_papyrus.js b/tests/01_03_01-lock_whitelist_pre_papyrus.js index c3076dcc..bae11d45 100644 --- a/tests/01_03_01-lock_whitelist_pre_papyrus.js +++ b/tests/01_03_01-lock_whitelist_pre_papyrus.js @@ -14,7 +14,7 @@ const { getBtcClient } = require('../lib/btc-client-provider'); const { sendPegin, ensurePeginIsRegistered } = require('../lib/2wp-utils'); const { getDerivedRSKAddressInformation } = require('@rsksmart/btc-rsk-derivation'); const { btcToWeis, btcToSatoshis, satoshisToBtc } = require('@rsksmart/btc-eth-unit-converter'); -const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); const { waitAndUpdateBridge } = require('../lib/rsk-utils'); let rskTxHelpers; @@ -36,13 +36,6 @@ const WHITELIST_ADDRESSES = { const WHITELIST_RANDOM_PUBLIC_KEY = 'msJRGyaYvT8YNjvU3q9nPgBpZj9umAgetn'; -/** - * Takes the blockchain to the required state for this test file to run in isolation. - */ -const fulfillRequirementsToRunAsSingleTestFile = async () => { - await rskUtils.activateFork(Runners.common.forks.wasabi100); -}; - const assertLockCreatingWhiteListAddress = async (rskTxHelper, btcTxHelper, useUnlimitedWhitelist) => { const minPeginValueInSatoshis = await bridge.methods.getMinimumLockTxValue().call(); const minPeginValueInBtc = Number(satoshisToBtc(minPeginValueInSatoshis)); @@ -84,14 +77,10 @@ const assertNonMatchedAmountsExist = (testCaseAmounts, peginBtcTx, returnTx) => describe('Lock whitelisting', () => { before(async () => { - if(process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(); - } - rskTxHelpers = getRskTransactionHelpers(); btcTxHelper = getBtcClient(); rskTxHelper = rskTxHelpers[0]; - bridge = getBridge(rskTxHelper.getClient(), await getLatestActiveForkName()); + bridge = getBridge(rskTxHelper.getClient()); federationAddress = await bridge.methods.getFederationAddress().call(); await btcTxHelper.importAddress(federationAddress, 'federations'); diff --git a/tests/01_03_04-2wp_segwit_not_compatible.js b/tests/01_03_04-2wp_segwit_not_compatible.js index 5390b939..d0dc0290 100644 --- a/tests/01_03_04-2wp_segwit_not_compatible.js +++ b/tests/01_03_04-2wp_segwit_not_compatible.js @@ -4,31 +4,22 @@ const rskUtils = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBtcClient } = require('../lib/btc-client-provider'); const { sendPegin } = require('../lib/2wp-utils'); -const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); const { isUtxoRegisteredInBridge } = require('../lib/2wp-utils'); let rskTxHelpers; let rskTxHelper; let btcTxHelper; -const fulfillRequirementsToRunAsSingleTestFile = async () => { - await rskUtils.activateFork(Runners.common.forks.wasabi100); -}; - describe('Lock p2sh-p2wpkh address', () => { before(async () => { rskTxHelpers = getRskTransactionHelpers(); rskTxHelper = rskTxHelpers[0]; btcTxHelper = getBtcClient() - - if(process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(); - } }); it('lock should fail when using p2sh-p2wpkh address', async () => { - const latestActiveForkName = await getLatestActiveForkName(); - const bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); + const bridge = getBridge(rskTxHelper.getClient()); const minimumPeginValueInSatoshis = await bridge.methods.getMinimumLockTxValue().call(); const minimumPeginValueInBtc = Number(satoshisToBtc(minimumPeginValueInSatoshis)); diff --git a/tests/01_03_05-2wp_multisig_not_compatible.js b/tests/01_03_05-2wp_multisig_not_compatible.js index 08f9d903..4886731a 100644 --- a/tests/01_03_05-2wp_multisig_not_compatible.js +++ b/tests/01_03_05-2wp_multisig_not_compatible.js @@ -1,35 +1,25 @@ const expect = require('chai').expect const { satoshisToBtc } = require('@rsksmart/btc-eth-unit-converter'); -const rskUtils = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBtcClient } = require('../lib/btc-client-provider'); const { sendPegin } = require('../lib/2wp-utils'); -const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); const { isUtxoRegisteredInBridge } = require('../lib/2wp-utils'); let rskTxHelpers; let rskTxHelper; let btcTxHelper; -const fulfillRequirementsToRunAsSingleTestFile = async () => { - await rskUtils.activateFork(Runners.common.forks.wasabi100); -}; - describe('Peg-in multisig address', () => { before(async () => { rskTxHelpers = getRskTransactionHelpers(); rskTxHelper = rskTxHelpers[0]; btcTxHelper = getBtcClient() - - if(process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(); - } }); // Should fail and not refund when sending a pengin from a multisig address pre papyrus it('Peg-in should fail when using multisig address', async () => { - const latestActiveForkName = await getLatestActiveForkName(); - const bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); + const bridge = getBridge(rskTxHelper.getClient()); const minimumPeginValueInSatoshis = await bridge.methods.getMinimumLockTxValue().call(); const minimumPeginValueInBtc = Number(satoshisToBtc(minimumPeginValueInSatoshis)); diff --git a/tests/01_03_06-2wp_no_locking_cap.js b/tests/01_03_06-2wp_no_locking_cap.js index d8a95b91..0ea0672c 100644 --- a/tests/01_03_06-2wp_no_locking_cap.js +++ b/tests/01_03_06-2wp_no_locking_cap.js @@ -3,7 +3,7 @@ const rskUtils = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBtcClient } = require('../lib/btc-client-provider'); const { sendPegin, ensurePeginIsRegistered, sendTxToBridge } = require('../lib/2wp-utils'); -const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); const { getDerivedRSKAddressInformation } = require('@rsksmart/btc-rsk-derivation'); const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); const whitelistingAssertions = require('../lib/assertions/whitelisting'); @@ -17,19 +17,11 @@ describe('Transfer BTC to RBTC before papyrus200', function() { const PEGIN_VALUE_IN_BTC = 3; const PEGOUT_VALUE_IN_RBTC = PEGIN_VALUE_IN_BTC / 3; const RSK_TX_FEE_IN_RBTC = 0.001; - - const fulfillRequirementsToRunAsSingleTestFile = async () => { - await rskUtils.activateFork(Runners.common.forks.wasabi100); - }; before(async () => { rskTxHelpers = getRskTransactionHelpers(); rskTxHelper = rskTxHelpers[0]; btcTxHelper = getBtcClient(); - - if(process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(); - }; }); @@ -43,8 +35,7 @@ describe('Transfer BTC to RBTC before papyrus200', function() { const unlocked = await rskTxHelper.unlockAccount(recipientRskAddressInfo.address); expect(unlocked, 'Account was not unlocked').to.be.true; - const latestActiveForkName = await getLatestActiveForkName(); - const bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); + const bridge = getBridge(rskTxHelper.getClient()); const federationAddress = await bridge.methods.getFederationAddress().call(); const federationAddressBalanceInitial = Number(await btcTxHelper.getAddressBalance(federationAddress)); diff --git a/tests/01_03_50-activate_papyrus_fork.js b/tests/01_03_50-activate_papyrus_fork.js deleted file mode 100644 index 107cbad8..00000000 --- a/tests/01_03_50-activate_papyrus_fork.js +++ /dev/null @@ -1,6 +0,0 @@ -const activateForkTest = require('../lib/tests/activate-fork'); - -activateForkTest.execute( - Runners.common.forks.papyrus200, - () => Runners.hosts.federates -); diff --git a/tests/01_03_52-disable_lock_whitelist.js b/tests/01_03_52-disable_lock_whitelist.js new file mode 100644 index 00000000..d01472a3 --- /dev/null +++ b/tests/01_03_52-disable_lock_whitelist.js @@ -0,0 +1,99 @@ +const expect = require('chai').expect +const rskUtils = require('../lib/rsk-utils'); +const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); +const { getBtcClient } = require('../lib/btc-client-provider'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); +const { satoshisToBtc, btcToSatoshis, satoshisToWeis } = require('@rsksmart/btc-eth-unit-converter'); +const { sendPegin, ensurePeginIsRegistered } = require('../lib/2wp-utils'); +const { getDerivedRSKAddressInformation } = require('@rsksmart/btc-rsk-derivation'); + +const { WHITELIST_CHANGE_PK, WHITELIST_CHANGE_ADDR} = require('../lib/assertions/whitelisting') + +let rskTxHelpers; +let rskTxHelper; +let btcTxHelper; +let bridge; +let federationAddress; +let MINIMUM_PEGIN_VALUE_IN_BTC; +let MINIMUM_PEGIN_VALUE_IN_SATS; +let WHITELIST_DISABLE_BLOCK_DELAY; +let FEE_IN_SATOSHI; +const DELAY_SET_SUCCSSFULY = 1; + +describe('Disable whitelisting', function() { + + before(async () => { + rskTxHelpers = getRskTransactionHelpers(); + rskTxHelper = rskTxHelpers[0]; + btcTxHelper = getBtcClient(); + + bridge = getBridge(rskTxHelper.getClient()); + federationAddress = await bridge.methods.getFederationAddress().call(); + MINIMUM_PEGIN_VALUE_IN_SATS = await bridge.methods.getMinimumLockTxValue().call(); + MINIMUM_PEGIN_VALUE_IN_BTC = Number(satoshisToBtc(MINIMUM_PEGIN_VALUE_IN_SATS)); + WHITELIST_DISABLE_BLOCK_DELAY = 20; + FEE_IN_SATOSHI = btcToSatoshis(btcTxHelper.getFee()) + }); + + it('should disable lock whitelist', async () => { + const btcAddressInfo = await btcTxHelper.generateBtcAddress('legacy'); + const btcAmountToFund = 2 * MINIMUM_PEGIN_VALUE_IN_BTC + 2 * btcTxHelper.getFee(); + await btcTxHelper.fundAddress(btcAddressInfo.address, btcAmountToFund); + const btcAddressBalanceInitial = Number(btcToSatoshis(await btcTxHelper.getAddressBalance(btcAddressInfo.address))); + expect(btcAddressBalanceInitial).to.be.equal(Number(btcToSatoshis(btcAmountToFund))); + + const federationAddressBalanceInitial = Number(await btcTxHelper.getAddressBalance(federationAddress)); + + // address is not whitelisted + await sendPegin(rskTxHelper, btcTxHelper, btcAddressInfo, MINIMUM_PEGIN_VALUE_IN_BTC); + const btcAddressBalanceAfterFirstPegin = Number(btcToSatoshis(await btcTxHelper.getAddressBalance(btcAddressInfo.address))); + expect(btcAddressBalanceAfterFirstPegin).to.be.equal(btcAddressBalanceInitial - MINIMUM_PEGIN_VALUE_IN_SATS - FEE_IN_SATOSHI); + const federationAddressBalanceAfterFirstPegin = Number(await btcTxHelper.getAddressBalance(federationAddress)); + expect(federationAddressBalanceAfterFirstPegin).to.be.equal(federationAddressBalanceInitial + MINIMUM_PEGIN_VALUE_IN_BTC) + + // wait for the btc to come back so we can use the sendPegin method again + await rskUtils.triggerRelease(rskTxHelpers, btcTxHelper); + const btcAddressBalanceAfterFirstTriggerRelease = Number(btcToSatoshis(await btcTxHelper.getAddressBalance(btcAddressInfo.address))); + expect(btcAddressBalanceInitial - btcAddressBalanceAfterFirstTriggerRelease).to.be.at.most(FEE_IN_SATOSHI * 2) + const federationAddressBalanceAfterFirstTriggerRelease = Number(await btcTxHelper.getAddressBalance(federationAddress)); + expect(federationAddressBalanceAfterFirstTriggerRelease).to.be.equal(federationAddressBalanceInitial) + + // disable whitelisting after 20 blocks + const unlocked = await rskUtils.getUnlockedAddress(rskTxHelper, WHITELIST_CHANGE_PK, WHITELIST_CHANGE_ADDR); + expect(unlocked).to.be.true; + const disableLockWhitelistMethod = bridge.methods.setLockWhitelistDisableBlockDelay(WHITELIST_DISABLE_BLOCK_DELAY); + const disableResultCallback = (disableResult) => expect(Number(disableResult)).to.equal(DELAY_SET_SUCCSSFULY); + await rskUtils.sendTxWithCheck(rskTxHelper, disableLockWhitelistMethod, WHITELIST_CHANGE_ADDR, disableResultCallback); + + await btcTxHelper.mine(WHITELIST_DISABLE_BLOCK_DELAY / 2); + await rskUtils.waitAndUpdateBridge(rskTxHelper); + + // address is still not able to send btc to bridge after 10 blocks + await sendPegin(rskTxHelper, btcTxHelper, btcAddressInfo, MINIMUM_PEGIN_VALUE_IN_BTC); + const btcAddressBalanceAfterSecondPegin = Number(btcToSatoshis(await btcTxHelper.getAddressBalance(btcAddressInfo.address))); + expect(btcAddressBalanceAfterFirstTriggerRelease - btcAddressBalanceAfterSecondPegin).to.be.at.most(Number(MINIMUM_PEGIN_VALUE_IN_SATS + FEE_IN_SATOSHI * 2)) + const federationAddressBalanceAfterSecondPegin = Number(await btcTxHelper.getAddressBalance(federationAddress)); + expect(federationAddressBalanceAfterSecondPegin).to.be.equal(federationAddressBalanceInitial + MINIMUM_PEGIN_VALUE_IN_BTC) + + await rskUtils.triggerRelease(rskTxHelpers, btcTxHelper); + const btcAddressBalanceAfterSecondTriggerRelease = Number(btcToSatoshis(await btcTxHelper.getAddressBalance(btcAddressInfo.address))); + expect(btcAddressBalanceAfterFirstTriggerRelease - btcAddressBalanceAfterSecondTriggerRelease).to.be.at.most(FEE_IN_SATOSHI * 2) + const federationAddressBalanceAfterSecondTriggerRelease = Number(await btcTxHelper.getAddressBalance(federationAddress)); + expect(federationAddressBalanceAfterSecondTriggerRelease).to.be.equal(federationAddressBalanceInitial) + + await btcTxHelper.mine(WHITELIST_DISABLE_BLOCK_DELAY / 2); + await rskUtils.waitAndUpdateBridge(rskTxHelper); + + // after 20 blocks the whitelist period has ended and we can send money to the bridge + const peginBtcTxHash = await sendPegin(rskTxHelper, btcTxHelper, btcAddressInfo, MINIMUM_PEGIN_VALUE_IN_BTC); + await rskUtils.triggerRelease(rskTxHelpers, btcTxHelper); + await ensurePeginIsRegistered(rskTxHelper, peginBtcTxHash); + + const federationAddressBalanceAfterPegin = Number(await btcTxHelper.getAddressBalance(federationAddress)); + expect(Number(federationAddressBalanceAfterPegin)).to.be.equal(Number(federationAddressBalanceInitial + MINIMUM_PEGIN_VALUE_IN_BTC)); + + const recipientRskAddressInfo = getDerivedRSKAddressInformation(btcAddressInfo.privateKey, btcTxHelper.btcConfig.network); + const recipientRskAddressBalance = Number(await rskTxHelper.getBalance(recipientRskAddressInfo.address)); + expect(recipientRskAddressBalance).to.be.equal(Number(satoshisToWeis(MINIMUM_PEGIN_VALUE_IN_SATS))); + }); +}); diff --git a/tests/01_03_54-post-papyrus_coinbase_information.js b/tests/01_03_54-post-papyrus_coinbase_information.js index 236a1300..3d8676be 100644 --- a/tests/01_03_54-post-papyrus_coinbase_information.js +++ b/tests/01_03_54-post-papyrus_coinbase_information.js @@ -3,7 +3,7 @@ const bitcoinJs = require('bitcoinjs-lib'); const rskUtils = require('../lib/rsk-utils'); const { wait, ensure0x, retryWithCheck } = require('../lib/utils'); const CustomError = require('../lib/CustomError'); -const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); const { getBtcClient } = require('../lib//btc-client-provider'); const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); @@ -50,7 +50,7 @@ describe('Calling coinbase information methods after papyrus', () => { const pmt = `0100000001${coinbaseTx.getHash().toString('hex')}0101`; - const bridge = getBridge(rskTxHelper.getClient(), await getLatestActiveForkName()); + const bridge = getBridge(rskTxHelper.getClient()); const registerBtcCoinbaseTransactionMethod = bridge.methods.registerBtcCoinbaseTransaction( ensure0x(coinbaseTxWithoutWitness.toHex()), diff --git a/tests/01_04_50-activate_iris_fork.js b/tests/01_04_50-activate_iris_fork.js deleted file mode 100644 index f00301f9..00000000 --- a/tests/01_04_50-activate_iris_fork.js +++ /dev/null @@ -1,6 +0,0 @@ -const activateForkTest = require('../lib/tests/activate-fork'); - -activateForkTest.execute( - Runners.common.forks.iris300, - () => Runners.hosts.federates -); diff --git a/tests/01_04_51-post_iris_register_flyover_btc_transaction.js b/tests/01_04_51-post_iris_register_flyover_btc_transaction.js index 0ec3b522..083bd6c4 100644 --- a/tests/01_04_51-post_iris_register_flyover_btc_transaction.js +++ b/tests/01_04_51-post_iris_register_flyover_btc_transaction.js @@ -3,7 +3,7 @@ const redeemScriptParser = require('@rsksmart/powpeg-redeemscript-parser'); const { ensure0x, additionalFederationAddresses, } = require('../lib/utils'); const { fundAddressAndGetData } = require('../lib/btc-utils'); const lbc = require('../lib/liquidity-bridge-contract'); -const { sendTxWithCheck, getFedsPubKeys, activateFork } = require('../lib/rsk-utils'); +const { sendTxWithCheck, getFedsPubKeys } = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBridge } = require('../lib/precompiled-abi-forks-util'); const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); @@ -16,22 +16,12 @@ let rskTxHelper; let btcTxHelper; let bridge; -/** - * Takes the blockchain to the required state for this test file to run in isolation. - */ -const fulfillRequirementsToRunAsSingleTestFile = async () => { - await activateFork(Runners.common.forks.iris300); -}; - describe('Calling registerFastBtcTransaction after iris', () => { before(async () => { rskTxHelpers = getRskTransactionHelpers(); rskTxHelper = rskTxHelpers[0]; btcTxHelper = getBtcClient(); - if(process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(); - } bridge = getBridge(rskTxHelper.getClient(), Runners.common.forks.iris300.name); }); diff --git a/tests/01_04_53-post_iris_register_fast_btc_transaction_surpass_locking_cap.js b/tests/01_04_53-post_iris_register_fast_btc_transaction_surpass_locking_cap.js index 3e2f17cc..05584018 100644 --- a/tests/01_04_53-post_iris_register_fast_btc_transaction_surpass_locking_cap.js +++ b/tests/01_04_53-post_iris_register_fast_btc_transaction_surpass_locking_cap.js @@ -3,22 +3,15 @@ const redeemScriptParser = require('@rsksmart/powpeg-redeemscript-parser'); const CustomError = require('../lib/CustomError'); const lbc = require('../lib/liquidity-bridge-contract'); const { REFUNDED_USER_ERROR } = require("../lib/flyover-pegin-response-codes"); -const { sendTxWithCheck, triggerRelease, getFedsPubKeys, activateFork } = require('../lib/rsk-utils'); +const { sendTxWithCheck, triggerRelease, getFedsPubKeys } = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBtcClient } = require('../lib/btc-client-provider'); const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); const { ensure0x, wait } = require('../lib/utils'); const { fundAddressAndGetData } = require('../lib/btc-utils'); -const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); const { mineForPeginRegistration } = require('../lib/2wp-utils'); -/** - * Takes the blockchain to the required state for this test file to run in isolation. - */ -const fulfillRequirementsToRunAsSingleTestFile = async () => { - await activateFork(Runners.common.forks.iris300); -}; - describe('Executing registerFastBtcTransaction after iris - with release', () => { let rskTxHelpers; @@ -30,13 +23,7 @@ describe('Executing registerFastBtcTransaction after iris - with release', () => rskTxHelpers = getRskTransactionHelpers(); rskTxHelper = rskTxHelpers[0]; btcTxHelper = getBtcClient(); - - if(process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(); - } - const latestActiveForkName = await getLatestActiveForkName(); - bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); - + bridge = getBridge(rskTxHelper.getClient()); }); it('should return funds when calling registerFastBtcTransaction method surpassing locking cap', async () => { diff --git a/tests/01_04_56-post_iris_flyover_sending_same_tx_without_witness_twice.js b/tests/01_04_56-post_iris_flyover_sending_same_tx_without_witness_twice.js index aac0ab3e..786c0cd3 100644 --- a/tests/01_04_56-post_iris_flyover_sending_same_tx_without_witness_twice.js +++ b/tests/01_04_56-post_iris_flyover_sending_same_tx_without_witness_twice.js @@ -3,22 +3,15 @@ const redeemScriptParser = require('@rsksmart/powpeg-redeemscript-parser'); const {UNPROCESSABLE_TX_ALREADY_PROCESSED_ERROR} = require("../lib/flyover-pegin-response-codes"); const CustomError = require('../lib/CustomError'); const lbc = require('../lib/liquidity-bridge-contract'); -const { sendTxWithCheck, getFedsPubKeys, activateFork } = require('../lib/rsk-utils'); +const { sendTxWithCheck, getFedsPubKeys } = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBtcClient } = require('../lib/btc-client-provider'); const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); const { ensure0x } = require('../lib/utils'); const { fundAddressAndGetData } = require('../lib/btc-utils'); -const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); const { mineForPeginRegistration } = require('../lib/2wp-utils'); -/** - * Takes the blockchain to the required state for this test file to run in isolation. - */ -const fulfillRequirementsToRunAsSingleTestFile = async () => { - await activateFork(Runners.common.forks.iris300); -}; - describe('Executing registerFastBtcTransaction post hop - sending same tx without witness twice', () => { let rskTxHelpers; @@ -30,13 +23,7 @@ describe('Executing registerFastBtcTransaction post hop - sending same tx withou rskTxHelpers = getRskTransactionHelpers(); rskTxHelper = rskTxHelpers[0]; btcTxHelper = getBtcClient(); - - if(process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(); - } - const latestActiveForkName = await getLatestActiveForkName(); - bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); - + bridge = getBridge(rskTxHelper.getClient()); }); it(`should execute first tx successfully and fail executing second tx due to hash already used when calling registerFastBtcTransaction sending same tx twice`, async () => { diff --git a/tests/01_04_57-post_iris_flyover_sending_same_tx_with_witness_twice.js b/tests/01_04_57-post_iris_flyover_sending_same_tx_with_witness_twice.js index 49fa13dd..a466f0b2 100644 --- a/tests/01_04_57-post_iris_flyover_sending_same_tx_with_witness_twice.js +++ b/tests/01_04_57-post_iris_flyover_sending_same_tx_with_witness_twice.js @@ -4,21 +4,14 @@ const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); const { UNPROCESSABLE_TX_ALREADY_PROCESSED_ERROR } = require("../lib/flyover-pegin-response-codes"); const CustomError = require('../lib/CustomError'); const lbc = require('../lib/liquidity-bridge-contract'); -const { sendTxWithCheck, getFedsPubKeys, activateFork } = require('../lib/rsk-utils'); +const { sendTxWithCheck, getFedsPubKeys } = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBtcClient } = require('../lib/btc-client-provider'); const { ensure0x } = require('../lib/utils'); const { fundAddressAndGetData } = require('../lib/btc-utils'); -const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); const { mineForPeginRegistration } = require('../lib/2wp-utils'); -/** - * Takes the blockchain to the required state for this test file to run in isolation. - */ -const fulfillRequirementsToRunAsSingleTestFile = async () => { - await activateFork(Runners.common.forks.iris300); -}; - describe('Executing registerFastBtcTransaction post hop - sending same tx with witness twice', () => { let rskTxHelpers; @@ -30,13 +23,7 @@ describe('Executing registerFastBtcTransaction post hop - sending same tx with w rskTxHelpers = getRskTransactionHelpers(); rskTxHelper = rskTxHelpers[0]; btcTxHelper = getBtcClient(); - - if(process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(); - } - const latestActiveForkName = await getLatestActiveForkName(); - bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); - + bridge = getBridge(rskTxHelper.getClient()); }); it(`should execute first tx successfully and fail executing second tx due to hash already used when calling registerFastBtcTransaction sending same tx twice`, async () => { diff --git a/tests/01_04_58-post_iris_flyover_surpassing_locking_cap_sending_same_tx_with_witness_twice.js b/tests/01_04_58-post_iris_flyover_surpassing_locking_cap_sending_same_tx_with_witness_twice.js index 04af2f4c..da6ad140 100644 --- a/tests/01_04_58-post_iris_flyover_surpassing_locking_cap_sending_same_tx_with_witness_twice.js +++ b/tests/01_04_58-post_iris_flyover_surpassing_locking_cap_sending_same_tx_with_witness_twice.js @@ -3,21 +3,14 @@ const redeemScriptParser = require('@rsksmart/powpeg-redeemscript-parser'); const { UNPROCESSABLE_TX_ALREADY_PROCESSED_ERROR, REFUNDED_USER_ERROR } = require("../lib/flyover-pegin-response-codes"); const CustomError = require('../lib/CustomError'); const lbc = require('../lib/liquidity-bridge-contract'); -const { sendTxWithCheck, getFedsPubKeys, activateFork } = require('../lib/rsk-utils'); +const { sendTxWithCheck, getFedsPubKeys } = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBtcClient } = require('../lib/btc-client-provider'); const { ensure0x } = require('../lib/utils'); const { fundAddressAndGetData } = require('../lib/btc-utils'); -const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); const { mineForPeginRegistration } = require('../lib/2wp-utils'); -/** - * Takes the blockchain to the required state for this test file to run in isolation. - */ -const fulfillRequirementsToRunAsSingleTestFile = async () => { - await activateFork(Runners.common.forks.iris300); -}; - describe('Executing registerFastBtcTransaction post hop - surpassing locking cap sending same tx with witness twice', () => { let rskTxHelpers; @@ -29,13 +22,7 @@ describe('Executing registerFastBtcTransaction post hop - surpassing locking cap rskTxHelpers = getRskTransactionHelpers(); rskTxHelper = rskTxHelpers[0]; btcTxHelper = getBtcClient(); - - if(process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(); - } - const latestActiveForkName = await getLatestActiveForkName(); - bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); - + bridge = getBridge(rskTxHelper.getClient()); }); it(`The first tx should fail due to surpassing the locking cap, and the second tx should fail due to hash already been used`, async () => { diff --git a/tests/01_04_59-post_iris_flyover_surpassing_locking_cap_sending_same_tx_without_witness_twice.js b/tests/01_04_59-post_iris_flyover_surpassing_locking_cap_sending_same_tx_without_witness_twice.js index bf939464..8a7983fb 100644 --- a/tests/01_04_59-post_iris_flyover_surpassing_locking_cap_sending_same_tx_without_witness_twice.js +++ b/tests/01_04_59-post_iris_flyover_surpassing_locking_cap_sending_same_tx_without_witness_twice.js @@ -3,21 +3,14 @@ const redeemScriptParser = require('@rsksmart/powpeg-redeemscript-parser'); const { UNPROCESSABLE_TX_ALREADY_PROCESSED_ERROR, REFUNDED_USER_ERROR } = require("../lib/flyover-pegin-response-codes"); const CustomError = require('../lib/CustomError'); const lbc = require('../lib/liquidity-bridge-contract'); -const { sendTxWithCheck, getFedsPubKeys, activateFork } = require('../lib/rsk-utils'); +const { sendTxWithCheck, getFedsPubKeys } = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBtcClient } = require('../lib/btc-client-provider'); const { ensure0x } = require('../lib/utils'); const { fundAddressAndGetData } = require('../lib/btc-utils'); -const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); const { mineForPeginRegistration } = require('../lib/2wp-utils'); -/** - * Takes the blockchain to the required state for this test file to run in isolation. - */ -const fulfillRequirementsToRunAsSingleTestFile = async () => { - await activateFork(Runners.common.forks.iris300); -}; - describe('Executing registerFastBtcTransaction post hop - surpassing locking cap sending same tx without witness twice', () => { let rskTxHelpers; @@ -29,12 +22,7 @@ describe('Executing registerFastBtcTransaction post hop - surpassing locking cap rskTxHelpers = getRskTransactionHelpers(); rskTxHelper = rskTxHelpers[0]; btcTxHelper = getBtcClient(); - - if(process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(); - } - const latestActiveForkName = await getLatestActiveForkName(); - bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); + bridge = getBridge(rskTxHelper.getClient()); }); diff --git a/tests/01_05_49-activate_hop_fork.js b/tests/01_05_49-activate_hop_fork.js deleted file mode 100644 index 936a5c09..00000000 --- a/tests/01_05_49-activate_hop_fork.js +++ /dev/null @@ -1,6 +0,0 @@ -const activateForkTest = require('../lib/tests/activate-fork'); - -activateForkTest.execute( - Runners.common.forks.hop400, - () => Runners.hosts.federates -); diff --git a/tests/01_05_50-activate_hop401_fork.js b/tests/01_05_50-activate_hop401_fork.js deleted file mode 100644 index a65f7fd3..00000000 --- a/tests/01_05_50-activate_hop401_fork.js +++ /dev/null @@ -1,6 +0,0 @@ -const activateForkTest = require('../lib/tests/activate-fork'); - -activateForkTest.execute( - Runners.common.forks.hop401, - () => Runners.hosts.federates -); diff --git a/tests/01_05_57-post_hop_active_powpeg_redeem_script.js b/tests/01_05_57-post_hop_active_powpeg_redeem_script.js index dabedcf4..fed64cf5 100644 --- a/tests/01_05_57-post_hop_active_powpeg_redeem_script.js +++ b/tests/01_05_57-post_hop_active_powpeg_redeem_script.js @@ -6,26 +6,17 @@ const redeemScriptParser = require('@rsksmart/powpeg-redeemscript-parser'); const CustomError = require('../lib/CustomError'); const removePrefix0x = require('../lib/utils').removePrefix0x; const {getRskTransactionHelpers} = require('../lib/rsk-tx-helper-provider'); -const {getBridge, getLatestActiveForkName} = require('../lib/precompiled-abi-forks-util'); +const {getBridge} = require('../lib/precompiled-abi-forks-util'); const {GENESIS_FEDERATION_ADDRESS, GENESIS_FEDERATION_REDEEM_SCRIPT} = require('../lib/constants'); -const {activateFork} = require('../lib/rsk-utils'); -/** - * Takes the blockchain to the required state for this test file to run in isolation. - */ -const fulfillRequirementsToRunAsSingleTestFile = async () => { - await activateFork(Runners.common.forks.hop400); -}; + describe('Calling getActivePowpegRedeemScript method after hop', function() { let rskTxHelpers; let rskTxHelper; let bridge; before(async () => { - if (process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(); - } rskTxHelpers = getRskTransactionHelpers(); rskTxHelper = rskTxHelpers[0]; - bridge = getBridge(rskTxHelper.getClient(), await getLatestActiveForkName()); + bridge = getBridge(rskTxHelper.getClient()); }); it('should return the active powpeg redeem script', async () => { diff --git a/tests/01_05_58-post_hop_register_fast_bridge_btc_below_minimum.js b/tests/01_05_58-post_hop_register_fast_bridge_btc_below_minimum.js index f567b501..5e372528 100644 --- a/tests/01_05_58-post_hop_register_fast_bridge_btc_below_minimum.js +++ b/tests/01_05_58-post_hop_register_fast_bridge_btc_below_minimum.js @@ -3,18 +3,14 @@ const redeemScriptParser = require('@rsksmart/powpeg-redeemscript-parser'); const { UNPROCESSABLE_TX_AMOUNT_SENT_BELOW_MINIMUM_ERROR } = require("../lib/flyover-pegin-response-codes"); const CustomError = require('../lib/CustomError'); const lbc = require('../lib/liquidity-bridge-contract'); -const { sendTxWithCheck, getFedsPubKeys, activateFork } = require('../lib/rsk-utils'); +const { sendTxWithCheck, getFedsPubKeys } = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBtcClient } = require('../lib/btc-client-provider'); const { ensure0x } = require('../lib/utils'); const { fundAddressAndGetData } = require('../lib/btc-utils'); -const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); const { mineForPeginRegistration } = require('../lib/2wp-utils'); -const fulfillRequirementsToRunAsSingleTestFile = async () => { - await activateFork(Runners.common.forks.hop400); -}; - describe('Executing registerFastBtcTransaction after hop - send funds below minimum', () => { let rskTxHelpers; @@ -26,12 +22,7 @@ describe('Executing registerFastBtcTransaction after hop - send funds below mini rskTxHelpers = getRskTransactionHelpers(); rskTxHelper = rskTxHelpers[0]; btcTxHelper = getBtcClient(); - - if(process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(); - } - const latestActiveForkName = await getLatestActiveForkName(); - bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); + bridge = getBridge(rskTxHelper.getClient()); }); it(`should return UNPROCESSABLE_TX_AMOUNT_SENT_BELOW_MINIMUM_ERROR(${UNPROCESSABLE_TX_AMOUNT_SENT_BELOW_MINIMUM_ERROR}) when calling registerFastBtcTransaction method sending amount below minimum`, async () => { diff --git a/tests/01_06_03-pre-fingerroot500-get-estimated-fees-for-next-pegout_returned_zero.js b/tests/01_06_03-pre-fingerroot500-get-estimated-fees-for-next-pegout_returned_zero.js index 8d1cd424..71edc04e 100644 --- a/tests/01_06_03-pre-fingerroot500-get-estimated-fees-for-next-pegout_returned_zero.js +++ b/tests/01_06_03-pre-fingerroot500-get-estimated-fees-for-next-pegout_returned_zero.js @@ -1,5 +1,5 @@ const expect = require('chai').expect; -const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); const CustomError = require('../lib/CustomError'); const { getRskTransactionHelper } = require('../lib/rsk-tx-helper-provider'); @@ -8,8 +8,8 @@ let bridge; describe('getEstimatedFeesForNextPegOutEvent - pre fingerroot', () => { before(async () => { const rskTxHelper = getRskTransactionHelper(); - const latestActiveForkName = await getLatestActiveForkName(); - bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); + + bridge = getBridge(rskTxHelper.getClient()); }); it('getEstimatedFeesForNextPegOutEvent bridge method returns zero when there are no pegout requests', async () => { diff --git a/tests/01_06_50-activate_fingerroot500_fork.js b/tests/01_06_50-activate_fingerroot500_fork.js deleted file mode 100644 index 1b2c3a33..00000000 --- a/tests/01_06_50-activate_fingerroot500_fork.js +++ /dev/null @@ -1,6 +0,0 @@ -const activateForkTest = require('../lib/tests/activate-fork'); - -activateForkTest.execute( - Runners.common.forks.fingerroot500, - () => Runners.hosts.federates -); diff --git a/tests/01_06_51-post_fingerroot500_get-estimated_fees_for_next_pegout_should_returned_correct_estimated.js b/tests/01_06_51-post_fingerroot500_get-estimated_fees_for_next_pegout_should_returned_correct_estimated.js index 8df03100..fd16e274 100644 --- a/tests/01_06_51-post_fingerroot500_get-estimated_fees_for_next_pegout_should_returned_correct_estimated.js +++ b/tests/01_06_51-post_fingerroot500_get-estimated_fees_for_next_pegout_should_returned_correct_estimated.js @@ -1,5 +1,5 @@ const expect = require('chai').expect -const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); const CustomError = require('../lib/CustomError'); const {MAX_ESTIMATED_FEE_PER_PEGOUT, FEE_DIFFERENCE_PER_PEGOUT} = require("../lib/constants"); const { getRskTransactionHelper } = require('../lib/rsk-tx-helper-provider'); @@ -9,8 +9,8 @@ let bridge; describe('getEstimatedFeesForNextPegOutEvent - post fingerroot', () => { before(async () => { const rskTxHelper = getRskTransactionHelper(); - const latestActiveForkName = await getLatestActiveForkName(); - bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); + + bridge = getBridge(rskTxHelper.getClient()); }); it('getEstimatedFeesForNextPegOutEvent bridge method returns fee estimation for one pegout when there are no pegout requests', async () => { diff --git a/tests/01_06_53-2wp_version1_exceeding-lockingCap.js b/tests/01_06_53-2wp_version1_exceeding-lockingCap.js index bb3241e3..0d9c64d1 100644 --- a/tests/01_06_53-2wp_version1_exceeding-lockingCap.js +++ b/tests/01_06_53-2wp_version1_exceeding-lockingCap.js @@ -2,7 +2,7 @@ const { expect } = require('chai'); const peginVerifier = require('pegin-address-verificator'); const rskUtils = require('../lib/rsk-utils'); const { sendPegin, assertRefundUtxosSameAsPeginUtxos } = require('../lib/2wp-utils'); -const { getBridge , getLatestActiveForkName} = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); const { getBtcClient } = require('../lib/btc-client-provider'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getDerivedRSKAddressInformation } = require('@rsksmart/btc-rsk-derivation'); @@ -19,13 +19,6 @@ let btcTxHelper; let rskTxHelper; let rskTxHelpers; -/** - * Takes the blockchain to the required state for this test file to run in isolation. - */ -const fulfillRequirementsToRunAsSingleTestFile = async () => { - await rskUtils.activateFork(Runners.common.forks.fingerroot500); -}; - describe('Lock funds using peg-in protocol version 1', () => { before(async () => { @@ -33,12 +26,7 @@ describe('Lock funds using peg-in protocol version 1', () => { rskTxHelpers = getRskTransactionHelpers(); rskTxHelper = rskTxHelpers[0]; - if(process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(); - } - - const latestActiveForkName = await getLatestActiveForkName(); - const bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); + const bridge = getBridge(rskTxHelper.getClient()); // Get the current locking cap lockingCapInBtc = Number(btcEthUnitConverter.satoshisToBtc(Number(await bridge.methods.getLockingCap().call()))); diff --git a/tests/01_07_50-activate-arrowhead600.js b/tests/01_07_50-activate-arrowhead600.js deleted file mode 100644 index bc727839..00000000 --- a/tests/01_07_50-activate-arrowhead600.js +++ /dev/null @@ -1,6 +0,0 @@ -const activateForkTest = require('../lib/tests/activate-fork'); - -activateForkTest.execute( - Runners.common.forks.arrowhead600, - () => Runners.hosts.federates -); diff --git a/tests/01_08_50-activate-lovell700.js b/tests/01_08_50-activate-lovell700.js deleted file mode 100644 index 389e9412..00000000 --- a/tests/01_08_50-activate-lovell700.js +++ /dev/null @@ -1,6 +0,0 @@ -const activateForkTest = require('../lib/tests/activate-fork'); - -activateForkTest.execute( - Runners.common.forks.lovell700, - () => Runners.hosts.federates -); diff --git a/tests/02_00_02-2wp_segwit_compatible.js b/tests/02_00_02-2wp_segwit_compatible.js index a3d8e65a..c717b871 100644 --- a/tests/02_00_02-2wp_segwit_compatible.js +++ b/tests/02_00_02-2wp_segwit_compatible.js @@ -1,10 +1,9 @@ const expect = require('chai').expect const { getDerivedRSKAddressInformation } = require('@rsksmart/btc-rsk-derivation'); const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); -const rskUtils = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { sendPegin, ensurePeginIsRegistered, disableWhitelisting } = require('../lib/2wp-utils'); -const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); const { getBtcClient } = require('../lib/btc-client-provider'); let rskTxHelpers; @@ -12,8 +11,6 @@ let rskTxHelper; let btcTxHelper; const fulfillRequirementsToRunAsSingleTestFile = async (rskTxHelper, btcTxHelper) => { - const latestForkName = rskUtils.getLatestForkName(); - await rskUtils.activateFork(latestForkName); await disableWhitelisting(rskTxHelper, btcTxHelper); }; @@ -29,8 +26,8 @@ describe('Lock using p2sh-p2wpkh address', () => { }); it('should do a legacy pegin using p2sh-p2wpkh address', async () => { - const latestActiveForkName = await getLatestActiveForkName(); - const bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); + + const bridge = getBridge(rskTxHelper.getClient()); const minimumPeginValueInSatoshis = Number(await bridge.methods.getMinimumLockTxValue().call()); const minimumPeginValueInBtc = Number(btcEthUnitConverter.satoshisToBtc(minimumPeginValueInSatoshis)); diff --git a/tests/02_00_03-2wp_multisig_compatible.js b/tests/02_00_03-2wp_multisig_compatible.js index 79513922..96c2a8cc 100644 --- a/tests/02_00_03-2wp_multisig_compatible.js +++ b/tests/02_00_03-2wp_multisig_compatible.js @@ -4,34 +4,22 @@ const rskUtils = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBtcClient } = require('../lib/btc-client-provider'); const { sendPegin } = require('../lib/2wp-utils'); -const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); let rskTxHelpers; let rskTxHelper; let btcTxHelper; -/** - * Takes the blockchain to the required state for this test file to run in isolation. - */ -const fulfillRequirementsToRunAsSingleTestFile = async () => { - await rskUtils.activateFork(Runners.common.forks.fingerroot500); -}; - describe('Lock multisig address', () => { before(async () => { rskTxHelpers = getRskTransactionHelpers(); rskTxHelper = rskTxHelpers[0]; btcTxHelper = getBtcClient() - - if(process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(); - } }); // Should refund if the btc sender address is a multisig it('lock should work when using multisig address', async () => { - const latestActiveForkName = await getLatestActiveForkName(); - const bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); + const bridge = getBridge(rskTxHelper.getClient()); const minimumPeginValueInSatoshis = await bridge.methods.getMinimumLockTxValue().call(); const minimumPeginValueInBtc = Number(satoshisToBtc(minimumPeginValueInSatoshis)); diff --git a/tests/02_00_05-2wp_version1.js b/tests/02_00_05-2wp_version1.js index 64424849..7fcc8eeb 100644 --- a/tests/02_00_05-2wp_version1.js +++ b/tests/02_00_05-2wp_version1.js @@ -18,12 +18,6 @@ let btcTxHelper; let rskTxHelper; let rskTxHelpers; -/** - * Takes the blockchain to the required state for this test file to run in isolation. - */ -const fulfillRequirementsToRunAsSingleTestFile = async () => { - await rskUtils.activateFork(rskUtils.getLatestForkName()); -}; describe('Lock funds using peg-in protocol version 1', () => { before(async () => { @@ -32,10 +26,6 @@ describe('Lock funds using peg-in protocol version 1', () => { rskTxHelpers = getRskTransactionHelpers(); rskTxHelper = rskTxHelpers[0]; - if(process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(); - } - }); it('should lock using multisig sender', async () => { diff --git a/tests/02_00_06-2wp-new-minimum.js b/tests/02_00_06-2wp-new-minimum.js index 7a67d40e..9495fe67 100644 --- a/tests/02_00_06-2wp-new-minimum.js +++ b/tests/02_00_06-2wp-new-minimum.js @@ -1,10 +1,10 @@ const { expect } = require('chai'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBtcClient } = require('../lib/btc-client-provider'); -const { getLatestForkName, activateFork, triggerRelease } = require('../lib/rsk-utils'); +const { triggerRelease } = require('../lib/rsk-utils'); const { sendPegin, ensurePeginIsRegistered, sendTxToBridge, BRIDGE_ADDRESS, MIN_PEGOUT_VALUE_IN_RBTC } = require('../lib/2wp-utils'); const { getDerivedRSKAddressInformation } = require('@rsksmart/btc-rsk-derivation'); -const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); const { btcToSatoshis, btcToWeis, satoshisToBtc } = require('@rsksmart/btc-eth-unit-converter'); describe('2wp after iris300, using new minimum values', () => { @@ -15,23 +15,13 @@ describe('2wp after iris300, using new minimum values', () => { let bridge; let federationAddress; - const fulfillRequirementsToRunAsSingleTestFile = async () => { - const latestForkName = getLatestForkName() - await activateFork(latestForkName); - }; - before(async () => { rskTxHelpers = getRskTransactionHelpers(); rskTxHelper = rskTxHelpers[0]; btcTxHelper = getBtcClient(); - if(process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(); - }; - // Get the current peg-in minimum - const latestActiveForkName = await getLatestActiveForkName(); - bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); + bridge = getBridge(rskTxHelper.getClient()); const minimumPeginValueInSatoshi = await bridge.methods.getMinimumLockTxValue().call(); minimumPeginValueInBTC = Number(satoshisToBtc(minimumPeginValueInSatoshi)); diff --git a/tests/03_00_01-powpeg_redeem_script.js b/tests/03_00_01-powpeg_redeem_script.js index 3212afe3..512f72ea 100644 --- a/tests/03_00_01-powpeg_redeem_script.js +++ b/tests/03_00_01-powpeg_redeem_script.js @@ -3,20 +3,14 @@ chai.use(require('chai-as-promised')); const expect = chai.expect; const redeemScriptParser = require('@rsksmart/powpeg-redeemscript-parser'); const {getRskTransactionHelpers} = require('../lib/rsk-tx-helper-provider'); -const {getBridge, getLatestActiveForkName} = require('../lib/precompiled-abi-forks-util'); +const {getBridge} = require('../lib/precompiled-abi-forks-util'); const CustomError = require('../lib/CustomError'); const removePrefix0x = require('../lib/utils').removePrefix0x; -const rskUtils = require('../lib/rsk-utils'); const { GENESIS_FEDERATION_ADDRESS, GENESIS_FEDERATION_REDEEM_SCRIPT, } = require('../lib/constants'); -const fulfillRequirementsToRunAsSingleTestFile = async () => { - const latestForkName = rskUtils.getLatestForkName(); - await rskUtils.activateFork(latestForkName); -}; - describe('Calling getActivePowpegRedeemScript method after last fork before fedchange', function() { let rskTxHelpers; let rskTxHelper; @@ -25,10 +19,7 @@ describe('Calling getActivePowpegRedeemScript method after last fork before fedc before(async () => { rskTxHelpers = getRskTransactionHelpers(); rskTxHelper = rskTxHelpers[0]; - if (process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(); - } - bridge = getBridge(rskTxHelper.getClient(), await getLatestActiveForkName()); + bridge = getBridge(rskTxHelper.getClient()); }); it('should return the active powpeg redeem script', async () => { diff --git a/tests/04_00_02-fedchange.js b/tests/04_00_02-fedchange.js index 082b3391..91e02991 100644 --- a/tests/04_00_02-fedchange.js +++ b/tests/04_00_02-fedchange.js @@ -77,13 +77,6 @@ let rskTxHelpers; let btcTxHelper; 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(rskUtils.getLatestForkName()); -}; - describe('RSK Federation change', function() { let addresses; @@ -104,10 +97,6 @@ describe('RSK Federation change', function() { rskTxHelper = rskTxHelpers[0]; btcTxHelper = getBtcClient(); - if(process.env.RUNNING_SINGLE_TEST_FILE) { - await fulfillRequirementsToRunAsSingleTestFile(rskTxHelper, btcTxHelper); - } - // Assume the last of the running federators belongs to the new federation rskClientNewFed = rskClients[rskClients.length-1]; pegClient = pegUtils.using(btcClient, rskClientOldFed); diff --git a/tests/04_00_05-fastbridge_operation_with_rejection.js b/tests/04_00_05-fastbridge_operation_with_rejection.js index cbd2ee1a..a842e4c2 100644 --- a/tests/04_00_05-fastbridge_operation_with_rejection.js +++ b/tests/04_00_05-fastbridge_operation_with_rejection.js @@ -10,7 +10,7 @@ const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBtcClient } = require('../lib/btc-client-provider'); const { ensure0x, wait } = require('../lib/utils'); const { fundAddressAndGetData } = require('../lib/btc-utils'); -const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); const { mineForPeginRegistration } = require('../lib/2wp-utils'); describe('Executing registerFastBtcTransaction after fed change - with release', () => { @@ -24,8 +24,7 @@ describe('Executing registerFastBtcTransaction after fed change - with release', rskTxHelpers = getRskTransactionHelpers(); rskTxHelper = rskTxHelpers[rskTxHelpers.length - 1]; btcTxHelper = getBtcClient(); - const latestActiveForkName = await getLatestActiveForkName(); - bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); + bridge = getBridge(rskTxHelper.getClient()); }); it('should return funds when calling registerFastBtcTransaction method surpassing locking cap after fed change', async () => { diff --git a/tests/04_00_06-fastbridge_after_fed_change.js b/tests/04_00_06-fastbridge_after_fed_change.js index 339b882d..66970d36 100644 --- a/tests/04_00_06-fastbridge_after_fed_change.js +++ b/tests/04_00_06-fastbridge_after_fed_change.js @@ -9,7 +9,7 @@ const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getBtcClient } = require('../lib/btc-client-provider'); const { ensure0x } = require('../lib/utils'); const { fundAddressAndGetData } = require('../lib/btc-utils'); -const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); const { mineForPeginRegistration } = require('../lib/2wp-utils'); describe('Executing registerFastBtcTransaction after hop and federation changed', () => { @@ -23,8 +23,7 @@ describe('Executing registerFastBtcTransaction after hop and federation changed' rskTxHelpers = getRskTransactionHelpers(); rskTxHelper = rskTxHelpers[rskTxHelpers.length - 1]; btcTxHelper = getBtcClient(); - const latestActiveForkName = await getLatestActiveForkName(); - bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); + bridge = getBridge(rskTxHelper.getClient()); }); it(`should return UNPROCESSABLE_TX_AMOUNT_SENT_BELOW_MINIMUM_ERROR(${UNPROCESSABLE_TX_AMOUNT_SENT_BELOW_MINIMUM_ERROR}) when calling registerFastBtcTransaction method sending amount below minimum after fed changed`, async () => { diff --git a/tests/05_00_01-powpeg_redeem_script.js b/tests/05_00_01-powpeg_redeem_script.js index e1f3e73b..26e39ad2 100644 --- a/tests/05_00_01-powpeg_redeem_script.js +++ b/tests/05_00_01-powpeg_redeem_script.js @@ -7,7 +7,7 @@ const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const CustomError = require('../lib/CustomError'); const { removePrefix0x } = require('../lib/utils'); const { publicKeyToCompressed } = require('../lib/btc-utils'); -const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); +const { getBridge } = require('../lib/precompiled-abi-forks-util'); // in order to run this as a single test file, it requires a federation change so follow the following command // npm run run-single-test-file 04_00_02-fedchange.js,05_02_01-last_fork_active_powpeg_redeem_script.js @@ -29,7 +29,7 @@ describe('Calling getActivePowpegRedeemScript method after last fork after fed c before(async () => { rskTxHelpers = getRskTransactionHelpers(); rskTxHelper = rskTxHelpers[0]; - bridge = getBridge(rskTxHelper.getClient(), await getLatestActiveForkName()); + bridge = getBridge(rskTxHelper.getClient()); }); it('should return the active powpeg redeem script', async () => {