Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds 'should create multiple pegouts with mixed values same and above… #163

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/2wp-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,19 @@ const assertRefundUtxosSameAsPeginUtxos = async(rskTxHelper, btcTxHelper, peginT
* @param {BN} amountInWeisBN
* @param {string} rskFromAddress
* @param {boolean} mine If true, mines 1 block after sending the transaction. If false, it will not mine the tx and will return undefined. Defaults to true.
* @returns {web3.eth.TransactionReceipt | undefined}
* @returns {Promise<web3.eth.TransactionReceipt | txPromise>} the rsk tx receipt if `mine` is true, otherwise the tx promise.
*/
const sendTxToBridge = async (rskTxHelper, amountInWeisBN, rskFromAddress, mine = true) => {

const txPromise = rskTxHelper.sendTransaction({
from: rskFromAddress,
to: BRIDGE_ADDRESS,
value: amountInWeisBN,
gasPrice: TO_BRIDGE_GAS_PRICE,
});

if(!mine) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
if(!mine) {
if (!mine) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed there is a mixed of if ( an if( in the test. I always prefer if(. But what should we always use? @nathanieliov , @marcos-iov , @julia-zack .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apancorb 's suggestion, as it seems to be the rule of our formatting settings. I formatted it in my local and the result was @apancorb suggestion.

return;
return txPromise;
}

// Wait for the rsk tx to be in the rsk mempool before mining
Expand All @@ -78,6 +80,7 @@ const sendTxToBridge = async (rskTxHelper, amountInWeisBN, rskFromAddress, mine
await mineAndSync(getRskTransactionHelpers());
const result = await txPromise;
return result;

};

/**
Expand Down
34 changes: 22 additions & 12 deletions lib/btc-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,27 @@ const waitForBitcoinMempoolToGetTxs = async (btcTxHelper, maxAttempts = 3, check
logger.debug(`[${waitForBitcoinMempoolToGetTxs.name}] The final bitcoin mempool size is ${finalBitcoinMempoolSize}, after ${attempts} attempts. Difference with initial mempool size: ${finalBitcoinMempoolSize - initialBitcoinMempoolSize}.`);

return bitcoinMempoolHasTx;
}
}

const getBtcAddressBalanceInSatoshis = async (btcTxHelper, btcAddress) => {
return Number(btcToSatoshis(await btcTxHelper.getAddressBalance(btcAddress)));
};
const getBtcAddressBalanceInSatoshis = async (btcTxHelper, btcAddress) => {
return Number(btcToSatoshis(await btcTxHelper.getAddressBalance(btcAddress)));
};

module.exports = {
publicKeyToCompressed,
fundAddressAndGetData,
getBitcoinTransactionsInMempool,
waitForBitcoinTxToBeInMempool,
waitForBitcoinMempoolToGetTxs,
getBtcAddressBalanceInSatoshis,
};
/**
* converts a base58 bitcoin address to its string hash160 representation
* @param {string} base58Address the bitcoin address in base58 format
* @returns {string} the hash160 representation of the base58 bitcoin address
*/
const base58AddressToHash160 = (base58Address) => {
return bitcoinJs.address.fromBase58Check(base58Address).hash.toString('hex');
};

module.exports = {
publicKeyToCompressed,
fundAddressAndGetData,
getBitcoinTransactionsInMempool,
waitForBitcoinTxToBeInMempool,
waitForBitcoinMempoolToGetTxs,
getBtcAddressBalanceInSatoshis,
base58AddressToHash160,
};
25 changes: 25 additions & 0 deletions lib/rsk-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,30 @@ const getNewFundedRskAddress = async (rskTxHelper, fundingAmountInRbtc = DEFAULT
return address;
};

/**
* Waits for the rsk mempool to get `atLeastExpectedCount` txs. Attempting `maxAttempts` times, checking every `waitTimeInMilliseconds`.
* @param {RskTransactionHelper} rskTxHelper
* @param {number} atLeastExpectedCount
* @param {number} waitTimeInMilliseconds defaults to 500 milliseconds
* @param {number} maxAttempts defaults to 20 attempts
* @returns {Promise<void>}
* @throws {Error} if the rsk mempool doesn't get at least `atLeastExpectedCount` txs after `maxAttempts` attempts
*/
const waitForRskMempoolToGetAtLeastThisManyTxs = async (rskTxHelper, atLeastExpectedCount, waitTimeInMilliseconds = 500, maxAttempts = 20) => {
let attempts = 1;
while(attempts <= maxAttempts) {
apancorb marked this conversation as resolved.
Show resolved Hide resolved
const rskMempoolTxs = await getRskMempoolTransactionHashes(rskTxHelper);
logger.debug(`[${waitForRskMempoolToGetAtLeastThisManyTxs.name}] rsk mempool txs: ${rskMempoolTxs.length}`);
if(rskMempoolTxs.length >= atLeastExpectedCount) {
logger.debug(`[${waitForRskMempoolToGetAtLeastThisManyTxs.name}] rsk mempool has ${rskMempoolTxs.length} (at least expected was ${atLeastExpectedCount}) txs after ${attempts} attempts`);
return;
}
await wait(waitTimeInMilliseconds);
attempts++;
}
throw new Error(`[${waitForRskMempoolToGetAtLeastThisManyTxs.name}] rsk mempool didn't get at least ${atLeastExpectedCount} txs after ${maxAttempts} attempts`);
};

module.exports = {
mineAndSync,
waitForBlock,
Expand All @@ -558,4 +582,5 @@ module.exports = {
getPegoutEventsInBlockRange,
setFeePerKb,
getNewFundedRskAddress,
waitForRskMempoolToGetAtLeastThisManyTxs,
};
Loading
Loading