HeliosLang / compiler

Helios is a DSL for writing Cardano smart contracts. This library lets you compile Helios scripts and build Cardano transactions.
https://www.hyperion-bt.org/helios-book
BSD 3-Clause "New" or "Revised" License
139 stars 30 forks source link

test-automation expect(...).`.toEqual()` wrong on MintingPolicyHash #91

Closed rjharmon closed 12 months ago

rjharmon commented 1 year ago
 ❯ tests/StellarContract.test.ts:222:36
    220|                 const t2 = await h.setup({randomSeed: 43});
    221|                 console.log(t2.mph.toBech32(), t.mph.toBech32())
    222|                 expect(t2.mph).not.toEqual(t.mph);

These two MintingPolicyHash objects are different references (toBe() doesn't match them).

Their toBech32()s are clearly different. But not.toEqual() fails.

.eq(other) works. but doesn't integrate with jest / vitest.

I think this may also be the case for some other types - hopefully they can all be fixed without much difficulty.

christianschmitz commented 1 year ago

I think you have to fall back to comparing the result of toString() for many types. According to the jest documentation toEqual compares the enumerable properties of an object, and the #bytes field of a MintingPolicyHash is strictly private and isn't visible from outside.

christianschmitz commented 1 year ago

v0.15.0 exposes the bytes property of MintingPolicyHash (along with several other properties of other classes)

Now Jest should work correctly for these types

rjharmon commented 12 months ago

Thank you, Christian!