Skip to content

Commit f4d34da

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

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: SCSpecType Superset
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
check:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- uses: actions/setup-node@v4
20+
with:
21+
node-version: 24
22+
23+
- name: Check SCSpecType is a superset of SCValType
24+
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)