@tonkite/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
54 lines (53 loc) • 1.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DebugReader = void 0;
const cell_1 = require("./cell");
class DebugReader {
entries;
index = 0;
constructor(entries) {
this.entries = entries;
}
static fromLogs(logs) {
return new DebugReader(logs
.split(/#DEBUG#: /)
.filter((item) => !!item)
.map((item) => item.trim()));
}
next() {
const entry = this.entries[this.index];
this.index++;
return entry;
}
nextAsStackItem() {
const entry = this.next();
return entry.replace(/^s\d+ = /, '');
}
nextInt() {
return parseInt(this.nextAsStackItem(), 10);
}
nextBigInt() {
return BigInt(this.nextAsStackItem());
}
nextBool() {
return this.nextAsStackItem() !== '0';
}
nextSlice() {
const stackItem = this.nextAsStackItem();
const matches = stackItem.match(/^CS{Cell{([a-f0-9]+)} bits: (\d+)..(\d+); refs: (\d+)..(\d+)}/);
if (!matches) {
throw new Error(`Slice entry expected. Given: ${stackItem}`);
}
const data = (0, cell_1.loadSliceFromBOC)(Buffer.from(matches[1], 'hex'));
const offset = parseInt(matches[2]);
data.skip(offset);
return data.clone();
}
nextAddress() {
return this.nextSlice().loadAddress();
}
isEOF() {
return this.index >= this.entries.length;
}
}
exports.DebugReader = DebugReader;