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

[Optimization]: make some unit tests more readable #3716

Merged
merged 2 commits into from
Feb 7, 2025

Conversation

nan01ab
Copy link
Contributor

@nan01ab nan01ab commented Feb 5, 2025

Description

Make TestUtils.SetupHeaderWithValues and TestUtils.SetupBlockWithValues simpler and clearer

Type of change

  • Optimization (the change is only an optimization)
  • Style (the change is only a code style for better maintenance or standard purpose)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

tests/Neo.UnitTests/Network/P2P/Payloads/UT_Block.cs Outdated Show resolved Hide resolved
UInt256 val256 = UInt256.Zero;
TestUtils.SetupBlockWithValues(null, uut, val256, out var merkRootVal, out _, out var timestampVal, out var nonceVal, out var indexVal, out var scriptVal, out _, 0);

var uut = TestUtils.MakeBlock(null, UInt256.Zero, 0);
Copy link
Member

Choose a reason for hiding this comment

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

What happen to this unit test? Same for the others.

Copy link
Contributor Author

@nan01ab nan01ab Feb 6, 2025

Choose a reason for hiding this comment

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

What happen to this unit test? Same for the others.

Too many unused out variables.
It isn't clear.

Copy link
Member

Choose a reason for hiding this comment

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

Ill have to download to it and look at it.

Copy link
Contributor Author

@nan01ab nan01ab Feb 6, 2025

Choose a reason for hiding this comment

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

Ill have to download to it and look at it.

SetupHeaderWithValues sets these out variables and header fields to same values.
So these Assert.AreEqual are meaningless.

Comment on lines 179 to 180
InvocationScript = Array.Empty<byte>(),
VerificationScript = Array.Empty<byte>()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
InvocationScript = Array.Empty<byte>(),
VerificationScript = Array.Empty<byte>()
InvocationScript = [],
VerificationScript = [],

Copy link
Contributor Author

Choose a reason for hiding this comment

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

InvocationScript

public ReadOnlyMemory<byte> InvocationScript;

Copy link
Member

Choose a reason for hiding this comment

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

ReadOnlyMemory<byte>.Empty or Memory<byte>.Empty

Jim8y
Jim8y previously approved these changes Feb 6, 2025
Copy link
Member

@shargon shargon left a comment

Choose a reason for hiding this comment

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

Replace the Replace by Concat?

tests/Neo.UnitTests/Network/P2P/Payloads/UT_Header.cs Outdated Show resolved Hide resolved
tests/Neo.UnitTests/Network/P2P/Payloads/UT_Block.cs Outdated Show resolved Hide resolved
@nan01ab
Copy link
Contributor Author

nan01ab commented Feb 6, 2025

Replace the Replace by Concat?

Done

shargon
shargon previously approved these changes Feb 6, 2025
@shargon shargon merged commit f99268b into neo-project:master Feb 7, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants