-
Notifications
You must be signed in to change notification settings - Fork 2
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
marcos-iov
merged 5 commits into
rits-refactors-9-2024-integration
from
increase-locking-cap
Sep 10, 2024
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
917196a
Increase locking cap to 21 million as part of the setup start
jeremy-then c2556a8
Asserts current locking cap is the same as the recently set locking cap.
jeremy-then 82aa799
Adds sendTransaction function and uses it in the locking cap test
jeremy-then 5ea54e9
Updates doc comment
jeremy-then 68f81ee
Removes options from send transaction functions.
jeremy-then File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -333,20 +333,22 @@ 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 | ||
* @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 | ||
* @param {function} checkCallback callback to check the result of the method 'call' before calling 'send' | ||
* @param {object} options optional. Object with the options for the transaction. It can contain the following properties: value, gasPrice, gas | ||
* @returns {web3.eth.TransactionReceipt} txReceipt | ||
*/ | ||
const sendTxWithCheck = async (rskTxHelper, method, from, checkCallback) => { | ||
|
||
const callResult = await method.call({ from }); | ||
const sendTxWithCheck = async (rskTxHelper, method, from, checkCallback, options = { value: 0, gasPrice: 0, gas: 0 }) => { | ||
|
||
if(checkCallback) { | ||
const callResult = await method.call({ from }); | ||
await checkCallback(callResult); | ||
} | ||
|
||
const estimatedGas = await method.estimateGas({ from }); | ||
const txReceiptPromise = method.send({ from, value: 0, gasPrice: 0, gas: estimatedGas }); | ||
const { value, gasPrice, gas } = options; | ||
|
||
const estimatedGas = gas ? gas : await method.estimateGas({ from }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check Sonar report here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
const txReceiptPromise = method.send({ from, value, gasPrice, gas: estimatedGas }); | ||
|
||
await waitForRskMempoolToGetNewTxs(rskTxHelper); | ||
await mineAndSync(getRskTransactionHelpers()); | ||
|
@@ -355,6 +357,18 @@ const sendTxWithCheck = async (rskTxHelper, method, from, checkCallback) => { | |
|
||
}; | ||
|
||
/** | ||
* 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 {string} from rsk address to send the transaction from | ||
* @param {object} options optional. Object with the options for the transaction. It can contain the following properties: value, gasPrice, gas | ||
* @returns {web3.eth.TransactionReceipt} txReceipt | ||
*/ | ||
const sendTransaction = async (rskTxHelper, method, from, options = { value: 0, gasPrice: 0, gas: 0 }) => { | ||
return await sendTxWithCheck(rskTxHelper, method, from, null, options); | ||
}; | ||
|
||
/** | ||
* | ||
* @param {RskTransactionHelper} rskTxHelper | ||
|
@@ -486,4 +500,5 @@ module.exports = { | |
waitForRskTxToBeInTheMempool, | ||
waitForRskMempoolToGetNewTxs, | ||
waitAndUpdateBridge, | ||
sendTransaction, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe receive options param first and checkCallback last? Mainly to avoid having to pass
null
when calling fromsendTransaction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.