From b53ddf0287097f809fdd5a4088428b3500641989 Mon Sep 17 00:00:00 2001 From: jeremy-then Date: Thu, 11 Jan 2024 14:43:07 -0400 Subject: [PATCH] Replaces the createPeginV1TxData with the one from pegin-address-verifier --- lib/2wp-utils-legacy.js | 183 ------------------ lib/2wp-utils.js | 40 +--- package-lock.json | 65 +++---- package.json | 2 +- tests/01_04_01-pre_iris_2wp.js | 7 +- ...06_53-2wp_version1_exceeding-lockingCap.js | 13 +- ...k.js => 01_07_50-activate-arrowhead600.js} | 0 tests/02_00_05-2wp_version1.js | 19 +- 8 files changed, 59 insertions(+), 270 deletions(-) rename tests/{01_07_50-activate-tbd600_fork.js => 01_07_50-activate-arrowhead600.js} (100%) diff --git a/lib/2wp-utils-legacy.js b/lib/2wp-utils-legacy.js index 1743ff66..798d29ea 100644 --- a/lib/2wp-utils-legacy.js +++ b/lib/2wp-utils-legacy.js @@ -1,57 +1,6 @@ const expect = require('chai').expect; const rsk = require('peglib').rsk; const rskUtilsLegacy = require('./rsk-utils-legacy'); -const { wait, retryWithCheck } = require('./utils'); -const { createPeginV1TxData } = require('./2wp-utils'); -const { getBridge, getLatestActiveForkName } = require('./precompiled-abi-forks-util'); -const { getBridgeState } = require('@rsksmart/bridge-state-data-parser'); - -const BTC_TO_RSK_MINIMUM_CONFIRMATIONS = 3; - -const peginRejectionCallback = (callBackParams) => (decodedLog) => { - let peginTxHash = callBackParams.peginTxHash; - let expectedErrorCode = callBackParams.expectedErrorCode; - expect(decodedLog[0]).to.be.equals('0x' + peginTxHash); - expect(parseInt(decodedLog[1])).to.be.equal(expectedErrorCode); -} - -const releaseRequestedCallback = (callBackParams) => (decodedLog) => { - let rskTxHash = callBackParams.rskTxHash; - let minExpectedValue = callBackParams.minExpectedValue; - expect(decodedLog[0]).to.be.equals(rskTxHash); - expect(decodedLog[1]).to.not.be.undefined; //This may not be necessary - expect(parseInt(decodedLog[2])).to.be.at.least(parseInt(minExpectedValue)); -} - -const assertRefundUtxosSameAsPeginUtxos = (btcClient, rskClient) => async(peginTxHash, refundAddress) => { - const latestActiveForkName = await getLatestActiveForkName(); - const bridge = getBridge(rskClient, latestActiveForkName); - const federationAddress = await bridge.methods.getFederationAddress().call(); - let peginTx = await btcClient.getTransaction(peginTxHash); - let outputsForFederation = peginTx.outs.filter(output => btcClient.getOutputAddress(output.script) == federationAddress); - let refundAddressUtxos = await btcClient.nodeClient.getUtxos(refundAddress); - expect(refundAddressUtxos.length).to.equal(outputsForFederation.length); - - let refundTxHash = refundAddressUtxos[0].txid; - let refundTx = await btcClient.getTransaction(refundTxHash); - expect(refundTx.ins.length).to.equal(outputsForFederation.length); - - refundTx.ins.forEach((input) => { - let inputHash = input.hash.reverse().toString('hex'); - expect(inputHash).to.equal(peginTxHash); - }); -} - -const sendTxToBridge = (rskClient) => async(senderAddress, valueInWeis) => { - const TO_BRIDGE_GAS_PRICE = 2; - - return await rskClient.rsk.sendTx({ - from: senderAddress, - to: rsk.getBridgeAddress(), - value: valueInWeis, - gasPrice: TO_BRIDGE_GAS_PRICE - }, rskClient.evm.mine); -} const sendTxToBridgeWithoutMining = (rskClient) => async (senderAddress, valueInWeis) => { @@ -88,140 +37,8 @@ const createPegoutRequest = async (rskClient, pegClient, amountInRBTC, requestSi await rskClient.evm.mine() } -/** - * - * @param {object} rskClient - * @param {string} peginTxHash to be found in the bridge's utxo list - * @returns {boolean} returns a boolean value indicating if the pegin was found in the bridge or not - */ -const isUtxoRegisteredInBridge = async (rskClient, peginTxHash, expectedUxtosCount) => { - const bridgeState = await getBridgeState(rskClient); - return bridgeState.activeFederationUtxos - .filter(utxo => utxo.btcTxHash === peginTxHash).length === expectedUxtosCount; -}; - -/** - * Simply sends funds to the federation and mines the required btc blocks for the pegin to go through, - * updates the bridge and mines 1 rsk block for the changes to take effect. - * @param {Web3} rskClient - * @param {BtcTransactionHelper} btcClient - * @param {object} btcSenderAddressInformation the btc object information that contains the btc address and private key to spend funds from - * @param {Array | number} outputAmountsInBtc the pegin amounts to send to the bridge in btc. If only one amount is sent, it will be converted to an array. - * @param {Array} data for pegin v1 script - */ -const sendPegin = async (rskClient, btcClient, btcSenderAddressInformation, outputAmountsInBtc, data) => { - - if (!Array.isArray(outputAmountsInBtc)) { - outputAmountsInBtc = Array.of(outputAmountsInBtc); - } - - const latestActiveForkName = await getLatestActiveForkName(); - const bridge = getBridge(rskClient, latestActiveForkName); - const federationAddress = await bridge.methods.getFederationAddress().call(); - - const recipientsTransferInformation = outputAmountsInBtc.map(amount => ({ recipientAddress: federationAddress, amountInBtc: amount })); - - const peginBtcTxHash = await btcClient.transferBtc(btcSenderAddressInformation, recipientsTransferInformation, data); - - await btcClient.mine(BTC_TO_RSK_MINIMUM_CONFIRMATIONS); - await waitAndUpdateBridge(rskClient, 500); - - return peginBtcTxHash; - -}; - -/** - * Ensures that the pegin with btc hash `peginBtcTxHash` is registered in the bridge, mining and waiting, trying to find - * multiple times. If it's not found after the maximum attempt, throws an exception. - * @param {Web3} rskClient - * @param {string} peginBtcTxHash - */ -const ensurePeginIsRegistered = async (rskClient, peginBtcTxHash, expectedUxtosCount = 1) => { - - const MAX_ATTEMPTS = 20; - const CHECK_EVERY_MILLISECONDS = 3000; - - const method = async () => { - return isUtxoRegisteredInBridge(rskClient, peginBtcTxHash, expectedUxtosCount) - }; - - const check = async (utxoIsRegistered, currentAttempts) => { - console.debug(`Attempting to find the pegin ${peginBtcTxHash} in the bridge. Attempt ${currentAttempts} out of ${MAX_ATTEMPTS}`); - if(!utxoIsRegistered) { - await waitAndUpdateBridge(rskClient, 1000); - } - return utxoIsRegistered; - }; - - const { result: utxoIsRegisteredInTheBridge } = await retryWithCheck(method, check, MAX_ATTEMPTS, CHECK_EVERY_MILLISECONDS); - - if(utxoIsRegisteredInTheBridge) { - console.debug(`Found pegin ${peginBtcTxHash} registered in the bridge.`); - // The pegin is already registered in the bridge, but the balance may still not be reflected on the user's rsk address - // So we need to update the bridge and mine one more block so the balance is reflected on the user's rsk address - await waitAndUpdateBridge(rskClient); - return; - } - - throw new Error(`Could not find the pegin registered in the bridge after ${MAX_ATTEMPTS} attempts`); - -}; - -/** - * - * @param {Web3} rskClient - * @param {number} timeInMilliseconds defaults to 1000 - */ -const waitAndUpdateBridge = async (rskClient, timeInMilliseconds = 1000) => { - await wait(timeInMilliseconds); - await rskClient.fed.updateBridge(); - await rskClient.evm.mine(); -}; - -/** - * Sends a pegin donation to the bridge - * @param {peglib.rsk.rskClient} rskClient - * @param {BtcTransactionHelper} btcClient - * @param {number} amountInBtc - * @returns {string} the pegin tx hash - */ -const donateToBridge = async (rskClient, btcClient, donatingBtcAddressInformation, amountInBtc) => { - const data = []; - data.push(createPeginV1TxData(rsk.getBridgeAddress())); - const peginBtcTxHash = await sendPegin(rskClient, btcClient, donatingBtcAddressInformation, amountInBtc, data); - await ensurePeginIsRegistered(rskClient, peginBtcTxHash); - return peginBtcTxHash; -}; - -const releaseRequestReceivedCallback = (callBackParams) => async (decodedLog) => { - let rskAddress = callBackParams.rskAddress; - let value = callBackParams.value; - expect(decodedLog[0].toLowerCase()).to.be.equals(rskAddress); - const btcRecipientAddress = decodedLog[1]; - expect(btcRecipientAddress).to.not.be.undefined; //btcDestinationAddress - - const isFingerroot500Active = Runners.common.forks.fingerroot500.isAlreadyActive(); - if(isFingerroot500Active) { - expect(btcRecipientAddress.startsWith("m") || btcRecipientAddress.startsWith("n")).to.be.true; // btcRecipientAddress in base58 format - } else { - expect(btcRecipientAddress.startsWith("0x")).to.be.true; // btcRecipientAddress in hash160 format - } - - expect(parseInt(decodedLog[2])).to.be.at.least(parseInt(value)); -}; - module.exports = { with: (btcClient, rskClient) => ({ - assertRefundUtxosSameAsPeginUtxos: assertRefundUtxosSameAsPeginUtxos(btcClient, rskClient), - sendTxToBridge: sendTxToBridge(rskClient) }), - peginRejectionCallback, - releaseRequestReceivedCallback, - releaseRequestedCallback, createPegoutRequest, - sendPegin, - ensurePeginIsRegistered, - isUtxoRegisteredInBridge, - donateToBridge, - BTC_TO_RSK_MINIMUM_CONFIRMATIONS, }; diff --git a/lib/2wp-utils.js b/lib/2wp-utils.js index f395022a..2b919e95 100644 --- a/lib/2wp-utils.js +++ b/lib/2wp-utils.js @@ -195,43 +195,6 @@ const ensurePeginIsRegistered = async (rskTxHelper, peginBtcTxHash, expectedUtxo }; -/** - * Creates a pegin v1 data for a user to indicate to which rsk address to receive their pegin funds. - * @param {string} rskDestinationAddress - * @param {string} btcRefundAddress - * @returns {string} pegin v1 tx data - */ -const createPeginV1TxData = (rskDestinationAddress, btcRefundAddress) => { - let data = '52534b54'; // 'RSKT' prefix hexa encoded - data += '01'; // Protocol version - - if (rskDestinationAddress.startsWith('0x')) { - rskDestinationAddress = rskDestinationAddress.substring(2); - } - data += rskDestinationAddress; - - if (btcRefundAddress) { - let refundAddressInfo = peginVerifier.getAddressInformation(btcRefundAddress); - if (refundAddressInfo) { - data += ADDRESS_TYPES_CODES[refundAddressInfo.type]; - switch (refundAddressInfo.type) { - case 'p2pkh': - data += refundAddressInfo.scriptPubKey; - break; - case 'p2sh': - data += refundAddressInfo.scriptHash; - break; - default: - throw new Error(`Unsupported btc refund address type: ${refundAddressInfo.type}`); - } - } else { - throw new Error(`Could not get address information for ${btcRefundAddress}`); - } - } - - return Buffer.from(data, 'hex'); -}; - /** * Sends a pegin donation to the bridge * @param {RskTransactionHelper} rskTxHelper @@ -241,7 +204,7 @@ const createPeginV1TxData = (rskDestinationAddress, btcRefundAddress) => { */ const donateToBridge = async (rskTxHelper, btcTxHelper, donatingBtcAddressInformation, amountInBtc) => { const data = []; - data.push(createPeginV1TxData(BRIDGE_ADDRESS)); + data.push(Buffer.from(peginVerifier.createPeginV1TxData(BRIDGE_ADDRESS), 'hex')); const peginBtcTxHash = await sendPegin(rskTxHelper, btcTxHelper, donatingBtcAddressInformation, amountInBtc, data); await ensurePeginIsRegistered(rskTxHelper, peginBtcTxHash); return peginBtcTxHash; @@ -276,7 +239,6 @@ module.exports = { donateToBridge, BTC_TO_RSK_MINIMUM_CONFIRMATIONS, BRIDGE_ADDRESS, - createPeginV1TxData, mineForPeginRegistration, MIN_PEGOUT_VALUE_IN_RBTC, disableWhitelisting, diff --git a/package-lock.json b/package-lock.json index df3ac778..eb31f865 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,7 +29,7 @@ "lodash": "^4.17.5", "mocha": "^10.1.0", "mocha-junit-reporter": "^1.17.0", - "pegin-address-verificator": "git+https://git@github.com/rsksmart/pegin-address-verifier#v0.2.1", + "pegin-address-verificator": "git+https://git@github.com/rsksmart/pegin-address-verifier#v0.4.0", "peglib": "git+https://github.com/rsksmart/rsk-peglib#v1.4.15", "precompiled-arrowhead600": "git+https://github.com/rsksmart/precompiled-abis#6.0.0-ARROWHEAD", "precompiled-fingerroot500": "npm:@rsksmart/rsk-precompiled-abis@^5.0.0-FINGERROOT", @@ -1524,9 +1524,9 @@ "integrity": "sha512-4tYFyifaFfGacoiObjJegolkwSU4xQNGbVgUiNYVUxbQ2x2lUsFvY4hVgVzGiIe6WLOPqycWXA40l+PWsxthUw==" }, "node_modules/chai": { - "version": "4.3.10", - "resolved": "https://registry.npmjs.org/chai/-/chai-4.3.10.tgz", - "integrity": "sha512-0UXG04VuVbruMUYbJ6JctvH0YnC/4q3/AkT18q4NaITo91CUm0liMS9VqzT9vZhVQ/1eqPanMWjBM+Juhfb/9g==", + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/chai/-/chai-4.4.0.tgz", + "integrity": "sha512-x9cHNq1uvkCdU+5xTkNh5WtgD4e4yDFCsp9jVc7N7qVeKeftv3gO/ZrviX5d+3ZfxdYnZXZYujjRInu1RogU6A==", "dependencies": { "assertion-error": "^1.1.0", "check-error": "^1.0.3", @@ -3577,11 +3577,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/isarray": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==" - }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -3679,9 +3674,9 @@ } }, "node_modules/just-extend": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.2.1.tgz", - "integrity": "sha512-g3UB796vUFIY90VIv/WX3L2c8CS2MdWUww3CNrYmqza1Fg0DURc2K/O4YrnklBdQarSJ/y8JnJYDGc+1iumQjg==" + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-6.2.0.tgz", + "integrity": "sha512-cYofQu2Xpom82S6qD778jBDpwvvy39s1l/hrYij2u9AMdQcGRpaBu6kY4mVhuno5kJVi1DAz4aiphA2WI1/OAw==" }, "node_modules/keccak": { "version": "3.0.4", @@ -4188,23 +4183,23 @@ "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==" }, "node_modules/nise": { - "version": "5.1.5", - "resolved": "https://registry.npmjs.org/nise/-/nise-5.1.5.tgz", - "integrity": "sha512-VJuPIfUFaXNRzETTQEEItTOP8Y171ijr+JLq42wHes3DiryR8vT+1TXQW/Rx8JNUhyYYWyIvjXTU6dOhJcs9Nw==", + "version": "5.1.7", + "resolved": "https://registry.npmjs.org/nise/-/nise-5.1.7.tgz", + "integrity": "sha512-wWtNUhkT7k58uvWTB/Gy26eA/EJKtPZFVAhEilN5UYVmmGRYOURbejRUyKm0Uu9XVEW7K5nBOZfR8VMB4QR2RQ==", "dependencies": { - "@sinonjs/commons": "^2.0.0", - "@sinonjs/fake-timers": "^10.0.2", - "@sinonjs/text-encoding": "^0.7.1", - "just-extend": "^4.0.2", - "path-to-regexp": "^1.7.0" + "@sinonjs/commons": "^3.0.0", + "@sinonjs/fake-timers": "^11.2.2", + "@sinonjs/text-encoding": "^0.7.2", + "just-extend": "^6.2.0", + "path-to-regexp": "^6.2.1" } }, - "node_modules/nise/node_modules/@sinonjs/commons": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-2.0.0.tgz", - "integrity": "sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg==", + "node_modules/nise/node_modules/@sinonjs/fake-timers": { + "version": "11.2.2", + "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-11.2.2.tgz", + "integrity": "sha512-G2piCSxQ7oWOxwGSAyFHfPIsyeJGXYtc6mFbnFA+kRXkiEnTl8c/8jul2S329iFBnDI9HGoeWWAZvuvOkZccgw==", "dependencies": { - "type-detect": "4.0.8" + "@sinonjs/commons": "^3.0.0" } }, "node_modules/node-addon-api": { @@ -4232,9 +4227,9 @@ } }, "node_modules/node-gyp-build": { - "version": "4.7.1", - "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.7.1.tgz", - "integrity": "sha512-wTSrZ+8lsRRa3I3H8Xr65dLWSgCvY2l4AOnaeKdPA9TB/WYMPaTcrzf3rXvFoVvjKNVnu0CcWSx54qq9GKRUYg==", + "version": "4.8.0", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.0.tgz", + "integrity": "sha512-u6fs2AEUljNho3EYTJNBfImO5QTo/J/1Etd+NVdCj7qWKUSN/bSLkZwhDv7I+w/MSC6qJ4cknepkAYykDdK8og==", "bin": { "node-gyp-build": "bin.js", "node-gyp-build-optional": "optional.js", @@ -4444,12 +4439,9 @@ "dev": true }, "node_modules/path-to-regexp": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz", - "integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==", - "dependencies": { - "isarray": "0.0.1" - } + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.2.1.tgz", + "integrity": "sha512-JLyh7xT1kizaEvcaXOQwOc2/Yhw6KZOvPf1S8401UyLk86CU79LN3vl7ztXGm/pZ+YjoyAJ4rxmHwbkBXJX+yw==" }, "node_modules/pathval": { "version": "1.1.1", @@ -4475,8 +4467,9 @@ } }, "node_modules/pegin-address-verificator": { - "version": "0.2.1", - "resolved": "git+https://git@github.com/rsksmart/pegin-address-verifier.git#840ee617889d9e103efbd2626f84c382db379dba", + "name": "pegin-address-verifier", + "version": "0.4.0", + "resolved": "git+https://git@github.com/rsksmart/pegin-address-verifier.git#38a24c27cceebfe403f46f061b17a488f99dda82", "license": "MIT", "dependencies": { "jssha": "^3.1.0" diff --git a/package.json b/package.json index 037bd61d..eb4659bc 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "lodash": "^4.17.5", "mocha": "^10.1.0", "mocha-junit-reporter": "^1.17.0", - "pegin-address-verificator": "git+https://git@github.com/rsksmart/pegin-address-verifier#v0.2.1", + "pegin-address-verificator": "git+https://git@github.com/rsksmart/pegin-address-verifier#v0.4.0", "peglib": "git+https://github.com/rsksmart/rsk-peglib#v1.4.15", "precompiled-arrowhead600": "git+https://github.com/rsksmart/precompiled-abis#6.0.0-ARROWHEAD", "precompiled-fingerroot500": "npm:@rsksmart/rsk-precompiled-abis@^5.0.0-FINGERROOT", diff --git a/tests/01_04_01-pre_iris_2wp.js b/tests/01_04_01-pre_iris_2wp.js index 91bae9b1..a6c378e7 100644 --- a/tests/01_04_01-pre_iris_2wp.js +++ b/tests/01_04_01-pre_iris_2wp.js @@ -1,5 +1,5 @@ const { expect } = require('chai'); -const { createPeginV1TxData } = require('../lib/2wp-utils'); +const peginVerifier = require('pegin-address-verificator'); const { getRskTransactionHelper } = require('../lib/rsk-tx-helper-provider'); const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter'); const { getBtcClient } = require('../lib/btc-client-provider'); @@ -33,7 +33,10 @@ describe('Lock funds using peg-in protocol version 1 before iris300', () => { // Create peg-in data const data = []; - data.push(createPeginV1TxData(rskDestinationAddress)); + + const peginV1DataString = peginVerifier.createPeginV1TxData(rskDestinationAddress); + + data.push(Buffer.from(peginV1DataString, 'hex')); await btcTxHelper.fundAddress(senderAddressInformation.address, AMOUNT_TO_LOCK_IN_BTC + btcTxHelper.getFee()); diff --git a/tests/01_06_53-2wp_version1_exceeding-lockingCap.js b/tests/01_06_53-2wp_version1_exceeding-lockingCap.js index 79616bc4..bb3241e3 100644 --- a/tests/01_06_53-2wp_version1_exceeding-lockingCap.js +++ b/tests/01_06_53-2wp_version1_exceeding-lockingCap.js @@ -1,6 +1,7 @@ const { expect } = require('chai'); +const peginVerifier = require('pegin-address-verificator'); const rskUtils = require('../lib/rsk-utils'); -const { createPeginV1TxData, sendPegin, assertRefundUtxosSameAsPeginUtxos } = require('../lib/2wp-utils'); +const { sendPegin, assertRefundUtxosSameAsPeginUtxos } = require('../lib/2wp-utils'); const { getBridge , getLatestActiveForkName} = require('../lib/precompiled-abi-forks-util'); const { getBtcClient } = require('../lib/btc-client-provider'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); @@ -61,7 +62,10 @@ describe('Lock funds using peg-in protocol version 1', () => { // Create peg-in data const data = []; - data.push(createPeginV1TxData(rskDestinationAddress, refundAddressInformation.address)); + + const peginV1TxDataString = peginVerifier.createPeginV1TxData(rskDestinationAddress, refundAddressInformation.address); + + data.push(Buffer.from(peginV1TxDataString, 'hex')); // Execute peg-in const AMOUNT_TO_LOCK_EXCEEDING_LOCKING_CAP = AMOUNT_TO_LOCK_IN_BTC + lockingCapInBtc; @@ -154,7 +158,10 @@ describe('Lock funds using peg-in protocol version 1', () => { // Create peg-in data const data = []; - data.push(createPeginV1TxData(rskDestinationAddress)); + + const peginV1DataString = peginVerifier.createPeginV1TxData(rskDestinationAddress); + + data.push(Buffer.from(peginV1DataString, 'hex')); // Execute peg-in const AMOUNT_TO_LOCK_EXCEEDING_LOCKING_CAP = AMOUNT_TO_LOCK_IN_BTC + lockingCapInBtc; diff --git a/tests/01_07_50-activate-tbd600_fork.js b/tests/01_07_50-activate-arrowhead600.js similarity index 100% rename from tests/01_07_50-activate-tbd600_fork.js rename to tests/01_07_50-activate-arrowhead600.js diff --git a/tests/02_00_05-2wp_version1.js b/tests/02_00_05-2wp_version1.js index 51ed7399..159a468c 100644 --- a/tests/02_00_05-2wp_version1.js +++ b/tests/02_00_05-2wp_version1.js @@ -1,6 +1,7 @@ const { expect } = require('chai'); +const peginVerifier = require('pegin-address-verificator'); const rskUtils = require('../lib/rsk-utils'); -const { createPeginV1TxData, sendPegin, ensurePeginIsRegistered, assertRefundUtxosSameAsPeginUtxos } = require('../lib/2wp-utils'); +const { sendPegin, ensurePeginIsRegistered, assertRefundUtxosSameAsPeginUtxos } = require('../lib/2wp-utils'); const { getBtcClient } = require('../lib/btc-client-provider'); const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); const { getDerivedRSKAddressInformation } = require('@rsksmart/btc-rsk-derivation'); @@ -50,7 +51,10 @@ describe('Lock funds using peg-in protocol version 1', () => { // Create peg-in data const data = []; - data.push(createPeginV1TxData(rskDestinationAddress)); + + const peginV1DataString = peginVerifier.createPeginV1TxData(rskDestinationAddress); + + data.push(Buffer.from(peginV1DataString, 'hex')); await btcTxHelper.fundAddress(senderAddressInformation.address, AMOUNT_TO_LOCK_IN_BTC + btcTxHelper.getFee()); @@ -80,7 +84,10 @@ describe('Lock funds using peg-in protocol version 1', () => { // Create peg-in data const data = []; - data.push(createPeginV1TxData(rskDestinationAddress)); + + const peginV1DataString = peginVerifier.createPeginV1TxData(rskDestinationAddress); + + data.push(Buffer.from(peginV1DataString, 'hex')); await btcTxHelper.fundAddress(senderAddressInformation.address, AMOUNT_TO_LOCK_IN_BTC + btcTxHelper.getFee()); @@ -116,8 +123,8 @@ describe('Lock funds using peg-in protocol version 1', () => { // Create peg-in data const data = []; - data.push(createPeginV1TxData(rskDestinationAddress1)); - data.push(createPeginV1TxData(rskDestinationAddress2)); + data.push(Buffer.from(peginVerifier.createPeginV1TxData(rskDestinationAddress1), 'hex')); + data.push(Buffer.from(peginVerifier.createPeginV1TxData(rskDestinationAddress2), 'hex')); await btcTxHelper.fundAddress(senderAddressInformation.address, AMOUNT_TO_LOCK_IN_BTC + btcTxHelper.getFee()); @@ -172,7 +179,7 @@ describe('Lock funds using peg-in protocol version 1', () => { // Create peg-in data const data = []; data.push(Buffer.from('some random data', 'hex')); - data.push(createPeginV1TxData(rskDestinationAddress)); + data.push(Buffer.from(peginVerifier.createPeginV1TxData(rskDestinationAddress), 'hex')); data.push(Buffer.from('some more random data', 'hex')); await btcTxHelper.fundAddress(senderAddressInformation.address, AMOUNT_TO_LOCK_IN_BTC + btcTxHelper.getFee());