Skip to content

Commit c38f797

Browse files
test(cashc): add blake3 coverage; drop orphaned v2_test example
blake3 had no test coverage anywhere in the suite. Add a corpus fixture and a focused codegen regression test, mirroring the multiplication.cash / arithmetic.test.ts precedent: - test/valid-contract-files/blake3.cash — exercised by the globbing compiler.test.ts (compiles cleanly) and AST.test.ts (parse round-trip) - test/generation/blake3.test.ts — asserts `blake3(...)` lowers to OP_BLAKE3 and stays distinct from `sha256(...)` / OP_SHA256 Remove examples/v2_test.rad: an unreferenced, single-commit V2 smoke test on the deprecated `function` method syntax that also used bitwise `<<` (now rejected on Radiant). Its `*`->OP_MUL behavior is already covered by generation/arithmetic.test.ts. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 0a349c6 commit c38f797

3 files changed

Lines changed: 62 additions & 15 deletions

File tree

examples/v2_test.rad

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* blake3.test.ts
2+
*
3+
* Coverage + regression test: the `blake3(...)` builtin must lower to its own
4+
* OP_BLAKE3 opcode and must stay DISTINCT from `sha256(...)` (OP_SHA256).
5+
* blake3 previously had no test coverage anywhere in the suite. See
6+
* ast/Globals.ts (GlobalFunction.BLAKE3) and generation/utils.ts
7+
* (GlobalFunction.BLAKE3 -> [OP_BLAKE3]).
8+
*/
9+
10+
import { compileString } from '../../src/index.js';
11+
12+
// blake3 only — must emit OP_BLAKE3 and must NOT be aliased to OP_SHA256.
13+
const blake3Only = `
14+
pragma radiantscript ^1.1.0;
15+
contract Blake3Only(bytes32 commitment) {
16+
return {
17+
reveal(bytes preimage) {
18+
require(blake3(preimage) == commitment);
19+
}
20+
};
21+
}
22+
`;
23+
24+
// blake3 + sha256 over the same preimage — proves the two builtins lower to
25+
// distinct opcodes (both must appear in the output).
26+
const blake3AndSha256 = `
27+
pragma radiantscript ^1.1.0;
28+
contract Blake3Mixed(bytes32 commitment) {
29+
return {
30+
reveal(bytes preimage) {
31+
require(blake3(preimage) == commitment);
32+
require(blake3(preimage) != sha256(preimage));
33+
}
34+
};
35+
}
36+
`;
37+
38+
describe('BLAKE3 hashing lowering', () => {
39+
it('lowers `blake3(...)` to OP_BLAKE3', () => {
40+
const asm: string = (compileString(blake3Only) as { asm: string }).asm;
41+
expect(asm).toContain('OP_BLAKE3');
42+
});
43+
44+
it('does not alias blake3 to OP_SHA256', () => {
45+
const asm: string = (compileString(blake3Only) as { asm: string }).asm;
46+
expect(asm).not.toContain('OP_SHA256');
47+
});
48+
49+
it('lowers blake3 and sha256 to distinct opcodes', () => {
50+
const asm: string = (compileString(blake3AndSha256) as { asm: string }).asm;
51+
expect(asm).toContain('OP_BLAKE3');
52+
expect(asm).toContain('OP_SHA256');
53+
});
54+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
contract Blake3Commit(bytes32 commitment) {
2+
return {
3+
reveal(bytes preimage) {
4+
// The revealed preimage must hash (BLAKE3) to the committed digest.
5+
require(blake3(preimage) == commitment);
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)