UNPKG

@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

59 lines (58 loc) 2.24 kB
"use strict"; /** * Copyright 2024 Scaleton Labs * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.extractTLBCode = extractTLBCode; exports.extractIntFieldFromTLB = extractIntFieldFromTLB; exports.extractSliceFieldFromTLB = extractSliceFieldFromTLB; const tlb_codegen_1 = require("@ton-community/tlb-codegen"); const tlb_parser_1 = require("@ton-community/tlb-parser"); function extractTLBCode(fuzzTlb) { const tlbTree = (0, tlb_parser_1.ast)(fuzzTlb); return (0, tlb_codegen_1.getTLBCodeByAST)(tlbTree, fuzzTlb); } function extractIntFieldFromTLB(tlbCode, fieldName) { const field = getFieldFromTLBCode(tlbCode, fieldName); switch (field?.fieldType?.kind) { case 'TLBNumberType': return { bits: field.fieldType.maxBits ?? 256, signed: field.fieldType.signed ?? true, }; case 'TLBNamedType': if (['coins', 'grams'].includes(field.fieldType.name.toLowerCase())) { return { bits: 120, signed: false, }; } default: throw new Error(`Field ${fieldName} is not of type TLBNumberType`); } } function extractSliceFieldFromTLB(tlbCode, fieldName) { const field = getFieldFromTLBCode(tlbCode, fieldName); if (field?.fieldType?.kind === 'TLBNamedType' && field?.fieldType?.name.toLowerCase() === 'address') { return 'address'; } return 'slice'; } function getFieldFromTLBCode(tlbCode, fieldName) { return tlbCode?.types .get('Args') ?.constructors[0].fields.find((field) => field.name === fieldName); }