import { decodeShortString, encodeShortString } from '../../src/utils/shortString'; describe('shortString', () => { test('should convert string to number', () => { expect(encodeShortString('hello')).toMatchInlineSnapshot(`"0x68656c6c6f"`); }); test('should convert number to string', () => { expect(decodeShortString('0x68656c6c6f')).toMatchInlineSnapshot(`"hello"`); }); test('should throw if string is too long', () => { expect(() => encodeShortString('hello world hello world hello world hello world hello world hello world') ).toThrowErrorMatchingInlineSnapshot( `"hello world hello world hello world hello world hello world hello world is too long"` ); }); test('should throw if string contains non ascii chars', () => { expect(() => encodeShortString('hello\uD83D\uDE00')).toThrowErrorMatchingInlineSnapshot( `"hello😀 is not an ASCII string"` ); }); });