multiformats / js-cid

CID implementation in JavaScript
MIT License
97 stars 39 forks source link

fix: allow CIDs to be compared through deep equality #132

Closed achingbrain closed 3 years ago

achingbrain commented 3 years ago

The changes in #131 broke the tests of IPFS and probably quite a few other modules.

This sort of thing used to work, now does not:

expect(ipfs.bitswap.unwant.calledWith(new CID(cidStr), defaultOptions)).to.be.true()

The reason it breaks is because internally calledWith does a deepEqual on the args which compares (among other things) the properties of the passed objects.

We used to use Object.defineProperty to create cached versions of expensive to calculate fields which makes fields non-enumerable by default so they are skipped during the deepEqual check.

Now we just set the fields on the object which means instances have different fields depending on which constructor branch was hit or worse, if the instances properties have been accessed.