Skip to content

Commit 147f1ac

Browse files
check SCSpecType is a superset of SCValType
1 parent 9c9c145 commit 147f1ac

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: SCSpecType Superset
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
check:
13+
runs-on: ubuntu-slim
14+
steps:
15+
- uses: actions/checkout@v7
16+
17+
- uses: actions/setup-node@v7
18+
with:
19+
node-version: lts/*
20+
21+
- run: node .scripts/check-scspectype-superset.ts
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Every SCValType that can appear at a contract function boundary must be
2+
// expressible in a contract spec, so SCSpecType needs a counterpart for it.
3+
// The names line up by prefix: SCV_U32 -> SC_SPEC_TYPE_U32.
4+
5+
import { readFileSync } from "node:fs";
6+
7+
// SCValType variants that cannot cross a contract function boundary, and so
8+
// intentionally have no SCSpecType counterpart.
9+
const EXCLUDED = [
10+
"CONTRACT_INSTANCE",
11+
"LEDGER_KEY_CONTRACT_INSTANCE",
12+
"LEDGER_KEY_NONCE",
13+
];
14+
15+
const spec = readFileSync("Stellar-contract-spec.x", "utf8");
16+
const val = readFileSync("Stellar-contract.x", "utf8").match(/\bSCV_\w+/g) ?? [];
17+
18+
const missing = [...new Set(val.map((name) => name.slice("SCV_".length)))]
19+
.filter((name) => !EXCLUDED.includes(name))
20+
.filter((name) => !new RegExp(`\\bSC_SPEC_TYPE_${name}\\b`).test(spec));
21+
22+
if (missing.length > 0) {
23+
console.log(`
24+
SCValType variants with no SCSpecType counterpart: ${missing.map((n) => "SCV_" + n).join(", ")}
25+
26+
SCSpecType must be a superset of SCValType so that every value type usable at a
27+
contract function boundary can be captured in a contract spec. Either add the
28+
missing SCSpecType variant, or, if the value cannot cross a contract boundary,
29+
add it to EXCLUDED in this script.`);
30+
process.exit(1);
31+
}
32+
33+
console.log("SCSpecType covers every SCValType variant.");

0 commit comments

Comments
 (0)