Skip to content

Batch Merkle Proof - override equals for matcher array equality #93

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

Merged
merged 2 commits into from
Jan 5, 2022

Conversation

ApexTheory
Copy link
Contributor

Required for ergoplatform/ergo#1526

ScalaTest matchers do not properly evaluate Array contents as per scalatest/scalatest#491.
Even when defining a custom Equality[BatchMerkleProof] trait, it does not get invoked when the target object is wrapped inside another container. This was causing problems in the Ergo Node PoPow serialization tests,

As we are not using BatchMerkleProof inside any hash-based collections, I think we can avoid overriding hashcode as well?

Open to any alternative suggestions.

@kushti
Copy link
Member

kushti commented Dec 23, 2021

Based on zip definition:

def zip[A1 >: A, B, That](that: GenIterable[B])(implicit bf: CanBuildFrom[Repr, (A1, B), That]): That = {
    val b = bf(repr)
    val these = this.iterator
    val those = that.iterator
    while (these.hasNext && those.hasNext)
      b += ((these.next(), those.next()))
    b.result()
}

that can be equal to this if indices and proofs are prefixes just, so not strict equality is really checked.

Please rewrite equals with comparing length of collections first, then doing by-index loops with per-element comparison (using .apply() from Seq), so avoiding collections re-allocations also

@kushti kushti merged commit 789bc95 into input-output-hk:master Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants