From b490fd66c18063a0db42d86a639392567dc3e5fc Mon Sep 17 00:00:00 2001 From: Marcos Irisarri <53787863+marcos-iov@users.noreply.github.com> Date: Mon, 13 Jan 2025 16:29:58 -0300 Subject: [PATCH 1/6] Disable RSKIP419 until tests are updated --- test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test.js b/test.js index 5ff3216f..46cfe325 100644 --- a/test.js +++ b/test.js @@ -216,6 +216,7 @@ before(async () => { // TODO: Remove once RIT refactors have been completed config.customConfig[`blockchain.config.consensusRules.rskip427`] = -1; + config.customConfig[`blockchain.config.consensusRules.rskip419`] = -1; // federatesToStart: [1, 2, 3] // additionalFederateNodes: [4, 5] From e4696b2b470d7bc869e8e98f58d9e9858a54c479 Mon Sep 17 00:00:00 2001 From: jeremy-then Date: Tue, 14 Jan 2025 15:44:10 -0400 Subject: [PATCH 2/6] Disable lovell --- lib/assertions/2wp.js | 19 +++++++++++++------ test.js | 5 ++++- tests/01_08_50-activate-lovell700.js | 6 ------ tests/02_00_05-2wp_version1.js | 6 +++--- 4 files changed, 20 insertions(+), 16 deletions(-) delete mode 100644 tests/01_08_50-activate-lovell700.js diff --git a/lib/assertions/2wp.js b/lib/assertions/2wp.js index f6fa6be7..c8f9ca52 100644 --- a/lib/assertions/2wp.js +++ b/lib/assertions/2wp.js @@ -117,21 +117,28 @@ const assertCallToPegoutBatchingBridgeMethods = (rskClient) => async (expectedCo expect(Number(nextPegoutCreationBlockNumber)).to.equal(expectedNextPegoutCreationBlockNumber); } -const assertRejectedPeginEvent = (rejectedPeginTx, expectedRejectionReason, expectedPeginBtcHash, expectedRefundAmountInSatoshis) => { +const assertRejectedPeginEvent = async (rejectedPeginTx, expectedRejectionReason, expectedPeginBtcHash, expectedRefundAmountInSatoshis) => { + const rejectedPeginEvent = rejectedPeginTx.events[0]; - expect(rejectedPeginEvent).to.not.be.null; + expect(rejectedPeginEvent).to.not.be.undefined; expect(rejectedPeginEvent.arguments.btcTxHash).to.equal(expectedPeginBtcHash); expect(rejectedPeginEvent.arguments.reason).to.equal(expectedRejectionReason); - const pegoutRequestedEvent = rejectedPeginTx.events[1]; - expect(pegoutRequestedEvent).to.not.be.null; + const releaseRequestedEvent = rejectedPeginTx.events[1]; + expect(releaseRequestedEvent).to.not.be.undefined; + + const isLovell700AlreadyActive = await Runners.common.forks.lovell700.isAlreadyActive(); + + if(!isLovell700AlreadyActive) { + return; + } const pegoutTransactionCreatedEvent = rejectedPeginTx.events[2]; - expect(pegoutTransactionCreatedEvent).to.not.be.null; + expect(pegoutTransactionCreatedEvent).to.not.be.undefined; const encodedUtxoOutpointValues = Buffer.from(removePrefix0x(pegoutTransactionCreatedEvent.arguments.utxoOutpointValues), 'hex'); - const federationUtxoValues = encodeOutpointValuesAsMap([{"valueInSatoshis": expectedRefundAmountInSatoshis}]); const outpointValues = decodeOutpointValues(encodedUtxoOutpointValues); expect(outpointValues.every(value => value in federationUtxoValues)).to.be.true; + } module.exports = { diff --git a/test.js b/test.js index 46cfe325..79bf53b2 100644 --- a/test.js +++ b/test.js @@ -60,6 +60,9 @@ const createForkObject = (name, activationHeight) => { if(isActive) { return isActive; } + if(this.activationHeight === -1) { + return false; + } rskTxHelper = rskTxHelper || getRskTransactionHelper(); // Cache the result to avoid calling the network again if the fork is already active const latestBlockNumber = await rskTxHelper.getBlockNumber(); @@ -88,7 +91,7 @@ global.Runners = { hop401: createForkObject('hop401', 1010), fingerroot500: createForkObject('fingerroot', 1350), arrowhead600: createForkObject('arrowhead', 1600), - lovell700: createForkObject('lovell', 1700) + lovell700: createForkObject('lovell', -1) }, additionalFederationAddresses: [] } 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_05-2wp_version1.js b/tests/02_00_05-2wp_version1.js index 64424849..df006548 100644 --- a/tests/02_00_05-2wp_version1.js +++ b/tests/02_00_05-2wp_version1.js @@ -169,7 +169,7 @@ describe('Lock funds using peg-in protocol version 1', () => { }); expect(rejectedPeginTx).to.not.be.null; - assertRejectedPeginEvent(rejectedPeginTx, PEGIN_V1_INVALID_PAYLOAD_REASON, peginBtcTxHashWith0xPrefix, amountSentInSatoshis) + await assertRejectedPeginEvent(rejectedPeginTx, PEGIN_V1_INVALID_PAYLOAD_REASON, peginBtcTxHashWith0xPrefix, amountSentInSatoshis) }); it('should lock with multiple OP_RETURN outputs but only one for RSK', async () => { @@ -251,7 +251,7 @@ describe('Lock funds using peg-in protocol version 1', () => { }); expect(rejectedPeginTx).to.not.be.null; - assertRejectedPeginEvent(rejectedPeginTx, PEGIN_V1_INVALID_PAYLOAD_REASON, peginBtcTxHashWith0xPrefix, amountSentInSatoshis) + await assertRejectedPeginEvent(rejectedPeginTx, PEGIN_V1_INVALID_PAYLOAD_REASON, peginBtcTxHashWith0xPrefix, amountSentInSatoshis) }); it('should refund lock with OP_RETURN output for RSK with invalid version number', async () => { @@ -311,6 +311,6 @@ describe('Lock funds using peg-in protocol version 1', () => { }); expect(rejectedPeginTx).to.not.be.null; - assertRejectedPeginEvent(rejectedPeginTx, PEGIN_V1_INVALID_PAYLOAD_REASON, peginBtcTxHashWith0xPrefix, amountSentInSatoshis); + await assertRejectedPeginEvent(rejectedPeginTx, PEGIN_V1_INVALID_PAYLOAD_REASON, peginBtcTxHashWith0xPrefix, amountSentInSatoshis); }); }); From 79b44de4e5d988933320822159935bed769a7245 Mon Sep 17 00:00:00 2001 From: jeremy-then Date: Tue, 14 Jan 2025 17:29:30 -0400 Subject: [PATCH 3/6] Updates FEDERATION_ACTIVATION_AGE --- lib/constants.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/constants.js b/lib/constants.js index 104a9a4f..86b8e733 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -39,7 +39,7 @@ const MAX_ESTIMATED_FEE_PER_PEGOUT = 68600; const FEE_DIFFERENCE_PER_PEGOUT = 3200; const NUMBER_OF_BLOCKS_BTW_PEGOUTS = 50; -const FEDERATION_ACTIVATION_AGE = 20; +const FEDERATION_ACTIVATION_AGE = 150; const PEGIN_REJECTION_REASONS = { PEGIN_CAP_SURPASSED_REASON: '1', From e7489cd72966eca38d4015fc4f4c483bc975955f Mon Sep 17 00:00:00 2001 From: jeremy-then Date: Thu, 16 Jan 2025 14:32:50 -0400 Subject: [PATCH 4/6] Mining correct amount of blocks for federation activation. --- lib/assertions/2wp.js | 21 ++++++++++----------- lib/tests/2wp.js | 9 +++++---- lib/tests/bridge-calls.js | 5 ++++- test.js | 2 +- tests/01_08_50-activate-lovell700.js | 6 ++++++ tests/04_00_02-fedchange.js | 12 ++++++------ 6 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 tests/01_08_50-activate-lovell700.js diff --git a/lib/assertions/2wp.js b/lib/assertions/2wp.js index c8f9ca52..ed07dfb0 100644 --- a/lib/assertions/2wp.js +++ b/lib/assertions/2wp.js @@ -127,17 +127,16 @@ const assertRejectedPeginEvent = async (rejectedPeginTx, expectedRejectionReason const releaseRequestedEvent = rejectedPeginTx.events[1]; expect(releaseRequestedEvent).to.not.be.undefined; - const isLovell700AlreadyActive = await Runners.common.forks.lovell700.isAlreadyActive(); - - if(!isLovell700AlreadyActive) { - return; - } - - const pegoutTransactionCreatedEvent = rejectedPeginTx.events[2]; - expect(pegoutTransactionCreatedEvent).to.not.be.undefined; - const encodedUtxoOutpointValues = Buffer.from(removePrefix0x(pegoutTransactionCreatedEvent.arguments.utxoOutpointValues), 'hex'); - const outpointValues = decodeOutpointValues(encodedUtxoOutpointValues); - expect(outpointValues.every(value => value in federationUtxoValues)).to.be.true; + // TODO: uncomment when RSKIP419 is active + // const isLovell700AlreadyActive = await Runners.common.forks.lovell700.isAlreadyActive(); + // if(!isLovell700AlreadyActive) { + // return; + // } + // const pegoutTransactionCreatedEvent = rejectedPeginTx.events[2]; + // expect(pegoutTransactionCreatedEvent).to.not.be.undefined; + // const encodedUtxoOutpointValues = Buffer.from(removePrefix0x(pegoutTransactionCreatedEvent.arguments.utxoOutpointValues), 'hex'); + // const outpointValues = decodeOutpointValues(encodedUtxoOutpointValues); + // expect(outpointValues.every(value => value in federationUtxoValues)).to.be.true; } diff --git a/lib/tests/2wp.js b/lib/tests/2wp.js index 2de59ed7..35f2db77 100644 --- a/lib/tests/2wp.js +++ b/lib/tests/2wp.js @@ -193,10 +193,11 @@ const execute = (description, getRskHost) => { expect(batchPegoutCreatedEvent.arguments.releaseRskTxHashes.includes(pegoutTransaction.transactionHash)).to.be.true; } - const isLovell700AlreadyActive = await Runners.common.forks.lovell700.isAlreadyActive(); - if (isLovell700AlreadyActive) { - await assertPegoutTransactionCreatedEventIsEmitted(localRskTxHelper, activeFederationUtxosBeforePegout); - } + // TODO: uncomment when RSKIP419 is active + // const isLovell700AlreadyActive = await Runners.common.forks.lovell700.isAlreadyActive(); + // if (isLovell700AlreadyActive) { + // await assertPegoutTransactionCreatedEventIsEmitted(localRskTxHelper, activeFederationUtxosBeforePegout); + // } }; const pegoutConfirmedValidations = async (localRskTxHelper) => { diff --git a/lib/tests/bridge-calls.js b/lib/tests/bridge-calls.js index 0051e5d2..b92b9f2c 100644 --- a/lib/tests/bridge-calls.js +++ b/lib/tests/bridge-calls.js @@ -113,7 +113,10 @@ const testMethod = (bridgeCallsAllowed) => (methodSignature, args, expectedWhenF }); if (bridgeCallsAllowed) { - it(`txs are mined and execution is reverted`, async () => { + // Skipped because it throws an error because it is expecting the Bridge to revert and mine the transaction, + // but the Bridge only allow local calls on these methods. + // This test is removed in upcoming refactor. + it.skip(`txs are mined and execution is reverted`, async () => { try { const txPromise = contractCallsTester.methods.doCall(abi).send({ from: address diff --git a/test.js b/test.js index 79bf53b2..badddee1 100644 --- a/test.js +++ b/test.js @@ -91,7 +91,7 @@ global.Runners = { hop401: createForkObject('hop401', 1010), fingerroot500: createForkObject('fingerroot', 1350), arrowhead600: createForkObject('arrowhead', 1600), - lovell700: createForkObject('lovell', -1) + lovell700: createForkObject('lovell', 1850) }, additionalFederationAddresses: [] } diff --git a/tests/01_08_50-activate-lovell700.js b/tests/01_08_50-activate-lovell700.js new file mode 100644 index 00000000..389e9412 --- /dev/null +++ b/tests/01_08_50-activate-lovell700.js @@ -0,0 +1,6 @@ +const activateForkTest = require('../lib/tests/activate-fork'); + +activateForkTest.execute( + Runners.common.forks.lovell700, + () => Runners.hosts.federates +); diff --git a/tests/04_00_02-fedchange.js b/tests/04_00_02-fedchange.js index 082b3391..fa45c792 100644 --- a/tests/04_00_02-fedchange.js +++ b/tests/04_00_02-fedchange.js @@ -117,7 +117,7 @@ describe('RSK Federation change', function() { utils = rskUtilsLegacy.with(btcClient, rskClientOldFed, pegClient); utilsNewFed = rskUtilsLegacy.with(btcClient, rskClientNewFed, pegClient); - await rskUtilsLegacy.waitForSync(rskClients); + await rskUtils.waitForSync(rskTxHelpers); // Grab the new federation public keys and calculate the federators addresses and expected federation // address from the existing runners. Use compressed public keys for federation change @@ -399,7 +399,7 @@ describe('RSK Federation change', function() { await getIndexAndExpectResult(rskClientOldFed, 'getFederatorPublicKeyOfType', i, oldFederation.publicKeys)(); } - // 20 blocks is what takes to activate the new federation in regtest. Mine half + // FEDERATION_ACTIVATION_AGE blocks is what takes to activate the new federation in regtest. Mine half // and check no activation happened await sequentialPromise(FEDERATION_ACTIVATION_AGE / 2, () => rskUtils.mineAndSync(rskTxHelpers)); @@ -434,9 +434,9 @@ describe('RSK Federation change', function() { it('should activate the new federation and assign the retiring federation', async () => { try { - // 20 blocks is what takes to activate the new federation in regtest. - // Already mined at least 10 before. Mine 20 more and check. - await sequentialPromise(FEDERATION_ACTIVATION_AGE, () => rskUtils.mineAndSync(rskTxHelpers)); + // FEDERATION_ACTIVATION_AGE blocks is what takes to activate the new federation in regtest. + // Already mined at least half of that before. Mine the other have + 1 more and check. + await sequentialPromise(FEDERATION_ACTIVATION_AGE / 2 + 1, () => rskUtils.mineAndSync(rskTxHelpers)); // Check new federation var activeFederationAddress = await getActiveFederationAddress(); @@ -635,7 +635,7 @@ describe('RSK Federation change', function() { // Mine some blocks (20) and the wait for nodes to sync so that the // federate nodes start being aware of the federation changes var valueToTransfer = bitcoin.btcToSatoshis(5); - await sequentialPromise(FEDERATION_ACTIVATION_AGE, () => rskUtils.mineAndSync(rskTxHelpers)); + await sequentialPromise(20, () => rskUtils.mineAndSync(rskTxHelpers)); await rskUtilsLegacy.waitForSync(rskClients); await testNewFed.assertLock( addresses, From f84925cc00854d292e9ab95038e95e970bf327d5 Mon Sep 17 00:00:00 2001 From: jeremy-then Date: Thu, 16 Jan 2025 15:35:58 -0400 Subject: [PATCH 5/6] Removes unnecessary block mining. --- tests/04_00_02-fedchange.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tests/04_00_02-fedchange.js b/tests/04_00_02-fedchange.js index fa45c792..474bdd51 100644 --- a/tests/04_00_02-fedchange.js +++ b/tests/04_00_02-fedchange.js @@ -1,6 +1,6 @@ const expect = require('chai').expect const BN = require('bn.js'); -const { sequentialPromise, wait, randomElement, randomNElements, additionalFederationAddresses } = require('../lib/utils'); +const { wait, randomElement, randomNElements, additionalFederationAddresses } = require('../lib/utils'); const CustomError = require('../lib/CustomError'); const peglib = require('peglib'); const redeemScriptParser = require('@rsksmart/powpeg-redeemscript-parser'); @@ -169,9 +169,6 @@ describe('RSK Federation change', function() { for (fedAddress of newFederatorRskAddressesRsk) { await utils.sendFromCow(fedAddress, rsk.btcToWeis(INITIAL_FEDERATOR_BALANCE_IN_BTC)); } - // mine a few rsk blocks to prevent being at the beginning of the chain, - // which could trigger border cases we're not interested in - await sequentialPromise(10, () => rskUtils.mineAndSync(rskTxHelpers)); } catch (err){ @@ -401,7 +398,7 @@ describe('RSK Federation change', function() { // FEDERATION_ACTIVATION_AGE blocks is what takes to activate the new federation in regtest. Mine half // and check no activation happened - await sequentialPromise(FEDERATION_ACTIVATION_AGE / 2, () => rskUtils.mineAndSync(rskTxHelpers)); + await rskUtils.mineAndSync(rskTxHelpers, FEDERATION_ACTIVATION_AGE / 2); // Check retiring federation is still not assigned address = await getRetiringFederationAddress(); @@ -436,7 +433,7 @@ describe('RSK Federation change', function() { try { // FEDERATION_ACTIVATION_AGE blocks is what takes to activate the new federation in regtest. // Already mined at least half of that before. Mine the other have + 1 more and check. - await sequentialPromise(FEDERATION_ACTIVATION_AGE / 2 + 1, () => rskUtils.mineAndSync(rskTxHelpers)); + await rskUtils.mineAndSync(rskTxHelpers, FEDERATION_ACTIVATION_AGE / 2 + 1); // Check new federation var activeFederationAddress = await getActiveFederationAddress(); @@ -506,9 +503,7 @@ describe('RSK Federation change', function() { expect(rawRetiringFederationBalance).to.be.finite; expect(rawRetiringFederationBalance).to.be.greaterThan(0, 'Retiring federation should have some balance to migrate'); - await sequentialPromise(20, (index) => { - return rskUtils.mineAndSync(rskTxHelpers); - }); + await rskUtils.mineAndSync(rskTxHelpers, 20); await rskUtilsLegacy.waitForSync(rskClients); @@ -635,7 +630,7 @@ describe('RSK Federation change', function() { // Mine some blocks (20) and the wait for nodes to sync so that the // federate nodes start being aware of the federation changes var valueToTransfer = bitcoin.btcToSatoshis(5); - await sequentialPromise(20, () => rskUtils.mineAndSync(rskTxHelpers)); + await rskUtils.mineAndSync(rskTxHelpers, 20); await rskUtilsLegacy.waitForSync(rskClients); await testNewFed.assertLock( addresses, From c530db0609d2c7b90d7c5691ea3cb49191aef863 Mon Sep 17 00:00:00 2001 From: jeremy-then Date: Fri, 24 Jan 2025 11:21:54 -0400 Subject: [PATCH 6/6] Increases rskUtils.waitForBlock wait and attempt --- lib/rsk-utils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/rsk-utils.js b/lib/rsk-utils.js index e085cbc0..b3eba1fd 100644 --- a/lib/rsk-utils.js +++ b/lib/rsk-utils.js @@ -46,11 +46,11 @@ const waitForSync = async (rskTransactionHelpers) => { * If the blockchain is at least advancing, we know that some time in the future the `blockNumber` will be reached, so no need to stop trying to find it. * @param {Web3} rskClient web3 client to make calls to the rsk network. * @param {Number} blockNumber min block height to wait for. - * @param {Number} waitTime defaults to 200 milliseconds. Time to wait before checking for the block on every iteration. - * @param {Number} maxAttempts defaults to 80 attempts by block. + * @param {Number} waitTime defaults to 500 milliseconds. Time to wait before checking for the block on every iteration. + * @param {Number} maxAttempts defaults to 500 attempts by block. * @returns {Promise} the latest block number the same or greater than `blockNumber`. */ -const waitForBlock = (rskClient, blockNumber, waitTime = 200, maxAttempts = 200) => { +const waitForBlock = (rskClient, blockNumber, waitTime = 500, maxAttempts = 500) => { return new Promise((resolve, reject) => { let attempts = 1; let latestBlockNumber = -1;