Skip to content
Merged
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
3 changes: 2 additions & 1 deletion src/__tests__/api/master/accelerate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Tbtc } from '@bitgo-beta/sdk-coin-btc';
import { app as expressApp } from '../../../masterBitGoExpressApp';
import { AppMode, MasterExpressConfig, TlsMode } from '../../../shared/types';
import { Environments, Wallet } from '@bitgo-beta/sdk-core';
import { BitGoAPITestHarness } from './testUtils';
import { BitGoAPITestHarness, DEFAULT_ASYNC_MODE_CONFIG } from './testUtils';

const TBTC_PREBUILD_PSBT_HEX = utxolib.bitgo
.createPsbtForNetwork({ network: utxolib.networks.testnet })
Expand Down Expand Up @@ -64,6 +64,7 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/accelerate', () => {
awmServerCaCert: 'test-cert',
tlsMode: TlsMode.DISABLED,
clientCertAllowSelfSigned: true,
asyncModeConfig: DEFAULT_ASYNC_MODE_CONFIG,
};

const app = expressApp(config);
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/api/master/awmBackupClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'should';
import { AppMode, MasterExpressConfig, TlsMode } from '../../../shared/types';
import { DEFAULT_ASYNC_MODE_CONFIG } from './testUtils';
import {
createAwmClient,
createAwmBackupClient,
Expand All @@ -19,6 +20,7 @@ describe('AWM Backup Client', () => {
awmServerCaCert: 'dummy-cert',
tlsMode: TlsMode.DISABLED,
clientCertAllowSelfSigned: true,
asyncModeConfig: DEFAULT_ASYNC_MODE_CONFIG,
};

describe('createAwmBackupClient', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/api/master/consolidate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AppMode, MasterExpressConfig, TlsMode } from '../../../shared/types';
import { Environments } from '@bitgo-beta/sdk-core';
import { Hteth } from '@bitgo-beta/sdk-coin-eth';
import * as transactionRequests from '../../../masterBitgoExpress/handlers/transactionRequests';
import { BitGoAPITestHarness } from './testUtils';
import { BitGoAPITestHarness, DEFAULT_ASYNC_MODE_CONFIG } from './testUtils';

describe('POST /api/v1/:coin/advancedwallet/:walletId/consolidate', () => {
let agent: request.SuperAgentTest;
Expand Down Expand Up @@ -61,6 +61,7 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/consolidate', () => {
awmServerCaCert: 'test-cert',
tlsMode: TlsMode.DISABLED,
clientCertAllowSelfSigned: true,
asyncModeConfig: DEFAULT_ASYNC_MODE_CONFIG,
};

const app = expressApp(config);
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/api/master/consolidateUnspents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Btc } from '@bitgo-beta/sdk-coin-btc';
import { app as expressApp } from '../../../masterBitGoExpressApp';
import { AppMode, MasterExpressConfig, TlsMode } from '../../../shared/types';
import { Environments, Wallet } from '@bitgo-beta/sdk-core';
import { BitGoAPITestHarness } from './testUtils';
import { BitGoAPITestHarness, DEFAULT_ASYNC_MODE_CONFIG } from './testUtils';

const BTC_PREBUILD_PSBT_HEX = utxolib.bitgo
.createPsbtForNetwork({ network: utxolib.networks.bitcoin })
Expand Down Expand Up @@ -64,6 +64,7 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/consolidateunspents', () =
awmServerCaCert: 'test-cert',
tlsMode: TlsMode.DISABLED,
clientCertAllowSelfSigned: true,
asyncModeConfig: DEFAULT_ASYNC_MODE_CONFIG,
};

const app = expressApp(config);
Expand Down
6 changes: 5 additions & 1 deletion src/__tests__/api/master/generateWallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Environments } from '@bitgo-beta/sdk-core';
import { BitGoAPI } from '@bitgo-beta/sdk-api';
import * as middleware from '../../../shared/middleware';
import { BitGoRequest } from '../../../types/request';
import { BitGoAPITestHarness } from './testUtils';
import { BitGoAPITestHarness, DEFAULT_ASYNC_MODE_CONFIG } from './testUtils';

