From e6397b5652d70d138c03b0d4180bee85ef9d2a41 Mon Sep 17 00:00:00 2001 From: Marcos Date: Tue, 19 Sep 2023 16:52:07 -0300 Subject: [PATCH] Remove usage of MINIMUM_PEGIN_VALUE_IN_BTC constant in 01_03_05-2wp_multisig_not_compatible --- tests/01_03_04-2wp_segwit_not_compatible.js | 8 +++--- tests/01_03_05-2wp_multisig_not_compatible.js | 26 ++++++++++--------- tests/02_00_03-2wp_multisig_compatible.js | 7 +++-- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/tests/01_03_04-2wp_segwit_not_compatible.js b/tests/01_03_04-2wp_segwit_not_compatible.js index c885571b..0334c8a7 100644 --- a/tests/01_03_04-2wp_segwit_not_compatible.js +++ b/tests/01_03_04-2wp_segwit_not_compatible.js @@ -27,16 +27,16 @@ describe('Lock p2sh-p2wpkh address', () => { }); it('lock should fail when using p2sh-p2wpkh address', async () => { + const latestActiveForkName = await getLatestActiveForkName(); + const bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); + const minimumPeginValueInSatoshis = await bridge.methods.getMinimumLockTxValue().call(); const minimumPeginValueInBtc = satoshisToBtc(minimumPeginValueInSatoshis); - const senderAddress = await btcTxHelper.generateBtcAddress('p2sh-segwit') - const latestActiveForkName = await getLatestActiveForkName(); - const bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); const federationAddress = await bridge.methods.getFederationAddress().call(); - const federationAddressBalanceInitial = Number(await btcTxHelper.getAddressBalance(federationAddress)); + const senderAddress = await btcTxHelper.generateBtcAddress('p2sh-segwit') await btcTxHelper.fundAddress(senderAddress.address, minimumPeginValueInBtc + btcTxHelper.getFee()); const btcPeginTxHash = await sendPegin(rskTxHelper, btcTxHelper, senderAddress, minimumPeginValueInBtc); diff --git a/tests/01_03_05-2wp_multisig_not_compatible.js b/tests/01_03_05-2wp_multisig_not_compatible.js index ef6bc051..cd771613 100644 --- a/tests/01_03_05-2wp_multisig_not_compatible.js +++ b/tests/01_03_05-2wp_multisig_not_compatible.js @@ -1,9 +1,9 @@ const expect = require('chai').expect +const { satoshisToBtc } = require('btc-eth-unit-converter'); const rskUtils = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); - const { getBtcClient } = require('../lib/btc-client-provider'); -const { sendPegin, MINIMUM_PEGIN_VALUE_IN_BTC } = require('../lib/2wp-utils'); +const { sendPegin } = require('../lib/2wp-utils'); const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); const { isUtxoRegisteredInBridge } = require('../lib/2wp-utils'); @@ -15,7 +15,7 @@ const fulfillRequirementsToRunAsSingleTestFile = async () => { await rskUtils.activateFork(Runners.common.forks.wasabi100); }; -describe('Lock multisig address', () => { +describe('Peg-in multisig address', () => { before(async () => { rskTxHelpers = getRskTransactionHelpers(); rskTxHelper = rskTxHelpers[0]; @@ -27,30 +27,32 @@ describe('Lock multisig address', () => { }); // Should fail and not refund when sending a pengin from a multisig address pre papyrus - it('lock should fail when using multisig address', async () => { - const senderAddress = await btcTxHelper.generateMultisigAddress(3, 2, 'legacy'); - + it('Peg-in should fail when using multisig address', async () => { const latestActiveForkName = await getLatestActiveForkName(); const bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); - const federationAddress = await bridge.methods.getFederationAddress().call(); + const minimumPeginValueInSatoshis = await bridge.methods.getMinimumLockTxValue().call(); + const minimumPeginValueInBtc = satoshisToBtc(minimumPeginValueInSatoshis); + + const federationAddress = await bridge.methods.getFederationAddress().call(); const federationAddressBalanceInitial = Number(await btcTxHelper.getAddressBalance(federationAddress)); - await btcTxHelper.fundAddress(senderAddress.address, MINIMUM_PEGIN_VALUE_IN_BTC + btcTxHelper.getFee()); + const senderAddress = await btcTxHelper.generateMultisigAddress(3, 2, 'legacy'); + await btcTxHelper.fundAddress(senderAddress.address, minimumPeginValueInBtc + btcTxHelper.getFee()); - const btcPeginTxHash = await sendPegin(rskTxHelper, btcTxHelper, senderAddress, MINIMUM_PEGIN_VALUE_IN_BTC); + const btcPeginTxHash = await sendPegin(rskTxHelper, btcTxHelper, senderAddress, minimumPeginValueInBtc); const federationAddressBalanceAfterPegin = Number(await btcTxHelper.getAddressBalance(federationAddress)); - expect(Number(federationAddressBalanceAfterPegin)).to.be.equal(Number(federationAddressBalanceInitial + MINIMUM_PEGIN_VALUE_IN_BTC)); + expect(Number(federationAddressBalanceAfterPegin)).to.be.equal(Number(federationAddressBalanceInitial + minimumPeginValueInBtc)); const isPeginUtxoRegistered = await isUtxoRegisteredInBridge(rskTxHelper, btcPeginTxHash); expect(isPeginUtxoRegistered).to.be.false; const federationAddressBalanceFinal = Number(await btcTxHelper.getAddressBalance(federationAddress)); - expect(Number(federationAddressBalanceFinal)).to.be.equal(Number(federationAddressBalanceInitial + MINIMUM_PEGIN_VALUE_IN_BTC)); + expect(Number(federationAddressBalanceFinal)).to.be.equal(Number(federationAddressBalanceInitial + minimumPeginValueInBtc)); const senderAddressBalanceFinal = await btcTxHelper.getAddressBalance(senderAddress.address); expect(Number(senderAddressBalanceFinal)).to.be.equal(0); - }) + }); }); diff --git a/tests/02_00_03-2wp_multisig_compatible.js b/tests/02_00_03-2wp_multisig_compatible.js index ce484edf..20c17b3e 100644 --- a/tests/02_00_03-2wp_multisig_compatible.js +++ b/tests/02_00_03-2wp_multisig_compatible.js @@ -32,15 +32,14 @@ describe('Lock multisig address', () => { it('lock should work when using multisig address', async () => { const latestActiveForkName = await getLatestActiveForkName(); const bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); - const federationAddress = await bridge.methods.getFederationAddress().call(); const minimumPeginValueInSatoshis = await bridge.methods.getMinimumLockTxValue().call(); const minimumPeginValueInBtc = satoshisToBtc(minimumPeginValueInSatoshis); - const senderAddressInfo = await btcTxHelper.generateMultisigAddress(3, 2, 'legacy'); - + const federationAddress = await bridge.methods.getFederationAddress().call(); const federationAddressBalanceInitial = Number(await btcTxHelper.getAddressBalance(federationAddress)); - + + const senderAddressInfo = await btcTxHelper.generateMultisigAddress(3, 2, 'legacy'); await btcTxHelper.fundAddress(senderAddressInfo.address, minimumPeginValueInBtc + btcTxHelper.getFee()); await sendPegin(rskTxHelper, btcTxHelper, senderAddressInfo, minimumPeginValueInBtc);