harb/kraiken-lib/src/tests/functions.test.ts
2025-10-01 14:43:55 +02:00

30 lines
1,008 B
TypeScript

import { describe, expect, test } from "@jest/globals";
import { bytesToUint256LittleEndian, uint256ToBytesLittleEndian } from "../subgraph";
import { Position, PositionStatus } from '../__generated__/graphql';
describe('BigInt Conversion Functions', () => {
test('converts uint256 to bytes and back (little endian)', async () => {
const mockPos: Position = {
__typename: 'Position',
id: uint256ToBytesLittleEndian(3n),
owner: '0x8db6b632d743aef641146dc943acb64957155388',
share: '0.000001',
creationTime: 1610000000,
taxRate: '0.01',
status: PositionStatus.Active, // Enum usage
};
let hexString = '0x';
for (let i = 0; i < mockPos.id.length; i++) {
// Convert each byte to a hexadecimal string and pad with zero if needed
hexString += mockPos.id[i].toString(16).padStart(2, '0');
}
expect(hexString).toEqual('0x03000000');
// return hexString;
expect(bytesToUint256LittleEndian(mockPos.id)).toEqual(3n);
});
});