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

[Add] IEquatable to WitnessCondition #3572

Merged

Conversation

cschuchardt88
Copy link
Member

Change Log

  • Added IEquatable to WitnessCondition, AndCondition, BooleanCondition, CalledByContractCondition, CalledByEntryCondition, CalledByGroupCondition, GroupCondition, NotCondition, OrCondition and ScriptHashCondition classes
  • Added Unit Tests for IEquatable on WitnessCondition, AndCondition, BooleanCondition, CalledByContractCondition, CalledByEntryCondition, CalledByGroupCondition, GroupCondition, NotCondition, OrCondition and ScriptHashCondition classes

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

How Has This Been Tested?

  • Test_IEquatable_OrCondition
  • Test_IEquatable_AndCondition
  • Test_IEquatable_BooleanCondition
  • Test_IEquatable_CalledByContractCondition
  • Test_IEquatable_CalledByEntryCondition
  • Test_IEquatable_CalledByGroupCondition
  • Test_IEquatable_GroupCondition
  • Test_IEquatable_ScriptHashCondition

Test Configuration:

  • Unit Tests

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

@cschuchardt88 cschuchardt88 added Feature Type: Large changes or new features Waiting for Review labels Nov 11, 2024
@cschuchardt88 cschuchardt88 added the Blocker Issues that are blocking other issues. Check issues details to see what it is blocking. label Nov 11, 2024
@cschuchardt88 cschuchardt88 mentioned this pull request Nov 11, 2024
15 tasks
@shargon shargon removed the Blocker Issues that are blocking other issues. Check issues details to see what it is blocking. label Nov 11, 2024
{
if (ReferenceEquals(this, other))
return true;
if (other is null) return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

null check before reference equal?

Copy link
Member Author

@cschuchardt88 cschuchardt88 Nov 12, 2024

Choose a reason for hiding this comment

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

no, because of

AndCondition a1 = null;

ReferenceEquals(a1, a1) = true;
a1.Equals(a1) = true;

Copy link
Member

Choose a reason for hiding this comment

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

I don't understand your example, I think @Jim8y is right, if we will check null reference, it's better to do it in the first line

Copy link
Contributor

Choose a reason for hiding this comment

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

So it should be this way? there are implementations in other classes that have the different order, should them be updated as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well this actually wont matter, not really affect the functionality of neo.

return true;
if (other is null) return false;
return Type == other.Type &&
Size == other.Size &&
Copy link
Contributor

Choose a reason for hiding this comment

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

should this also be updated to is ?

Jim8y
Jim8y previously approved these changes Nov 12, 2024
@Jim8y
Copy link
Contributor

Jim8y commented Nov 12, 2024

LGTM, minor potential issues being commented.

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.

I prefer to move null checks to the first line, but if @neo-project/core is ok with that, i'm not against to

Size == other.Size;
return
Type == other.Type &&
Expression.Equals(other.Expression);
Copy link
Member

Choose a reason for hiding this comment

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

We should review this test, because it was wrong

@shargon shargon merged commit cf2b559 into neo-project:master Nov 12, 2024
6 of 7 checks passed
@shargon shargon deleted the fix/equals-witnessconditions branch November 12, 2024 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Type: Large changes or new features Ready to Merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants