Skip to content

Ensure IInteroperable.Clone#3829

Merged
shargon merged 24 commits intomasterfrom
safe-clone-interop
Mar 20, 2025
Merged

Ensure IInteroperable.Clone#3829
shargon merged 24 commits intomasterfrom
safe-clone-interop

Conversation

@shargon
Copy link
Member

@shargon shargon commented Mar 12, 2025

Description

When creating a clone from interop, some classes may be modified when modifying the clone. Before this fix, this test fault.

[TestMethod]
public void TestClone()
{
    var clone = ((IInteroperable)contract).Clone() as ContractState;
    clone.Nef.CheckSum++;
    Assert.AreNotEqual(clone.Nef.CheckSum, contract.Nef.CheckSum);
}

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?

  • TestClone

Test Configuration:

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

@shargon shargon added Blocker Issues that are blocking other issues. Check issues details to see what it is blocking. Waiting for Review Bug Used to tag confirmed bugs labels Mar 12, 2025
Wi1l-B0t
Wi1l-B0t previously approved these changes Mar 13, 2025
@Wi1l-B0t Wi1l-B0t dismissed their stale review March 13, 2025 01:29

click twice

@shargon
Copy link
Member Author

shargon commented Mar 13, 2025

I found a new bug, I will be fixed before

Transaction = from.Transaction;
State = from.State;
if (_rawTransaction.IsEmpty)
_rawTransaction = from._rawTransaction;
Copy link
Member Author

Choose a reason for hiding this comment

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

That was a bug

}

[TestMethod]
public void AvoidReplicaBug()
Copy link
Member Author

Choose a reason for hiding this comment

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

This test fault before this pr, multiple FromReplica to same object use a different _rawTransaction.

@shargon
Copy link
Member Author

shargon commented Mar 13, 2025

Ready to review again

@Wi1l-B0t
Copy link
Contributor

Has conflicts with the master branch.

vncoelho
vncoelho previously approved these changes Mar 17, 2025
@shargon
Copy link
Member Author

shargon commented Mar 17, 2025

Has conflicts with the master branch.

Done

vncoelho
vncoelho previously approved these changes Mar 17, 2025
/// </summary>
public VMState State { get; set; }

private ReadOnlyMemory<byte> _rawTransaction;
Copy link
Member Author

Choose a reason for hiding this comment

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

Cache should be done in Transaction.ToArray

@shargon shargon merged commit 1790dcc into master Mar 20, 2025
7 checks passed
@shargon shargon deleted the safe-clone-interop branch March 20, 2025 15:15
Jim8y added a commit that referenced this pull request Mar 24, 2025
* master: (52 commits)
  Add SHA512 (#3845)
  Clean crypto (#3844)
  Review of #3782 (#3843)
  [`Fix`] References in `StorageKey` (#3782)
  Ensure `IInteroperable.Clone` (#3829)
  Ensure the interop types are serializable before commit (#3802)
  fix: ModInverse extension in BigIntegerExtensions (#3840)
  Style: avoid allocating emtpy array (#3841)
  Style: format json in tests/ (#3839)
  Reduce mem arguments (#3838)
  Avoid returning the entire mempool when only `maxTransactionsPerBlock` is required (#3823)
  style: use proper Assert methods (#3834)
  Nullable and fix `lock` in `SQLiteWallet` (#3816)
  [`Add`]: `Witness.Empty` for simplifing somethings (#3836)
  Style: format too-long literal strings (#3835)
  Add: NotNullWhen(true) for some out parameters (#3833)
  Update SQLiteWallet.cs (#3830)
  Revert "Optimize DeleteAccount"
  Revert "add lock to Version"
  Revert "Optimize LoadAccounts"
  ...

# Conflicts:
#	neo.sln
cschuchardt88 pushed a commit to cschuchardt88/neo that referenced this pull request Jun 8, 2025
* Ensure clone

* Fix TransactionState bug

* Ensure clone is equal

* clean code

* Ensure tests

* clean

* Fix tx changes don't reflect in ToStackItem

* Cache

* Clean var

* Header.Clone

* Optimize

* Remove cache

* Witness.Clone

* cache

---------

Co-authored-by: Jimmy <jinghui@wayne.edu>
Co-authored-by: Will <201105916+Wi1l-B0t@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Blocker Issues that are blocking other issues. Check issues details to see what it is blocking. Bug Used to tag confirmed bugs Ready to Merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants