Skip to content

fix(utxo-core): use tsx to run test files #6552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

module.exports = {
require: 'ts-node/register',
"node-option": ["import=tsx"],
extension: ['.js', '.ts'],
};
10 changes: 7 additions & 3 deletions modules/utxo-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"lint": "eslint --quiet .",
"prepare": "npm run build",
"test": "npm run unit-test",
"unit-test": "mocha --recursive \"dist/test/**/*.js\""
"unit-test": "mocha --recursive test"
},
"author": "BitGo SDK Team <[email protected]>",
"license": "MIT",
Expand All @@ -45,7 +45,7 @@
"publishConfig": {
"access": "public"
},
"type": "commonjs",
"type": "module",
"nyc": {
"extension": [
".ts"
Expand All @@ -58,5 +58,9 @@
"bip174": "npm:@bitgo-forks/[email protected]",
"bitcoinjs-message": "npm:@bitgo-forks/[email protected]"
},
"gitHead": "18e460ddf02de2dbf13c2aa243478188fb539f0c"
"gitHead": "18e460ddf02de2dbf13c2aa243478188fb539f0c",
"devDependencies": {
"@types/node": "^24",
"tsx": "^4.20.3"
}
}
2 changes: 1 addition & 1 deletion modules/utxo-core/src/bip65/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './locktime';
export * from './locktime.js';
6 changes: 3 additions & 3 deletions modules/utxo-core/src/descriptor/Output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import assert from 'assert';

import { Descriptor } from '@bitgo/wasm-miniscript';

import { getFixedOutputSum, MaxOutput, Output, PrevOutput } from '../Output';
import { getFixedOutputSum, MaxOutput, Output, PrevOutput } from '../Output.js';

import { DescriptorMap } from './DescriptorMap';
import { getDescriptorAtIndexCheckScript } from './derive';
import { DescriptorMap } from './DescriptorMap.js';
import { getDescriptorAtIndexCheckScript } from './derive.js';

export type WithDescriptor<T> = T & {
descriptor: Descriptor;
Expand Down
4 changes: 2 additions & 2 deletions modules/utxo-core/src/descriptor/VirtualSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as utxolib from '@bitgo/utxo-lib';
import { Dimensions, VirtualSizes } from '@bitgo/unspents';
import { Descriptor } from '@bitgo/wasm-miniscript';

import { DescriptorMap } from './DescriptorMap';
import { findDescriptorForInput } from './psbt';
import { DescriptorMap } from './DescriptorMap.js';
import { findDescriptorForInput } from './psbt/findDescriptors.js';

function getScriptPubKeyLength(descType: string): number {
// See https://bitcoinops.org/en/tools/calc-size/
Expand Down
18 changes: 9 additions & 9 deletions modules/utxo-core/src/descriptor/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export * from './psbt';
export * from './address';
export * from './DescriptorMap';
export * from './derive';
export * from './Output';
export * from './VirtualSize';
export * from './fromFixedScriptWallet';
export * from './parse/PatternMatcher';
export * from './psbt/index.js';
export * from './address.js';
export * from './DescriptorMap.js';
export * from './derive.js';
export * from './Output.js';
export * from './VirtualSize.js';
export * from './fromFixedScriptWallet.js';
export * from './parse/PatternMatcher.js';

/** @deprecated - import from @bitgo/utxo-core directly instead */
export * from '../Output';
export * from '../Output.js';
10 changes: 5 additions & 5 deletions modules/utxo-core/src/descriptor/psbt/createPsbt.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TapLeafScript } from 'bip174/src/lib/interfaces';
import { TapLeafScript } from 'bip174/src/lib/interfaces.js';
import * as utxolib from '@bitgo/utxo-lib';
import { Descriptor, Miniscript } from '@bitgo/wasm-miniscript';

import { DerivedDescriptorWalletOutput, WithOptDescriptor } from '../Output';
import { Output } from '../../Output';
import { DerivedDescriptorWalletOutput, WithOptDescriptor } from '../Output.js';
import { Output } from '../../Output.js';

import { toUtxoPsbt, toWrappedPsbt } from './wrap';
import { assertSatisfiable } from './assertSatisfiable';
import { toUtxoPsbt, toWrappedPsbt } from './wrap.js';
import { assertSatisfiable } from './assertSatisfiable.js';

/**
* Non-Final (Replaceable)
Expand Down
4 changes: 2 additions & 2 deletions modules/utxo-core/src/descriptor/psbt/findDescriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ It will probably only work correctly if all xpubs in the descriptor are derivabl
We should take a look at a more robust and standard approach like this: https://github.com/bitcoin/bips/pull/1548

*/
import { PsbtInput, PsbtOutput } from 'bip174/src/lib/interfaces';
import { PsbtInput, PsbtOutput } from 'bip174/src/lib/interfaces.js';
import { Descriptor } from '@bitgo/wasm-miniscript';

import { DescriptorMap } from '../DescriptorMap';
import { DescriptorMap } from '../DescriptorMap.js';

type DescriptorWithoutIndex = { descriptor: Descriptor; index: undefined };

Expand Down
12 changes: 6 additions & 6 deletions modules/utxo-core/src/descriptor/psbt/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './assertSatisfiable';
export * from './createPsbt';
export * from './parse';
export * from './findDescriptors';
export * from './wrap';
export * from './sign';
export * from './assertSatisfiable.js';
export * from './createPsbt.js';
export * from './parse.js';
export * from './findDescriptors.js';
export * from './wrap.js';
export * from './sign.js';
8 changes: 4 additions & 4 deletions modules/utxo-core/src/descriptor/psbt/parse.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Descriptor } from '@bitgo/wasm-miniscript';
import * as utxolib from '@bitgo/utxo-lib';

