test: test properly test clarity type narrowing

This commit is contained in:
Hugo Caillard
2023-11-27 11:34:07 +01:00
committed by janniks
parent 6eb13197ad
commit a9f419684b

View File

@@ -49,6 +49,7 @@ import {
} from '../src/clarity/clarityValue';
import { addressToString } from '../src/common';
import { deserializeAddress } from '../src/types';
import assert from 'assert';
const ADDRESS = 'SP2JXKMSH007NPYAQHKJPQMAQYAD90NQGTVJVQ02B';
@@ -695,6 +696,16 @@ describe('Clarity Types', () => {
const vInt = Cl.int(1) as ClarityValue;
expect(isClarityType(vInt, ClarityType.Int)).toBeTruthy();
expect(isClarityType(vInt, ClarityType.UInt)).toBeFalsy();
// test the type assertion
assert(isClarityType(vUint, ClarityType.UInt));
const uintTest: UIntCV = vUint;
uintTest; // avoid the "value is never read warning"
assert(isClarityType(vInt, ClarityType.Int));
const intTest: IntCV = vInt;
intTest; // avoid the "value is never read warning"
});
});
});