Skip to content

chore: update imports for node 24 #6513

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion modules/abstract-eth/test/unit/token.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test';
import * as sdkTest from '@bitgo/sdk-test';
import type { TestBitGoAPI } from '@bitgo/sdk-test';

import { BitGoAPI } from '@bitgo/sdk-api';

const { TestBitGo } = sdkTest;

export function runTokenTestInitialization(
currentCoinToken,
coinName: string,
Expand Down
18 changes: 7 additions & 11 deletions modules/account-lib/test/unit/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
import { BaseCoin } from '@bitgo/statics';
import {
BaseMessage,
BaseMessageBuilder,
BaseMessageBuilderFactory,
IMessage,
IMessageBuilder,
MessageOptions,
MessageStandardType,
} from '@bitgo/sdk-core';
import * as sdkCore from '@bitgo/sdk-core';
Copy link
Contributor

@prabh-codes prabh-codes Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less effective, often pulls in more code than necessary.

import { BaseMessage, BaseMessageBuilder, BaseMessageBuilderFactory, IMessage, IMessageBuilder, MessageOptions, MessageStandardType, } from '@bitgo/sdk-core'; was good. While you can import type separately for readability but importing by first approach is still considered as good due to:

  1. Optimal Tree Shaking
  2. Clear Intent
  3. Simplicity

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prabh-codes This was done more so to resolve this type of error rather than readability:

@bitgo/abstract-eth: file:///Users/michaelhahn/bitgo/BitGoJS/modules/abstract-eth/test/unit/token.ts:1
@bitgo/abstract-eth: import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test';
@bitgo/abstract-eth: ^^^^^^^^^^^^
@bitgo/abstract-eth: SyntaxError: Named export 'TestBitGoAPI' not found. The requested module '@bitgo/sdk-test' is a CommonJS module, which may not support all module.exports as named exports.
@bitgo/abstract-eth: CommonJS modules can always be imported via the default export, for example using:
@bitgo/abstract-eth: import pkg from '@bitgo/sdk-test';
@bitgo/abstract-eth: const { TestBitGo, TestBitGoAPI } = pkg;
@bitgo/abstract-eth: at ModuleJob.#_instantiate (node:internal/modules/esm/module_job:254:21)
@bitgo/abstract-eth: at async ModuleJob.run (node:internal/modules/esm/module_job:362:5)
@bitgo/abstract-eth: at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:665:26)
@bitgo/abstract-eth: at async formattedImport (/Users/michaelhahn/bitgo/BitGoJS/node_modules/mocha/lib/nodejs/esm-utils.js:7:14)
@bitgo/abstract-eth: at async Object.exports.requireOrImport (/Users/michaelhahn/bitgo/BitGoJS/node_modules/mocha/lib/nodejs/esm-utils.js:48:32)
@bitgo/abstract-eth: at async Object.exports.loadFilesAsync (/Users/michaelhahn/bitgo/BitGoJS/node_modules/mocha/lib/nodejs/esm-utils.js:103:20)
@bitgo/abstract-eth: at async singleRun (/Users/michaelhahn/bitgo/BitGoJS/node_modules/mocha/lib/cli/run-helpers.js:125:3)
@bitgo/abstract-eth: at async Object.exports.handler (/Users/michaelhahn/bitgo/BitGoJS/node_modules/mocha/lib/cli/run.js:374:5)
@bitgo/abstract-eth: error Command failed with exit code 1.
@bitgo/abstract-eth: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Copy link
Contributor

@andrew-scott-fischer andrew-scott-fischer Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error you post is related to @bitgo/sdk-test, not @bitgo/sdk-core. Regardless, @prabh-codes is correct. You should go fix this in the module you are importing from, rather than just importing everything with a * wild card.

import type { IMessage, IMessageBuilder, MessageOptions } from '@bitgo/sdk-core';
const { BaseMessage, BaseMessageBuilder, BaseMessageBuilderFactory, MessageStandardType } = sdkCore;

type MessageStandardTypeValue = (typeof MessageStandardType)[keyof typeof MessageStandardType];