import { DescriptorMap } from '../DescriptorMap';
import { getVirtualSize } from '../VirtualSize';
import { DescriptorMap } from '../DescriptorMap.js';
import { getVirtualSize } from '../VirtualSize.js';

import { findDescriptorForInput, findDescriptorForOutput } from './findDescriptors';
import { assertSatisfiable } from './assertSatisfiable';
import { findDescriptorForInput, findDescriptorForOutput } from './findDescriptors.js';
import { assertSatisfiable } from './assertSatisfiable.js';

export type ScriptId = { descriptor: Descriptor; index: number | undefined };

Expand Down
16 changes: 8 additions & 8 deletions modules/utxo-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export * as bip65 from './bip65';
export * as descriptor from './descriptor';
export * as testutil from './testutil';
export * as paygo from './paygo';
export * as bip32utils from './bip32utils';
export * from './dustThreshold';
export * from './Output';
export * from './xOnlyPubkey';
export * as bip65 from './bip65/index.js';
export * as descriptor from './descriptor/index.js';
export * as testutil from './testutil/index.js';
export * as paygo from './paygo/index.js';
export * as bip32utils from './bip32utils.js';
export * from './dustThreshold.js';
export * from './Output.js';
export * from './xOnlyPubkey.js';
4 changes: 2 additions & 2 deletions modules/utxo-core/src/paygo/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './parsePayGoAttestation';
export * from './psbt';
export * from './parsePayGoAttestation.js';
export * from './psbt/index.js';
2 changes: 1 addition & 1 deletion modules/utxo-core/src/paygo/psbt/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './payGoAddressProof';
export * from './payGoAddressProof.js';
8 changes: 4 additions & 4 deletions modules/utxo-core/src/paygo/psbt/payGoAddressProof.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import * as utxolib from '@bitgo/utxo-lib';
import { checkForOutput } from 'bip174/src/lib/utils';
import { checkForOutput } from 'bip174/src/lib/utils.js';

import { verifyMessage } from '../../bip32utils';
import { createPayGoAttestationBuffer } from '../attestation';
import { verifyMessage } from '../../bip32utils.js';
import { createPayGoAttestationBuffer } from '../attestation.js';

import {
ErrorMultiplePayGoProof,
ErrorMultiplePayGoProofAtPsbtIndex,
ErrorNoPayGoProof,
ErrorOutputIndexOutOfBounds,
ErrorPayGoAddressProofFailedVerification,
} from './Errors';
} from './Errors.js';

