Skip to content

Unexpected handling of undefined in bytesToHex #3998

@gabrocheleau

Description

@gabrocheleau

Our bytesToHex helper returns '0x' when its input is undefined. This seems odd and prone to errors. @jochem-brouwer and I have discussed this and we feel like this should be removed.

I have attempted removing it, but noticed that this led to many test errors in the monorepo that rely on undefined being handled in this way, so I thought it'd be better to leave this for a standalone PR.

export const bytesToHex = (bytes: Uint8Array): PrefixedHexString => {
  if (bytes === undefined || bytes.length === 0) return '0x'
  const unprefixedHex = bytesToUnprefixedHex(bytes)
  return `0x${unprefixedHex}`
}

(Src:

if (bytes === undefined || bytes.length === 0) return '0x'
)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions