{"version":3,"sources":["../../../../node_modules/@jest/globals/build/index.js","../../src/utils/bytes32.test.ts"],"sourcesContent":["/*!\n * /**\n *  * Copyright (c) Meta Platforms, Inc. and affiliates.\n *  *\n *  * This source code is licensed under the MIT license found in the\n *  * LICENSE file in the root directory of this source tree.\n *  * /\n */\n/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\nvar __webpack_exports__ = {};\n\n\n/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\n\nthrow new Error('Do not import `@jest/globals` outside of the Jest test environment');\nmodule.exports = __webpack_exports__;\n/******/ })()\n;","import { describe, expect, it } from '@jest/globals';\nimport { Subaccount } from '../common';\nimport {\n  subaccountFromBytes32,\n  subaccountFromHex,\n  subaccountNameBytesToStr,\n  subaccountNameToBytes12,\n  subaccountToBytes32,\n  subaccountToHex,\n} from './bytes32';\n\nconst TEST_ADDRESS = '0xb92EFcF519EDC2f1FE60b4491Ef51d97Ed4d7685';\n\ndescribe('bytes32', () => {\n  it('converts a subaccount to bytes', () => {\n    const expectedBytes = new Uint8Array([\n      185, 46, 252, 245, 25, 237, 194, 241, 254, 96, 180, 73, 30, 245, 29, 151,\n      237, 77, 118, 133, 116, 101, 115, 116, 0, 0, 0, 0, 0, 0, 0, 0,\n    ]);\n    expect(\n      subaccountToBytes32({\n        subaccountName: 'test',\n        subaccountOwner: TEST_ADDRESS,\n      }),\n    ).toStrictEqual(expectedBytes);\n  });\n\n  it('converts bytes to a subaccount', () => {\n    const subaccountBytes = new Uint8Array([\n      185, 46, 252, 245, 25, 237, 194, 241, 254, 96, 180, 73, 30, 245, 29, 151,\n      237, 77, 118, 133, 116, 101, 115, 116, 0, 0, 0, 0, 0, 0, 0, 0,\n    ]);\n    const expectedSubaccount: Subaccount = {\n      subaccountOwner: TEST_ADDRESS,\n      subaccountName: 'test',\n    };\n    const convertedSubaccount = subaccountFromBytes32(subaccountBytes);\n\n    expect(convertedSubaccount.subaccountOwner.toLowerCase()).toBe(\n      expectedSubaccount.subaccountOwner.toLowerCase(),\n    );\n    expect(convertedSubaccount.subaccountName).toBe(\n      expectedSubaccount.subaccountName,\n    );\n  });\n\n  it('converts a string subaccount name to bytes', () => {\n    const nameBytes = subaccountNameToBytes12('test');\n\n    expect(nameBytes).toStrictEqual(\n      new Uint8Array([116, 101, 115, 116, 0, 0, 0, 0, 0, 0, 0, 0]),\n    );\n  });\n\n  it('converts a hex string subaccount name to bytes', () => {\n    // `test` in hex form\n    const nameBytes = subaccountNameToBytes12('0x74657374');\n\n    expect(nameBytes).toStrictEqual(\n      new Uint8Array([116, 101, 115, 116, 0, 0, 0, 0, 0, 0, 0, 0]),\n    );\n  });\n\n  it('converts a subaccount with a string subaccount name to a hex string', () => {\n    const subaccount: Subaccount = {\n      subaccountOwner: TEST_ADDRESS,\n      subaccountName: 'test',\n    };\n\n    expect(subaccountToHex(subaccount)).toBe(\n      '0xb92efcf519edc2f1fe60b4491ef51d97ed4d7685746573740000000000000000',\n    );\n  });\n\n  it('converts a subaccount with a hex subaccount name to a hex string', () => {\n    const subaccount: Subaccount = {\n      subaccountOwner: TEST_ADDRESS,\n      // `test` in hex form\n      subaccountName: '0x74657374',\n    };\n\n    expect(subaccountToHex(subaccount)).toBe(\n      '0xb92efcf519edc2f1fe60b4491ef51d97ed4d7685746573740000000000000000',\n    );\n  });\n\n  it('converts a hex string to a subaccount', () => {\n    const convertedSubaccount = subaccountFromHex(\n      '0xb92efcf519edc2f1fe60b4491ef51d97ed4d7685746573740000000000000000',\n    );\n\n    expect(convertedSubaccount.subaccountOwner.toLowerCase()).toBe(\n      TEST_ADDRESS.toLowerCase(),\n    );\n    expect(convertedSubaccount.subaccountName).toBe('test');\n  });\n\n  it('handles leading zero bytes in subaccount name properly', () => {\n    const subaccount: Subaccount = {\n      subaccountOwner: TEST_ADDRESS,\n      subaccountName: '\\u0000\\u0000\\u0002\\u0000iso\\u0000',\n    };\n    const subaccountHex =\n      '0xb92efcf519edc2f1fe60b4491ef51d97ed4d76850000020069736f0000000000';\n\n    expect(subaccountToHex(subaccount)).toBe(subaccountHex);\n    // Trailing 0 bytes are trimmed\n    expect(subaccountFromHex(subaccountHex).subaccountName).toBe(\n      '\\u0000\\u0000\\u0002\\u0000iso',\n    );\n  });\n\n  it('handles converting non-utf8 byte sequences by converting bytes to a hex string', () => {\n    const invalidUtf8Array = new Uint8Array([0x80, 0x81, 0x82]);\n    expect(subaccountNameBytesToStr(invalidUtf8Array)).toBe('0x808182');\n  });\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,oDAAAA,UAAAC,SAAA;AAAA;AAQS,KAAC,MAAM;AACN;AACV,UAAI,sBAAsB,CAAC;AAY3B,YAAM,IAAI,MAAM,oEAAoE;AACpF,MAAAA,QAAO,UAAU;AAAA,IACR,GAAG;AAAA;AAAA;;;ACxBZ,qBAAqC;AAErC,qBAOO;AAEP,IAAM,eAAe;AAAA,IAErB,yBAAS,WAAW,MAAM;AACxB,yBAAG,kCAAkC,MAAM;AACzC,UAAM,gBAAgB,IAAI,WAAW;AAAA,MACnC;AAAA,MAAK;AAAA,MAAI;AAAA,MAAK;AAAA,MAAK;AAAA,MAAI;AAAA,MAAK;AAAA,MAAK;AAAA,MAAK;AAAA,MAAK;AAAA,MAAI;AAAA,MAAK;AAAA,MAAI;AAAA,MAAI;AAAA,MAAK;AAAA,MAAI;AAAA,MACrE;AAAA,MAAK;AAAA,MAAI;AAAA,MAAK;AAAA,MAAK;AAAA,MAAK;AAAA,MAAK;AAAA,MAAK;AAAA,MAAK;AAAA,MAAG;AAAA,MAAG;AAAA,MAAG;AAAA,MAAG;AAAA,MAAG;AAAA,MAAG;AAAA,MAAG;AAAA,IAC9D,CAAC;AACD;AAAA,UACE,oCAAoB;AAAA,QAClB,gBAAgB;AAAA,QAChB,iBAAiB;AAAA,MACnB,CAAC;AAA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