Skip to content

Removes pre lovell tests. Deletes unnecesary tests. Renames some test… #256

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions lib/assertions/2wp.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,34 +118,10 @@ const assertCallToPegoutBatchingBridgeMethods = (rskClient) => async (expectedCo
expect(Number(nextPegoutCreationBlockNumber)).to.equal(expectedNextPegoutCreationBlockNumber);
}

const assertRejectedPeginEvent = async (rejectedPeginTx, expectedRejectionReason, expectedPeginBtcHash, expectedRefundAmountInSatoshis) => {

const rejectedPeginEvent = rejectedPeginTx.events[0];
expect(rejectedPeginEvent).to.not.be.undefined;
expect(rejectedPeginEvent.arguments.btcTxHash).to.equal(expectedPeginBtcHash);
expect(rejectedPeginEvent.arguments.reason).to.equal(expectedRejectionReason);

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;

}

module.exports = {
with: (btcClient, rskClient, pegClient) => ({
assertBitcoinBalance: assertBitcoinBalance(btcClient, rskClient, pegClient),
assertLock: assertLock(btcClient, rskClient, pegClient),
}),
assertCallToPegoutBatchingBridgeMethods,
assertRejectedPeginEvent,
};
16 changes: 2 additions & 14 deletions lib/bridge-provider.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const precompiledAbisArrowhead = require("@rsksmart/rsk-precompiled-abis");
const precompiledAbisLovell = require("@rsksmart/rsk-precompiled-abis-lovell");
const Web3 = require("web3");

Expand All @@ -8,26 +7,15 @@ const Web3 = require("web3");
* @returns {Bridge}
*/
const getBridge = async (rskClient) => {

const isLovellActive = await Runners.common.forks.lovell700.isAlreadyActive();

if(isLovellActive) {
return new rskClient.eth.Contract(precompiledAbisLovell.bridge.abi, precompiledAbisLovell.bridge.address);
}

return new rskClient.eth.Contract(precompiledAbisArrowhead.bridge.abi, precompiledAbisArrowhead.bridge.address);
return new rskClient.eth.Contract(precompiledAbisLovell.bridge.abi, precompiledAbisLovell.bridge.address);
};

/**
* Returns the abi of the bridge for the latest fork.
* @returns {json} The bridge abi in json format
*/
const getBridgeAbi = async () => {
const isLovellActive = await Runners.common.forks.lovell700.isAlreadyActive();
if(isLovellActive) {
return precompiledAbisLovell.bridge.abi;
}
return precompiledAbisArrowhead.bridge.abi;
return precompiledAbisLovell.bridge.abi;
};

