-
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
Adds 'should reject and refund a pegout when fee per kb is above valu… #140
Changes from 8 commits
23140c0
16fd814
f94ad38
25b2655
e21c93e
a3e42fd
48b9e4e
f5065f6
01deb04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ const { getBridge } = require('../precompiled-abi-forks-util'); | |
const { getBtcClient } = require('../btc-client-provider'); | ||
const { getRskTransactionHelper, getRskTransactionHelpers } = require('../rsk-tx-helper-provider'); | ||
const { satoshisToBtc, btcToSatoshis, satoshisToWeis } = require('@rsksmart/btc-eth-unit-converter'); | ||
const { findEventInBlock, triggerRelease, getPegoutEventsInBlockRange } = require('../rsk-utils'); | ||
const { findEventInBlock, triggerRelease, getPegoutEventsInBlockRange, setFeePerKb } = require('../rsk-utils'); | ||
const { | ||
PEGIN_REJECTION_REASONS, | ||
PEGIN_UNREFUNDABLE_REASONS, | ||
|
@@ -774,6 +774,51 @@ const execute = (description, getRskHost) => { | |
|
||
}); | ||
|
||
it('should reject and refund a pegout when fee per kb is above value', async () => { | ||
|
||
// Arrange | ||
|
||
// Create a pegin for the sender to ensure there is enough funds to pegout and because this is the natural process | ||
const senderRecipientInfo = await createSenderRecipientInfo(rskTxHelper, btcTxHelper); | ||
await fundRskAccountThroughAPegin(rskTxHelper, btcTxHelper, senderRecipientInfo.btcSenderAddressInfo); | ||
|
||
const initial2wpBalances = await get2wpBalances(rskTxHelper, btcTxHelper); | ||
const initialBtcRecipientAddressBalanceInSatoshis = await getBtcAddressBalanceInSatoshis(btcTxHelper, senderRecipientInfo.btcSenderAddressInfo.address); | ||
const initialRskSenderBalanceInWeisBN = await rskTxHelper.getBalance(senderRecipientInfo.rskRecipientRskAddressInfo.address); | ||
const pegoutValueInSatoshis = MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS - 1; | ||
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. Is this a good idea? We want the pegout to be rejected for the fee value, I wouldn't see an invalid pegout request. That could create some confusion 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 initialFeePerKb = Number(await bridge.methods.getFeePerKb().call()); | ||
// We just need to have a feePerKB that will cause the pegout to rejected due to FEE_ABOVE_VALUE reason. | ||
// This value is way bigger than what we need, but actual calculation is complex and and estimation so we cannot know for sure. | ||
// That's we we just use a big enough value. The MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS is perfect for this in this case. | ||
const newFeePerKbInSatoshis = MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS; | ||
await setFeePerKb(rskTxHelper, newFeePerKbInSatoshis); | ||
|
||
// Act | ||
|
||
const pegoutTransaction = await sendTxToBridge(rskTxHelper, new BN(satoshisToWeis(pegoutValueInSatoshis)), senderRecipientInfo.rskRecipientRskAddressInfo.address); | ||
|
||
// Assert | ||
|
||
await assertExpectedReleaseRequestRejectedEventIsEmitted(senderRecipientInfo.rskRecipientRskAddressInfo.address, pegoutValueInSatoshis, PEGOUT_REJECTION_REASONS.FEE_ABOVE_VALUE); | ||
|
||
await assert2wpBalanceIsUnchanged(initial2wpBalances); | ||
|
||
// The rsk sender balance is the same as the initial balance minus the gas fee, because the pegout amount was refunded. | ||
const finalRskSenderBalanceInWeisBN = await rskTxHelper.getBalance(senderRecipientInfo.rskRecipientRskAddressInfo.address); | ||
const gasFee = pegoutTransaction.gasUsed * pegoutTransaction.effectiveGasPrice; | ||
const expectedRskSenderBalanceInWeisBN = initialRskSenderBalanceInWeisBN.sub(new BN(`${gasFee}`)); | ||
expect(finalRskSenderBalanceInWeisBN.eq(expectedRskSenderBalanceInWeisBN)).to.be.true; | ||
|
||
// The btc recipient address balance is the same as the initial balance, because the pegout didn't go though. | ||
const finalBtcRecipientBalanceInSatoshis = await getBtcAddressBalanceInSatoshis(btcTxHelper, senderRecipientInfo.btcSenderAddressInfo.address); | ||
expect(finalBtcRecipientBalanceInSatoshis).to.be.equal(initialBtcRecipientAddressBalanceInSatoshis); | ||
|
||
// Setting fee per kb back to its original value | ||
await setFeePerKb(rskTxHelper, initialFeePerKb); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}; | ||
|
@@ -940,4 +985,3 @@ const assertExpectedReleaseRequestRejectedEventIsEmitted = async (rskSenderAddre | |
module.exports = { | ||
execute, | ||
}; | ||
|
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.
You could also do a
call
before sending the transaction, and assert the response codeThere 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.
A
call
tovoteFeePerKbChange
orgetFeePerKb
?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, by calling
sendTxWithCheck
.