From 7c98f35a2da5da6708bec7cd8d3285a0518cca34 Mon Sep 17 00:00:00 2001 From: Kevin Cheng Date: Thu, 26 Sep 2024 12:01:45 -0400 Subject: [PATCH 1/3] feat(sdk-core): add new param to fanout interface TICKET: BTC-1501 --- modules/bitgo/test/v2/unit/wallet.ts | 22 +++++++++++++++++++- modules/sdk-core/src/bitgo/wallet/iWallet.ts | 1 + modules/sdk-core/src/bitgo/wallet/wallet.ts | 3 ++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/modules/bitgo/test/v2/unit/wallet.ts b/modules/bitgo/test/v2/unit/wallet.ts index 885f1cedb4..0c8b621485 100644 --- a/modules/bitgo/test/v2/unit/wallet.ts +++ b/modules/bitgo/test/v2/unit/wallet.ts @@ -1461,9 +1461,13 @@ describe('V2 Wallet:', function () { }); }); - describe('maxNumInputsToUse verification', function () { + describe('fanout input maxNumInputsToUse and unspents verification', function () { const address = '5b34252f1bf349930e34020a'; const maxNumInputsToUse = 2; + const unspents = [ + 'cc30565750e2aeb818625aaedaf89db5c614e5977b9645cee1d7289f616fb1d8:0', + '8c45164787a954ab07864af9b05b34fbde3a8e430a8c65b0e60e4e543d8e1b6c:2', + ]; let basecoin; let wallet; @@ -1492,6 +1496,22 @@ describe('V2 Wallet:', function () { response.isDone().should.be.true(); }); + + it('should pass unspents parameter when calling fanout unspents', async function () { + const path = `/api/v2/${wallet.coin()}/wallet/${wallet.id()}/fanoutUnspents`; + const response = nock(bgUrl) + .post(path, _.matches({ unspents })) // use _.matches to do a partial match on request body object instead of strict matching + .reply(200); + + try { + await wallet.fanoutUnspents({ address, unspents }); + } catch (e) { + // the fanoutUnspents method will probably throw an exception for not having all of the correct nocks + // we only care about /fanoutUnspents and whether unspents is an allowed parameter + } + + response.isDone().should.be.true(); + }); }); describe('manage unspents', function () { diff --git a/modules/sdk-core/src/bitgo/wallet/iWallet.ts b/modules/sdk-core/src/bitgo/wallet/iWallet.ts index 608a8fa652..98d05f5d35 100644 --- a/modules/sdk-core/src/bitgo/wallet/iWallet.ts +++ b/modules/sdk-core/src/bitgo/wallet/iWallet.ts @@ -341,6 +341,7 @@ export interface FanoutUnspentsOptions extends WalletSignTransactionOptions { maxValue?: number | string; minHeight?: number; maxNumInputsToUse?: number; + unspents?: string[]; numUnspentsToMake?: number; minConfirms?: number; enforceMinConfirmsForChange?: boolean; diff --git a/modules/sdk-core/src/bitgo/wallet/wallet.ts b/modules/sdk-core/src/bitgo/wallet/wallet.ts index 9d7a88e28e..643543372b 100644 --- a/modules/sdk-core/src/bitgo/wallet/wallet.ts +++ b/modules/sdk-core/src/bitgo/wallet/wallet.ts @@ -680,6 +680,7 @@ export class Wallet implements IWallet { common.validateParams(params, [], ['walletPassphrase', 'xprv']); const reqId = new RequestTracer(); + const fanoutInputFormat = params.maxNumInputsToUse ? 'maxNumInputsToUse' : 'unspents'; const filteredParams = _.pick(params, [ 'feeRate', 'maxFeeRate', @@ -695,7 +696,7 @@ export class Wallet implements IWallet { 'txFormat', 'bulk', - routeName === 'consolidate' ? 'limit' : 'maxNumInputsToUse', + routeName === 'consolidate' ? 'limit' : fanoutInputFormat, 'numUnspentsToMake', ]); this.bitgo.setRequestTracer(reqId); From 54bd2b7185f0749fde939cf84273adb3f71441df Mon Sep 17 00:00:00 2001 From: Kevin Cheng Date: Thu, 26 Sep 2024 14:43:52 -0400 Subject: [PATCH 2/3] fix(sdk-core): merge unit tests TICKET: BTC-1501 --- modules/bitgo/test/v2/unit/wallet.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/bitgo/test/v2/unit/wallet.ts b/modules/bitgo/test/v2/unit/wallet.ts index 0c8b621485..69e912660f 100644 --- a/modules/bitgo/test/v2/unit/wallet.ts +++ b/modules/bitgo/test/v2/unit/wallet.ts @@ -1500,12 +1500,16 @@ describe('V2 Wallet:', function () { it('should pass unspents parameter when calling fanout unspents', async function () { const path = `/api/v2/${wallet.coin()}/wallet/${wallet.id()}/fanoutUnspents`; const response = nock(bgUrl) + .persist() .post(path, _.matches({ unspents })) // use _.matches to do a partial match on request body object instead of strict matching .reply(200); try { + console.log('try fanout'); await wallet.fanoutUnspents({ address, unspents }); + console.log(response); } catch (e) { + console.log(e); // the fanoutUnspents method will probably throw an exception for not having all of the correct nocks // we only care about /fanoutUnspents and whether unspents is an allowed parameter } From dc22770e987e3de98e6e18f1fd585f1756a89f1e Mon Sep 17 00:00:00 2001 From: Kevin Cheng Date: Thu, 26 Sep 2024 14:45:21 -0400 Subject: [PATCH 3/3] fix(sdk-core): remove logs TICKET: BTC-1501 --- modules/bitgo/test/v2/unit/wallet.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/bitgo/test/v2/unit/wallet.ts b/modules/bitgo/test/v2/unit/wallet.ts index 69e912660f..0f0317f6cf 100644 --- a/modules/bitgo/test/v2/unit/wallet.ts +++ b/modules/bitgo/test/v2/unit/wallet.ts @@ -1505,11 +1505,8 @@ describe('V2 Wallet:', function () { .reply(200); try { - console.log('try fanout'); await wallet.fanoutUnspents({ address, unspents }); - console.log(response); } catch (e) { - console.log(e); // the fanoutUnspents method will probably throw an exception for not having all of the correct nocks // we only care about /fanoutUnspents and whether unspents is an allowed parameter }