export class MockMessageBuilderFactory extends BaseMessageBuilderFactory {
constructor(coinConfig: Readonly<BaseCoin>) {
super(coinConfig);
}

getMessageBuilder(type: MessageStandardType): IMessageBuilder {
getMessageBuilder(type: MessageStandardTypeValue): IMessageBuilder {
return new MockMessageBuilder(this.coinConfig, type);
}
}

export class MockMessageBuilder extends BaseMessageBuilder {
constructor(coinConfig: Readonly<BaseCoin>, type: MessageStandardType = MessageStandardType.UNKNOWN) {
constructor(coinConfig: Readonly<BaseCoin>, type: MessageStandardTypeValue = MessageStandardType.UNKNOWN) {
super(coinConfig, type);
}

Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/test/ecdh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as utxolib from '@bitgo/utxo-lib';

import { getSharedSecret, signMessageWithDerivedEcdhKey, verifyEcdhSignature } from '@bitgo/sdk-core';
import { TestBitGo } from '@bitgo/sdk-test';
import * as assert from 'assert';
import assert from 'assert';
import { BitGo } from '../src/bitgo';

describe('ECDH utils', () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/test/integration/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const TestBitGo = require('../lib/test_bitgo');
import * as utxolib from '@bitgo/utxo-lib';
import { getAddressP2PKH, getNetwork } from '../../src/bitcoin';
import { common } from '@bitgo/sdk-core';
import * as nock from 'nock';
import nock from 'nock';

const TEST_WALLET_LABEL = 'wallet management test';

Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/test/unit/bip32path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @prettier
*/
import 'should';
import { bip32, BIP32Interface } from '@bitgo/utxo-lib';
import { bip32, type BIP32Interface } from '@bitgo/utxo-lib';
import { sanitizeLegacyPath, bitcoin } from '@bitgo/sdk-core';
import { getSeed } from '@bitgo/sdk-test';
const { HDNode, hdPath } = bitcoin;
Expand Down
4 changes: 2 additions & 2 deletions modules/bitgo/test/unit/bitgo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
//

import * as crypto from 'crypto';
import * as nock from 'nock';
import nock from 'nock';
import * as should from 'should';
import assert = require('assert');
import assert from 'assert';

import { common, generateGPGKeyPair } from '@bitgo/sdk-core';
import { bip32, ECPair } from '@bitgo/utxo-lib';
Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/test/unit/decryptKeychain.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'should';
import { decryptKeychainPrivateKey, OptionalKeychainEncryptedKey } from '@bitgo/sdk-core';
import { decryptKeychainPrivateKey, type OptionalKeychainEncryptedKey } from '@bitgo/sdk-core';
import { BitGoAPI } from '@bitgo/sdk-api';

describe('decryptKeychainPrivateKey', () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/test/unit/keychains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//

import * as _ from 'lodash';
import * as nock from 'nock';
import nock from 'nock';
import 'should';

import { common } from '@bitgo/sdk-core';
Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/test/v2/integration/coins/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as should from 'should';
import 'should-http';

import { TestBitGo } from '../../../lib/test_bitgo';
import * as nock from 'nock';
import nock from 'nock';
nock.restore();

describe('ETH:', function () {
Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/test/v2/integration/coins/xlm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BaseCoin } from '../../../../src/v2';

import { TestBitGo } from '../../../lib/test_bitgo';

import * as nock from 'nock';
import nock from 'nock';

describe('XLM:', function () {
let bitgo: typeof TestBitGo;
Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/test/v2/integration/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import * as should from 'should';
import * as _ from 'lodash';
import * as nock from 'nock';
import nock from 'nock';

import { TestBitGo } from '../../lib/test_bitgo';

Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/test/v2/lib/recovery-nocks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @prettier
*/
import * as nock from 'nock';
import nock from 'nock';
import { Environments } from '@bitgo/sdk-core';

module.exports.nockXrpRecovery = function nockXrpRecovery() {
Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/test/v2/unit/PrebuildAndSign.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as sinon from 'sinon';
import * as nock from 'nock';
import nock from 'nock';

import { Environments, Wallet } from '@bitgo/sdk-core';
import { TestableBG, TestBitGo } from '@bitgo/sdk-test';
Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/test/v2/unit/accountConsolidations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as sinon from 'sinon';
require('should-sinon');

import '../lib/asserts';
import * as nock from 'nock';
import nock from 'nock';

import { common, Wallet } from '@bitgo/sdk-core';

Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/test/v2/unit/ams/ams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as should from 'should';
import * as nock from 'nock';
import nock from 'nock';

import { Environments } from '@bitgo/sdk-core';
import { TestBitGo } from '@bitgo/sdk-test';
Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/test/v2/unit/apiNocks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as nock from 'nock';
import nock from 'nock';

export async function nockGetSigningKey(params: {
userId: string;
Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/test/v2/unit/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as nock from 'nock';
import nock from 'nock';
import 'should';
import * as sinon from 'sinon';

Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/test/v2/unit/baseCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//

import 'should';
import * as nock from 'nock';
import nock from 'nock';

import { TestBitGo } from '@bitgo/sdk-test';
import { BitGo } from '../../../src/bitgo';
Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/test/v2/unit/coins/utxo/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @prettier
*/
import 'should';
import * as assert from 'assert';
import assert from 'assert';
import * as utxolib from '@bitgo/utxo-lib';
const { chainCodes } = utxolib.bitgo;

Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/test/v2/unit/coins/utxo/coins.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as assert from 'assert';
import assert from 'assert';
import * as utxolib from '@bitgo/utxo-lib';

import { getUtxoCoinForNetwork, utxoCoins } from './util';
Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/test/v2/unit/coins/utxo/keySignatures.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as assert from 'assert';
import assert from 'assert';
import { AbstractUtxoCoin } from '@bitgo/abstract-utxo';
import { Keychain } from '@bitgo/sdk-core';

Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/test/v2/unit/coins/utxo/keychains.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as assert from 'assert';
import assert from 'assert';
import 'should';
import { AbstractUtxoCoin } from '@bitgo/abstract-utxo';
import { utxoCoins } from './util';
Expand Down
4 changes: 2 additions & 2 deletions modules/bitgo/test/v2/unit/coins/utxo/prebuildAndSign.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* @prettier
*/
import * as assert from 'assert';
import assert from 'assert';

import { AbstractUtxoCoin, getReplayProtectionAddresses } from '@bitgo/abstract-utxo';
import * as utxolib from '@bitgo/utxo-lib';
import * as nock from 'nock';
import nock from 'nock';

import { encryptKeychain, getDefaultWalletKeys, getUtxoWallet, keychainsBase58, utxoCoins } from './util';
import { common, HalfSignedUtxoTransaction, Wallet } from '@bitgo/sdk-core';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import 'should';
import * as mocha from 'mocha';
import * as sinon from 'sinon';
import * as nock from 'nock';
import nock from 'nock';
import { BIP32Interface } from '@bitgo/utxo-lib';

import * as utxolib from '@bitgo/utxo-lib';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* @prettier
*/
import * as assert from 'assert';
import assert from 'assert';
import * as should from 'should';
import * as nock from 'nock';
import nock from 'nock';
import * as utxolib from '@bitgo/utxo-lib';
import { Triple } from '@bitgo/sdk-core';
import {
Expand Down
16 changes: 9 additions & 7 deletions modules/bitgo/test/v2/unit/coins/utxo/recovery/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @prettier
*/
import { bitgo } from '@bitgo/utxo-lib';
import { AddressInfo, TransactionIO } from '@bitgo/blockapis';
import { AbstractUtxoCoin, RecoveryProvider } from '@bitgo/abstract-utxo';
import type { AddressInfo, TransactionIO } from '@bitgo/blockapis';
import type { AbstractUtxoCoin, RecoveryProvider } from '@bitgo/abstract-utxo';
import * as utxolib from '@bitgo/utxo-lib';
import { Bch } from '@bitgo/sdk-coin-bch';
import { Bsv } from '@bitgo/sdk-coin-bsv';
Expand Down Expand Up @@ -52,13 +52,15 @@ export class MockRecoveryProvider implements RecoveryProvider {
}
}
export class MockCrossChainRecoveryProvider<TNumber extends number | bigint> implements RecoveryProvider {
public coin: AbstractUtxoCoin;
public unspents: Unspent<TNumber>[];
public tx: utxolib.bitgo.UtxoTransaction<TNumber>;
private addressVersion: 'cashaddr' | 'base58';
private addressFormat: utxolib.addressFormat.AddressFormat;
constructor(
public coin: AbstractUtxoCoin,
public unspents: Unspent<TNumber>[],
public tx: utxolib.bitgo.UtxoTransaction<TNumber>
) {
constructor(coin: AbstractUtxoCoin, unspents: Unspent<TNumber>[], tx: utxolib.bitgo.UtxoTransaction<TNumber>) {
this.coin = coin;
this.unspents = unspents;
this.tx = tx;
// this is how blockchair will return the data, as a cashaddr for BCH like coins
// BSV supports cashaddr, but at the time of writing the SDK does not support cashaddr for bsv
this.addressFormat = this.coin instanceof Bch && !(this.coin instanceof Bsv) ? 'cashaddr' : 'default';
Expand Down
4 changes: 2 additions & 2 deletions modules/bitgo/test/v2/unit/coins/utxo/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*/
import 'mocha';
import * as _ from 'lodash';
import * as assert from 'assert';
import assert from 'assert';
import * as utxolib from '@bitgo/utxo-lib';
import * as nock from 'nock';
import nock from 'nock';
import { BIP32Interface, bitgo, testutil } from '@bitgo/utxo-lib';

import { AbstractUtxoCoin, getReplayProtectionAddresses } from '@bitgo/abstract-utxo';
Expand Down
4 changes: 2 additions & 2 deletions modules/bitgo/test/v2/unit/coins/utxo/util/keychains.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* @prettier
*/
import { Triple } from '@bitgo/sdk-core';
import type { Triple } from '@bitgo/sdk-core';
import { encrypt } from '@bitgo/sdk-api';
import { getSeed } from '@bitgo/sdk-test';
import { bip32, BIP32Interface, bitgo } from '@bitgo/utxo-lib';
import { bip32, type BIP32Interface, bitgo } from '@bitgo/utxo-lib';

type RootWalletKeys = bitgo.RootWalletKeys;

Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/test/v2/unit/coins/utxo/util/nockBitGo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as nock from 'nock';
import nock from 'nock';
import { Environment, Environments } from '@bitgo/sdk-core';
import { defaultBitGo } from './utxoCoins';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @prettier
*/
import * as nock from 'nock';
import nock from 'nock';
import * as utxolib from '@bitgo/utxo-lib';
import { AbstractUtxoCoin } from '@bitgo/abstract-utxo';
import { nockBitGo } from './nockBitGo';
Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/test/v2/unit/enterprise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Tests for enterprises
//

import * as nock from 'nock';
import nock from 'nock';
import * as sinon from 'sinon';
import { common, ECDSAUtils, Enterprise } from '@bitgo/sdk-core';

Expand Down
3 changes: 2 additions & 1 deletion modules/bitgo/test/v2/unit/errors.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'should';
const assert = require('assert');
import assert from 'assert';
import { BitGoJsError, NodeEnvironmentError } from '@bitgo/sdk-core';

describe('Error handling', () => {
it('should capture stack trace', function namedFunc() {
const { stack } = new BitGoJsError();
assert(stack);
assert.match(stack, /BitGoJsError/);
assert.match(stack, /at Context\.namedFunc/);
new NodeEnvironmentError().stack!.should.match(/NodeEnvironmentError:/);
Expand Down
8 changes: 4 additions & 4 deletions modules/bitgo/test/v2/unit/internal/opengpgUtils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as openpgp from 'openpgp';
import * as should from 'should';
import should from 'should';
import * as crypto from 'crypto';
import * as assert from 'assert';
import assert from 'assert';

import { openpgpUtils } from '@bitgo/sdk-core';
import { ecc as secp256k1 } from '@bitgo/utxo-lib';
import * as sinon from 'sinon';
import sinon from 'sinon';

const sodium = require('libsodium-wrappers-sumo');
import sodium from 'libsodium-wrappers-sumo';

describe('OpenGPG Utils Tests', function () {
let senderKey: { publicKey: string; privateKey: string };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { TestBitGo } from '@bitgo/sdk-test';

import { BitGo } from '../../../../../src';
import * as openpgp from 'openpgp';
import nock = require('nock');
import assert = require('assert');
import nock from 'nock';
import assert from 'assert';

class TestEcdsaMpcv2Utils extends ECDSAUtils.EcdsaMPCv2Utils {
public async testPickBitgoPubGpgKeyForSigning(
Expand Down
4 changes: 2 additions & 2 deletions modules/bitgo/test/v2/unit/internal/tssUtils/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExchangeCommitmentResponse, RequestType, SignatureShareRecord } from '@bitgo/sdk-core';
import * as nock from 'nock';
import { type ExchangeCommitmentResponse, RequestType, type SignatureShareRecord } from '@bitgo/sdk-core';
import nock from 'nock';
import * as _ from 'lodash';

export async function nockSendTxRequest(params: {
Expand Down
6 changes: 3 additions & 3 deletions modules/bitgo/test/v2/unit/internal/tssUtils/ecdsa.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as assert from 'assert';
import assert from 'assert';
import * as _ from 'lodash';
import * as nock from 'nock';
import nock from 'nock';
import * as openpgp from 'openpgp';
import * as should from 'should';
import should from 'should';
import * as sinon from 'sinon';

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as assert from 'assert';
import * as nock from 'nock';
import assert from 'assert';
import nock from 'nock';
import * as openpgp from 'openpgp';
import * as crypto from 'crypto';

Expand Down
Loading