Skip to content

fix(common): mOption returns None for 0, 0n and empty byte string - #882

Open
takinanton wants to merge 1 commit into
MeshJS:mainfrom
takinanton:fix/moption-falsy-some
Open

takinanton wants to merge 1 commit into
MeshJS:mainfrom
takinanton:fix/moption-falsy-some

Conversation

@takinanton

Copy link
Copy Markdown
Contributor

Summary

mOption checks the value with a plain truthiness test so mOption(0), mOption(0n) and mOption("") all come back as mNone(). Those are valid Plutus data. An Option<Int> holding zero or an empty byte string ends up on chain as None which is a different datum. mOption(0) serializes to d87a80 while option(integer(0)) gives d8799f00ff.

It now returns None only when the value is missing. The JSON option helper is not affected because it always gets an object.

Affect components

  • @meshsdk/common
  • @meshsdk/contract
  • @meshsdk/core
  • @meshsdk/core-cst
  • @meshsdk/hydra
  • @meshsdk/provider
  • @meshsdk/react
  • @meshsdk/svelte
  • @meshsdk/transaction
  • @meshsdk/wallet
  • Mesh playground (i.e. https://meshjs.dev/)
  • Mesh CLI

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Bug fix (non-breaking change which fixes an issue)
  • Code refactoring (improving code quality without changing its behavior)
  • Documentation update (adding or updating documentation related to the project)

Related Issues

Did not find one.

Checklist

  • My code is appropriately commented and includes relevant documentation, if necessary
  • I have added tests to cover my changes, if necessary
  • I have updated the documentation, if necessary
  • All new and existing tests pass (i.e. npm run test)
  • The build is pass (i.e. npm run build)

Additional Information

There were no tests for mOption so I added five to the mesh aliases test that compare its CBOR with the JSON option. Three of them fail on main and all pass with the change. I built only @meshsdk/common and @meshsdk/core-cst and ran the common jest suite. 23 suites pass. time.test.ts and tx-tester.test.ts could not load because they import @meshsdk/core which I did not build. I did not run the full npm run test or npm run build so I left those two boxes unticked.

🤖 Generated with Claude Code

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant