diff --git a/lib/rsk-utils.js b/lib/rsk-utils.js index e085cbc0..99fc1d73 100644 --- a/lib/rsk-utils.js +++ b/lib/rsk-utils.js @@ -330,22 +330,16 @@ const triggerRelease = async (rskTransactionHelpers, btcClient, callbacks = {}) }; /** - * Executes a method 'call' and calls the callback with the result of the call, then calls 'send' and waits for the transaction receipt to be available and returns it + * Calls the `method` as a `send` transaction and wait for the transaction receipt to be available. * @param {RskTransactionHelper} rskTxHelper to make transactions to the rsk network * @param {web3.eth.Contract.ContractSendMethod} method contract method to be invoked - * @param {function} checkCallback callback to check the result of the method 'call' before calling 'send' * @param {string} from rsk address to send the transaction from * @returns {web3.eth.TransactionReceipt} txReceipt - */ -const sendTxWithCheck = async (rskTxHelper, method, from, checkCallback) => { - - const callResult = await method.call({ from }); - - if(checkCallback) { - await checkCallback(callResult); - } +*/ +const sendTransaction = async (rskTxHelper, method, from) => { const estimatedGas = await method.estimateGas({ from }); + const txReceiptPromise = method.send({ from, value: 0, gasPrice: 0, gas: estimatedGas }); await waitForRskMempoolToGetNewTxs(rskTxHelper); @@ -355,6 +349,28 @@ const sendTxWithCheck = async (rskTxHelper, method, from, checkCallback) => { }; + +/** + * Executes a method 'call' and calls the callback with the result of the call, then calls 'send' and waits for the transaction receipt to be available and returns it + * @param {RskTransactionHelper} rskTxHelper to make transactions to the rsk network + * @param {web3.eth.Contract.ContractSendMethod} method contract method to be invoked + * @param {string} from rsk address to send the transaction from + * @param {function} checkCallback callback to check the result of the method 'call' before calling 'send' + * @returns {web3.eth.TransactionReceipt} txReceipt + */ +const sendTxWithCheck = async (rskTxHelper, method, from, checkCallback) => { + + if(!checkCallback) { + throw new Error('`checkCallback` is required'); + } + + const callResult = await method.call({ from }); + await checkCallback(callResult); + + return await sendTransaction(rskTxHelper, method, from); + +}; + /** * * @param {RskTransactionHelper} rskTxHelper @@ -486,4 +502,5 @@ module.exports = { waitForRskTxToBeInTheMempool, waitForRskMempoolToGetNewTxs, waitAndUpdateBridge, + sendTransaction, }; diff --git a/tests/00_00_3-vote_for_locking_cap_to_21m.js b/tests/00_00_3-vote_for_locking_cap_to_21m.js new file mode 100644 index 00000000..953eb0bb --- /dev/null +++ b/tests/00_00_3-vote_for_locking_cap_to_21m.js @@ -0,0 +1,57 @@ +const rskUtils = require('../lib/rsk-utils'); +const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider'); +const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util'); +const { btcToWeis, btcToSatoshis } = require('@rsksmart/btc-eth-unit-converter'); +const { expect } = require('chai'); + +const lockingCapAuthorizerPrivateKey = 'da6a5451bfd74829307ec6d4a8c55174d4859169f162a8ed8fcba8f7636e77cc'; + +describe('Vote for locking cap to the max 21 million btc', function() { + + let rskTxHelpers; + + before(async () => { + rskTxHelpers = getRskTransactionHelpers(); + }); + + it('should increase locking cap to the max 21 million btc', async () => { + + const rskTxHelper = rskTxHelpers[0]; + + const authAddress = await rskTxHelper.getClient().eth.personal.importRawKey(lockingCapAuthorizerPrivateKey, ''); + await rskUtils.sendFromCow(rskTxHelper, authAddress, btcToWeis(1)); + + const bridge = getBridge(rskTxHelper.getClient(), await getLatestActiveForkName()); + + const MAX_BTC = 21_000_000; + + const targetLockingCapInSatoshis = Number(btcToSatoshis(MAX_BTC)); + + let currentLockingCapValueInSatoshis = Number(await bridge.methods.getLockingCap().call()); + + let nextIncrement = 0; + + while(nextIncrement < targetLockingCapInSatoshis) { + + nextIncrement = currentLockingCapValueInSatoshis * 2; + + // Ensuring that the next increment is not greater than the target locking cap. + nextIncrement = Math.min(nextIncrement, targetLockingCapInSatoshis); + + const increaseLockingCapMethod = bridge.methods.increaseLockingCap(nextIncrement); + + await rskUtils.sendTransaction(rskTxHelper, increaseLockingCapMethod, authAddress); + + currentLockingCapValueInSatoshis = Number(await bridge.methods.getLockingCap().call()); + + // Ensuring that the locking cap is being increased on every iteration. + expect(currentLockingCapValueInSatoshis).to.be.equal(nextIncrement, 'The new locking cap value should be equal to the set value'); + + } + + const finalLockingCapValueInSatoshis = Number(await bridge.methods.getLockingCap().call()); + + expect(finalLockingCapValueInSatoshis).to.be.equal(targetLockingCapInSatoshis); + + }); +}); diff --git a/tests/01_03_54-post-papyrus_coinbase_information.js b/tests/01_03_54-post-papyrus_coinbase_information.js index 326d840b..236a1300 100644 --- a/tests/01_03_54-post-papyrus_coinbase_information.js +++ b/tests/01_03_54-post-papyrus_coinbase_information.js @@ -60,7 +60,7 @@ describe('Calling coinbase information methods after papyrus', () => { ensure0x(witnessReservedValue) ); - const txReceipt = await rskUtils.sendTxWithCheck(rskTxHelper, registerBtcCoinbaseTransactionMethod, rskTxSenderAddress); + const txReceipt = await rskUtils.sendTransaction(rskTxHelper, registerBtcCoinbaseTransactionMethod, rskTxSenderAddress); expect(txReceipt).not.to.be.null;