From 0f23f0930fcad96850a82aaa443481acb6e5a530 Mon Sep 17 00:00:00 2001 From: nathanieliov Date: Mon, 15 Jul 2024 14:20:18 -0400 Subject: [PATCH] Moved function to the root of the file to simplify the test and get rid of too much levels of nested functions --- tests/01_03_01-lock_whitelist_pre_papyrus.js | 25 +++++++++++--------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/01_03_01-lock_whitelist_pre_papyrus.js b/tests/01_03_01-lock_whitelist_pre_papyrus.js index 6d928799..c3076dcc 100644 --- a/tests/01_03_01-lock_whitelist_pre_papyrus.js +++ b/tests/01_03_01-lock_whitelist_pre_papyrus.js @@ -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).reverse().toString('hex'); + 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) { @@ -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); }); });