Skip to content

Commit

Permalink
test: test properly test clarity type narrowing
Browse files Browse the repository at this point in the history
  • Loading branch information
hugocaillard authored and janniks committed Dec 14, 2023
1 parent 6eb1319 commit a9f4196
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/transactions/tests/clarity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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"
});
});
});

0 comments on commit a9f4196

Please sign in to comment.