Commit 36da4222 authored by Will Cory's avatar Will Cory

fix bug with 0x0

parent 4f5cc382
...@@ -41,8 +41,11 @@ describe(parseAttestationBytes.name, () => { ...@@ -41,8 +41,11 @@ describe(parseAttestationBytes.name, () => {
}) })
it('should work for raw bytes', () => { it('should work for raw bytes', () => {
const bytes = '0x420' expect(parseAttestationBytes('0x420', 'bytes')).toMatchInlineSnapshot(
expect(parseAttestationBytes(bytes, 'bytes')).toBe(bytes) '"0x420"'
)
expect(parseAttestationBytes('0x', 'string')).toMatchInlineSnapshot('""')
expect(parseAttestationBytes('0x0', 'string')).toMatchInlineSnapshot('""')
}) })
it('should return raw bytes for invalid type', () => { it('should return raw bytes for invalid type', () => {
...@@ -57,12 +60,16 @@ describe('parseFoo', () => { ...@@ -57,12 +60,16 @@ describe('parseFoo', () => {
const str = 'Hello World' const str = 'Hello World'
const bytes = BigNumber.from(toUtf8Bytes(str)).toHexString() as WagmiBytes const bytes = BigNumber.from(toUtf8Bytes(str)).toHexString() as WagmiBytes
expect(parseString(bytes)).toBe(str) expect(parseString(bytes)).toBe(str)
expect(parseString('0x')).toMatchInlineSnapshot('""')
expect(parseString('0x0')).toMatchInlineSnapshot('""')
expect(parseString('0x0')).toMatchInlineSnapshot('""')
}) })
it('works for numbers', () => { it('works for numbers', () => {
const num = 123 const num = 123
const bytes = BigNumber.from(num).toHexString() as WagmiBytes const bytes = BigNumber.from(num).toHexString() as WagmiBytes
expect(parseNumber(bytes)).toEqual(BigNumber.from(num)) expect(parseNumber(bytes)).toEqual(BigNumber.from(num))
expect(parseNumber('0x')).toEqual(BigNumber.from(0))
}) })
it('works for addresses', () => { it('works for addresses', () => {
...@@ -74,5 +81,8 @@ describe('parseFoo', () => { ...@@ -74,5 +81,8 @@ describe('parseFoo', () => {
it('works for booleans', () => { it('works for booleans', () => {
const bytes = BigNumber.from(1).toHexString() as WagmiBytes const bytes = BigNumber.from(1).toHexString() as WagmiBytes
expect(parseBool(bytes)).toBe(true) expect(parseBool(bytes)).toBe(true)
expect(parseBool('0x')).toBe(false)
expect(parseBool('0x0')).toBe(false)
expect(parseBool('0x00000')).toBe(false)
}) })
}) })
...@@ -10,7 +10,7 @@ import { ParseBytesReturn } from '../types/ParseBytesReturn' ...@@ -10,7 +10,7 @@ import { ParseBytesReturn } from '../types/ParseBytesReturn'
* Parses a string attestion * Parses a string attestion
*/ */
export const parseString = (rawAttestation: WagmiBytes): string => { export const parseString = (rawAttestation: WagmiBytes): string => {
rawAttestation = rawAttestation === '0x' ? '0x0' : rawAttestation rawAttestation = rawAttestation === '0x0' ? '0x' : rawAttestation
return rawAttestation ? toUtf8String(rawAttestation) : '' return rawAttestation ? toUtf8String(rawAttestation) : ''
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment