diff --git a/tests/02_00_02-2wp_segwit_compatible.js b/tests/02_00_02-2wp_segwit_compatible.js index 64edc27c..636e5a5d 100644 --- a/tests/02_00_02-2wp_segwit_compatible.js +++ b/tests/02_00_02-2wp_segwit_compatible.js @@ -1,18 +1,16 @@ const expect = require('chai').expect +const { getDerivedRSKAddressInformation } = require('@rsksmart/btc-rsk-derivation'); +const btcEthUnitConverter = require('btc-eth-unit-converter'); const rskUtils = require('../lib/rsk-utils'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); -const { sendPegin, MINIMUM_PEGIN_VALUE_IN_BTC, ensurePeginIsRegistered } = require('../lib/2wp-utils'); +const { sendPegin, ensurePeginIsRegistered } = require('../lib/2wp-utils'); const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); const { getBtcClient } = require('../lib/btc-client-provider'); -const { getDerivedRSKAddressInformation } = require('@rsksmart/btc-rsk-derivation'); -const btcEthUnitConverter = require('btc-eth-unit-converter'); - let rskTxHelpers; let rskTxHelper; let btcTxHelper; - const fulfillRequirementsToRunAsSingleTestFile = async () => { const latestForkName = rskUtils.getLatestForkName() await rskUtils.activateFork(latestForkName); @@ -30,30 +28,33 @@ describe('Lock using p2sh-p2wpkh address', () => { }); it('should do a legacy pegin using p2sh-p2wpkh address', async () => { - const senderAddressInfo = await btcTxHelper.generateBtcAddress('p2sh-segwit'); - const latestActiveForkName = await getLatestActiveForkName(); const bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName); + + const minimumPeginValueInSatoshis = await bridge.methods.getMinimumLockTxValue().call(); + const minimumPeginValueInBtc = btcEthUnitConverter.satoshisToBtc(minimumPeginValueInSatoshis); + const federationAddress = await bridge.methods.getFederationAddress().call(); const federationAddressBalanceInitial = Number(await btcTxHelper.getAddressBalance(federationAddress)); + const senderAddressInfo = await btcTxHelper.generateBtcAddress('p2sh-segwit'); const recipientRskAddressInfo = getDerivedRSKAddressInformation(senderAddressInfo.privateKey, btcTxHelper.btcConfig.network); await rskTxHelper.importAccount(recipientRskAddressInfo.privateKey); const unlocked = await rskTxHelper.unlockAccount(recipientRskAddressInfo.address); expect(unlocked, 'Account was not unlocked').to.be.true; - await btcTxHelper.fundAddress(senderAddressInfo.address, MINIMUM_PEGIN_VALUE_IN_BTC + btcTxHelper.getFee()); + await btcTxHelper.fundAddress(senderAddressInfo.address, minimumPeginValueInBtc + btcTxHelper.getFee()); - const btcPeginTxHash = await sendPegin(rskTxHelper, btcTxHelper, senderAddressInfo, MINIMUM_PEGIN_VALUE_IN_BTC); + const btcPeginTxHash = await sendPegin(rskTxHelper, btcTxHelper, senderAddressInfo, minimumPeginValueInBtc); await ensurePeginIsRegistered(rskTxHelper, btcPeginTxHash); const federationAddressBalanceAfterPegin = Number(await btcTxHelper.getAddressBalance(federationAddress)); - expect(federationAddressBalanceAfterPegin).to.be.equal(Number(federationAddressBalanceInitial + MINIMUM_PEGIN_VALUE_IN_BTC)); + expect(federationAddressBalanceAfterPegin).to.be.equal(Number(federationAddressBalanceInitial + minimumPeginValueInBtc)); const senderAddressBalanceAfterPegin = Number(await btcTxHelper.getAddressBalance(senderAddressInfo.address)); expect(senderAddressBalanceAfterPegin).to.be.equal(0); const recipientRskAddressBalanceAfterPegin = Number(await rskTxHelper.getBalance(recipientRskAddressInfo.address)); - expect(recipientRskAddressBalanceAfterPegin).to.be.equal(btcEthUnitConverter.btcToWeis(MINIMUM_PEGIN_VALUE_IN_BTC)); + expect(recipientRskAddressBalanceAfterPegin).to.be.equal(btcEthUnitConverter.btcToWeis(minimumPeginValueInBtc)); }); });