From 46a0a0f65ed6cce10b40097f0e1f44aa8d893558 Mon Sep 17 00:00:00 2001 From: Julian Len Date: Thu, 9 Apr 2026 11:08:02 -0300 Subject: [PATCH 01/31] added a test for the getEstimatedFeesForNextPegoutEvent --- ...get_estimatedFees_for_next_pegout_event.js | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 tests/01_07_01-get_estimatedFees_for_next_pegout_event.js diff --git a/tests/01_07_01-get_estimatedFees_for_next_pegout_event.js b/tests/01_07_01-get_estimatedFees_for_next_pegout_event.js new file mode 100644 index 00000000..709eb49e --- /dev/null +++ b/tests/01_07_01-get_estimatedFees_for_next_pegout_event.js @@ -0,0 +1,113 @@ +const expect = require('chai').expect; +const BN = require('bn.js'); +const { getBridgeState } = require('@rsksmart/bridge-state-data-parser'); +const { btcToWeis, satoshisToBtc, satoshisToWeis } = require('@rsksmart/btc-eth-unit-converter'); +const { getBridge } = require('../lib/bridge-provider'); +const CustomError = require('../lib/CustomError'); +const { + createSenderRecipientInfo, + ensurePeginIsRegistered, + sendPeginToActiveFederation, + sendTxToBridge, +} = require('../lib/2wp-utils'); +const { getBtcClient } = require('../lib/btc-client-provider'); +const { + MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS, +} = require('../lib/constants/pegout-constants'); +const { getRskTransactionHelper, getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); +const { sendFromCow, triggerRelease } = require('../lib/rsk-utils'); + +const FEDERATION_PEGIN_AMOUNT_IN_SATOSHIS = 500_000; +const FEDERATION_PEGIN_AMOUNT_IN_BTC = Number(satoshisToBtc(FEDERATION_PEGIN_AMOUNT_IN_SATOSHIS)); +const BTC_FUNDING_AMOUNT_IN_BTC = 2; +const PEGOUT_SENDER_FUNDING_IN_BTC = 2; + +let bridge; +let rskTxHelper; +let rskTxHelpers; +let btcTxHelper; + +const getQueuedPegoutsCount = async () => Number(await bridge.methods.getQueuedPegoutsCount().call()); + +const getEstimatedFeesForNextPegoutEvent = async () => + Number(await bridge.methods.getEstimatedFeesForNextPegOutEvent().call()); + +describe('getEstimatedFeesForNextPegOutEvent', () => { + before(async () => { + rskTxHelper = getRskTransactionHelper(); + rskTxHelpers = getRskTransactionHelpers(); + btcTxHelper = getBtcClient(); + bridge = await getBridge(rskTxHelper.getClient()); + }); + + beforeEach(async () => { + await triggerRelease(rskTxHelpers, btcTxHelper); + }); + + afterEach(async () => { + await triggerRelease(rskTxHelpers, btcTxHelper); + }); + + it('should allow constructing a second pegout request using the estimated fees and process both', async () => { + try { + const senderInfo = await createSenderRecipientInfo( + rskTxHelper, + btcTxHelper, + 'legacy', + BTC_FUNDING_AMOUNT_IN_BTC + ); + + const peginBtcTxHash = await sendPeginToActiveFederation( + rskTxHelper, + btcTxHelper, + senderInfo.btcSenderAddressInfo, + FEDERATION_PEGIN_AMOUNT_IN_BTC + ); + await ensurePeginIsRegistered(rskTxHelper, peginBtcTxHash); + + const bridgeStateAfterPegin = await getBridgeState(rskTxHelper.getClient()); + const peginUtxoInBridgeState = bridgeStateAfterPegin.activeFederationUtxos.find( + (utxo) => + utxo.btcTxHash === peginBtcTxHash && + utxo.valueInSatoshis === FEDERATION_PEGIN_AMOUNT_IN_SATOSHIS + ); + expect(peginUtxoInBridgeState).to.not.be.undefined; + + await sendFromCow( + rskTxHelper, + senderInfo.rskRecipientRskAddressInfo.address, + Number(btcToWeis(PEGOUT_SENDER_FUNDING_IN_BTC)) + ); + + await sendTxToBridge( + rskTxHelper, + new BN(satoshisToWeis(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS)), + senderInfo.rskRecipientRskAddressInfo.address + ); + + const estimatedFeesForNextPegout = await getEstimatedFeesForNextPegoutEvent(); + expect(estimatedFeesForNextPegout).to.be.greaterThan(0); + + const secondPegoutAmountInSatoshis = + MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS + estimatedFeesForNextPegout; + await sendTxToBridge( + rskTxHelper, + new BN(satoshisToWeis(secondPegoutAmountInSatoshis)), + senderInfo.rskRecipientRskAddressInfo.address + ); + + const countBeforeRelease = await getQueuedPegoutsCount(); + expect(countBeforeRelease).to.equal(2); + + await triggerRelease(rskTxHelpers, btcTxHelper); + + const countAfterRelease = await getQueuedPegoutsCount(); + expect(countAfterRelease).to.equal(0); + } catch (err) { + throw new CustomError( + 'Error validating getEstimatedFeesForNextPegOutEvent with two pegouts', + err + ); + } + }); +}); From 24679f8ce54b8944898b45955a4189a1547871df Mon Sep 17 00:00:00 2001 From: Julian Len Date: Thu, 9 Apr 2026 13:28:47 -0300 Subject: [PATCH 02/31] renamed test 01_07_01 --- ...nt.js => 01_07_01-get_estimated_fees_for_next_pegout_event.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{01_07_01-get_estimatedFees_for_next_pegout_event.js => 01_07_01-get_estimated_fees_for_next_pegout_event.js} (100%) diff --git a/tests/01_07_01-get_estimatedFees_for_next_pegout_event.js b/tests/01_07_01-get_estimated_fees_for_next_pegout_event.js similarity index 100% rename from tests/01_07_01-get_estimatedFees_for_next_pegout_event.js rename to tests/01_07_01-get_estimated_fees_for_next_pegout_event.js From f93c36d73260f3d0b1862e82df0978da7a8e8015 Mon Sep 17 00:00:00 2001 From: Julian Len Date: Thu, 9 Apr 2026 15:50:57 -0300 Subject: [PATCH 03/31] added a test for getEstimatedFeesForPegoutAomunt --- ...02-get_estimated_fees_for_pegout_amount.js | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 tests/01_07_02-get_estimated_fees_for_pegout_amount.js diff --git a/tests/01_07_02-get_estimated_fees_for_pegout_amount.js b/tests/01_07_02-get_estimated_fees_for_pegout_amount.js new file mode 100644 index 00000000..02c3876f --- /dev/null +++ b/tests/01_07_02-get_estimated_fees_for_pegout_amount.js @@ -0,0 +1,123 @@ +const expect = require('chai').expect; +const BN = require('bn.js'); +const { getBridgeState } = require('@rsksmart/bridge-state-data-parser'); +const { btcToWeis, satoshisToBtc, satoshisToWeis } = require('@rsksmart/btc-eth-unit-converter'); +const { assertContractCallFails } = require('../lib/assertions/contractMethods'); +const { getBridge } = require('../lib/bridge-provider'); +const CustomError = require('../lib/CustomError'); +const { + createSenderRecipientInfo, + ensurePeginIsRegistered, + sendPeginToActiveFederation, + sendTxToBridge, +} = require('../lib/2wp-utils'); +const { getBtcClient } = require('../lib/btc-client-provider'); +const { + MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS, +} = require('../lib/constants/pegout-constants'); +const { getRskTransactionHelper, getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); +const { sendFromCow, triggerRelease } = require('../lib/rsk-utils'); + +const FEDERATION_PEGIN_AMOUNT_IN_SATOSHIS = 500_000; +const FEDERATION_PEGIN_AMOUNT_IN_BTC = Number(satoshisToBtc(FEDERATION_PEGIN_AMOUNT_IN_SATOSHIS)); +const BTC_FUNDING_AMOUNT_IN_BTC = 2; +const PEGOUT_SENDER_FUNDING_IN_BTC = 2; + +let bridge; +let rskTxHelper; +let rskTxHelpers; +let btcTxHelper; + +const getQueuedPegoutsCount = async () => Number(await bridge.methods.getQueuedPegoutsCount().call()); + +describe('getEstimatedFeesForPegOutAmount', () => { + before(async () => { + rskTxHelper = getRskTransactionHelper(); + rskTxHelpers = getRskTransactionHelpers(); + btcTxHelper = getBtcClient(); + bridge = await getBridge(rskTxHelper.getClient()); + }); + + beforeEach(async () => { + await triggerRelease(rskTxHelpers, btcTxHelper); + }); + + afterEach(async () => { + await triggerRelease(rskTxHelpers, btcTxHelper); + }); + + it('should allow constructing a second pegout request using the estimated fees for pegout amount and process both', async () => { + try { + const senderInfo = await createSenderRecipientInfo( + rskTxHelper, + btcTxHelper, + 'legacy', + BTC_FUNDING_AMOUNT_IN_BTC + ); + + const peginBtcTxHash = await sendPeginToActiveFederation( + rskTxHelper, + btcTxHelper, + senderInfo.btcSenderAddressInfo, + FEDERATION_PEGIN_AMOUNT_IN_BTC + ); + await ensurePeginIsRegistered(rskTxHelper, peginBtcTxHash); + + const bridgeStateAfterPegin = await getBridgeState(rskTxHelper.getClient()); + const peginUtxoInBridgeState = bridgeStateAfterPegin.activeFederationUtxos.find( + (utxo) => + utxo.btcTxHash === peginBtcTxHash && + utxo.valueInSatoshis === FEDERATION_PEGIN_AMOUNT_IN_SATOSHIS + ); + expect(peginUtxoInBridgeState).to.not.be.undefined; + + await sendFromCow( + rskTxHelper, + senderInfo.rskRecipientRskAddressInfo.address, + Number(btcToWeis(PEGOUT_SENDER_FUNDING_IN_BTC)) + ); + + await sendTxToBridge( + rskTxHelper, + new BN(satoshisToWeis(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS)), + senderInfo.rskRecipientRskAddressInfo.address + ); + + const estimatedFeesForPegout = Number( + await bridge.methods + .getEstimatedFeesForPegOutAmount(satoshisToWeis(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS)) + .call() + ); + expect(estimatedFeesForPegout).to.be.greaterThan(0); + + const secondPegoutAmountInSatoshis = + MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS + estimatedFeesForPegout; + await sendTxToBridge( + rskTxHelper, + new BN(satoshisToWeis(secondPegoutAmountInSatoshis)), + senderInfo.rskRecipientRskAddressInfo.address + ); + + const countBeforeRelease = await getQueuedPegoutsCount(); + expect(countBeforeRelease).to.equal(2); + + await triggerRelease(rskTxHelpers, btcTxHelper); + + const countAfterRelease = await getQueuedPegoutsCount(); + expect(countAfterRelease).to.equal(0); + } catch (err) { + throw new CustomError( + 'Error validating getEstimatedFeesForPegOutAmount with two pegouts', + err + ); + } + }); + + it('should revert when peg-out amount in weis is below minimum peg-out', async () => { + await assertContractCallFails( + bridge.methods.getEstimatedFeesForPegOutAmount( + satoshisToWeis(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS - 1) + ) + ); + }); +}); From 7b6cb5bac55019fc14096150ec71985d5fd9d8ea Mon Sep 17 00:00:00 2001 From: Julian Len Date: Thu, 9 Apr 2026 15:51:07 -0300 Subject: [PATCH 04/31] improved tests names --- tests/01_07_01-get_estimated_fees_for_next_pegout_event.js | 2 +- tests/01_07_02-get_estimated_fees_for_pegout_amount.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/01_07_01-get_estimated_fees_for_next_pegout_event.js b/tests/01_07_01-get_estimated_fees_for_next_pegout_event.js index 709eb49e..380c87fe 100644 --- a/tests/01_07_01-get_estimated_fees_for_next_pegout_event.js +++ b/tests/01_07_01-get_estimated_fees_for_next_pegout_event.js @@ -48,7 +48,7 @@ describe('getEstimatedFeesForNextPegOutEvent', () => { await triggerRelease(rskTxHelpers, btcTxHelper); }); - it('should allow constructing a second pegout request using the estimated fees and process both', async () => { + it('should allow constructing a second pegout request using the fees from getEstimatedFeesForNextPegoutEvent and process both', async () => { try { const senderInfo = await createSenderRecipientInfo( rskTxHelper, diff --git a/tests/01_07_02-get_estimated_fees_for_pegout_amount.js b/tests/01_07_02-get_estimated_fees_for_pegout_amount.js index 02c3876f..5c344c68 100644 --- a/tests/01_07_02-get_estimated_fees_for_pegout_amount.js +++ b/tests/01_07_02-get_estimated_fees_for_pegout_amount.js @@ -46,7 +46,7 @@ describe('getEstimatedFeesForPegOutAmount', () => { await triggerRelease(rskTxHelpers, btcTxHelper); }); - it('should allow constructing a second pegout request using the estimated fees for pegout amount and process both', async () => { + it('should allow constructing a second pegout request using the estimated fees from getEstimatedFeesForPegOutAmount and process both', async () => { try { const senderInfo = await createSenderRecipientInfo( rskTxHelper, From 036cad46c2158b2ef6cdeb76546a140f256316aa Mon Sep 17 00:00:00 2001 From: Julian Len Date: Fri, 10 Apr 2026 09:31:17 -0300 Subject: [PATCH 05/31] extracted the call to getEstimatedFeesForPegOutAmount --- tests/01_07_02-get_estimated_fees_for_pegout_amount.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/01_07_02-get_estimated_fees_for_pegout_amount.js b/tests/01_07_02-get_estimated_fees_for_pegout_amount.js index 5c344c68..8886f9f6 100644 --- a/tests/01_07_02-get_estimated_fees_for_pegout_amount.js +++ b/tests/01_07_02-get_estimated_fees_for_pegout_amount.js @@ -30,6 +30,9 @@ let btcTxHelper; const getQueuedPegoutsCount = async () => Number(await bridge.methods.getQueuedPegoutsCount().call()); +const getEstimatedFeesForPegOutAmount = async (amountInWeis) => + Number(await bridge.methods.getEstimatedFeesForPegOutAmount(amountInWeis).call()); + describe('getEstimatedFeesForPegOutAmount', () => { before(async () => { rskTxHelper = getRskTransactionHelper(); @@ -83,10 +86,8 @@ describe('getEstimatedFeesForPegOutAmount', () => { senderInfo.rskRecipientRskAddressInfo.address ); - const estimatedFeesForPegout = Number( - await bridge.methods - .getEstimatedFeesForPegOutAmount(satoshisToWeis(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS)) - .call() + const estimatedFeesForPegout = await getEstimatedFeesForPegOutAmount( + satoshisToWeis(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS) ); expect(estimatedFeesForPegout).to.be.greaterThan(0); From 30c16f78c4f93376cebc96aa80dd42305ab41a15 Mon Sep 17 00:00:00 2001 From: Julian Len Date: Fri, 10 Apr 2026 09:53:24 -0300 Subject: [PATCH 06/31] merge both getEstimatedFees methods in one file --- lib/tests/get_estimated_fees_methods.js | 170 ++++++++++++++++++ ...et_estimated_fees_for_next_pegout_event.js | 113 ------------ tests/01_07_01-get_estimated_fees_methods.js | 3 + ...02-get_estimated_fees_for_pegout_amount.js | 124 ------------- 4 files changed, 173 insertions(+), 237 deletions(-) create mode 100644 lib/tests/get_estimated_fees_methods.js delete mode 100644 tests/01_07_01-get_estimated_fees_for_next_pegout_event.js create mode 100644 tests/01_07_01-get_estimated_fees_methods.js delete mode 100644 tests/01_07_02-get_estimated_fees_for_pegout_amount.js diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js new file mode 100644 index 00000000..32c189f1 --- /dev/null +++ b/lib/tests/get_estimated_fees_methods.js @@ -0,0 +1,170 @@ +const expect = require('chai').expect; +const BN = require('bn.js'); +const { getBridgeState } = require('@rsksmart/bridge-state-data-parser'); +const { btcToWeis, satoshisToBtc, satoshisToWeis } = require('@rsksmart/btc-eth-unit-converter'); +const { assertContractCallFails } = require('../assertions/contractMethods'); +const { getBridge } = require('../bridge-provider'); +const CustomError = require('../CustomError'); +const { + createSenderRecipientInfo, + ensurePeginIsRegistered, + sendPeginToActiveFederation, + sendTxToBridge, +} = require('../2wp-utils'); +const { getBtcClient } = require('../btc-client-provider'); +const { MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS } = require('../constants/pegout-constants'); +const { getRskTransactionHelper, getRskTransactionHelpers } = require('../rsk-tx-helper-provider'); +const { sendFromCow, triggerRelease } = require('../rsk-utils'); + +const FEDERATION_PEGIN_AMOUNT_IN_SATOSHIS = 500_000; +const FEDERATION_PEGIN_AMOUNT_IN_BTC = Number(satoshisToBtc(FEDERATION_PEGIN_AMOUNT_IN_SATOSHIS)); +const BTC_FUNDING_AMOUNT_IN_BTC = 2; +const PEGOUT_SENDER_FUNDING_IN_BTC = 2; + +/** + * @param {string} [description] + */ +const execute = (description) => { + let bridge; + let rskTxHelper; + let rskTxHelpers; + let btcTxHelper; + let senderInfo; + + const getQueuedPegoutsCount = async () => + Number(await bridge.methods.getQueuedPegoutsCount().call()); + + const getEstimatedFeesForNextPegoutEvent = async () => + Number(await bridge.methods.getEstimatedFeesForNextPegOutEvent().call()); + + const getEstimatedFeesForPegOutAmount = async (amountInWeis) => + Number(await bridge.methods.getEstimatedFeesForPegOutAmount(amountInWeis).call()); + + const setupFedUtxosAndCreateAPegoutRequest = async () => { + senderInfo = await createSenderRecipientInfo( + rskTxHelper, + btcTxHelper, + 'legacy', + BTC_FUNDING_AMOUNT_IN_BTC + ); + + const peginBtcTxHash = await sendPeginToActiveFederation( + rskTxHelper, + btcTxHelper, + senderInfo.btcSenderAddressInfo, + FEDERATION_PEGIN_AMOUNT_IN_BTC + ); + await ensurePeginIsRegistered(rskTxHelper, peginBtcTxHash); + + const bridgeStateAfterPegin = await getBridgeState(rskTxHelper.getClient()); + const peginUtxoInBridgeState = bridgeStateAfterPegin.activeFederationUtxos.find( + (utxo) => + utxo.btcTxHash === peginBtcTxHash && + utxo.valueInSatoshis === FEDERATION_PEGIN_AMOUNT_IN_SATOSHIS + ); + expect(peginUtxoInBridgeState).to.not.be.undefined; + + await sendFromCow( + rskTxHelper, + senderInfo.rskRecipientRskAddressInfo.address, + Number(btcToWeis(PEGOUT_SENDER_FUNDING_IN_BTC)) + ); + + await sendTxToBridge( + rskTxHelper, + new BN(satoshisToWeis(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS)), + senderInfo.rskRecipientRskAddressInfo.address + ); + }; + + const assertReleaseRequestsAreProcessed = async () => { + const countBeforeRelease = await getQueuedPegoutsCount(); + const expectedPegoutCount = 2; + expect(countBeforeRelease).to.equal(expectedPegoutCount); + + await triggerRelease(rskTxHelpers, btcTxHelper); + + const countAfterRelease = await getQueuedPegoutsCount(); + expect(countAfterRelease).to.equal(0); + }; + + describe(description, () => { + before(async () => { + rskTxHelper = getRskTransactionHelper(); + rskTxHelpers = getRskTransactionHelpers(); + btcTxHelper = getBtcClient(); + bridge = await getBridge(rskTxHelper.getClient()); + }); + + beforeEach(async () => { + await triggerRelease(rskTxHelpers, btcTxHelper); + await setupFedUtxosAndCreateAPegoutRequest(); + }); + + afterEach(async () => { + await triggerRelease(rskTxHelpers, btcTxHelper); + }); + + describe('getEstimatedFeesForNextPegOutEvent', () => { + it('should allow constructing a second pegout request using the fees from getEstimatedFeesForNextPegoutEvent and process both', async () => { + try { + const estimatedFeesForNextPegout = await getEstimatedFeesForNextPegoutEvent(); + expect(estimatedFeesForNextPegout).to.be.greaterThan(0); + + const secondPegoutAmountInSatoshis = + MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS + estimatedFeesForNextPegout; + await sendTxToBridge( + rskTxHelper, + new BN(satoshisToWeis(secondPegoutAmountInSatoshis)), + senderInfo.rskRecipientRskAddressInfo.address + ); + + await assertReleaseRequestsAreProcessed(); + } catch (err) { + throw new CustomError( + 'Error validating getEstimatedFeesForNextPegOutEvent with two pegouts', + err + ); + } + }); + }); + + describe('getEstimatedFeesForPegOutAmount', () => { + it('should allow constructing a second pegout request using the estimated fees from getEstimatedFeesForPegOutAmount and process both', async () => { + try { + const estimatedFeesForPegout = await getEstimatedFeesForPegOutAmount( + satoshisToWeis(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS) + ); + expect(estimatedFeesForPegout).to.be.greaterThan(0); + + const secondPegoutAmountInSatoshis = + MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS + estimatedFeesForPegout; + await sendTxToBridge( + rskTxHelper, + new BN(satoshisToWeis(secondPegoutAmountInSatoshis)), + senderInfo.rskRecipientRskAddressInfo.address + ); + + await assertReleaseRequestsAreProcessed(); + } catch (err) { + throw new CustomError( + 'Error validating getEstimatedFeesForPegOutAmount with two pegouts', + err + ); + } + }); + + it('should revert when peg-out amount in weis is below minimum peg-out', async () => { + await assertContractCallFails( + getEstimatedFeesForPegOutAmount( + satoshisToWeis(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS - 1) + ) + ); + }); + }); + }); +}; + +module.exports = { + execute, +}; diff --git a/tests/01_07_01-get_estimated_fees_for_next_pegout_event.js b/tests/01_07_01-get_estimated_fees_for_next_pegout_event.js deleted file mode 100644 index 380c87fe..00000000 --- a/tests/01_07_01-get_estimated_fees_for_next_pegout_event.js +++ /dev/null @@ -1,113 +0,0 @@ -const expect = require('chai').expect; -const BN = require('bn.js'); -const { getBridgeState } = require('@rsksmart/bridge-state-data-parser'); -const { btcToWeis, satoshisToBtc, satoshisToWeis } = require('@rsksmart/btc-eth-unit-converter'); -const { getBridge } = require('../lib/bridge-provider'); -const CustomError = require('../lib/CustomError'); -const { - createSenderRecipientInfo, - ensurePeginIsRegistered, - sendPeginToActiveFederation, - sendTxToBridge, -} = require('../lib/2wp-utils'); -const { getBtcClient } = require('../lib/btc-client-provider'); -const { - MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS, -} = require('../lib/constants/pegout-constants'); -const { getRskTransactionHelper, getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); -const { sendFromCow, triggerRelease } = require('../lib/rsk-utils'); - -const FEDERATION_PEGIN_AMOUNT_IN_SATOSHIS = 500_000; -const FEDERATION_PEGIN_AMOUNT_IN_BTC = Number(satoshisToBtc(FEDERATION_PEGIN_AMOUNT_IN_SATOSHIS)); -const BTC_FUNDING_AMOUNT_IN_BTC = 2; -const PEGOUT_SENDER_FUNDING_IN_BTC = 2; - -let bridge; -let rskTxHelper; -let rskTxHelpers; -let btcTxHelper; - -const getQueuedPegoutsCount = async () => Number(await bridge.methods.getQueuedPegoutsCount().call()); - -const getEstimatedFeesForNextPegoutEvent = async () => - Number(await bridge.methods.getEstimatedFeesForNextPegOutEvent().call()); - -describe('getEstimatedFeesForNextPegOutEvent', () => { - before(async () => { - rskTxHelper = getRskTransactionHelper(); - rskTxHelpers = getRskTransactionHelpers(); - btcTxHelper = getBtcClient(); - bridge = await getBridge(rskTxHelper.getClient()); - }); - - beforeEach(async () => { - await triggerRelease(rskTxHelpers, btcTxHelper); - }); - - afterEach(async () => { - await triggerRelease(rskTxHelpers, btcTxHelper); - }); - - it('should allow constructing a second pegout request using the fees from getEstimatedFeesForNextPegoutEvent and process both', async () => { - try { - const senderInfo = await createSenderRecipientInfo( - rskTxHelper, - btcTxHelper, - 'legacy', - BTC_FUNDING_AMOUNT_IN_BTC - ); - - const peginBtcTxHash = await sendPeginToActiveFederation( - rskTxHelper, - btcTxHelper, - senderInfo.btcSenderAddressInfo, - FEDERATION_PEGIN_AMOUNT_IN_BTC - ); - await ensurePeginIsRegistered(rskTxHelper, peginBtcTxHash); - - const bridgeStateAfterPegin = await getBridgeState(rskTxHelper.getClient()); - const peginUtxoInBridgeState = bridgeStateAfterPegin.activeFederationUtxos.find( - (utxo) => - utxo.btcTxHash === peginBtcTxHash && - utxo.valueInSatoshis === FEDERATION_PEGIN_AMOUNT_IN_SATOSHIS - ); - expect(peginUtxoInBridgeState).to.not.be.undefined; - - await sendFromCow( - rskTxHelper, - senderInfo.rskRecipientRskAddressInfo.address, - Number(btcToWeis(PEGOUT_SENDER_FUNDING_IN_BTC)) - ); - - await sendTxToBridge( - rskTxHelper, - new BN(satoshisToWeis(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS)), - senderInfo.rskRecipientRskAddressInfo.address - ); - - const estimatedFeesForNextPegout = await getEstimatedFeesForNextPegoutEvent(); - expect(estimatedFeesForNextPegout).to.be.greaterThan(0); - - const secondPegoutAmountInSatoshis = - MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS + estimatedFeesForNextPegout; - await sendTxToBridge( - rskTxHelper, - new BN(satoshisToWeis(secondPegoutAmountInSatoshis)), - senderInfo.rskRecipientRskAddressInfo.address - ); - - const countBeforeRelease = await getQueuedPegoutsCount(); - expect(countBeforeRelease).to.equal(2); - - await triggerRelease(rskTxHelpers, btcTxHelper); - - const countAfterRelease = await getQueuedPegoutsCount(); - expect(countAfterRelease).to.equal(0); - } catch (err) { - throw new CustomError( - 'Error validating getEstimatedFeesForNextPegOutEvent with two pegouts', - err - ); - } - }); -}); diff --git a/tests/01_07_01-get_estimated_fees_methods.js b/tests/01_07_01-get_estimated_fees_methods.js new file mode 100644 index 00000000..48cb727a --- /dev/null +++ b/tests/01_07_01-get_estimated_fees_methods.js @@ -0,0 +1,3 @@ +const getEstimatedFeesMethodsTests = require('../lib/tests/get_estimated_fees_methods'); + +getEstimatedFeesMethodsTests.execute('Bridge peg-out fee estimation methods'); diff --git a/tests/01_07_02-get_estimated_fees_for_pegout_amount.js b/tests/01_07_02-get_estimated_fees_for_pegout_amount.js deleted file mode 100644 index 8886f9f6..00000000 --- a/tests/01_07_02-get_estimated_fees_for_pegout_amount.js +++ /dev/null @@ -1,124 +0,0 @@ -const expect = require('chai').expect; -const BN = require('bn.js'); -const { getBridgeState } = require('@rsksmart/bridge-state-data-parser'); -const { btcToWeis, satoshisToBtc, satoshisToWeis } = require('@rsksmart/btc-eth-unit-converter'); -const { assertContractCallFails } = require('../lib/assertions/contractMethods'); -const { getBridge } = require('../lib/bridge-provider'); -const CustomError = require('../lib/CustomError'); -const { - createSenderRecipientInfo, - ensurePeginIsRegistered, - sendPeginToActiveFederation, - sendTxToBridge, -} = require('../lib/2wp-utils'); -const { getBtcClient } = require('../lib/btc-client-provider'); -const { - MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS, -} = require('../lib/constants/pegout-constants'); -const { getRskTransactionHelper, getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); -const { sendFromCow, triggerRelease } = require('../lib/rsk-utils'); - -const FEDERATION_PEGIN_AMOUNT_IN_SATOSHIS = 500_000; -const FEDERATION_PEGIN_AMOUNT_IN_BTC = Number(satoshisToBtc(FEDERATION_PEGIN_AMOUNT_IN_SATOSHIS)); -const BTC_FUNDING_AMOUNT_IN_BTC = 2; -const PEGOUT_SENDER_FUNDING_IN_BTC = 2; - -let bridge; -let rskTxHelper; -let rskTxHelpers; -let btcTxHelper; - -const getQueuedPegoutsCount = async () => Number(await bridge.methods.getQueuedPegoutsCount().call()); - -const getEstimatedFeesForPegOutAmount = async (amountInWeis) => - Number(await bridge.methods.getEstimatedFeesForPegOutAmount(amountInWeis).call()); - -describe('getEstimatedFeesForPegOutAmount', () => { - before(async () => { - rskTxHelper = getRskTransactionHelper(); - rskTxHelpers = getRskTransactionHelpers(); - btcTxHelper = getBtcClient(); - bridge = await getBridge(rskTxHelper.getClient()); - }); - - beforeEach(async () => { - await triggerRelease(rskTxHelpers, btcTxHelper); - }); - - afterEach(async () => { - await triggerRelease(rskTxHelpers, btcTxHelper); - }); - - it('should allow constructing a second pegout request using the estimated fees from getEstimatedFeesForPegOutAmount and process both', async () => { - try { - const senderInfo = await createSenderRecipientInfo( - rskTxHelper, - btcTxHelper, - 'legacy', - BTC_FUNDING_AMOUNT_IN_BTC - ); - - const peginBtcTxHash = await sendPeginToActiveFederation( - rskTxHelper, - btcTxHelper, - senderInfo.btcSenderAddressInfo, - FEDERATION_PEGIN_AMOUNT_IN_BTC - ); - await ensurePeginIsRegistered(rskTxHelper, peginBtcTxHash); - - const bridgeStateAfterPegin = await getBridgeState(rskTxHelper.getClient()); - const peginUtxoInBridgeState = bridgeStateAfterPegin.activeFederationUtxos.find( - (utxo) => - utxo.btcTxHash === peginBtcTxHash && - utxo.valueInSatoshis === FEDERATION_PEGIN_AMOUNT_IN_SATOSHIS - ); - expect(peginUtxoInBridgeState).to.not.be.undefined; - - await sendFromCow( - rskTxHelper, - senderInfo.rskRecipientRskAddressInfo.address, - Number(btcToWeis(PEGOUT_SENDER_FUNDING_IN_BTC)) - ); - - await sendTxToBridge( - rskTxHelper, - new BN(satoshisToWeis(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS)), - senderInfo.rskRecipientRskAddressInfo.address - ); - - const estimatedFeesForPegout = await getEstimatedFeesForPegOutAmount( - satoshisToWeis(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS) - ); - expect(estimatedFeesForPegout).to.be.greaterThan(0); - - const secondPegoutAmountInSatoshis = - MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS + estimatedFeesForPegout; - await sendTxToBridge( - rskTxHelper, - new BN(satoshisToWeis(secondPegoutAmountInSatoshis)), - senderInfo.rskRecipientRskAddressInfo.address - ); - - const countBeforeRelease = await getQueuedPegoutsCount(); - expect(countBeforeRelease).to.equal(2); - - await triggerRelease(rskTxHelpers, btcTxHelper); - - const countAfterRelease = await getQueuedPegoutsCount(); - expect(countAfterRelease).to.equal(0); - } catch (err) { - throw new CustomError( - 'Error validating getEstimatedFeesForPegOutAmount with two pegouts', - err - ); - } - }); - - it('should revert when peg-out amount in weis is below minimum peg-out', async () => { - await assertContractCallFails( - bridge.methods.getEstimatedFeesForPegOutAmount( - satoshisToWeis(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS - 1) - ) - ); - }); -}); From d3ede49247e247c29ae977fa52fd2007e1abcdc0 Mon Sep 17 00:00:00 2001 From: Julian Len Date: Mon, 13 Apr 2026 10:19:21 -0300 Subject: [PATCH 07/31] activate vetiver900 from block 1 --- test.js | 1 + tests/01_07_00-activate-latest-fork.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/test.js b/test.js index 0c6dd215..2bf9004a 100644 --- a/test.js +++ b/test.js @@ -101,6 +101,7 @@ global.Runners = { arrowhead631: createForkObject('arrowhead631', 1), lovell700: createForkObject('lovell700', 1), reed800: createForkObject('reed800', 1), + vetiver900: createForkObject('vetiver900', 1), }, additionalFederationAddresses: [], }, diff --git a/tests/01_07_00-activate-latest-fork.js b/tests/01_07_00-activate-latest-fork.js index 97d6e817..bb6e4f99 100644 --- a/tests/01_07_00-activate-latest-fork.js +++ b/tests/01_07_00-activate-latest-fork.js @@ -2,5 +2,5 @@ const activateForkTest = require('../lib/tests/activate-fork'); // Skipped activate-fork.js. When there is a new fork to be tested pre and post, unskip it in the activate-fork.js file // activateForkTest.execute( -// Runners.common.forks.reed800 +// Runners.common.forks.vetiver900 // ); From 5356a9741b0d54b56af4431a7e5ab6ed8e6b4a16 Mon Sep 17 00:00:00 2001 From: Julian Len Date: Mon, 13 Apr 2026 10:35:40 -0300 Subject: [PATCH 08/31] getEstimatedFeesForPegoutAmount method is called once --- lib/tests/get_estimated_fees_methods.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js index 32c189f1..98fd4cbc 100644 --- a/lib/tests/get_estimated_fees_methods.js +++ b/lib/tests/get_estimated_fees_methods.js @@ -37,9 +37,6 @@ const execute = (description) => { const getEstimatedFeesForNextPegoutEvent = async () => Number(await bridge.methods.getEstimatedFeesForNextPegOutEvent().call()); - const getEstimatedFeesForPegOutAmount = async (amountInWeis) => - Number(await bridge.methods.getEstimatedFeesForPegOutAmount(amountInWeis).call()); - const setupFedUtxosAndCreateAPegoutRequest = async () => { senderInfo = await createSenderRecipientInfo( rskTxHelper, @@ -132,9 +129,9 @@ const execute = (description) => { describe('getEstimatedFeesForPegOutAmount', () => { it('should allow constructing a second pegout request using the estimated fees from getEstimatedFeesForPegOutAmount and process both', async () => { try { - const estimatedFeesForPegout = await getEstimatedFeesForPegOutAmount( - satoshisToWeis(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS) - ); + const estimatedFeesForPegout = Number(await bridge.methods + .getEstimatedFeesForPegOutAmount(satoshisToWeis(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS)) + .call()); expect(estimatedFeesForPegout).to.be.greaterThan(0); const secondPegoutAmountInSatoshis = @@ -156,7 +153,7 @@ const execute = (description) => { it('should revert when peg-out amount in weis is below minimum peg-out', async () => { await assertContractCallFails( - getEstimatedFeesForPegOutAmount( + bridge.methods.getEstimatedFeesForPegOutAmount( satoshisToWeis(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS - 1) ) ); From 319267654d7231ae1c2149737d3337f70d4f753d Mon Sep 17 00:00:00 2001 From: Julian Len Date: Mon, 13 Apr 2026 12:03:34 -0300 Subject: [PATCH 09/31] instead of calling getRskTransactionHelper and getRskTransactionHelpers, call the last one and use it --- lib/tests/get_estimated_fees_methods.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js index 98fd4cbc..92d6a93c 100644 --- a/lib/tests/get_estimated_fees_methods.js +++ b/lib/tests/get_estimated_fees_methods.js @@ -87,8 +87,8 @@ const execute = (description) => { describe(description, () => { before(async () => { - rskTxHelper = getRskTransactionHelper(); rskTxHelpers = getRskTransactionHelpers(); + rskTxHelper = rskTxHelpers[0]; btcTxHelper = getBtcClient(); bridge = await getBridge(rskTxHelper.getClient()); }); From 18b783f76cf848974938ddaedae6d5f46fa5f5f7 Mon Sep 17 00:00:00 2001 From: Julian Len Date: Mon, 13 Apr 2026 12:04:38 -0300 Subject: [PATCH 10/31] deleted unused import --- lib/tests/get_estimated_fees_methods.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js index 92d6a93c..a1d12085 100644 --- a/lib/tests/get_estimated_fees_methods.js +++ b/lib/tests/get_estimated_fees_methods.js @@ -13,7 +13,7 @@ const { } = require('../2wp-utils'); const { getBtcClient } = require('../btc-client-provider'); const { MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS } = require('../constants/pegout-constants'); -const { getRskTransactionHelper, getRskTransactionHelpers } = require('../rsk-tx-helper-provider'); +const { getRskTransactionHelpers } = require('../rsk-tx-helper-provider'); const { sendFromCow, triggerRelease } = require('../rsk-utils'); const FEDERATION_PEGIN_AMOUNT_IN_SATOSHIS = 500_000; From 6b657f43ac8f7b13dd2771a0488856f97e2dbe31 Mon Sep 17 00:00:00 2001 From: Julian Len Date: Mon, 13 Apr 2026 12:05:21 -0300 Subject: [PATCH 11/31] it's not needed to trigger a release before and after each test, after is enough --- lib/tests/get_estimated_fees_methods.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js index a1d12085..14bb71a9 100644 --- a/lib/tests/get_estimated_fees_methods.js +++ b/lib/tests/get_estimated_fees_methods.js @@ -94,7 +94,6 @@ const execute = (description) => { }); beforeEach(async () => { - await triggerRelease(rskTxHelpers, btcTxHelper); await setupFedUtxosAndCreateAPegoutRequest(); }); From 11118678ebf8098dc7c9f1e4680acbf8cca06012 Mon Sep 17 00:00:00 2001 From: Julian Len Date: Mon, 13 Apr 2026 12:06:44 -0300 Subject: [PATCH 12/31] added comment to explain why triggerRelease is called after each test --- lib/tests/get_estimated_fees_methods.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js index 14bb71a9..05992ceb 100644 --- a/lib/tests/get_estimated_fees_methods.js +++ b/lib/tests/get_estimated_fees_methods.js @@ -97,6 +97,8 @@ const execute = (description) => { await setupFedUtxosAndCreateAPegoutRequest(); }); + // Ensuring there's no pegout pending in the Bridge contract + // after each test to avoid interference between tests afterEach(async () => { await triggerRelease(rskTxHelpers, btcTxHelper); }); From 16a933f9131ca0c55505b4a7421e332b689ee101 Mon Sep 17 00:00:00 2001 From: Julian Len Date: Mon, 13 Apr 2026 12:17:19 -0300 Subject: [PATCH 13/31] renamed assertReleaseRequestsAreProcessed to processReleaseRequestsAndAssertQueueCleared --- lib/tests/get_estimated_fees_methods.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js index 05992ceb..afe3d846 100644 --- a/lib/tests/get_estimated_fees_methods.js +++ b/lib/tests/get_estimated_fees_methods.js @@ -74,7 +74,7 @@ const execute = (description) => { ); }; - const assertReleaseRequestsAreProcessed = async () => { + const processReleaseRequestsAndAssertQueueCleared = async () => { const countBeforeRelease = await getQueuedPegoutsCount(); const expectedPegoutCount = 2; expect(countBeforeRelease).to.equal(expectedPegoutCount); @@ -117,7 +117,7 @@ const execute = (description) => { senderInfo.rskRecipientRskAddressInfo.address ); - await assertReleaseRequestsAreProcessed(); + await processReleaseRequestsAndAssertQueueCleared(); } catch (err) { throw new CustomError( 'Error validating getEstimatedFeesForNextPegOutEvent with two pegouts', @@ -143,7 +143,7 @@ const execute = (description) => { senderInfo.rskRecipientRskAddressInfo.address ); - await assertReleaseRequestsAreProcessed(); + await processReleaseRequestsAndAssertQueueCleared(); } catch (err) { throw new CustomError( 'Error validating getEstimatedFeesForPegOutAmount with two pegouts', From 0a3543831cbc351191ce94fdddd6e93a1543ff2d Mon Sep 17 00:00:00 2001 From: Julian Len Date: Mon, 13 Apr 2026 12:24:50 -0300 Subject: [PATCH 14/31] renamed setupFedUtxosAndCreateAPegoutRequest to setupFedUtxosAndAddAPegoutRequestToTheBridge --- lib/tests/get_estimated_fees_methods.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js index afe3d846..4900486b 100644 --- a/lib/tests/get_estimated_fees_methods.js +++ b/lib/tests/get_estimated_fees_methods.js @@ -37,7 +37,7 @@ const execute = (description) => { const getEstimatedFeesForNextPegoutEvent = async () => Number(await bridge.methods.getEstimatedFeesForNextPegOutEvent().call()); - const setupFedUtxosAndCreateAPegoutRequest = async () => { + const setupFedUtxosAndAddAPegoutRequestToTheBridge = async () => { senderInfo = await createSenderRecipientInfo( rskTxHelper, btcTxHelper, @@ -94,7 +94,7 @@ const execute = (description) => { }); beforeEach(async () => { - await setupFedUtxosAndCreateAPegoutRequest(); + await setupFedUtxosAndAddAPegoutRequestToTheBridge(); }); // Ensuring there's no pegout pending in the Bridge contract From 6335839a3f0d7b7667eddb17dceafcf027e44323 Mon Sep 17 00:00:00 2001 From: Julian Len Date: Tue, 14 Apr 2026 10:50:00 -0300 Subject: [PATCH 15/31] changed estimatedFeesForNextPegout to estimatedFeesForNextPegOut --- lib/tests/get_estimated_fees_methods.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js index 4900486b..3443cad6 100644 --- a/lib/tests/get_estimated_fees_methods.js +++ b/lib/tests/get_estimated_fees_methods.js @@ -34,7 +34,7 @@ const execute = (description) => { const getQueuedPegoutsCount = async () => Number(await bridge.methods.getQueuedPegoutsCount().call()); - const getEstimatedFeesForNextPegoutEvent = async () => + const getEstimatedFeesForNextPegOutEvent = async () => Number(await bridge.methods.getEstimatedFeesForNextPegOutEvent().call()); const setupFedUtxosAndAddAPegoutRequestToTheBridge = async () => { @@ -104,13 +104,13 @@ const execute = (description) => { }); describe('getEstimatedFeesForNextPegOutEvent', () => { - it('should allow constructing a second pegout request using the fees from getEstimatedFeesForNextPegoutEvent and process both', async () => { + it('should allow constructing a second pegout request using the fees from getEstimatedFeesForNextPegOutEvent and process both', async () => { try { - const estimatedFeesForNextPegout = await getEstimatedFeesForNextPegoutEvent(); - expect(estimatedFeesForNextPegout).to.be.greaterThan(0); + const estimatedFeesForNextPegOut = await getEstimatedFeesForNextPegOutEvent(); + expect(estimatedFeesForNextPegOut).to.be.greaterThan(0); const secondPegoutAmountInSatoshis = - MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS + estimatedFeesForNextPegout; + MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS + estimatedFeesForNextPegOut; await sendTxToBridge( rskTxHelper, new BN(satoshisToWeis(secondPegoutAmountInSatoshis)), From 748854064f86c6f04cb2e8bd4cf0a8fce4843663 Mon Sep 17 00:00:00 2001 From: Julian Len Date: Tue, 14 Apr 2026 10:59:49 -0300 Subject: [PATCH 16/31] removed unnecessary try/catch --- lib/tests/get_estimated_fees_methods.js | 62 ++++++++++--------------- 1 file changed, 24 insertions(+), 38 deletions(-) diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js index 3443cad6..3c7a469d 100644 --- a/lib/tests/get_estimated_fees_methods.js +++ b/lib/tests/get_estimated_fees_methods.js @@ -105,51 +105,37 @@ const execute = (description) => { describe('getEstimatedFeesForNextPegOutEvent', () => { it('should allow constructing a second pegout request using the fees from getEstimatedFeesForNextPegOutEvent and process both', async () => { - try { - const estimatedFeesForNextPegOut = await getEstimatedFeesForNextPegOutEvent(); - expect(estimatedFeesForNextPegOut).to.be.greaterThan(0); - - const secondPegoutAmountInSatoshis = - MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS + estimatedFeesForNextPegOut; - await sendTxToBridge( - rskTxHelper, - new BN(satoshisToWeis(secondPegoutAmountInSatoshis)), - senderInfo.rskRecipientRskAddressInfo.address - ); - - await processReleaseRequestsAndAssertQueueCleared(); - } catch (err) { - throw new CustomError( - 'Error validating getEstimatedFeesForNextPegOutEvent with two pegouts', - err - ); - } + const estimatedFeesForNextPegOut = await getEstimatedFeesForNextPegOutEvent(); + expect(estimatedFeesForNextPegOut).to.be.greaterThan(0); + + const secondPegoutAmountInSatoshis = + MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS + estimatedFeesForNextPegOut; + await sendTxToBridge( + rskTxHelper, + new BN(satoshisToWeis(secondPegoutAmountInSatoshis)), + senderInfo.rskRecipientRskAddressInfo.address + ); + + await processReleaseRequestsAndAssertQueueCleared(); }); }); describe('getEstimatedFeesForPegOutAmount', () => { it('should allow constructing a second pegout request using the estimated fees from getEstimatedFeesForPegOutAmount and process both', async () => { - try { - const estimatedFeesForPegout = Number(await bridge.methods - .getEstimatedFeesForPegOutAmount(satoshisToWeis(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS)) - .call()); + const estimatedFeesForPegout = Number(await bridge.methods + .getEstimatedFeesForPegOutAmount(satoshisToWeis(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS)) + .call()); expect(estimatedFeesForPegout).to.be.greaterThan(0); - const secondPegoutAmountInSatoshis = - MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS + estimatedFeesForPegout; - await sendTxToBridge( - rskTxHelper, - new BN(satoshisToWeis(secondPegoutAmountInSatoshis)), - senderInfo.rskRecipientRskAddressInfo.address - ); - - await processReleaseRequestsAndAssertQueueCleared(); - } catch (err) { - throw new CustomError( - 'Error validating getEstimatedFeesForPegOutAmount with two pegouts', - err - ); - } + const secondPegoutAmountInSatoshis = + MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS + estimatedFeesForPegout; + await sendTxToBridge( + rskTxHelper, + new BN(satoshisToWeis(secondPegoutAmountInSatoshis)), + senderInfo.rskRecipientRskAddressInfo.address + ); + + await processReleaseRequestsAndAssertQueueCleared(); }); it('should revert when peg-out amount in weis is below minimum peg-out', async () => { From 3b7148f777db08431270470c2a033d1f3ad11bd1 Mon Sep 17 00:00:00 2001 From: Julian Len Date: Tue, 14 Apr 2026 11:05:17 -0300 Subject: [PATCH 17/31] Extracted getEstimatedFeesForPegOutAmount --- lib/tests/get_estimated_fees_methods.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js index 3c7a469d..e1b42c1b 100644 --- a/lib/tests/get_estimated_fees_methods.js +++ b/lib/tests/get_estimated_fees_methods.js @@ -4,7 +4,6 @@ const { getBridgeState } = require('@rsksmart/bridge-state-data-parser'); const { btcToWeis, satoshisToBtc, satoshisToWeis } = require('@rsksmart/btc-eth-unit-converter'); const { assertContractCallFails } = require('../assertions/contractMethods'); const { getBridge } = require('../bridge-provider'); -const CustomError = require('../CustomError'); const { createSenderRecipientInfo, ensurePeginIsRegistered, @@ -37,6 +36,9 @@ const execute = (description) => { const getEstimatedFeesForNextPegOutEvent = async () => Number(await bridge.methods.getEstimatedFeesForNextPegOutEvent().call()); + const getEstimatedFeesForPegOutAmount = async (satoshis) => await bridge.methods + .getEstimatedFeesForPegOutAmount(satoshisToWeis(satoshis)) + const setupFedUtxosAndAddAPegoutRequestToTheBridge = async () => { senderInfo = await createSenderRecipientInfo( rskTxHelper, @@ -122,9 +124,7 @@ const execute = (description) => { describe('getEstimatedFeesForPegOutAmount', () => { it('should allow constructing a second pegout request using the estimated fees from getEstimatedFeesForPegOutAmount and process both', async () => { - const estimatedFeesForPegout = Number(await bridge.methods - .getEstimatedFeesForPegOutAmount(satoshisToWeis(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS)) - .call()); + const estimatedFeesForPegout = Number(getEstimatedFeesForPegOutAmount(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS).call()); expect(estimatedFeesForPegout).to.be.greaterThan(0); const secondPegoutAmountInSatoshis = @@ -140,9 +140,7 @@ const execute = (description) => { it('should revert when peg-out amount in weis is below minimum peg-out', async () => { await assertContractCallFails( - bridge.methods.getEstimatedFeesForPegOutAmount( - satoshisToWeis(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS - 1) - ) + getEstimatedFeesForPegOutAmount(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS - 1) ); }); }); From d8a1d241bd8d027ae19112ff3013a74d7b70cc2f Mon Sep 17 00:00:00 2001 From: Julian Len Date: Tue, 14 Apr 2026 11:12:38 -0300 Subject: [PATCH 18/31] extracted sendPegoutWithEstimatedFees --- lib/tests/get_estimated_fees_methods.js | 30 +++++++++++-------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js index e1b42c1b..cb0ef8a5 100644 --- a/lib/tests/get_estimated_fees_methods.js +++ b/lib/tests/get_estimated_fees_methods.js @@ -87,6 +87,16 @@ const execute = (description) => { expect(countAfterRelease).to.equal(0); }; + const sendPegoutWithEstimatedFees = async (estimatedFees) => { + const secondPegoutAmountInSatoshis = + MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS + estimatedFees; + await sendTxToBridge( + rskTxHelper, + new BN(satoshisToWeis(secondPegoutAmountInSatoshis)), + senderInfo.rskRecipientRskAddressInfo.address + ); + }; + describe(description, () => { before(async () => { rskTxHelpers = getRskTransactionHelpers(); @@ -110,14 +120,7 @@ const execute = (description) => { const estimatedFeesForNextPegOut = await getEstimatedFeesForNextPegOutEvent(); expect(estimatedFeesForNextPegOut).to.be.greaterThan(0); - const secondPegoutAmountInSatoshis = - MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS + estimatedFeesForNextPegOut; - await sendTxToBridge( - rskTxHelper, - new BN(satoshisToWeis(secondPegoutAmountInSatoshis)), - senderInfo.rskRecipientRskAddressInfo.address - ); - + await sendPegoutWithEstimatedFees(estimatedFeesForNextPegOut); await processReleaseRequestsAndAssertQueueCleared(); }); }); @@ -125,16 +128,9 @@ const execute = (description) => { describe('getEstimatedFeesForPegOutAmount', () => { it('should allow constructing a second pegout request using the estimated fees from getEstimatedFeesForPegOutAmount and process both', async () => { const estimatedFeesForPegout = Number(getEstimatedFeesForPegOutAmount(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS).call()); - expect(estimatedFeesForPegout).to.be.greaterThan(0); - - const secondPegoutAmountInSatoshis = - MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS + estimatedFeesForPegout; - await sendTxToBridge( - rskTxHelper, - new BN(satoshisToWeis(secondPegoutAmountInSatoshis)), - senderInfo.rskRecipientRskAddressInfo.address - ); + expect(estimatedFeesForPegout).to.be.greaterThan(0); + await sendPegoutWithEstimatedFees(estimatedFeesForPegout); await processReleaseRequestsAndAssertQueueCleared(); }); From 856bf83e5428d33a71dd56a9d9566ae5d26727f1 Mon Sep 17 00:00:00 2001 From: Julian Len Date: Tue, 14 Apr 2026 12:21:56 -0300 Subject: [PATCH 19/31] fix estimatedFeesForPegout --- lib/tests/get_estimated_fees_methods.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js index cb0ef8a5..c8957028 100644 --- a/lib/tests/get_estimated_fees_methods.js +++ b/lib/tests/get_estimated_fees_methods.js @@ -36,7 +36,7 @@ const execute = (description) => { const getEstimatedFeesForNextPegOutEvent = async () => Number(await bridge.methods.getEstimatedFeesForNextPegOutEvent().call()); - const getEstimatedFeesForPegOutAmount = async (satoshis) => await bridge.methods + const getEstimatedFeesForPegOutAmount = (satoshis) => bridge.methods .getEstimatedFeesForPegOutAmount(satoshisToWeis(satoshis)) const setupFedUtxosAndAddAPegoutRequestToTheBridge = async () => { @@ -127,7 +127,7 @@ const execute = (description) => { describe('getEstimatedFeesForPegOutAmount', () => { it('should allow constructing a second pegout request using the estimated fees from getEstimatedFeesForPegOutAmount and process both', async () => { - const estimatedFeesForPegout = Number(getEstimatedFeesForPegOutAmount(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS).call()); + const estimatedFeesForPegout = Number(await getEstimatedFeesForPegOutAmount(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS).call()); expect(estimatedFeesForPegout).to.be.greaterThan(0); await sendPegoutWithEstimatedFees(estimatedFeesForPegout); From 1f2080e0c220b908988103aa6b9d76887c339cb7 Mon Sep 17 00:00:00 2001 From: Julian Len Date: Tue, 14 Apr 2026 12:22:37 -0300 Subject: [PATCH 20/31] renaming test for consistency --- lib/tests/get_estimated_fees_methods.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js index c8957028..09caa251 100644 --- a/lib/tests/get_estimated_fees_methods.js +++ b/lib/tests/get_estimated_fees_methods.js @@ -116,7 +116,7 @@ const execute = (description) => { }); describe('getEstimatedFeesForNextPegOutEvent', () => { - it('should allow constructing a second pegout request using the fees from getEstimatedFeesForNextPegOutEvent and process both', async () => { + it('should allow constructing a second pegout request using the estimated fees from getEstimatedFeesForNextPegOutEvent and process both', async () => { const estimatedFeesForNextPegOut = await getEstimatedFeesForNextPegOutEvent(); expect(estimatedFeesForNextPegOut).to.be.greaterThan(0); From 98fd3d23ca4af2eccd6a6f7df1b36aaa7efa98e6 Mon Sep 17 00:00:00 2001 From: Julian Len Date: Tue, 14 Apr 2026 12:47:12 -0300 Subject: [PATCH 21/31] Added a test to check getEstimatedFees with no requests enqueue --- lib/tests/get_estimated_fees_methods.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js index 09caa251..ac662ba7 100644 --- a/lib/tests/get_estimated_fees_methods.js +++ b/lib/tests/get_estimated_fees_methods.js @@ -19,6 +19,8 @@ const FEDERATION_PEGIN_AMOUNT_IN_SATOSHIS = 500_000; const FEDERATION_PEGIN_AMOUNT_IN_BTC = Number(satoshisToBtc(FEDERATION_PEGIN_AMOUNT_IN_SATOSHIS)); const BTC_FUNDING_AMOUNT_IN_BTC = 2; const PEGOUT_SENDER_FUNDING_IN_BTC = 2; +const TWO_PEGOUT_REQUESTS_EXPECTED = 2; +const ONE_PEGOUT_REQUEST_EXPECTED = 1; /** * @param {string} [description] @@ -76,10 +78,9 @@ const execute = (description) => { ); }; - const processReleaseRequestsAndAssertQueueCleared = async () => { + const processReleaseRequestsAndAssertQueueCleared = async (expectedPegoutRequestCountBeforeRelease) => { const countBeforeRelease = await getQueuedPegoutsCount(); - const expectedPegoutCount = 2; - expect(countBeforeRelease).to.equal(expectedPegoutCount); + expect(countBeforeRelease).to.equal(expectedPegoutRequestCountBeforeRelease); await triggerRelease(rskTxHelpers, btcTxHelper); @@ -121,7 +122,13 @@ const execute = (description) => { expect(estimatedFeesForNextPegOut).to.be.greaterThan(0); await sendPegoutWithEstimatedFees(estimatedFeesForNextPegOut); - await processReleaseRequestsAndAssertQueueCleared(); + await processReleaseRequestsAndAssertQueueCleared(TWO_PEGOUT_REQUESTS_EXPECTED); + + const estimatedFeesForNextPegOutWithNoEnqueuedRequests = await getEstimatedFeesForNextPegOutEvent(); + expect(estimatedFeesForNextPegOutWithNoEnqueuedRequests).to.be.greaterThan(0); + + await sendPegoutWithEstimatedFees(estimatedFeesForNextPegOutWithNoEnqueuedRequests); + await processReleaseRequestsAndAssertQueueCleared(ONE_PEGOUT_REQUEST_EXPECTED); }); }); @@ -131,7 +138,13 @@ const execute = (description) => { expect(estimatedFeesForPegout).to.be.greaterThan(0); await sendPegoutWithEstimatedFees(estimatedFeesForPegout); - await processReleaseRequestsAndAssertQueueCleared(); + await processReleaseRequestsAndAssertQueueCleared(TWO_PEGOUT_REQUESTS_EXPECTED); + + const estimatedFeesForPegOutWithNoEnqueuedRequests = Number(await getEstimatedFeesForPegOutAmount(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS).call()); + expect(estimatedFeesForPegOutWithNoEnqueuedRequests).to.be.greaterThan(0); + + await sendPegoutWithEstimatedFees(estimatedFeesForPegOutWithNoEnqueuedRequests); + await processReleaseRequestsAndAssertQueueCleared(ONE_PEGOUT_REQUEST_EXPECTED); }); it('should revert when peg-out amount in weis is below minimum peg-out', async () => { From e937fc373dfc62fde63607cb51c5c0102815e18c Mon Sep 17 00:00:00 2001 From: Julian Len Date: Tue, 14 Apr 2026 12:52:30 -0300 Subject: [PATCH 22/31] changed test name for consistency --- lib/tests/get_estimated_fees_methods.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js index ac662ba7..7a4dc569 100644 --- a/lib/tests/get_estimated_fees_methods.js +++ b/lib/tests/get_estimated_fees_methods.js @@ -147,7 +147,7 @@ const execute = (description) => { await processReleaseRequestsAndAssertQueueCleared(ONE_PEGOUT_REQUEST_EXPECTED); }); - it('should revert when peg-out amount in weis is below minimum peg-out', async () => { + it('should revert when pegout amount in weis is below minimum pegout', async () => { await assertContractCallFails( getEstimatedFeesForPegOutAmount(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS - 1) ); From 313572edd60728f1a3d60d1840cef8ef688a0a0a Mon Sep 17 00:00:00 2001 From: Julian Len Date: Tue, 14 Apr 2026 12:54:00 -0300 Subject: [PATCH 23/31] added a trailing semi colon --- lib/tests/get_estimated_fees_methods.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js index 7a4dc569..202bd550 100644 --- a/lib/tests/get_estimated_fees_methods.js +++ b/lib/tests/get_estimated_fees_methods.js @@ -39,7 +39,7 @@ const execute = (description) => { Number(await bridge.methods.getEstimatedFeesForNextPegOutEvent().call()); const getEstimatedFeesForPegOutAmount = (satoshis) => bridge.methods - .getEstimatedFeesForPegOutAmount(satoshisToWeis(satoshis)) + .getEstimatedFeesForPegOutAmount(satoshisToWeis(satoshis)); const setupFedUtxosAndAddAPegoutRequestToTheBridge = async () => { senderInfo = await createSenderRecipientInfo( From 1254091157c1b4aa911c0e5dd59141979a3463c3 Mon Sep 17 00:00:00 2001 From: Julian Len Date: Tue, 14 Apr 2026 12:56:05 -0300 Subject: [PATCH 24/31] changed pegout for pegOut for consistency --- lib/tests/get_estimated_fees_methods.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js index 202bd550..8dbb37db 100644 --- a/lib/tests/get_estimated_fees_methods.js +++ b/lib/tests/get_estimated_fees_methods.js @@ -134,10 +134,10 @@ const execute = (description) => { describe('getEstimatedFeesForPegOutAmount', () => { it('should allow constructing a second pegout request using the estimated fees from getEstimatedFeesForPegOutAmount and process both', async () => { - const estimatedFeesForPegout = Number(await getEstimatedFeesForPegOutAmount(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS).call()); - expect(estimatedFeesForPegout).to.be.greaterThan(0); + const estimatedFeesForPegOut = Number(await getEstimatedFeesForPegOutAmount(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS).call()); + expect(estimatedFeesForPegOut).to.be.greaterThan(0); - await sendPegoutWithEstimatedFees(estimatedFeesForPegout); + await sendPegoutWithEstimatedFees(estimatedFeesForPegOut); await processReleaseRequestsAndAssertQueueCleared(TWO_PEGOUT_REQUESTS_EXPECTED); const estimatedFeesForPegOutWithNoEnqueuedRequests = Number(await getEstimatedFeesForPegOutAmount(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS).call()); From 6ea18296a327d98c95cb13d662054c86c137c04e Mon Sep 17 00:00:00 2001 From: Julian Len Date: Tue, 14 Apr 2026 13:01:33 -0300 Subject: [PATCH 25/31] fixed tests title --- lib/tests/get_estimated_fees_methods.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js index 8dbb37db..1edb1511 100644 --- a/lib/tests/get_estimated_fees_methods.js +++ b/lib/tests/get_estimated_fees_methods.js @@ -117,7 +117,7 @@ const execute = (description) => { }); describe('getEstimatedFeesForNextPegOutEvent', () => { - it('should allow constructing a second pegout request using the estimated fees from getEstimatedFeesForNextPegOutEvent and process both', async () => { + it('should build pegouts from getEstimatedFeesForNextPegOutEvent when one pegout is queued and when none are queued, and process all pegouts', async () => { const estimatedFeesForNextPegOut = await getEstimatedFeesForNextPegOutEvent(); expect(estimatedFeesForNextPegOut).to.be.greaterThan(0); @@ -133,11 +133,11 @@ const execute = (description) => { }); describe('getEstimatedFeesForPegOutAmount', () => { - it('should allow constructing a second pegout request using the estimated fees from getEstimatedFeesForPegOutAmount and process both', async () => { - const estimatedFeesForPegOut = Number(await getEstimatedFeesForPegOutAmount(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS).call()); - expect(estimatedFeesForPegOut).to.be.greaterThan(0); + it('should build pegouts from getEstimatedFeesForPegOutAmount when one pegout is queued and when none are queued, and process all pegouts', async () => { + const estimatedFeesForPegout = Number(await getEstimatedFeesForPegOutAmount(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS).call()); + expect(estimatedFeesForPegout).to.be.greaterThan(0); - await sendPegoutWithEstimatedFees(estimatedFeesForPegOut); + await sendPegoutWithEstimatedFees(estimatedFeesForPegout); await processReleaseRequestsAndAssertQueueCleared(TWO_PEGOUT_REQUESTS_EXPECTED); const estimatedFeesForPegOutWithNoEnqueuedRequests = Number(await getEstimatedFeesForPegOutAmount(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS).call()); From d99c7526dc4daff8c64719b9cd436309ec907201 Mon Sep 17 00:00:00 2001 From: Julian Len Date: Thu, 16 Apr 2026 11:22:28 -0300 Subject: [PATCH 26/31] added error messages --- lib/tests/get_estimated_fees_methods.js | 31 ++++++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js index 1edb1511..11ed7311 100644 --- a/lib/tests/get_estimated_fees_methods.js +++ b/lib/tests/get_estimated_fees_methods.js @@ -32,6 +32,9 @@ const execute = (description) => { let btcTxHelper; let senderInfo; + const shouldReturnGreaterThanZeroErrorMessage = (methodName) => + `${methodName} should return a value greater than 0`; + const getQueuedPegoutsCount = async () => Number(await bridge.methods.getQueuedPegoutsCount().call()); @@ -80,12 +83,16 @@ const execute = (description) => { const processReleaseRequestsAndAssertQueueCleared = async (expectedPegoutRequestCountBeforeRelease) => { const countBeforeRelease = await getQueuedPegoutsCount(); - expect(countBeforeRelease).to.equal(expectedPegoutRequestCountBeforeRelease); + expect(countBeforeRelease).to.equal(expectedPegoutRequestCountBeforeRelease, + `Number of pegout requests should be ${expectedPegoutRequestCountBeforeRelease} in the queue before triggering release` + ); await triggerRelease(rskTxHelpers, btcTxHelper); const countAfterRelease = await getQueuedPegoutsCount(); - expect(countAfterRelease).to.equal(0); + expect(countAfterRelease).to.equal(0, + 'All pegout requests should have been processed and the queue should be cleared after triggering release' + ); }; const sendPegoutWithEstimatedFees = async (estimatedFees) => { @@ -119,13 +126,19 @@ const execute = (description) => { describe('getEstimatedFeesForNextPegOutEvent', () => { it('should build pegouts from getEstimatedFeesForNextPegOutEvent when one pegout is queued and when none are queued, and process all pegouts', async () => { const estimatedFeesForNextPegOut = await getEstimatedFeesForNextPegOutEvent(); - expect(estimatedFeesForNextPegOut).to.be.greaterThan(0); + expect(estimatedFeesForNextPegOut).to.be.greaterThan( + 0, + shouldReturnGreaterThanZeroErrorMessage('getEstimatedFeesForNextPegOutEvent') + ); await sendPegoutWithEstimatedFees(estimatedFeesForNextPegOut); await processReleaseRequestsAndAssertQueueCleared(TWO_PEGOUT_REQUESTS_EXPECTED); const estimatedFeesForNextPegOutWithNoEnqueuedRequests = await getEstimatedFeesForNextPegOutEvent(); - expect(estimatedFeesForNextPegOutWithNoEnqueuedRequests).to.be.greaterThan(0); + expect(estimatedFeesForNextPegOutWithNoEnqueuedRequests).to.be.greaterThan( + 0, + shouldReturnGreaterThanZeroErrorMessage('getEstimatedFeesForNextPegOutEvent') + ); await sendPegoutWithEstimatedFees(estimatedFeesForNextPegOutWithNoEnqueuedRequests); await processReleaseRequestsAndAssertQueueCleared(ONE_PEGOUT_REQUEST_EXPECTED); @@ -135,13 +148,19 @@ const execute = (description) => { describe('getEstimatedFeesForPegOutAmount', () => { it('should build pegouts from getEstimatedFeesForPegOutAmount when one pegout is queued and when none are queued, and process all pegouts', async () => { const estimatedFeesForPegout = Number(await getEstimatedFeesForPegOutAmount(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS).call()); - expect(estimatedFeesForPegout).to.be.greaterThan(0); + expect(estimatedFeesForPegout).to.be.greaterThan( + 0, + shouldReturnGreaterThanZeroErrorMessage('getEstimatedFeesForNextPegOutEvent') + ); await sendPegoutWithEstimatedFees(estimatedFeesForPegout); await processReleaseRequestsAndAssertQueueCleared(TWO_PEGOUT_REQUESTS_EXPECTED); const estimatedFeesForPegOutWithNoEnqueuedRequests = Number(await getEstimatedFeesForPegOutAmount(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS).call()); - expect(estimatedFeesForPegOutWithNoEnqueuedRequests).to.be.greaterThan(0); + expect(estimatedFeesForPegOutWithNoEnqueuedRequests).to.be.greaterThan( + 0, + shouldReturnGreaterThanZeroErrorMessage('getEstimatedFeesForNextPegOutEvent') + ); await sendPegoutWithEstimatedFees(estimatedFeesForPegOutWithNoEnqueuedRequests); await processReleaseRequestsAndAssertQueueCleared(ONE_PEGOUT_REQUEST_EXPECTED); From 78554849aa1f379256387b91eb66e5b913bc423b Mon Sep 17 00:00:00 2001 From: Julian Len Date: Thu, 16 Apr 2026 16:00:59 -0300 Subject: [PATCH 27/31] shouldReturnGreaterThanZeroErrorMessage used also with getEstimatedFeesForPegOutAmount --- lib/tests/get_estimated_fees_methods.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js index 11ed7311..0af76b07 100644 --- a/lib/tests/get_estimated_fees_methods.js +++ b/lib/tests/get_estimated_fees_methods.js @@ -150,7 +150,7 @@ const execute = (description) => { const estimatedFeesForPegout = Number(await getEstimatedFeesForPegOutAmount(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS).call()); expect(estimatedFeesForPegout).to.be.greaterThan( 0, - shouldReturnGreaterThanZeroErrorMessage('getEstimatedFeesForNextPegOutEvent') + shouldReturnGreaterThanZeroErrorMessage('getEstimatedFeesForPegOutAmount') ); await sendPegoutWithEstimatedFees(estimatedFeesForPegout); @@ -159,7 +159,7 @@ const execute = (description) => { const estimatedFeesForPegOutWithNoEnqueuedRequests = Number(await getEstimatedFeesForPegOutAmount(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS).call()); expect(estimatedFeesForPegOutWithNoEnqueuedRequests).to.be.greaterThan( 0, - shouldReturnGreaterThanZeroErrorMessage('getEstimatedFeesForNextPegOutEvent') + shouldReturnGreaterThanZeroErrorMessage('getEstimatedFeesForPegOutAmount') ); await sendPegoutWithEstimatedFees(estimatedFeesForPegOutWithNoEnqueuedRequests); From 15cf620de5df81c0113863ab35d60c271f508ebc Mon Sep 17 00:00:00 2001 From: Julian Len Date: Thu, 16 Apr 2026 16:02:25 -0300 Subject: [PATCH 28/31] changed the file name --- ...ted_fees_methods.js => 01_06_53-get_estimated_fees_methods.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{01_07_01-get_estimated_fees_methods.js => 01_06_53-get_estimated_fees_methods.js} (100%) diff --git a/tests/01_07_01-get_estimated_fees_methods.js b/tests/01_06_53-get_estimated_fees_methods.js similarity index 100% rename from tests/01_07_01-get_estimated_fees_methods.js rename to tests/01_06_53-get_estimated_fees_methods.js From 44cefb75e16d300c597df8f818bf9895ab3aa328 Mon Sep 17 00:00:00 2001 From: Julian Len Date: Thu, 16 Apr 2026 16:22:46 -0300 Subject: [PATCH 29/31] deleted sending from cow to the pegin's recipient --- lib/tests/get_estimated_fees_methods.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js index 0af76b07..f972b600 100644 --- a/lib/tests/get_estimated_fees_methods.js +++ b/lib/tests/get_estimated_fees_methods.js @@ -1,7 +1,7 @@ const expect = require('chai').expect; const BN = require('bn.js'); const { getBridgeState } = require('@rsksmart/bridge-state-data-parser'); -const { btcToWeis, satoshisToBtc, satoshisToWeis } = require('@rsksmart/btc-eth-unit-converter'); +const { satoshisToBtc, satoshisToWeis } = require('@rsksmart/btc-eth-unit-converter'); const { assertContractCallFails } = require('../assertions/contractMethods'); const { getBridge } = require('../bridge-provider'); const { @@ -13,12 +13,11 @@ const { const { getBtcClient } = require('../btc-client-provider'); const { MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS } = require('../constants/pegout-constants'); const { getRskTransactionHelpers } = require('../rsk-tx-helper-provider'); -const { sendFromCow, triggerRelease } = require('../rsk-utils'); +const { triggerRelease } = require('../rsk-utils'); const FEDERATION_PEGIN_AMOUNT_IN_SATOSHIS = 500_000; const FEDERATION_PEGIN_AMOUNT_IN_BTC = Number(satoshisToBtc(FEDERATION_PEGIN_AMOUNT_IN_SATOSHIS)); const BTC_FUNDING_AMOUNT_IN_BTC = 2; -const PEGOUT_SENDER_FUNDING_IN_BTC = 2; const TWO_PEGOUT_REQUESTS_EXPECTED = 2; const ONE_PEGOUT_REQUEST_EXPECTED = 1; @@ -68,12 +67,6 @@ const execute = (description) => { ); expect(peginUtxoInBridgeState).to.not.be.undefined; - await sendFromCow( - rskTxHelper, - senderInfo.rskRecipientRskAddressInfo.address, - Number(btcToWeis(PEGOUT_SENDER_FUNDING_IN_BTC)) - ); - await sendTxToBridge( rskTxHelper, new BN(satoshisToWeis(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS)), From 9bf91f03d002ca728a108f7038924f9e871aab44 Mon Sep 17 00:00:00 2001 From: Julian Len Date: Thu, 16 Apr 2026 16:23:04 -0300 Subject: [PATCH 30/31] assert there is one pegout request after sending a tx to the bridge --- lib/tests/get_estimated_fees_methods.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js index f972b600..db8e1842 100644 --- a/lib/tests/get_estimated_fees_methods.js +++ b/lib/tests/get_estimated_fees_methods.js @@ -72,6 +72,11 @@ const execute = (description) => { new BN(satoshisToWeis(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS)), senderInfo.rskRecipientRskAddressInfo.address ); + + const countAfterRelease = await getQueuedPegoutsCount(); + expect(countAfterRelease).to.equal(1, + 'One pegout request should have been added to the queue after sending a pegout request to the Bridge contract' + ); }; const processReleaseRequestsAndAssertQueueCleared = async (expectedPegoutRequestCountBeforeRelease) => { From ea8b9bd5c36cf12de8509889f001d39fe5b1d93a Mon Sep 17 00:00:00 2001 From: Julian Len Date: Thu, 16 Apr 2026 16:38:08 -0300 Subject: [PATCH 31/31] changed estimatedFees parameter to estimatedFeesInSatoshis --- lib/tests/get_estimated_fees_methods.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tests/get_estimated_fees_methods.js b/lib/tests/get_estimated_fees_methods.js index db8e1842..9bfe72a6 100644 --- a/lib/tests/get_estimated_fees_methods.js +++ b/lib/tests/get_estimated_fees_methods.js @@ -93,9 +93,9 @@ const execute = (description) => { ); }; - const sendPegoutWithEstimatedFees = async (estimatedFees) => { + const sendPegoutWithEstimatedFees = async (estimatedFeesInSatoshis) => { const secondPegoutAmountInSatoshis = - MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS + estimatedFees; + MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS + estimatedFeesInSatoshis; await sendTxToBridge( rskTxHelper, new BN(satoshisToWeis(secondPegoutAmountInSatoshis)),