Skip to content

Commit

Permalink
Using BN for all weis
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-then committed Sep 26, 2024
1 parent 74e64d5 commit a7e1868
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/tests/2wp.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let minimumPeginValueInBtc;
let btcFeeInSatoshis;

const get2wpInitialBalances = async () => {
const initialBridgeBalanceInWeisBN = Number(await rskTxHelper.getBalance(BRIDGE_ADDRESS));
const initialBridgeBalanceInWeisBN = await rskTxHelper.getBalance(BRIDGE_ADDRESS);
const initialBridgeUtxosBalanceInSatoshis = await getBridgeUtxosBalance(rskTxHelper);
const initialFederationAddressBalanceInSatoshis = await getBtcAddressBalanceInSatoshis(btcTxHelper, federationAddress);
return {
Expand All @@ -45,15 +45,17 @@ const assertExpectedPeginBtcEventIsEmitted = async (btcPeginTxHash, rskRecipient

const assertSuccessfulPegin2wpFinalBalances = async (initial2wpBalances, peginValueInSatoshis) => {

const { initialBridgeBalanceInWeisBN, initialBridgeUtxosBalanceInSatoshis, initialFederationAddressBalanceInSatoshis } = initial2wpBalances
const { initialBridgeBalanceInWeisBN, initialBridgeUtxosBalanceInSatoshis, initialFederationAddressBalanceInSatoshis } = initial2wpBalances;

// The federation balance is increased by the pegin value
const finalFederationAddressBalanceInSatoshis = await getBtcAddressBalanceInSatoshis(btcTxHelper, federationAddress);
expect(finalFederationAddressBalanceInSatoshis).to.be.equal(initialFederationAddressBalanceInSatoshis + peginValueInSatoshis);

// After the successful pegin, the Bridge balance should be reduced by the pegin value
const finalBridgeBalance = Number(await rskTxHelper.getBalance(BRIDGE_ADDRESS));
expect(finalBridgeBalance).to.be.equal(initialBridgeBalanceInWeisBN - satoshisToWeis(peginValueInSatoshis));
const finalBridgeBalanceInWeisBN = await rskTxHelper.getBalance(BRIDGE_ADDRESS);
const peginValueInWeisBN = rskTxHelper.getClient().utils.BN(satoshisToWeis(peginValueInSatoshis));
const expectedFinalBridgeBalancesInWeisBN = initialBridgeBalanceInWeisBN.sub(peginValueInWeisBN);
expect(finalBridgeBalanceInWeisBN.eq(expectedFinalBridgeBalancesInWeisBN)).to.be.true;

// After the successful pegin, the Bridge utxos sum should be incremented by the pegin value
const finalBridgeUtxosBalance = await getBridgeUtxosBalance(rskTxHelper);
Expand Down

0 comments on commit a7e1868

Please sign in to comment.