function mockWalletResponse(id: string, coinName: string, overrides: Record<string, unknown> = {}) {
return {
Expand Down Expand Up @@ -86,6 +86,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
awmServerCaCert: 'dummy-cert',
tlsMode: TlsMode.DISABLED,
clientCertAllowSelfSigned: true,
asyncModeConfig: DEFAULT_ASYNC_MODE_CONFIG,
};

// Setup middleware stubs before creating app
Expand Down Expand Up @@ -125,6 +126,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
awmServerCaCert: 'dummy-cert',
tlsMode: TlsMode.DISABLED,
clientCertAllowSelfSigned: true,
asyncModeConfig: DEFAULT_ASYNC_MODE_CONFIG,
};

sinon.stub(middleware, 'prepareBitGo').callsFake(() => (req, res, next) => {
Expand Down Expand Up @@ -366,6 +368,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
awmServerCaCert: 'dummy-cert',
tlsMode: TlsMode.DISABLED,
clientCertAllowSelfSigned: true,
asyncModeConfig: DEFAULT_ASYNC_MODE_CONFIG,
};

sinon.stub(middleware, 'prepareBitGo').callsFake(() => (req, res, next) => {
Expand Down Expand Up @@ -1018,6 +1021,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
awmServerCaCert: 'dummy-cert',
tlsMode: TlsMode.DISABLED,
clientCertAllowSelfSigned: true,
asyncModeConfig: DEFAULT_ASYNC_MODE_CONFIG,
};

sinon.stub(middleware, 'prepareBitGo').callsFake(() => (req, res, next) => {
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/api/master/musigRecovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as request from 'supertest';
import { app as expressApp } from '../../../masterBitGoExpressApp';
import { AppMode, MasterExpressConfig, TlsMode } from '../../../shared/types';
import { data as ethRecoveryData } from '../../mocks/ethRecoveryMusigMockData';
import { BitGoAPITestHarness } from './testUtils';
import { BitGoAPITestHarness, DEFAULT_ASYNC_MODE_CONFIG } from './testUtils';

describe('POST /api/v1/:coin/advancedwallet/recovery', () => {
let agent: request.SuperAgentTest;
Expand All @@ -32,6 +32,7 @@ describe('POST /api/v1/:coin/advancedwallet/recovery', () => {
tlsMode: TlsMode.DISABLED,
clientCertAllowSelfSigned: true,
recoveryMode: true,
asyncModeConfig: DEFAULT_ASYNC_MODE_CONFIG,
};

const app = expressApp(config);
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/api/master/nonRecovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import nock from 'nock';
import sinon from 'sinon';
import { app as expressApp } from '../../../masterBitGoExpressApp';
import { AppMode, MasterExpressConfig, TlsMode } from '../../../shared/types';
import { BitGoAPITestHarness } from './testUtils';
import { BitGoAPITestHarness, DEFAULT_ASYNC_MODE_CONFIG } from './testUtils';

describe('Non Recovery Tests', () => {
let agent: request.SuperAgentTest;
Expand All @@ -24,6 +24,7 @@ describe('Non Recovery Tests', () => {
httpLoggerFile: '',
clientCertAllowSelfSigned: true,
recoveryMode: false,
asyncModeConfig: DEFAULT_ASYNC_MODE_CONFIG,
};

before(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import nock from 'nock';
import { app as expressApp } from '../../../masterBitGoExpressApp';
import { AppMode, MasterExpressConfig, TlsMode } from '../../../shared/types';
import { Trx } from '@bitgo-beta/sdk-coin-trx';
import { BitGoAPITestHarness } from './testUtils';
import { BitGoAPITestHarness, DEFAULT_ASYNC_MODE_CONFIG } from './testUtils';

describe('POST /api/v1/:coin/advancedwallet/recoveryconsolidations', () => {
let agent: request.SuperAgentTest;
Expand Down Expand Up @@ -143,6 +143,7 @@ describe('POST /api/v1/:coin/advancedwallet/recoveryconsolidations', () => {
tlsMode: TlsMode.DISABLED,
clientCertAllowSelfSigned: true,
recoveryMode: true,
asyncModeConfig: DEFAULT_ASYNC_MODE_CONFIG,
};
const app = expressApp(config);
agent = request.agent(app);
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/api/master/recoveryWallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import nock from 'nock';
import sinon from 'sinon';
import { app as expressApp } from '../../../masterBitGoExpressApp';
import { AppMode, MasterExpressConfig, TlsMode } from '../../../shared/types';
import { BitGoAPITestHarness } from './testUtils';
import { BitGoAPITestHarness, DEFAULT_ASYNC_MODE_CONFIG } from './testUtils';

describe('Recovery Tests', () => {
let agent: request.SuperAgentTest;
Expand All @@ -24,6 +24,7 @@ describe('Recovery Tests', () => {
tlsMode: TlsMode.DISABLED,
clientCertAllowSelfSigned: true,
recoveryMode: true,
asyncModeConfig: DEFAULT_ASYNC_MODE_CONFIG,
};

before(() => {
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/api/master/recoveryWalletMpcV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import nock from 'nock';
import sinon from 'sinon';
import { app as expressApp } from '../../../masterBitGoExpressApp';
import { AppMode, MasterExpressConfig, TlsMode } from '../../../shared/types';
import { BitGoAPITestHarness } from './testUtils';
import { BitGoAPITestHarness, DEFAULT_ASYNC_MODE_CONFIG } from './testUtils';

describe('MBE mpcv2 recovery', () => {
let agent: request.SuperAgentTest;
Expand All @@ -31,6 +31,7 @@ describe('MBE mpcv2 recovery', () => {
tlsMode: TlsMode.DISABLED,
clientCertAllowSelfSigned: true,
recoveryMode: true,
asyncModeConfig: DEFAULT_ASYNC_MODE_CONFIG,
};

const app = expressApp(config);
Expand Down
8 changes: 7 additions & 1 deletion src/__tests__/api/master/sendMany.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import * as utxolib from '@bitgo-beta/utxo-lib';
import { Tbtc } from '@bitgo-beta/sdk-coin-btc';
import { Tsol } from '@bitgo-beta/sdk-coin-sol';
import assert from 'assert';
import { BitGoAPITestHarness, nockEcdsaMpcv2SendManySigningFlow } from './testUtils';
import {
BitGoAPITestHarness,
DEFAULT_ASYNC_MODE_CONFIG,
nockEcdsaMpcv2SendManySigningFlow,
} from './testUtils';

const testWalletId = 'test-wallet-id';
const testBitgoApiUrl = Environments.test.uri;
Expand Down Expand Up @@ -129,6 +133,7 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/sendMany', () => {
awmServerCaCert: 'dummy-cert',
tlsMode: TlsMode.DISABLED,
clientCertAllowSelfSigned: true,
asyncModeConfig: DEFAULT_ASYNC_MODE_CONFIG,
};

const app = expressApp(config);
Expand Down Expand Up @@ -812,6 +817,7 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/sendMany', () => {
authVersion: 2,
tlsMode: TlsMode.DISABLED,
clientCertAllowSelfSigned: true,
asyncModeConfig: DEFAULT_ASYNC_MODE_CONFIG,
};

try {
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/api/master/signAndSendTxRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
DEFAULT_ECDSA_MPCV2_TX_REQUEST_ID,
DEFAULT_ECDSA_MPCV2_WALLET_ID,
nockEcdsaMpcv2SigningFlow,
DEFAULT_ASYNC_MODE_CONFIG,
} from './testUtils';

const walletId = DEFAULT_ECDSA_MPCV2_WALLET_ID;
Expand Down Expand Up @@ -40,6 +41,7 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/txrequest/:txRequestId/sig
awmServerCaCert: 'dummy-cert',
tlsMode: TlsMode.DISABLED,
clientCertAllowSelfSigned: true,
asyncModeConfig: DEFAULT_ASYNC_MODE_CONFIG,
};

const app = expressApp(config);
Expand Down
9 changes: 9 additions & 0 deletions src/__tests__/api/master/testUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { BitGoAPI } from '@bitgo-beta/sdk-api';
import { SignatureShareRecord, SignatureShareType } from '@bitgo-beta/sdk-core';
import nock from 'nock';
import { AsyncModeConfig } from '../../../shared/types';

export const DEFAULT_ASYNC_MODE_CONFIG: AsyncModeConfig = {
enabled: false,
awmAsyncUrl: '',
pollIntervalInMs: 30000,
jobTtlInSeconds: 3600,
jobTtlMpcInSeconds: 7200,
};

export class BitGoAPITestHarness extends BitGoAPI {
static clearConstantsCache(): void {
Expand Down
87 changes: 87 additions & 0 deletions src/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ describe('Configuration', () => {
delete process.env.AWM_BACKUP_CLIENT_TLS_CERT_PATH;
delete process.env.AWM_BACKUP_CLIENT_TLS_KEY;
delete process.env.AWM_BACKUP_CLIENT_TLS_CERT;
delete process.env.ASYNC_MODE;
delete process.env.AWM_ASYNC_URL;
delete process.env.MBE_POLL_INTERVAL_MS;
delete process.env.MBE_JOB_TTL_S;
delete process.env.MBE_JOB_TTL_MPC_S;
});

after(() => {
Expand Down Expand Up @@ -650,5 +655,87 @@ describe('Configuration', () => {
(cfg.awmBackupClientTlsCert === undefined).should.be.true();
}
});

it('should default asyncModeConfig to disabled with default values', () => {
process.env.TLS_MODE = 'disabled';
const cfg = initConfig();
isMasterExpressConfig(cfg).should.be.true();
if (isMasterExpressConfig(cfg)) {
cfg.asyncModeConfig.enabled.should.be.false();
cfg.asyncModeConfig.awmAsyncUrl.should.equal('');
cfg.asyncModeConfig.pollIntervalInMs.should.equal(30000);
cfg.asyncModeConfig.jobTtlInSeconds.should.equal(3600);
cfg.asyncModeConfig.jobTtlMpcInSeconds.should.equal(7200);
}
});

it('should load asyncModeConfig from env vars when ASYNC_MODE is true', () => {
process.env.TLS_MODE = 'disabled';
process.env.ASYNC_MODE = 'true';
process.env.AWM_ASYNC_URL = 'http://awm-async:8080';
process.env.MBE_POLL_INTERVAL_MS = '5000';
process.env.MBE_JOB_TTL_S = '1800';
process.env.MBE_JOB_TTL_MPC_S = '3600';
const cfg = initConfig();
isMasterExpressConfig(cfg).should.be.true();
if (isMasterExpressConfig(cfg)) {
cfg.asyncModeConfig.enabled.should.be.true();
cfg.asyncModeConfig.awmAsyncUrl.should.equal('http://awm-async:8080');
cfg.asyncModeConfig.pollIntervalInMs.should.equal(5000);
cfg.asyncModeConfig.jobTtlInSeconds.should.equal(1800);
cfg.asyncModeConfig.jobTtlMpcInSeconds.should.equal(3600);
}
});

it('should use default numeric values when async mode numeric env vars are not set', () => {
process.env.TLS_MODE = 'disabled';
process.env.ASYNC_MODE = 'true';
process.env.AWM_ASYNC_URL = 'http://awm-async:8080';
const cfg = initConfig();
isMasterExpressConfig(cfg).should.be.true();
if (isMasterExpressConfig(cfg)) {
cfg.asyncModeConfig.pollIntervalInMs.should.equal(30000);
cfg.asyncModeConfig.jobTtlInSeconds.should.equal(3600);
cfg.asyncModeConfig.jobTtlMpcInSeconds.should.equal(7200);
}
});

it('should throw when ASYNC_MODE is true but AWM_ASYNC_URL is missing', () => {
process.env.TLS_MODE = 'disabled';
process.env.ASYNC_MODE = 'true';
(() => initConfig()).should.throw('AWM_ASYNC_URL is required when ASYNC_MODE is true');
});

it('should allow missing ADVANCED_WALLET_MANAGER_URL when ASYNC_MODE is true', () => {
process.env.TLS_MODE = 'disabled';
process.env.ASYNC_MODE = 'true';
process.env.AWM_ASYNC_URL = 'http://awm-async:8080';
delete process.env.ADVANCED_WALLET_MANAGER_URL;
(() => initConfig()).should.not.throw();
});

it('should throw when MBE_POLL_INTERVAL_MS is negative', () => {
process.env.TLS_MODE = 'disabled';
process.env.ASYNC_MODE = 'true';
process.env.AWM_ASYNC_URL = 'http://awm-async:8080';
process.env.MBE_POLL_INTERVAL_MS = '-1';
(() => initConfig()).should.throw('MBE_POLL_INTERVAL_MS must be a positive number, got -1');
});

it('should throw when MBE_JOB_TTL_S is negative', () => {
process.env.TLS_MODE = 'disabled';
process.env.ASYNC_MODE = 'true';
process.env.AWM_ASYNC_URL = 'http://awm-async:8080';
process.env.MBE_JOB_TTL_S = '-1';
(() => initConfig()).should.throw('MBE_JOB_TTL_S must be a positive number, got -1');
});

it('should throw when MBE_JOB_TTL_MPC_S is negative', () => {
process.env.TLS_MODE = 'disabled';
process.env.ASYNC_MODE = 'true';
process.env.AWM_ASYNC_URL = 'http://awm-async:8080';
process.env.MBE_JOB_TTL_MPC_S = '-1';
(() => initConfig()).should.throw('MBE_JOB_TTL_MPC_S must be a positive number, got -1');
});
});
});
2 changes: 2 additions & 0 deletions src/__tests__/integration/health.integ.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as http from 'http';
import { app as awmApp } from '../../advancedWalletManagerApp';
import { app as mbeApp } from '../../masterBitGoExpressApp';
import { AppMode, TlsMode, SigningMode } from '../../shared/types';
import { DEFAULT_ASYNC_MODE_CONFIG } from '../api/master/testUtils';
import { listen, close, LOCALHOST } from './helpers/servers';

describe('Integration Test — health checks', () => {
Expand Down Expand Up @@ -38,6 +39,7 @@ describe('Integration Test — health checks', () => {
disableEnvCheck: true,
advancedWalletManagerUrl: `http://${LOCALHOST}:${awmPort}`,
awmServerCertAllowSelfSigned: true,
asyncModeConfig: DEFAULT_ASYNC_MODE_CONFIG,
}),
);
mbePort = await listen(mbeServer);
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/integration/helpers/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as http from 'http';
import { app as awmApp } from '../../../advancedWalletManagerApp';
import { app as mbeApp } from '../../../masterBitGoExpressApp';
import { AppMode, TlsMode, SigningMode } from '../../../shared/types';
import { DEFAULT_ASYNC_MODE_CONFIG } from '../../api/master/testUtils';
import { listen, close, LOCALHOST } from './servers';
import { startMockKeyProviderServer, MockKeyProviderServer } from './mockKeyProviderServer';
import { startMockBitgoServer, MockBitgoServer } from './mockBitgoServer';
Expand Down Expand Up @@ -50,6 +51,7 @@ export async function startServices(opts: StartServicesOptions = {}): Promise<In
advancedWalletManagerUrl: `http://${LOCALHOST}:${awmPort}`,
awmServerCertAllowSelfSigned: true,
customRootUri: `http://${LOCALHOST}:${bitgo.port}`,
asyncModeConfig: DEFAULT_ASYNC_MODE_CONFIG,
}),
);
const mbePort = await listen(mbeServer);
Expand Down
Loading
Loading