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

Increase locking cap to 21 million as part of the setup start #77

Merged
merged 5 commits into from
Sep 10, 2024
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
37 changes: 27 additions & 10 deletions lib/rsk-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -486,4 +502,5 @@ module.exports = {
waitForRskTxToBeInTheMempool,
waitForRskMempoolToGetNewTxs,
waitAndUpdateBridge,
sendTransaction,
};
57 changes: 57 additions & 0 deletions tests/00_00_3-vote_for_locking_cap_to_21m.js
Original file line number Diff line number Diff line change
@@ -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);

});
});
2 changes: 1 addition & 1 deletion tests/01_03_54-post-papyrus_coinbase_information.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down