Skip to content

Commit b86dd45

Browse files
feat: add AST dump utility for descriptor tests
Add helper to write descriptor AST to JSON files for test fixtures. Issue: BTC-1829
1 parent 02d179a commit b86dd45

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1278
-49
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
js/wasm
2-
target/
2+
test/fixtures/
3+
target/

packages/wasm-miniscript/test/descriptorUtil.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
1+
import * as fs from "fs/promises";
12
import * as utxolib from "@bitgo/utxo-lib";
3+
import { Descriptor } from "../js";
4+
import * as assert from "node:assert";
5+
6+
async function assertEqualJSON(path: string, value: unknown): Promise<void> {
7+
try {
8+
const data = JSON.parse(await fs.readFile(path, "utf8"));
9+
assert.deepStrictEqual(data, value);
10+
} catch (e: any) {
11+
if (e.code === "ENOENT") {
12+
await fs.writeFile(path, JSON.stringify(value, null, 2));
13+
throw new Error("Expected file not found, wrote it instead");
14+
}
15+
throw e;
16+
}
17+
}
18+
19+
export async function assertEqualAst(path: string, descriptor: Descriptor): Promise<void> {
20+
await assertEqualJSON(path, { descriptor: descriptor.toString(), ast: descriptor.node() });
21+
}
222

323
/** Expand a template with the given root wallet keys and chain code */
424
function expand(template: string, rootWalletKeys: utxolib.bitgo.RootWalletKeys, chainCode: number) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"descriptor": "pk(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd)#9pcxlpvx",
3+
"ast": {
4+
"Bare": {
5+
"Check": {
6+
"PkK": {
7+
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
8+
}
9+
}
10+
}
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"descriptor": "pk(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd)#9pcxlpvx",
3+
"ast": {
4+
"Bare": {
5+
"Check": {
6+
"PkK": {
7+
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
8+
}
9+
}
10+
}
11+
}
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"descriptor": "pkh(04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b8dec5235a0fa8722476c7709c02559e3aa73aa03918ba2d492eea75abea235)#9907vvwz",
3+
"ast": {
4+
"Pkh": {
5+
"Single": "04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b8dec5235a0fa8722476c7709c02559e3aa73aa03918ba2d492eea75abea235"
6+
}
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"descriptor": "pkh(04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b8dec5235a0fa8722476c7709c02559e3aa73aa03918ba2d492eea75abea235)#9907vvwz",
3+
"ast": {
4+
"Pkh": {
5+
"Single": "04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b8dec5235a0fa8722476c7709c02559e3aa73aa03918ba2d492eea75abea235"
6+
}
7+
}
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"descriptor": "sh(pk(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd))#s53ls94y",
3+
"ast": {
4+
"Sh": {
5+
"Ms": {
6+
"Check": {
7+
"PkK": {
8+
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
9+
}
10+
}
11+
}
12+
}
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"descriptor": "sh(pk(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd))#s53ls94y",
3+
"ast": {
4+
"Sh": {
5+
"Ms": {
6+
"Check": {
7+
"PkK": {
8+
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
9+
}
10+
}
11+
}
12+
}
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"descriptor": "sh(pkh(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd))#dr3u9ynx",
3+
"ast": {
4+
"Sh": {
5+
"Ms": {
6+
"Check": {
7+
"PkH": {
8+
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
9+
}
10+
}
11+
}
12+
}
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"descriptor": "sh(pkh(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd))#dr3u9ynx",
3+
"ast": {
4+
"Sh": {
5+
"Ms": {
6+
"Check": {
7+
"PkH": {
8+
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
9+
}
10+
}
11+
}
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)