Skip to content

Commit

Permalink
Remove usage of MINIMUM_PEGIN_VALUE_IN_BTC constant in 02_00_02-2wp_s…
Browse files Browse the repository at this point in the history
…egwit_compatible.js
  • Loading branch information
marcos-iov committed Sep 20, 2023
1 parent f0c3e37 commit fd90755
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions tests/02_00_02-2wp_segwit_compatible.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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));
});
});

0 comments on commit fd90755

Please sign in to comment.