module.exports = {
Expand Down
56 changes: 19 additions & 37 deletions lib/tests/2wp.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,14 +463,8 @@ const execute = (description, getRskHost) => {

// To ensure no refund is made, let's try to push any possible refund pegout.
await triggerRelease(rskTxHelpers, btcTxHelper);

const isLovellActive = await Runners.common.forks.lovell700.isAlreadyActive();

if(isLovellActive) {
await assertBtcPeginTxHashProcessed(btcPeginTxHash);
} else {
await assertPeginTxHashNotProcessed(btcPeginTxHash);
}
await assertBtcPeginTxHashProcessed(btcPeginTxHash);

// Two events are emitted in this scenario: rejected_pegin and unrefundable_pegin.
await assertExpectedRejectedPeginEventIsEmitted(btcPeginTxHash, blockNumberBeforePegin, PEGIN_REJECTION_REASONS.LEGACY_PEGIN_UNDETERMINED_SENDER);
Expand Down Expand Up @@ -769,8 +763,7 @@ const execute = (description, getRskHost) => {

// Assert

const isLovellActive = await Runners.common.forks.lovell700.isAlreadyActive();
const expectedPegoutValue = isLovellActive ? satoshisToWeis(pegoutValueInSatoshis) : pegoutValueInSatoshis;
const expectedPegoutValue = satoshisToWeis(pegoutValueInSatoshis);
await assertExpectedReleaseRequestRejectedEventIsEmitted(senderRecipientInfo.rskRecipientRskAddressInfo.address, expectedPegoutValue, PEGOUT_REJECTION_REASONS.LOW_AMOUNT);

await assert2wpBalanceIsUnchanged(initial2wpBalances);
Expand Down Expand Up @@ -813,8 +806,7 @@ const execute = (description, getRskHost) => {

// Assert

const isLovellActive = await Runners.common.forks.lovell700.isAlreadyActive();
const expectedPegoutValue = isLovellActive ? satoshisToWeis(pegoutValueInSatoshis) : pegoutValueInSatoshis;
const expectedPegoutValue = satoshisToWeis(pegoutValueInSatoshis);
await assertExpectedReleaseRequestRejectedEventIsEmitted(senderRecipientInfo.rskRecipientRskAddressInfo.address, expectedPegoutValue, PEGOUT_REJECTION_REASONS.FEE_ABOVE_VALUE);

await assert2wpBalanceIsUnchanged(initial2wpBalances);
Expand Down Expand Up @@ -853,8 +845,7 @@ const execute = (description, getRskHost) => {

// Assert

const isLovellActive = await Runners.common.forks.lovell700.isAlreadyActive();
const expectedPegoutValue = isLovellActive ? satoshisToWeis(pegoutValueInSatoshis) : pegoutValueInSatoshis;
const expectedPegoutValue = satoshisToWeis(pegoutValueInSatoshis);

const contractAddressChecksummed = rskTxHelper.getClient().utils.toChecksumAddress(ensure0x(callReleaseBtcContract.options.address));
const expectedEvent = createExpectedReleaseRequestRejectedEvent(contractAddressChecksummed, expectedPegoutValue, PEGOUT_REJECTION_REASONS.CALLER_CONTRACT);
Expand Down Expand Up @@ -994,24 +985,22 @@ const execute = (description, getRskHost) => {
const blockNumberAfterPegoutRelease = await rskTxHelper.getBlockNumber();
const pegoutsEvents = await getPegoutEventsInBlockRange(rskTxHelper, pegoutTransaction1.blockNumber, blockNumberAfterPegoutRelease);

const isLovellActive = await Runners.common.forks.lovell700.isAlreadyActive();

// The release_request_received event of the first pegout request
const rskSender1Address = rskTxHelper.getClient().utils.toChecksumAddress(ensure0x(senderRecipientInfo1.rskRecipientRskAddressInfo.address));
const releaseRequestReceivedEvent1 = pegoutsEvents.find(event => event.arguments.sender === rskSender1Address);
const expectedPegoutValue1 = isLovellActive ? satoshisToWeis(pegout1ValueInSatoshis) : pegout1ValueInSatoshis;
const expectedPegoutValue1 = satoshisToWeis(pegout1ValueInSatoshis);
assertReleaseRequestReceivedEvent(releaseRequestReceivedEvent1, rskSender1Address, senderRecipientInfo1.btcSenderAddressInfo.address, expectedPegoutValue1);

// The release_request_received event of the second pegout request
const rskSender2Address = rskTxHelper.getClient().utils.toChecksumAddress(ensure0x(senderRecipientInfo2.rskRecipientRskAddressInfo.address));
const releaseRequestReceivedEvent2 = pegoutsEvents.find(event => event.arguments.sender === rskSender2Address);
const expectedPegoutValue2 = isLovellActive ? satoshisToWeis(pegout2ValueInSatoshis) : pegout2ValueInSatoshis;
const expectedPegoutValue2 = satoshisToWeis(pegout2ValueInSatoshis);
assertReleaseRequestReceivedEvent(releaseRequestReceivedEvent2, rskSender2Address, senderRecipientInfo2.btcSenderAddressInfo.address, expectedPegoutValue2);

// The release_request_received event of the third pegout request
const rskSender3Address = rskTxHelper.getClient().utils.toChecksumAddress(ensure0x(senderRecipientInfo3.rskRecipientRskAddressInfo.address));
const releaseRequestReceivedEvent3 = pegoutsEvents.find(event => event.arguments.sender === rskSender3Address);
const expectedPegoutValue3 = isLovellActive ? satoshisToWeis(pegout3ValueInSatoshis) : pegout3ValueInSatoshis;
const expectedPegoutValue3 = satoshisToWeis(pegout3ValueInSatoshis);
assertReleaseRequestReceivedEvent(releaseRequestReceivedEvent3, rskSender3Address, senderRecipientInfo3.btcSenderAddressInfo.address, expectedPegoutValue3);

const pegoutWaitingForConfirmationWhenPegoutWasCreated = bridgeStateAfterPegoutCreation.pegoutsWaitingForConfirmations[0];
Expand All @@ -1022,22 +1011,19 @@ const execute = (description, getRskHost) => {
const releaseRequestedEvent = pegoutsEvents[3];
assertReleaseRequestedEvent(releaseRequestedEvent, pegoutCreationRskTransactionHash, btcTransaction.getId(), totalPegoutValueInSatoshis);

if(isLovellActive) {
// pegout_transaction_created event
const pegoutTransactionCreatedEvent = pegoutsEvents[4];
assertPegoutTransactionCreatedEvent(pegoutTransactionCreatedEvent, btcTransaction, bridgeStateBeforePegoutCreation);
}

const pegoutTransactionCreatedEvent = pegoutsEvents[4];
assertPegoutTransactionCreatedEvent(pegoutTransactionCreatedEvent, btcTransaction, bridgeStateBeforePegoutCreation);

// batch_pegout_created event
const batchPegoutCreatedEvent = pegoutsEvents[isLovellActive ? 5 : 4];
const batchPegoutCreatedEvent = pegoutsEvents[5];
assertBatchPegoutCreatedEvent(batchPegoutCreatedEvent, btcTransaction.getId(), [pegoutTransaction1.transactionHash, pegoutTransaction2.transactionHash, pegoutTransaction3.transactionHash]);

// pegout_confirmed event
const pegoutConfirmedEvent = pegoutsEvents[isLovellActive ? 6 : 5];
const pegoutConfirmedEvent = pegoutsEvents[6];
assertPegoutConfirmedEvent(pegoutConfirmedEvent, btcTransaction.getId(), pegoutWaitingForConfirmationWhenPegoutWasCreated.pegoutCreationBlockNumber);

// add_signature events
const addSignatureEvents = pegoutsEvents.slice(isLovellActive ? 7 : 6, pegoutsEvents.length - 1);
const addSignatureEvents = pegoutsEvents.slice(7, pegoutsEvents.length - 1);
assertAddSignatureEvents(addSignatureEvents, releaseRequestedEvent);

// release_btc event
Expand Down Expand Up @@ -1218,30 +1204,26 @@ const assertSuccessfulPegoutEventsAreEmitted = async (pegoutsEvents, pegoutReque
// release_request_received event
const releaseRequestReceivedEvent = pegoutsEvents[0];

const isLovellActive = await Runners.common.forks.lovell700.isAlreadyActive();
const expectedPegoutValue = isLovellActive ? (pegoutValueInWeis || satoshisToWeis(pegoutValueInSatoshis)) : pegoutValueInSatoshis;
const expectedPegoutValue = pegoutValueInWeis || satoshisToWeis(pegoutValueInSatoshis);
assertReleaseRequestReceivedEvent(releaseRequestReceivedEvent, rskSenderAddress, senderRecipientInfo.btcSenderAddressInfo.address, expectedPegoutValue);

// release_requested event
const pegoutCreationRskTransactionHash = ensure0x(pegoutWaitingForConfirmationWhenPegoutWasCreated.rskTxHash.padStart(64, '0'));
const releaseRequestedEvent = pegoutsEvents[1];
assertReleaseRequestedEvent(releaseRequestedEvent, pegoutCreationRskTransactionHash, btcTransaction.getId(), pegoutValueInSatoshis);

if(isLovellActive) {
// pegout_transaction_created event
const pegoutTransactionCreatedEvent = pegoutsEvents[2];
assertPegoutTransactionCreatedEvent(pegoutTransactionCreatedEvent, btcTransaction, bridgeStateBeforePegoutCreation);
}
const pegoutTransactionCreatedEvent = pegoutsEvents[2];
assertPegoutTransactionCreatedEvent(pegoutTransactionCreatedEvent, btcTransaction, bridgeStateBeforePegoutCreation);

// batch_pegout_created event
const batchPegoutCreatedEvent = pegoutsEvents[isLovellActive ? 3 : 2];
const batchPegoutCreatedEvent = pegoutsEvents[3];
assertBatchPegoutCreatedEvent(batchPegoutCreatedEvent, btcTransaction.getId(), [pegoutRequestReceivedTransactionHash]);

// pegout_confirmed event
const pegoutConfirmedEvent = pegoutsEvents[isLovellActive ? 4 : 3];
const pegoutConfirmedEvent = pegoutsEvents[4];
assertPegoutConfirmedEvent(pegoutConfirmedEvent, btcTransaction.getId(), pegoutWaitingForConfirmationWhenPegoutWasCreated.pegoutCreationBlockNumber);

const addSignatureEvents = pegoutsEvents.slice(isLovellActive ? 5 : 4, pegoutsEvents.length - 1);
const addSignatureEvents = pegoutsEvents.slice(5, pegoutsEvents.length - 1);
assertAddSignatureEvents(addSignatureEvents, releaseRequestedEvent);

// Final event, release_btc
Expand Down
3 changes: 2 additions & 1 deletion lib/tests/activate-fork → lib/tests/activate-fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const { getRskTransactionHelpers } = require('../rsk-tx-helper-provider');

const execute = (fork) => {

describe(`Activate ${fork.name} fork`, () => {
// Unskip when there is a new fork to be tested pre and post.
describe.skip(`Activate ${fork.name} fork`, () => {

it(`should mine blocks until reach ${fork.activationHeight}th block in order to activate the fork`, async () => {
try {
Expand Down
27 changes: 1 addition & 26 deletions lib/tests/change-federation.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ const execute = (description, newFederationConfig) => {
let newFederationPublicKeys;
let btcTxHelper;
let minimumPeginValueInSatoshis;
let isLovellActive;
let expectedFlyoverAddress;
let svpSpendBtcTransaction;
let proposedFederationInfo;
Expand Down Expand Up @@ -153,8 +152,6 @@ const execute = (description, newFederationConfig) => {
await ensurePeginIsRegistered(rskTxHelper, btcPeginTxHash);
}

isLovellActive = await Runners.common.forks.lovell700.isAlreadyActive();

});

it('should create a pending federation', async () => {
Expand Down Expand Up @@ -260,10 +257,6 @@ const execute = (description, newFederationConfig) => {

it('should create the proposed federation', async function () {

if(!isLovellActive) {
return this.skip();
}

proposedFederationInfo = await getProposedFederationInfo(bridge);

expect(proposedFederationInfo.size).to.be.equal(newFederationPublicKeys.length, 'The proposed federation size should be the expected one.');
Expand All @@ -276,10 +269,6 @@ const execute = (description, newFederationConfig) => {
});

it('should not have created svp fund transaction and there should not be any SVP values in storage yet', async function () {

if(!isLovellActive) {
return this.skip();
}

const bridgeState = await getBridgeState(rskTxHelper.getClient());

Expand All @@ -292,10 +281,6 @@ const execute = (description, newFederationConfig) => {

it('should create the SVP Fund transaction on the next updateCollections call', async function () {

if(!isLovellActive) {
return this.skip();
}

// Act

const initialBridgeState = await getBridgeState(rskTxHelper.getClient());
Expand Down Expand Up @@ -367,10 +352,6 @@ const execute = (description, newFederationConfig) => {

it('should release and register the svp fund transaction and create the svp spend transaction', async function () {

if(!isLovellActive) {
return this.skip();
}

// Mining to have enough confirmations for the SVP fund transaction and updating the bridge.
await rskUtils.mineAndSync(rskTxHelpers, 3);
await rskUtils.waitAndUpdateBridge(rskTxHelper);
Expand Down Expand Up @@ -400,10 +381,6 @@ const execute = (description, newFederationConfig) => {

it('should register the SVP Spend transaction and finish the SVP process', async function () {

if(!isLovellActive) {
return this.skip();
}

const blockNumberBeforeUpdateCollections = await rskTxHelper.getBlockNumber();
const expectedCountOfSignatures = Math.floor(newFederationPublicKeys.length / 2) + 1;

Expand Down Expand Up @@ -467,9 +444,7 @@ const execute = (description, newFederationConfig) => {
expect(activeFederationAddressInfo.creationBlockNumber).to.be.equal(commitFederationCreationBlockNumber, 'The new active federation creation block number should be the expected one.');
expect(activeFederationAddressInfo.size).to.be.equal(newFederationPublicKeys.length, 'The new active federation size should be the expected one.');

if(isLovellActive) {
expect(activeFederationAddressInfo.creationTime).to.be.equal(proposedFederationInfo.creationTime, 'The new active federation creation time should be the same as the proposed federation creation time.');
}
expect(activeFederationAddressInfo.creationTime).to.be.equal(proposedFederationInfo.creationTime, 'The new active federation creation time should be the same as the proposed federation creation time.');

const retiringFederationSize = Number(await bridge.methods.getRetiringFederationSize().call());
expect(retiringFederationSize).to.be.equal(initialFederationPublicKeys.length, 'The retiring federation size should be the same as the initial federation size.');
Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ global.Runners = {
fingerroot500: createForkObject('fingerroot500', 1),
arrowhead600: createForkObject('arrowhead600', 1),
arrowhead631: createForkObject('arrowhead631', 1),
lovell700: createForkObject('lovell700', 1750),
lovell700: createForkObject('lovell700', 1),
},
additionalFederationAddresses: []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ const {
GENESIS_FEDERATION_REDEEM_SCRIPT,
} = require('../lib/constants/federation-constants');

// No need for this test now since it is checking the genesis regtest fed address but we changed the federation at the start of the test.
describe.skip('Calling getActivePowpegRedeemScript method after last fork before fedchange', function() {
describe('Calling getActivePowpegRedeemScript method before federation change', function() {
let rskTxHelpers;
let rskTxHelper;
let bridge;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const fedAssertions = require('../lib/assertions/fed');

var fedAssert;
let fedAssert;

const INITIAL_FEDERATION_SIZE = 5;
const INITIAL_FEDERATION_SIZE = 3;

// TODO: refactor this test to stop using lib/assertions/fed library since it uses the peglib library
describe('Federate nodes key control - initial federation', function() {
before(() => {
fedAssert = fedAssertions.with(Runners.hosts.federates);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const rsk = require('peglib').rsk;
const fedAssertions = require('../lib/assertions/fed');

var fedAssert;
let fedAssert;

const INITIAL_FEDERATION_SIZE = 5;
const INITIAL_FEDERATION_SIZE = 3;
const INITIAL_FEDERATOR_BALANCE_IN_BTC = 1;

// TODO: refactor this test to get rid of the peglib library
describe('Federate nodes key control - second federation', function() {
before(() => {
console.log('Runners.hosts.federates.length', Runners.hosts.federates.length);
fedAssert = fedAssertions.with(Runners.hosts.federates);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let rskTxHelper;
let rskTxHelpers;
let bridge;

describe('RFS-170 test after fork', () => {
describe('Whitelist methods tests', () => {
before(async () => {
btcTxHelper = getBtcClient();
rskTxHelpers = getRskTransactionHelpers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let rskTxHelper;
let fedChangeAddress;
let bridge;

describe('Multiple federation member keys test after fork', () => {
describe('Bridge federator methods tests', () => {

before(async () => {
rskTxHelper = getRskTransactionHelper();
Expand Down
Loading