@@ -66,16 +66,10 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
6666
6767 let bitgo : BitGoAPI ;
6868
69- before ( ( ) => {
70- nock . disableNetConnect ( ) ;
71- nock . enableNetConnect ( '127.0.0.1' ) ;
72-
73- // Create a BitGo instance that we'll use for stubbing
74- bitgo = new BitGoAPI ( { env : 'test' } ) ;
75-
76- const config : MasterExpressConfig = {
69+ function makeConfig ( overrides : Partial < MasterExpressConfig > = { } ) : MasterExpressConfig {
70+ return {
7771 appMode : AppMode . MASTER_EXPRESS ,
78- port : 0 , // Let OS assign a free port
72+ port : 0 ,
7973 bind : 'localhost' ,
8074 timeout : 60000 ,
8175 httpLoggerFile : '' ,
@@ -87,7 +81,17 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
8781 tlsMode : TlsMode . DISABLED ,
8882 clientCertAllowSelfSigned : true ,
8983 asyncModeConfig : DEFAULT_ASYNC_MODE_CONFIG ,
84+ ...overrides ,
9085 } ;
86+ }
87+
88+ before ( ( ) => {
89+ nock . disableNetConnect ( ) ;
90+ nock . enableNetConnect ( '127.0.0.1' ) ;
91+
92+ bitgo = new BitGoAPI ( { env : 'test' } ) ;
93+
94+ const config = makeConfig ( ) ;
9195
9296 // Setup middleware stubs before creating app
9397 sinon . stub ( middleware , 'prepareBitGo' ) . callsFake ( ( ) => ( req , res , next ) => {
@@ -109,25 +113,9 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
109113 it ( 'should generate an onchain wallet with separate backup AWM (separate-HSM mode)' , async ( ) => {
110114 const backupAwmUrl = 'http://backup-awm.invalid' ;
111115
112- // Override middleware to inject a separate backup client
113116 sinon . restore ( ) ;
114117 const backupBitgo = new BitGoAPI ( { env : 'test' } ) ;
115- const configWithBackup : MasterExpressConfig = {
116- appMode : AppMode . MASTER_EXPRESS ,
117- port : 0 ,
118- bind : 'localhost' ,
119- timeout : 60000 ,
120- httpLoggerFile : '' ,
121- env : 'test' ,
122- disableEnvCheck : true ,
123- authVersion : 2 ,
124- advancedWalletManagerUrl : advancedWalletManagerUrl ,
125- advancedWalletManagerBackupUrl : backupAwmUrl ,
126- awmServerCaCert : 'dummy-cert' ,
127- tlsMode : TlsMode . DISABLED ,
128- clientCertAllowSelfSigned : true ,
129- asyncModeConfig : DEFAULT_ASYNC_MODE_CONFIG ,
130- } ;
118+ const configWithBackup = makeConfig ( { advancedWalletManagerBackupUrl : backupAwmUrl } ) ;
131119
132120 sinon . stub ( middleware , 'prepareBitGo' ) . callsFake ( ( ) => ( req , res , next ) => {
133121 ( req as BitGoRequest < MasterExpressConfig > ) . bitgo = backupBitgo ;
@@ -354,22 +342,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
354342 . get ( '/api/v1/client/constants' )
355343 . reply ( 200 , { constants : { mpc : { bitgoPublicKey : 'test-bitgo-public-key' } } } ) ;
356344 const backupBitgo = new BitGoAPI ( { env : 'test' } ) ;
357- const configWithBackup : MasterExpressConfig = {
358- appMode : AppMode . MASTER_EXPRESS ,
359- port : 0 ,
360- bind : 'localhost' ,
361- timeout : 60000 ,
362- httpLoggerFile : '' ,
363- env : 'test' ,
364- disableEnvCheck : true ,
365- authVersion : 2 ,
366- advancedWalletManagerUrl : advancedWalletManagerUrl ,
367- advancedWalletManagerBackupUrl : backupAwmUrl ,
368- awmServerCaCert : 'dummy-cert' ,
369- tlsMode : TlsMode . DISABLED ,
370- clientCertAllowSelfSigned : true ,
371- asyncModeConfig : DEFAULT_ASYNC_MODE_CONFIG ,
372- } ;
345+ const configWithBackup = makeConfig ( { advancedWalletManagerBackupUrl : backupAwmUrl } ) ;
373346
374347 sinon . stub ( middleware , 'prepareBitGo' ) . callsFake ( ( ) => ( req , res , next ) => {
375348 ( req as BitGoRequest < MasterExpressConfig > ) . bitgo = backupBitgo ;
@@ -1007,22 +980,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
1007980 . get ( '/api/v1/client/constants' )
1008981 . reply ( 200 , { constants : { mpc : { bitgoMPCv2PublicKey : 'test-bitgo-public-key' } } } ) ;
1009982 const backupBitgo = new BitGoAPI ( { env : 'test' } ) ;
1010- const configWithBackup : MasterExpressConfig = {
1011- appMode : AppMode . MASTER_EXPRESS ,
1012- port : 0 ,
1013- bind : 'localhost' ,
1014- timeout : 60000 ,
1015- httpLoggerFile : '' ,
1016- env : 'test' ,
1017- disableEnvCheck : true ,
1018- authVersion : 2 ,
1019- advancedWalletManagerUrl : advancedWalletManagerUrl ,
1020- advancedWalletManagerBackupUrl : backupAwmUrl ,
1021- awmServerCaCert : 'dummy-cert' ,
1022- tlsMode : TlsMode . DISABLED ,
1023- clientCertAllowSelfSigned : true ,
1024- asyncModeConfig : DEFAULT_ASYNC_MODE_CONFIG ,
1025- } ;
983+ const configWithBackup = makeConfig ( { advancedWalletManagerBackupUrl : backupAwmUrl } ) ;
1026984
1027985 sinon . stub ( middleware , 'prepareBitGo' ) . callsFake ( ( ) => ( req , res , next ) => {
1028986 ( req as BitGoRequest < MasterExpressConfig > ) . bitgo = backupBitgo ;
@@ -2420,6 +2378,44 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
24202378 bitgoKeyNock . done ( ) ;
24212379 } ) ;
24222380
2381+ it ( 'should return 202 with jobId when async mode is enabled for onchain wallet' , async ( ) => {
2382+ const bridgeUrl = 'http://bridge.invalid' ;
2383+ const jobId = 'test-job-id-123' ;
2384+
2385+ sinon . restore ( ) ;
2386+ const asyncBitgo = new BitGoAPI ( { env : 'test' } ) ;
2387+ const asyncConfig = makeConfig ( {
2388+ asyncModeConfig : {
2389+ enabled : true ,
2390+ awmAsyncUrl : bridgeUrl ,
2391+ pollIntervalInMs : 30000 ,
2392+ jobTtlInSeconds : 3600 ,
2393+ jobTtlMpcInSeconds : 7200 ,
2394+ } ,
2395+ } ) ;
2396+
2397+ sinon . stub ( middleware , 'prepareBitGo' ) . callsFake ( ( ) => ( req , res , next ) => {
2398+ ( req as BitGoRequest < MasterExpressConfig > ) . bitgo = asyncBitgo ;
2399+ ( req as BitGoRequest < MasterExpressConfig > ) . config = asyncConfig ;
2400+ next ( ) ;
2401+ } ) ;
2402+
2403+ const asyncApp = expressApp ( asyncConfig ) ;
2404+ const asyncAgent = request . agent ( asyncApp ) ;
2405+
2406+ const bridgeNock = nock ( bridgeUrl ) . post ( `/api/${ coin } /key/independent` ) . reply ( 202 , { jobId } ) ;
2407+
2408+ const response = await asyncAgent
2409+ . post ( `/api/v1/${ coin } /advancedwallet/generate` )
2410+ . set ( 'Authorization' , `Bearer ${ accessToken } ` )
2411+ . send ( { label : 'test_wallet' , enterprise : 'test_enterprise' , multisigType : 'onchain' } ) ;
2412+
2413+ response . status . should . equal ( 202 ) ;
2414+ response . body . should . have . property ( 'jobId' , jobId ) ;
2415+ response . body . should . have . property ( 'status' , 'pending' ) ;
2416+ bridgeNock . done ( ) ;
2417+ } ) ;
2418+
24232419 it ( 'should fail when evmKeyRingReferenceWalletId is provided for a non-EVM coin' , async ( ) => {
24242420 const response = await agent
24252421 . post ( `/api/v1/${ coin } /advancedwallet/generate` )
0 commit comments