/** This function adds the entropy and signature into the PSBT output unknown key vals.
* We store the entropy so that we reconstruct the message <ENTROPY><ADDRESS><UUID>
Expand Down
4 changes: 2 additions & 2 deletions modules/utxo-core/src/testutil/descriptor/descriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import assert from 'assert';
import { Miniscript, Descriptor, ast } from '@bitgo/wasm-miniscript';
import { bip32, BIP32Interface } from '@bitgo/utxo-lib';

import { DescriptorMap, PsbtParams } from '../../descriptor';
import { getKeyTriple, Triple, KeyTriple } from '../key.utils';
import { DescriptorMap, PsbtParams } from '../../descriptor/index.js';
import { getKeyTriple, Triple, KeyTriple } from '../key.utils.js';

export function getDefaultXPubs(seed?: string): Triple<string> {
return getKeyTriple(seed).map((k) => k.neutered().toBase58()) as Triple<string>;
Expand Down
6 changes: 3 additions & 3 deletions modules/utxo-core/src/testutil/descriptor/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './descriptors';
export * from './mock.utils';
export * from './psbt.utils';
export * from './descriptors.js';
export * from './mock.utils.js';
export * from './psbt.utils.js';
4 changes: 2 additions & 2 deletions modules/utxo-core/src/testutil/descriptor/mock.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
createPsbt,
createScriptPubKeyFromDescriptor,
DerivedDescriptorTransactionInput,
} from '../../descriptor';
} from '../../descriptor/index.js';

import { DescriptorTemplate, getDefaultXPubs, getDescriptor } from './descriptors';
import { DescriptorTemplate, getDefaultXPubs, getDescriptor } from './descriptors.js';

type MockOutputIdParams = { hash?: string; vout?: number };

Expand Down
2 changes: 1 addition & 1 deletion modules/utxo-core/src/testutil/descriptor/psbt.utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as utxolib from '@bitgo/utxo-lib';

import { matchPath, PathElement, toPlainObject } from '../../../src/testutil';
import { matchPath, PathElement, toPlainObject } from '../../../src/testutil/index.js';

export function toPlainObjectFromPsbt(v: utxolib.Psbt): unknown {
return toPlainObject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import crypto from 'crypto';

import { bufferutils } from '@bitgo/utxo-lib';

import { Prefix } from '../paygo';
import { Prefix } from '../paygo/index.js';

/** We have a mirrored function similar to our hsm that generates our Bitcoin signed
* message so that we can use for testing. This creates a random entropy as well using
Expand Down
10 changes: 5 additions & 5 deletions modules/utxo-core/src/testutil/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './fixtures.utils';
export * from './key.utils';
export * from './toPlainObject.utils';
export * from './generatePayGoAttestationProof.utils';
export * from './trimMessagePrefix';
export * from './fixtures.utils.js';
export * from './key.utils.js';
export * from './toPlainObject.utils.js';
export * from './generatePayGoAttestationProof.utils.js';
export * from './trimMessagePrefix.js';
2 changes: 1 addition & 1 deletion modules/utxo-core/test/Output.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from 'assert';

import { getFixedOutputSum, getMaxOutput, getOutputSum, isMaxOutput, toFixedOutputs } from '../src';
import { getFixedOutputSum, getMaxOutput, getOutputSum, isMaxOutput, toFixedOutputs } from '../src/index.js';

describe('Output', function () {
const oBigInt = { value: 1n };
Expand Down
9 changes: 7 additions & 2 deletions modules/utxo-core/test/bip32utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as assert from 'assert';

import * as utxolib from '@bitgo/utxo-lib';

import { signMessage, verifyMessage } from '../src/bip32utils';
import { signMessage, verifyMessage } from '../src/bip32utils.js';

describe('bip32utils', function () {
function getSeedBuffers(length: number) {
Expand All @@ -21,7 +21,12 @@ describe('bip32utils', function () {
const expectValid = message === otherMessage && key === otherKey;
assert.strictEqual(verifyMessage(otherMessage, otherKey, signature, utxolib.networks.bitcoin), expectValid);
assert.strictEqual(
verifyMessage(Buffer.from(otherMessage), otherKey, signature, utxolib.networks.bitcoin),
verifyMessage(
typeof otherMessage === 'string' ? Buffer.from(otherMessage) : otherMessage,
otherKey,
signature,
utxolib.networks.bitcoin
),
expectValid
);
});
Expand Down
2 changes: 1 addition & 1 deletion modules/utxo-core/test/bip65/locktime.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from 'assert';

import { encodeLocktime } from '../../src/bip65/locktime';
import { encodeLocktime } from '../../src/bip65/locktime.js';

describe('locktime', function () {
it('encodes relative and absolute locktimes', function () {
Expand Down
6 changes: 3 additions & 3 deletions modules/utxo-core/test/descriptor/Output.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import assert from 'assert';

import { isExternalOutput, isInternalOutput, toDerivedDescriptorWalletOutput } from '../../src/descriptor/Output';
import { getDescriptor } from '../../src/testutil/descriptor';
import { createScriptPubKeyFromDescriptor } from '../../src/descriptor';
import { isExternalOutput, isInternalOutput, toDerivedDescriptorWalletOutput } from '../../src/descriptor/Output.js';
import { getDescriptor } from '../../src/testutil/descriptor/index.js';
import { createScriptPubKeyFromDescriptor } from '../../src/descriptor/index.js';

describe('decscriptor.Output', function () {
const descriptor = getDescriptor('Wsh2Of3');
Expand Down
4 changes: 2 additions & 2 deletions modules/utxo-core/test/descriptor/derive.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from 'assert';

import { getDescriptor } from '../../src/testutil/descriptor';
import { getDescriptorAtIndex, getDescriptorAtIndexCheckScript } from '../../src/descriptor/derive';
import { getDescriptor } from '../../src/testutil/descriptor/index.js';
import { getDescriptorAtIndex, getDescriptorAtIndexCheckScript } from '../../src/descriptor/derive.js';

describe('derive', function () {
const derivable = getDescriptor('Wsh2Of3');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Descriptor } from '@bitgo/wasm-miniscript';
import {
getDescriptorForScriptType,
getNamedDescriptorsForRootWalletKeys,
} from '../../src/descriptor/fromFixedScriptWallet';
} from '../../src/descriptor/fromFixedScriptWallet.js';

function getRootWalletKeys(derivationPrefixes?: utxolib.bitgo.Triple<string>): utxolib.bitgo.RootWalletKeys {
// This is a fixed script wallet, so we use a fixed key triple.
Expand Down
6 changes: 3 additions & 3 deletions modules/utxo-core/test/descriptor/parse/PatternMatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import assert from 'assert';

import { Descriptor, ast } from '@bitgo/wasm-miniscript';

import { getKey } from '../../../src/testutil';
import { toXOnlyPublicKey } from '../../../src';
import { PatternMatcher, Pattern } from '../../../src/descriptor/parse/PatternMatcher';
import { getKey } from '../../../src/testutil/index.js';
import { toXOnlyPublicKey } from '../../../src/index.js';
import { PatternMatcher, Pattern } from '../../../src/descriptor/parse/PatternMatcher.js';

function key32(seed: string): Buffer {
// return x-only public key from seed
Expand Down
8 changes: 4 additions & 4 deletions modules/utxo-core/test/descriptor/psbt/VirtualSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import {
getInputVSizesForDescriptors,
getVirtualSize,
getVirtualSizeEstimateForPsbt,
} from '../../../src/descriptor/VirtualSize';
} from '../../../src/descriptor/VirtualSize.js';
import {
DescriptorTemplate,
getDefaultXPubs,
getDescriptor,
getDescriptorMap,
mockPsbtDefault,
} from '../../../src/testutil/descriptor';
import { getKeyTriple } from '../../../src/testutil';
import { finalizePsbt } from '../../../src/descriptor';
} from '../../../src/testutil/descriptor/index.js';
import { getKeyTriple } from '../../../src/testutil/index.js';
import { finalizePsbt } from '../../../src/descriptor/index.js';

describe('VirtualSize', function () {
describe('getInputVSizesForDescriptorWallet', function () {
Expand Down
4 changes: 2 additions & 2 deletions modules/utxo-core/test/descriptor/psbt/assertSatisfiable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as assert from 'assert';

import { Descriptor } from '@bitgo/wasm-miniscript';

import { getDefaultXPubs } from '../../../src/testutil/descriptor';
import { getRequiredLocktime } from '../../../src/descriptor';
import { getDefaultXPubs } from '../../../src/testutil/descriptor/index.js';
import { getRequiredLocktime } from '../../../src/descriptor/index.js';

function d(s: string): Descriptor {
return Descriptor.fromString(s, 'derivable');
Expand Down
9 changes: 7 additions & 2 deletions modules/utxo-core/test/descriptor/psbt/findDescriptors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import * as assert from 'assert';

import { DescriptorTemplate, getDefaultXPubs, getDescriptor, mockPsbt } from '../../../src/testutil/descriptor';
import { findDescriptorForInput, findDescriptorForOutput } from '../../../src/descriptor';
import {
DescriptorTemplate,
getDefaultXPubs,
getDescriptor,
mockPsbt,
} from '../../../src/testutil/descriptor/index.js';
import { findDescriptorForInput, findDescriptorForOutput } from '../../../src/descriptor/index.js';

function describeWithTemplates(templateSelf: DescriptorTemplate, templateOther: DescriptorTemplate) {
describe(`parsePsbt [${templateSelf},${templateOther}]`, function () {
Expand Down
Loading
Loading