@kstasi/jest-tolk
Version:
<p align="center"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/tonkite/tonkite/main/assets/logo-dark.svg"> <img alt="tonkite logo" src="https://raw.githubusercontent.com/tonkite/tonkite/main/a
33 lines (32 loc) • 1.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@ton/core");
const slice_strategy_1 = require("./slice-strategy");
describe('generateSlice', () => {
it('returns a fixture cell if fixtures are provided', () => {
const fixtures = [{ type: 'slice', cell: core_1.Cell.EMPTY }];
const result = (0, slice_strategy_1.generateSlice)('slice', fixtures);
expect(result).toBeInstanceOf(core_1.Cell);
expect(result).toBe(fixtures[0].cell);
});
it('throws an error if a fixture is not of type slice', () => {
const fixtures = [{ type: 'int', value: 42n }];
expect(() => (0, slice_strategy_1.generateSlice)(undefined, fixtures)).toThrow('All fixtures must be of type slice, but got int');
});
it('generates a random address when type is address and bias is towards random', () => {
jest.spyOn(Math, 'random').mockReturnValue(0.95); // Bias towards random
const result = (0, slice_strategy_1.generateSlice)('address');
const address = result.beginParse().loadAddress();
expect(address).toBeDefined();
});
it('generates an edge address when type is address and bias is towards edge', () => {
jest.spyOn(Math, 'random').mockReturnValue(0.05); // Bias towards edge
const result = (0, slice_strategy_1.generateSlice)('address');
const address = result.beginParse().loadAddress();
expect(address.hash.toString('hex')).toBe('0000000000000000000000000000000000000000000000000000000000000000');
});
it('generates a random slice when no type is provided', () => {
const result = (0, slice_strategy_1.generateSlice)();
expect(result).toBeInstanceOf(core_1.Cell);
});
});