Skip to content

Commit

Permalink
Merge pull request #201 from rsksmart/disable-rskip419
Browse files Browse the repository at this point in the history
Disable rskip419
  • Loading branch information
marcos-iov authored Jan 24, 2025
2 parents 3dba43c + c530db0 commit 98c354c
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 37 deletions.
26 changes: 16 additions & 10 deletions lib/assertions/2wp.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,27 @@ 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;

// 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;

const pegoutTransactionCreatedEvent = rejectedPeginTx.events[2];
expect(pegoutTransactionCreatedEvent).to.not.be.null;
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 = {
Expand Down
2 changes: 1 addition & 1 deletion lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 3 additions & 3 deletions lib/rsk-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<Number>} 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;
Expand Down
9 changes: 5 additions & 4 deletions lib/tests/2wp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
5 changes: 4 additions & 1 deletion lib/tests/bridge-calls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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', 1850)
},
additionalFederationAddresses: []
}
Expand Down Expand Up @@ -216,6 +219,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]
Expand Down
6 changes: 3 additions & 3 deletions tests/02_00_05-2wp_version1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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);
});
});
23 changes: 9 additions & 14 deletions tests/04_00_02-fedchange.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -399,9 +396,9 @@ 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));
await rskUtils.mineAndSync(rskTxHelpers, FEDERATION_ACTIVATION_AGE / 2);

// Check retiring federation is still not assigned
address = await getRetiringFederationAddress();
Expand Down Expand Up @@ -434,9 +431,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 rskUtils.mineAndSync(rskTxHelpers, FEDERATION_ACTIVATION_AGE / 2 + 1);

// Check new federation
var activeFederationAddress = await getActiveFederationAddress();
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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(FEDERATION_ACTIVATION_AGE, () => rskUtils.mineAndSync(rskTxHelpers));
await rskUtils.mineAndSync(rskTxHelpers, 20);
await rskUtilsLegacy.waitForSync(rskClients);
await testNewFed.assertLock(
addresses,
Expand Down

0 comments on commit 98c354c

Please sign in to comment.