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 reject and refund a pegout when fee per kb is above valu… #140

Conversation

jeremy-then
Copy link
Contributor

Adds 'should reject and refund a pegout when fee per kb is above value' test

@jeremy-then jeremy-then self-assigned this Oct 22, 2024
@jeremy-then jeremy-then requested a review from a team as a code owner October 22, 2024 15:13
Copy link

@apancorb apancorb left a comment

Choose a reason for hiding this comment

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

LGTM

lib/tests/2wp.js Outdated

// 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);
const peginValueInSatoshis = btcToSatoshis(0.5);

Choose a reason for hiding this comment

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

Maybe we can have a default constant for 0.5 as well?

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 think there's no need for this. This is not the minimum pegin value or any significan value. This is just to have enough funds on the rsk address. This value could change from test to test. For example, in the future pegout test where we will need to create a lot of pegouts to assert that the Bridge split them, we will probably need to send way more funds. So, that value could change.

Copy link
Contributor

Choose a reason for hiding this comment

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

As long as this value does not repeat in other places, it is ok to me.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Left a similar comment in another PR.

Not a big deal, open to discuss it. If the value won't always be the same then maybe it doesn't make sense to have a constant. But it could maybe at least be a constant within the test to not make it a magic number.

Option 2 is to calculate this value depending on what the test needs. If we are doing a peg-out for pegoutValue=X, then this value could be pegoutValue * 2

Open to hear other ideas

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

lib/tests/2wp.js Outdated Show resolved Hide resolved
@jeremy-then jeremy-then force-pushed the add-pegout-with-fee-above-value-test branch from 57c7280 to 08d4d77 Compare October 24, 2024 15:27
@jeremy-then jeremy-then force-pushed the add-should-reject-and-refund-pegout-below-minimum-test branch from 36834c7 to c792c63 Compare October 26, 2024 15:37
@jeremy-then jeremy-then force-pushed the add-pegout-with-fee-above-value-test branch from 08d4d77 to aed2792 Compare October 26, 2024 22:19
lib/constants.js Outdated
@@ -116,6 +116,9 @@ const PEGIN_V1_RSKT_PREFIX_HEX = '52534b54';

const MINIMUM_PEGOUT_AMOUNT_IN_RBTC = 0.0025;

const FEE_PER_KB_CHANGE_PK = '6a4b49312b91e203ddfb9bc2d900ebbd46fbede46a7462e770bedcb11ad405e9';
Copy link
Collaborator

Choose a reason for hiding this comment

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

A bit nit from my side, but whenever I see PK I wish I could tell if it means public or private key. And the difference is quite important

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

await sendTransaction(rskTxHelper, bridge.methods.voteFeePerKbChange(feePerKbInSatoshis), FEE_PER_KB_CHANGE_ADDR);

const finalFeePerKb = await bridge.methods.getFeePerKb().call();
expect(Number(finalFeePerKb)).to.equal(Number(feePerKbInSatoshis));
Copy link
Collaborator

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 code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A call to voteFeePerKbChange or getFeePerKb?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, by calling sendTxWithCheck.

lib/tests/2wp.js Outdated

// 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);
const peginValueInSatoshis = btcToSatoshis(0.5);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Left a similar comment in another PR.

Not a big deal, open to discuss it. If the value won't always be the same then maybe it doesn't make sense to have a constant. But it could maybe at least be a constant within the test to not make it a magic number.

Option 2 is to calculate this value depending on what the test needs. If we are doing a peg-out for pegoutValue=X, then this value could be pegoutValue * 2

Open to hear other ideas

lib/tests/2wp.js Outdated
const btcPeginTxHash = await sendPegin(rskTxHelper, btcTxHelper, senderRecipientInfo.btcSenderAddressInfo, satoshisToBtc(peginValueInSatoshis));
await ensurePeginIsRegistered(rskTxHelper, btcPeginTxHash);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could this whole part maybe be moved to a method? fundBridgeForPegout or something of the sort. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@jeremy-then jeremy-then force-pushed the add-should-reject-and-refund-pegout-below-minimum-test branch from c792c63 to c8d5e3e Compare October 30, 2024 17:30
@jeremy-then jeremy-then force-pushed the add-pegout-with-fee-above-value-test branch from 58d00aa to 102700b Compare October 30, 2024 18:12
@jeremy-then jeremy-then force-pushed the add-pegout-with-fee-above-value-test branch from f39a419 to f5065f6 Compare October 30, 2024 19:07
Base automatically changed from add-should-reject-and-refund-pegout-below-minimum-test to rits-refactors-9-2024-integration October 30, 2024 19:14
lib/tests/2wp.js Outdated
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

Copy link

@marcos-iov marcos-iov merged commit 1aecc22 into rits-refactors-9-2024-integration Oct 31, 2024
3 of 5 checks passed
@marcos-iov marcos-iov deleted the add-pegout-with-fee-above-value-test branch October 31, 2024 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants