Skip to content

Commit

Permalink
Moved function to the root of the file to simplify the test and get r…
Browse files Browse the repository at this point in the history
…id of too much levels of nested functions
  • Loading branch information
nathanieliov committed Jul 15, 2024
1 parent 383432a commit 73347db
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions tests/01_03_01-lock_whitelist_pre_papyrus.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ const assertLockCreatingWhiteListAddress = async (rskTxHelper, btcTxHelper, useU
expect(finalRskAddressBalanceInWeis).to.equal(initialRskAddressBalanceInWeis + peginValueInWeis);
};

const assertNonMatchedAmountsExist = (testCaseAmounts, peginBtcTx, returnTx) => {
const peginBtcTxHash = peginBtcTx.getHash(false);
let nonMatchedAmounts = testCaseAmounts.slice(0);
returnTx.ins.forEach((txInput) => {
const inputTxHash = txInput.hash.reverse().toString('hex');
expect(inputTxHash).to.equal(peginBtcTxHash);
const spentUtxo = peginBtcTx.outs[txInput.index];
const amountInBtc = Number(satoshisToBtc(spentUtxo.value));
nonMatchedAmounts = nonMatchedAmounts.filter(a => a !== amountInBtc);
});
expect(nonMatchedAmounts.length).to.equal(0);
}

describe('Lock whitelisting', () => {
before(async () => {
if(process.env.RUNNING_SINGLE_TEST_FILE) {
Expand Down Expand Up @@ -197,17 +210,7 @@ describe('Lock whitelisting', () => {
expect(returnTx.ins.length).to.equal(peginBtcTx.outs.length - 1); // Don't consider the change output
expect(returnTx.ins.length).to.equal(testCaseAmounts.length); // Don't consider the change output

let nonMatchedAmounts = testCaseAmounts.slice(0);

returnTx.ins.forEach((txInput) => {
const inputTxHash = txInput.hash.reverse().toString('hex');
expect(inputTxHash).to.equal(peginBtcTxHash);
const spentUtxo = peginBtcTx.outs[txInput.index];
const amountInBtc = Number(satoshisToBtc(spentUtxo.value));
nonMatchedAmounts = nonMatchedAmounts.filter(a => a !== amountInBtc);
});

expect(nonMatchedAmounts.length).to.equal(0);
assertNonMatchedAmountsExist(testCaseAmounts, peginBtcTx, returnTx);
});
});

Expand Down

0 comments on commit 73347db

Please sign in to comment.