|
1 | 1 | import * as assert from "assert"; |
2 | 2 | import * as crypto from "crypto"; |
3 | 3 | import { Descriptor } from "../js/index.js"; |
| 4 | +import { fromDescriptor, formatNode } from "../js/ast/index.js"; |
4 | 5 | import { getDefaultXPubs, getUnspendableKey } from "../js/testutils/descriptor/descriptors.js"; |
5 | 6 |
|
6 | 7 | // sBTC protocol uses two taproot script leaves: |
@@ -245,4 +246,29 @@ describe("sBTC taproot descriptor", function () { |
245 | 246 | assert.strictEqual(reclaimLeaf.AndV[0].Drop.Older.relLockTime, 1); |
246 | 247 | }); |
247 | 248 | }); |
| 249 | + |
| 250 | + describe("fromDescriptor (wasm → JS AST)", function () { |
| 251 | + it("does not throw on a descriptor containing payload_drop", () => { |
| 252 | + assert.doesNotThrow(() => fromDescriptor(descriptor)); |
| 253 | + }); |
| 254 | + |
| 255 | + it("emits a payload_drop node carrying the original hex payload", () => { |
| 256 | + const ast = fromDescriptor(descriptor); |
| 257 | + const formatted = formatNode(ast); |
| 258 | + assert.ok( |
| 259 | + formatted.includes( |
| 260 | + "payload_drop(0000000000013880051ad206838b7981a116c334e8cb1b950afb73eb54a5)", |
| 261 | + ), |
| 262 | + `expected payload_drop(<hex>) in formatted AST, got: ${formatted}`, |
| 263 | + ); |
| 264 | + }); |
| 265 | + |
| 266 | + it("round-trips the reclaim leaf via formatNode", () => { |
| 267 | + const ast = fromDescriptor(descriptor) as unknown as { |
| 268 | + tr: [string, [unknown, Parameters<typeof formatNode>[0]]]; |
| 269 | + }; |
| 270 | + const reclaimAst = ast.tr[1][1]; |
| 271 | + assert.strictEqual(formatNode(reclaimAst), RECLAIM_LEAF); |
| 272 | + }); |
| 273 | + }); |
248 | 274 | }); |
0 commit comments