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

refactor: enhance migration testing tool #17246

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

mustafauzunn
Copy link
Collaborator

Description:

Enhance the migration testing tool to work with new transactions of bytes.

Related issue(s):

Fixes #16842

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

@mustafauzunn mustafauzunn added the Platform Tickets pertaining to the platform label Jan 7, 2025
@mustafauzunn mustafauzunn added this to the v0.59 milestone Jan 7, 2025
@mustafauzunn mustafauzunn self-assigned this Jan 7, 2025
Copy link

codecov bot commented Jan 7, 2025

Codecov Report

Attention: Patch coverage is 76.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 67.43%. Comparing base (be1981d) to head (f2dc3db).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...rlds/demo/migration/MigrationTestingToolState.java 72.22% 3 Missing and 2 partials ⚠️
...irlds/demo/migration/MigrationTestingToolMain.java 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main   #17246      +/-   ##
============================================
+ Coverage     67.41%   67.43%   +0.02%     
- Complexity    22063    22076      +13     
============================================
  Files          2585     2585              
  Lines         96408    96433      +25     
  Branches      10071    10073       +2     
============================================
+ Hits          64992    65031      +39     
+ Misses        27698    27682      -16     
- Partials       3718     3720       +2     
Files with missing lines Coverage Δ
...a/com/swirlds/demo/migration/TransactionUtils.java 72.72% <100.00%> (+32.72%) ⬆️
...irlds/demo/migration/MigrationTestingToolMain.java 0.00% <0.00%> (ø)
...rlds/demo/migration/MigrationTestingToolState.java 32.98% <72.22%> (+32.98%) ⬆️

... and 1 file with indirect coverage changes

Impacted file tree graph

Copy link

codacy-production bot commented Jan 7, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.02% (target: -1.00%) 84.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (be1981d) 96191 68558 71.27%
Head commit (f2dc3db) 96216 (+25) 68599 (+41) 71.30% (+0.02%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#17246) 25 21 84.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

@mustafauzunn mustafauzunn marked this pull request as ready for review January 9, 2025 12:28
@mustafauzunn mustafauzunn requested review from a team as code owners January 9, 2025 12:28
Signed-off-by: Mustafa Uzun <[email protected]>
andrewb1269hg
andrewb1269hg previously approved these changes Jan 9, 2025
Copy link
Contributor

@andrewb1269hg andrewb1269hg left a comment

Choose a reason for hiding this comment

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

Review and approve file platform-sdk/platform-apps/tests/MigrationTestingTool/build.gradle.kts

…2-enhance-migration-testing-tool

# Conflicts:
#	platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java
Signed-off-by: Mustafa Uzun <[email protected]>
@@ -207,4 +209,9 @@ public PlatformMerkleStateRoot newMerkleStateRoot() {
public BasicSoftwareVersion getSoftwareVersion() {
return softwareVersion;
}

@Override
public Bytes encodeSystemTransaction(@NonNull StateSignatureTransaction transaction) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add final for the argument and nonnull annotation for the return type

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added

@Override
public void preHandle(
@NonNull Event event,
@NonNull Consumer<ScopedSystemTransaction<StateSignatureTransaction>> stateSignatureTransaction) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Make all arguments final

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Refactored

@NonNull Event event,
@NonNull Consumer<ScopedSystemTransaction<StateSignatureTransaction>> stateSignatureTransaction) {
event.forEachTransaction(transaction -> {
if (!transaction.isSystem() && isSystemTransaction(transaction.getApplicationTransaction())) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can extract the isSystem() check as a separate code before the if statement and add a comment on top of it - about why we check whether it's the deprecated system transaction format

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Refactored

@@ -335,4 +355,18 @@ public int getVersion() {
public int getMinimumSupportedVersion() {
return ClassVersion.VIRTUAL_MAP;
}

private void consumeSystemTransaction(
final Transaction transaction,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add nonnull annotations for all arguments

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added

public static boolean isSystemTransaction(@NonNull final Bytes bytes) {
final SerializableDataInputStream in = new SerializableDataInputStream(bytes.toInputStream());

try {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It might be performance heavy to try to serialize every transaction that is incoming with having a try/catch block. You can add a marker byte as @lpetrovic05 suggested in another PR.

import org.mockito.MockedStatic;
import org.mockito.Mockito;

public class MigrationTestingToolStateTest {
Copy link
Collaborator

Choose a reason for hiding this comment

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

public can be removed

import org.mockito.Mockito;

public class MigrationTestingToolStateTest {
private static MigrationTestingToolState state;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need the state to be static?

Signed-off-by: Mustafa Uzun <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform Tickets pertaining to the platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adapt MigrationTestingTool to work with new proto types and add README
3 participants