Skip to content

Commit faddbb4

Browse files
OttoAllmendingerllm-git
andcommitted
feat(wasm-utxo): add test utilities for PSBT testing
Add AcidTest class for comprehensive PSBT testing across multiple conditions: - Different coin networks - All supported script types - Various signing stages (unsigned, half-signed, fully-signed) - Different PSBT formats Also adds utility functions for deterministic key generation to support test reproducibility. Issue: BTC-2980 Co-authored-by: llm-git <llm-git@ttll.de>
1 parent b1ad24d commit faddbb4

File tree

8 files changed

+1009
-23
lines changed

8 files changed

+1009
-23
lines changed

packages/wasm-utxo/js/fixedScriptWallet/chains.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ const chainCodeSet = new Set<number>(chainCodes);
2121
const chainToMeta = new Map<ChainCode, { scope: Scope; scriptType: OutputScriptType }>();
2222
const scriptTypeToChain = new Map<OutputScriptType, { internal: ChainCode; external: ChainCode }>();
2323

24-
// Initialize from WASM (called once at load time)
25-
function assertChainCode(n: number): ChainCode {
24+
/**
25+
* Assert that a number is a valid chain code.
26+
* @throws Error if the number is not a valid chain code
27+
*/
28+
export function assertChainCode(n: number): ChainCode {
2629
if (!chainCodeSet.has(n)) {
27-
throw new Error(`Invalid chain code from WASM: ${n}`);
30+
throw new Error(`Invalid chain code: ${n}`);
2831
}
2932
return n as ChainCode;
3033
}

packages/wasm-utxo/js/fixedScriptWallet/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ export { RootWalletKeys, type WalletKeysArg, type IWalletKeys } from "./RootWall
55
export { ReplayProtection, type ReplayProtectionArg } from "./ReplayProtection.js";
66
export { outputScript, address } from "./address.js";
77
export { Dimensions } from "./Dimensions.js";
8-
export { type OutputScriptType, type InputScriptType, type ScriptType } from "./scriptType.js";
9-
export { ChainCode, chainCodes, type Scope } from "./chains.js";
8+
export {
9+
outputScriptTypes,
10+
inputScriptTypes,
11+
type OutputScriptType,
12+
type InputScriptType,
13+
type ScriptType,
14+
} from "./scriptType.js";
15+
export { ChainCode, chainCodes, assertChainCode, type Scope } from "./chains.js";
1016

1117
// Bitcoin-like PSBT (for all non-Zcash networks)
1218
export {

packages/wasm-utxo/js/fixedScriptWallet/scriptType.ts

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,43 @@
11
/**
2-
* Fixed-script wallet output script types (2-of-3 multisig)
2+
* All output script types for fixed-script wallets (2-of-3 multisig)
33
*
4-
* This type represents the abstract script type, independent of chain (external/internal).
4+
* This represents the abstract script type, independent of chain (external/internal).
55
* Use this for checking network support or when you need the script type without derivation info.
66
*/
7-
export type OutputScriptType =
8-
| "p2sh"
9-
| "p2shP2wsh"
10-
| "p2wsh"
11-
| "p2tr" // alias for p2trLegacy
12-
| "p2trLegacy"
13-
| "p2trMusig2";
7+
export const outputScriptTypes = [
8+
"p2sh",
9+
"p2shP2wsh",
10+
"p2wsh",
11+
"p2trLegacy",
12+
"p2trMusig2",
13+
] as const;
1414

1515
/**
16-
* Input script types for fixed-script wallets
16+
* Output script type for fixed-script wallets
17+
*
18+
* Note: "p2tr" is an alias for "p2trLegacy" for backward compatibility.
19+
*/
20+
export type OutputScriptType = (typeof outputScriptTypes)[number] | "p2tr";
21+
22+
/**
23+
* All input script types for fixed-script wallets
1724
*
1825
* These are more specific than output types and include single-sig and taproot variants.
1926
*/
20-
export type InputScriptType =
21-
| "p2shP2pk"
22-
| "p2sh"
23-
| "p2shP2wsh"
24-
| "p2wsh"
25-
| "p2trLegacy"
26-
| "p2trMusig2ScriptPath"
27-
| "p2trMusig2KeyPath";
27+
export const inputScriptTypes = [
28+
"p2shP2pk",
29+
"p2sh",
30+
"p2shP2wsh",
31+
"p2wsh",
32+
"p2trLegacy",
33+
"p2trMusig2ScriptPath",
34+
"p2trMusig2KeyPath",
35+
] as const;
36+
37+
/**
38+
* Input script type for fixed-script wallets
39+
*/
40+
export type InputScriptType = (typeof inputScriptTypes)[number];
2841

2942
/**
3043
* Union of all script types that can be checked for network support

0 commit comments

Comments
 (0)