Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/wasm-utxo/js/testutils/AcidTest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BitGoPsbt, type SignerKey } from "../fixedScriptWallet/BitGoPsbt.js";
import { BitGoPsbt, type NetworkName, type SignerKey } from "../fixedScriptWallet/BitGoPsbt.js";
import { ZcashBitGoPsbt } from "../fixedScriptWallet/ZcashBitGoPsbt.js";
import { RootWalletKeys } from "../fixedScriptWallet/RootWalletKeys.js";
import { BIP32 } from "../bip32.js";
Expand Down Expand Up @@ -113,7 +113,7 @@ export { inputScriptTypes, outputScriptTypes };
* - psbt-lite: Only witness_utxo (no non_witness_utxo)
*/
export class AcidTest {
public readonly network: CoinName;
public readonly network: CoinName | NetworkName;
public readonly signStage: SignStage;
public readonly txFormat: TxFormat;
public readonly rootWalletKeys: RootWalletKeys;
Expand All @@ -126,7 +126,7 @@ export class AcidTest {
private readonly bitgoXprv: BIP32;

constructor(
network: CoinName,
network: CoinName | NetworkName,
signStage: SignStage,
txFormat: TxFormat,
rootWalletKeys: RootWalletKeys,
Expand All @@ -151,7 +151,7 @@ export class AcidTest {
* Create an AcidTest with specific configuration
*/
static withConfig(
network: CoinName,
network: CoinName | NetworkName,
signStage: SignStage,
txFormat: TxFormat,
suiteConfig: SuiteConfig = {},
Expand Down
25 changes: 10 additions & 15 deletions packages/wasm-utxo/test/dimensions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import assert from "node:assert";
import * as utxolib from "@bitgo/utxo-lib";
import { Dimensions, fixedScriptWallet } from "../js/index.js";
import { Transaction } from "../js/transaction.js";
import {
Expand Down Expand Up @@ -383,16 +382,14 @@ describe("Dimensions", function () {
describe("integration tests with fixtures", function () {
// Zcash has additional transaction overhead (version group, expiry height, etc.)
// that we don't account for in Dimensions - skip it for now
const networksToTest = getFixtureNetworks().filter((n) => n !== utxolib.networks.zcash);

networksToTest.forEach((network) => {
const networkName = utxolib.getNetworkName(network);
const networksToTest = getFixtureNetworks().filter((n) => n !== "zcash");

networksToTest.forEach((networkName) => {
describe(`${networkName}`, function () {
let fixture: Fixture;

before(function () {
fixture = loadPsbtFixture(networkName, "fullsigned");
before(async function () {
fixture = await loadPsbtFixture(networkName, "fullsigned");
});

it("actual vSize is within estimated min/max bounds", function () {
Expand Down Expand Up @@ -432,8 +429,8 @@ describe("Dimensions", function () {
});

describe("manual construction test", function () {
it("builds correct dimensions for bitcoin fixture", function () {
const fixture = loadPsbtFixture("bitcoin", "fullsigned");
it("builds correct dimensions for bitcoin fixture", async function () {
const fixture = await loadPsbtFixture("bitcoin", "fullsigned");
if (!fixture.extractedTransaction) {
return;
}
Expand Down Expand Up @@ -492,14 +489,12 @@ describe("Dimensions", function () {

describe("fromPsbt", function () {
// Zcash has additional transaction overhead that we don't account for
const networksToTest = getFixtureNetworks().filter((n) => n !== utxolib.networks.zcash);

networksToTest.forEach((network) => {
const networkName = utxolib.getNetworkName(network);
const networksToTest = getFixtureNetworks().filter((n) => n !== "zcash");

networksToTest.forEach((networkName) => {
describe(`${networkName}`, function () {
it("actual vSize is within fromPsbt estimated bounds", function () {
const fixture = loadPsbtFixture(networkName, "fullsigned");
it("actual vSize is within fromPsbt estimated bounds", async function () {
const fixture = await loadPsbtFixture(networkName, "fullsigned");
if (!fixture.extractedTransaction) {
this.skip();
return;
Expand Down
14 changes: 3 additions & 11 deletions packages/wasm-utxo/test/fixedScript/finalizeExtract.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import assert from "node:assert";
import * as utxolib from "@bitgo/utxo-lib";
import { fixedScriptWallet } from "../../js/index.js";
import {
loadPsbtFixture,
Expand All @@ -10,16 +9,14 @@ import {
import { getFixtureNetworks } from "./networkSupport.util.js";

describe("finalize and extract transaction", function () {
getFixtureNetworks().forEach((network) => {
const networkName = utxolib.getNetworkName(network);

getFixtureNetworks().forEach((networkName) => {
describe(`network: ${networkName}`, function () {
let fullsignedFixture: Fixture;
let fullsignedPsbtBuffer: Buffer;
let fullsignedBitgoPsbt: fixedScriptWallet.BitGoPsbt;

before(function () {
fullsignedFixture = loadPsbtFixture(networkName, "fullsigned");
before(async function () {
fullsignedFixture = await loadPsbtFixture(networkName, "fullsigned");
fullsignedPsbtBuffer = getPsbtBuffer(fullsignedFixture);
fullsignedBitgoPsbt = fixedScriptWallet.BitGoPsbt.fromBytes(
fullsignedPsbtBuffer,
Expand Down Expand Up @@ -108,11 +105,6 @@ describe("finalize and extract transaction", function () {
const txid = extractedTx.getId();
assert.strictEqual(txid.length, 64, "txid should be 64 characters");
assert.match(txid, /^[0-9a-f]{64}$/, "txid should be lowercase hex");

// Verify txid matches utxolib calculation
const expectedTxHex = getExtractedTransactionHex(fullsignedFixture);
const utxolibTx = utxolib.bitgo.createTransactionFromHex(expectedTxHex, network);
assert.strictEqual(txid, utxolibTx.getId(), "txid should match utxolib calculation");
});
});
});
Expand Down
37 changes: 30 additions & 7 deletions packages/wasm-utxo/test/fixedScript/fixtureUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { RootWalletKeys } from "../../js/fixedScriptWallet/RootWalletKeys.js";
import { ECPair } from "../../js/ecpair.js";
import { fixedScriptWallet } from "../../js/index.js";
import type { BitGoPsbt, NetworkName } from "../../js/fixedScriptWallet/index.js";
import { getFixture } from "../fixtures.js";
import { generateAllStates } from "./generateFixture.js";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
Expand Down Expand Up @@ -115,19 +117,40 @@ export function getBitGoPsbt(fixture: Fixture, networkName: NetworkName): BitGoP
return fixedScriptWallet.BitGoPsbt.fromBytes(getPsbtBuffer(fixture), networkName);
}

/**
* Load a PSBT fixture from JSON file
*/
export function loadPsbtFixture(network: string, signatureState: string): Fixture {
const fixturePath = path.join(
function getFixturePath(network: string, signatureState: string): string {
return path.join(
__dirname,
"..",
"fixtures",
"fixed-script",
`psbt-lite.${network}.${signatureState}.json`,
);
const fixtureContent = fs.readFileSync(fixturePath, "utf-8");
return JSON.parse(fixtureContent) as Fixture;
}

const SIGNATURE_STATES: SignatureState[] = ["unsigned", "halfsigned", "fullsigned"];

/**
* Load a PSBT fixture from JSON file.
* If the fixture does not exist, generates all three signature states
* (unsigned, halfsigned, fullsigned) and writes them to disk.
*/
export async function loadPsbtFixture(
network: string,
signatureState: SignatureState,
): Promise<Fixture> {
const fixturePath = getFixturePath(network, signatureState);
return getFixture(fixturePath, () => {
const allStates = generateAllStates(network as NetworkName);
// Write sibling states so all three are consistent
for (const state of SIGNATURE_STATES) {
if (state !== signatureState) {
const siblingPath = getFixturePath(network, state);
fs.mkdirSync(path.dirname(siblingPath), { recursive: true });
fs.writeFileSync(siblingPath, JSON.stringify(allStates[state], null, 2));
}
}
return allStates[signatureState];
}) as Promise<Fixture>;
}

/**
Expand Down
Loading
Loading