-
Notifications
You must be signed in to change notification settings - Fork 268
Added a test to check what is the maximum number of inputs allowed #3405
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
base: mtmu-integration
Are you sure you want to change the base?
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
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.
Pull request overview
This PR adds tests to verify the maximum number of inputs allowed in Bitcoin pegout transactions while staying within the Bitcoin standard transaction size limit. The changes include updates to the PegoutTransactionBuilder to accept custom script signatures, a new utility method for calculating SegWit transaction virtual size, and two test cases that verify transaction sizes with different input counts.
- Added
calculateSignedSegwitBtcTxVirtualSizeutility method for calculating transaction virtual sizes - Updated
PegoutTransactionBuilder.withInputto accept a script parameter instead of hardcoding an empty byte array - Added tests verifying that 150 inputs stay below the limit while 210 inputs exceed it
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| rskj-core/src/main/java/co/rsk/peg/BridgeUtils.java | Extracted virtual byte calculation into reusable methods and added public method for calculating SegWit transaction virtual size |
| rskj-core/src/test/java/co/rsk/peg/BridgeUtilsTest.java | Added test case to verify virtual size calculation using a real SegWit transaction |
| rskj-core/src/test/java/co/rsk/peg/ReleaseTransactionBuilderTest.java | Added tests verifying transaction size limits with varying input counts and refactored UTXO generation helper |
| rskj-core/src/test/java/co/rsk/test/builders/PegoutTransactionBuilder.java | Modified withInput method to accept script parameter for more flexible test setup |
| rskj-core/src/test/java/co/rsk/peg/BridgeSupportSvpTest.java | Updated test calls to match new withInput signature |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
rskj-core/src/test/java/co/rsk/peg/ReleaseTransactionBuilderTest.java
Outdated
Show resolved
Hide resolved
rskj-core/src/test/java/co/rsk/peg/ReleaseTransactionBuilderTest.java
Outdated
Show resolved
Hide resolved
1044f07 to
9fbd0d3
Compare
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.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
As a comment, the method |
| int actualVirtualBytes = calculateSignedSegwitBtcTxVirtualSize(btcTx); | ||
|
|
||
| //assert | ||
| Assertions.assertEquals(expectedVirtualBytes, actualVirtualBytes); |
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.
very very nice
rskj-core/src/test/java/co/rsk/test/builders/PegoutTransactionBuilder.java
Outdated
Show resolved
Hide resolved
rskj-core/src/test/java/co/rsk/peg/ReleaseTransactionBuilderTest.java
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| @Test | ||
| void createPegoutTransaction_with210Inputs_with50Outputs_shouldHaveASizeAboveMaximumBtcStandardSize() { |
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.
should we do these tests for migrations also?
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.
As it is right now, a migration tx has only 3 outputs (if there is change). Would you think it makes sense at this stage? Perhaps in the future with multiple utxos?
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.
i mean creating it manually, no big deal at all anyways
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.
(btw, there's no change in the migration tx)
rskj-core/src/test/java/co/rsk/peg/ReleaseTransactionBuilderTest.java
Outdated
Show resolved
Hide resolved
rskj-core/src/test/java/co/rsk/peg/ReleaseTransactionBuilderTest.java
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| @Test | ||
| void calculateSignedSegwitBtcTxVirtualSize_withASegwitTx_shouldReturnCorrectVirtualSize() { |
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.
| void calculateSignedSegwitBtcTxVirtualSize_withASegwitTx_shouldReturnCorrectVirtualSize() { | |
| void calculateSignedSegwitBtcTxVirtualSize_whenSignedSegwitTx_shouldReturnCorrectVirtualSize() { |
Wdyt?
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.
hmm the tx is not being signed
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.
I missed the article. I refer to the noun ASignedSegwitTx, which denotes a signed segwit tx is being passed. The point is to make that test case explicit and to test it with other types of txs as well.
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.
it was changed to calculateBtcTxVirtualSize_withARealBtcTx_shouldReturnCorrectVirtualSize
| return baseSize + signingSize; | ||
| } | ||
|
|
||
| public static int calculateSignedSegwitBtcTxVirtualSize(BtcTransaction btcTx) { |
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.
What happens if you pass an unsigned segwit transaction? Does it work? Return the correct value? Or should throw an exception?
I think we are missing more tests for this method. To mention some cases:
- Passing unsigned segwit tx(as said)?
- Bech32 tx?
- Legacy tx?
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.
For unsigned segwit tx there is a different method that estimates the size calculateSegwitTxSize
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.
If you pass an unsigned segwit tx or another type of tx, it will attempt to calculate the btc tx size. Will it succeed on it? If so, will the result be correct? I guess no. Since this used is not expected, should we throw an exception if the method is misused so we can catch this error early?
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.
The thing is that this method isn't used anywhere but to calculate the btc tx size limit for a SegWit tx.
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.
As discussed, let's create a task to further analyze the missing test cases.
rskj-core/src/test/java/co/rsk/peg/ReleaseTransactionBuilderTest.java
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| @Test | ||
| void createPegoutTransaction_with210Inputs_with50Outputs_shouldHaveASizeAboveMaximumBtcStandardSize() { |
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.
The test naming is confusing to me. The name says you are testing the createPegoutTransaction method, but it is a test helper method, so I guess what is being tested is calculateSignedSegwitBtcTxVirtualSize. Then, why have these tests in ReleaseTransactionBuilderTest? According to what I see, these tests are using nothing from it. I would rather move them to BridgeUtilsTest, or better yet, to their own test class. Wdyt?
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.
these tests are one step before creating migration transactions with multiple utxos. That is why it is confusing. The test will be createMigrationTransactionWithMultipleUtxos..
In BridgeUtilsTest I am testing calculateBtcTxVirtualSize_withARealBtcTx_shouldReturnCorrectVirtualSize
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.
The same, let's create a task for the future refactors.
| private final Federation p2shP2wshErpProposedFederation = P2shP2wshErpFederationBuilder.builder().build(); | ||
| private final List<BtcECKey> signingKeys = BitcoinTestUtils.getBtcEcKeys(20); | ||
| private final Federation p2shP2wshErpProposedFederation = P2shP2wshErpFederationBuilder.builder().withMembersBtcPublicKeys(signingKeys).build(); | ||
| private final Federation p2shP2wshErpFederation = P2shP2wshErpFederationBuilder.builder().withMembersBtcPublicKeys(signingKeys).build(); |
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.
| private final Federation p2shP2wshErpFederation = P2shP2wshErpFederationBuilder.builder().withMembersBtcPublicKeys(signingKeys).build(); | |
| private final Federation activeP2shP2wshErpFederation = P2shP2wshErpFederationBuilder.builder().withMembersBtcPublicKeys(signingKeys).build(); |
wdyt? and move the declaration below the activeP2shErpFederation
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.
done!
julia-zack
left a comment
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.
great work! left one suggestion
|



Description
Motivation and Context
How Has This Been Tested?
Types of changes
Checklist: