@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
96 lines (95 loc) • 5.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ASSERTIONS = void 0;
const jest_matcher_utils_1 = require("jest-matcher-utils");
const core_1 = require("@ton/core");
const DEFAULT_ERROR = 'AssertError';
exports.ASSERTIONS = {
ASSERT_COMPARE_INT: (debugReader) => {
const type = debugReader.next();
const expected = debugReader.nextBigInt();
const actual = debugReader.nextBigInt();
const error = debugReader.next();
const prefix = (0, jest_matcher_utils_1.BOLD_WEIGHT)(error || DEFAULT_ERROR);
switch (type) {
case 'EQ':
throw new Error(`${prefix} - Value "${(0, jest_matcher_utils_1.BOLD_WEIGHT)(actual.toString())}" does not equal expected value "${(0, jest_matcher_utils_1.BOLD_WEIGHT)(expected.toString())}".`);
case 'NEQ':
throw new Error(`${prefix} - Value "${(0, jest_matcher_utils_1.BOLD_WEIGHT)(actual.toString())}" was not expected to be equal to value "${(0, jest_matcher_utils_1.BOLD_WEIGHT)(expected.toString())}".`);
case 'LT':
throw new Error(`${prefix} - Provided "${(0, jest_matcher_utils_1.BOLD_WEIGHT)(actual.toString())}" is not less than "${(0, jest_matcher_utils_1.BOLD_WEIGHT)(expected.toString())}".`);
case 'LTE':
throw new Error(`${prefix} - Provided "${(0, jest_matcher_utils_1.BOLD_WEIGHT)(actual.toString())}" is not less than or equal to "${(0, jest_matcher_utils_1.BOLD_WEIGHT)(expected.toString())}".`);
case 'GT':
throw new Error(`${prefix} - Provided "${(0, jest_matcher_utils_1.BOLD_WEIGHT)(actual.toString())}" is not greater than "${(0, jest_matcher_utils_1.BOLD_WEIGHT)(expected.toString())}".`);
case 'GTE':
throw new Error(`${prefix} - Provided "${(0, jest_matcher_utils_1.BOLD_WEIGHT)(actual.toString())}" is not greater than or equal to "${(0, jest_matcher_utils_1.BOLD_WEIGHT)(expected.toString())}".`);
default:
console.log('ASSERT_COMPARE_INT', {
type,
expected,
actual,
error,
});
}
},
ASSERT_TUPLE_SIZE: (debugReader) => {
const actual = debugReader.nextInt();
const expected = debugReader.nextInt();
const error = debugReader.next();
throw new Error(`${(0, jest_matcher_utils_1.BOLD_WEIGHT)(error || DEFAULT_ERROR)} - Tuple does not contain exactly ${(0, jest_matcher_utils_1.BOLD_WEIGHT)(expected)} elements (${(0, jest_matcher_utils_1.BOLD_WEIGHT)(actual)} given).`);
},
ASSERT_ADDRESS_TYPE: (debugReader) => {
const expectedType = debugReader.next();
const actual = debugReader.nextSlice().loadAddressAny();
const error = debugReader.next();
const getAddressType = (address) => {
if (address instanceof core_1.Address)
return 'internal';
if (address instanceof core_1.ExternalAddress)
return 'external';
return 'none';
};
const prefix = (0, jest_matcher_utils_1.BOLD_WEIGHT)(error || DEFAULT_ERROR);
switch (expectedType) {
case 'INTERNAL':
throw new Error(`${prefix} - Address was expected to be internal (${(0, jest_matcher_utils_1.BOLD_WEIGHT)(getAddressType(actual))} given).`);
case 'NONE':
throw new Error(`${prefix} - Address was expected to be none (${(0, jest_matcher_utils_1.BOLD_WEIGHT)(getAddressType(actual))} given).`);
case 'EXTERNAL':
throw new Error(`${prefix} - Address was expected to be external (${(0, jest_matcher_utils_1.BOLD_WEIGHT)(getAddressType(actual))} given).`);
}
},
ASSERT_IS_NULL: (debugReader) => {
const expectNull = debugReader.next();
const error = debugReader.next();
throw new Error(expectNull
? `${(0, jest_matcher_utils_1.BOLD_WEIGHT)(error || DEFAULT_ERROR)} - Value is not null, but null value was expected.`
: `${(0, jest_matcher_utils_1.BOLD_WEIGHT)(error || DEFAULT_ERROR)} - Value is null, but non null value was expected.`);
},
ASSERT_EQUAL_ADDRESS: (debugReader) => {
const actual = debugReader.nextAddress();
const expected = debugReader.nextAddress();
const error = debugReader.next();
throw new Error(`${(0, jest_matcher_utils_1.BOLD_WEIGHT)(error || DEFAULT_ERROR)} - Address does not equal expected one.\n\n` +
`Expected: ${(0, jest_matcher_utils_1.EXPECTED_COLOR)(`"${expected}"`)}\n` +
`Received: ${(0, jest_matcher_utils_1.RECEIVED_COLOR)(`"${actual}"`)}\n`);
},
ASSERT_BOOL: (debugReader) => {
const actual = debugReader.nextBool();
const expected = debugReader.nextBool();
const error = debugReader.next();
throw new Error(`${(0, jest_matcher_utils_1.BOLD_WEIGHT)(error || DEFAULT_ERROR)} - Value "${(0, jest_matcher_utils_1.BOLD_WEIGHT)(actual)}" is not ${expected}.`);
},
ASSERT_CONSUME_LESS: (debugReader) => {
const actual = debugReader.nextInt();
const expected = debugReader.nextInt();
const error = debugReader.next();
throw new Error(`${(0, jest_matcher_utils_1.BOLD_WEIGHT)(error || DEFAULT_ERROR)} - Function consumed more than ${(0, jest_matcher_utils_1.BOLD_WEIGHT)(expected)} gas units (${(0, jest_matcher_utils_1.BOLD_WEIGHT)(actual)} consumed).`);
},
ASSERT_FAIL: (debugReader) => {
const message = debugReader.next();
const error = debugReader.next();
throw new Error(`${(0, jest_matcher_utils_1.BOLD_WEIGHT)(error || DEFAULT_ERROR)} - ${message}`);
},
};