Skip to content

Commit 9cfedc8

Browse files
OttoAllmendingerllm-git
andcommitted
feat(wasm-utxo): add network support utilities for fixtures
Extract fixture network filtering into a utility function. This improves code organization and reduces duplication across test files. Now includes bitcoincash and bitcoingold in fixture networks. Issue: BTC-2656 Co-authored-by: llm-git <[email protected]>
1 parent ef05527 commit 9cfedc8

File tree

4 files changed

+23
-36
lines changed

4 files changed

+23
-36
lines changed

packages/wasm-utxo/test/fixedScript/finalizeExtract.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,10 @@ import {
77
getExtractedTransactionHex,
88
type Fixture,
99
} from "./fixtureUtil.js";
10+
import { getFixtureNetworks } from "./networkSupport.util.js";
1011

1112
describe("finalize and extract transaction", function () {
12-
const supportedNetworks = utxolib.getNetworkList().filter((network) => {
13-
return (
14-
utxolib.isMainnet(network) &&
15-
network !== utxolib.networks.bitcoincash &&
16-
network !== utxolib.networks.bitcoingold &&
17-
network !== utxolib.networks.bitcoinsv &&
18-
network !== utxolib.networks.ecash &&
19-
network !== utxolib.networks.zcash
20-
);
21-
});
22-
23-
supportedNetworks.forEach((network) => {
13+
getFixtureNetworks().forEach((network) => {
2414
const networkName = utxolib.getNetworkName(network);
2515

2616
describe(`network: ${networkName}`, function () {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as utxolib from "@bitgo/utxo-lib";
2+
3+
/**
4+
* Get networks that have psbt fixtures
5+
*/
6+
export function getFixtureNetworks(): utxolib.Network[] {
7+
return utxolib.getNetworkList().filter((network) => {
8+
return (
9+
// we only have fixtures for mainnet networks
10+
utxolib.isMainnet(network) &&
11+
// we don't have fixtures for bitcoinsv since it is not really supported any longer
12+
network !== utxolib.networks.bitcoinsv &&
13+
// we do have zcash fixtures but it is not fully implemented yet
14+
network !== utxolib.networks.zcash
15+
);
16+
});
17+
}

packages/wasm-utxo/test/fixedScript/parseTransactionWithWalletKeys.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
loadReplayProtectionKeyFromFixture,
1212
type Fixture,
1313
} from "./fixtureUtil.js";
14+
import { getFixtureNetworks } from "./networkSupport.util.js";
1415

1516
function getExpectedInputScriptType(fixtureScriptType: string): InputScriptType {
1617
// Map fixture types to InputScriptType values
@@ -38,18 +39,7 @@ function getOtherWalletKeys(): utxolib.bitgo.RootWalletKeys {
3839
}
3940

4041
describe("parseTransactionWithWalletKeys", function () {
41-
const supportedNetworks = utxolib.getNetworkList().filter((network) => {
42-
return (
43-
utxolib.isMainnet(network) &&
44-
network !== utxolib.networks.bitcoincash &&
45-
network !== utxolib.networks.bitcoingold &&
46-
network !== utxolib.networks.bitcoinsv &&
47-
network !== utxolib.networks.ecash &&
48-
network !== utxolib.networks.zcash
49-
);
50-
});
51-
52-
supportedNetworks.forEach((network) => {
42+
getFixtureNetworks().forEach((network) => {
5343
const networkName = utxolib.getNetworkName(network);
5444

5545
describe(`network: ${networkName}`, function () {

packages/wasm-utxo/test/fixedScript/signAndVerifySignature.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
type Fixture,
1515
loadReplayProtectionKeyFromFixture,
1616
} from "./fixtureUtil.js";
17+
import { getFixtureNetworks } from "./networkSupport.util.js";
1718

1819
type SignatureStage = "unsigned" | "halfsigned" | "fullsigned";
1920

@@ -279,18 +280,7 @@ function runTestsForFixture(
279280
}
280281

281282
describe("verifySignature", function () {
282-
const supportedNetworks = utxolib.getNetworkList().filter((network) => {
283-
return (
284-
utxolib.isMainnet(network) &&
285-
network !== utxolib.networks.bitcoincash &&
286-
network !== utxolib.networks.bitcoingold &&
287-
network !== utxolib.networks.bitcoinsv &&
288-
network !== utxolib.networks.ecash &&
289-
network !== utxolib.networks.zcash
290-
);
291-
});
292-
293-
supportedNetworks.forEach((network) => {
283+
getFixtureNetworks().forEach((network) => {
294284
const networkName = utxolib.getNetworkName(network);
295285

296286
describe(`network: ${networkName}`, function () {

0 commit comments

Comments
 (0)