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 modules/express/src/clientRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
GetNetworkPartnersResponse,
GShare,
MPCType,
multisigTypes,
ShareType,
SignShare,
SShare,
Expand Down Expand Up @@ -816,7 +817,7 @@ export async function handleV2ConsolidateAccount(

let result: any;
try {
if (coin.supportsTss()) {
if (wallet._wallet.multisigType === multisigTypes.tss) {
result = await wallet.sendAccountConsolidations(createTSSSendParams(req, wallet));
} else {
result = await wallet.sendAccountConsolidations(createSendParams(req));
Expand Down
43 changes: 39 additions & 4 deletions modules/express/test/unit/clientRoutes/consolidateAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as express from 'express';
import { handleV2ConsolidateAccount } from '../../../src/clientRoutes';

import { BitGo } from 'bitgo';
import { MultisigType } from '@bitgo/sdk-core';

describe('Consolidate account', () => {
it('should fail if coin does not allow consolidation', async () => {
Expand Down Expand Up @@ -71,11 +72,13 @@ describe('Consolidate account', () => {
);
});

function createConsolidateMocks(res, allowsAccountConsolidations = false, supportsTss = false) {
function createConsolidateMocks(res, allowsAccountConsolidations = false, multisigType: MultisigType = 'onchain') {
const consolidationStub = sinon.stub().returns(res);
const walletStub = { sendAccountConsolidations: consolidationStub };
const walletStub = {
sendAccountConsolidations: consolidationStub,
_wallet: { multisigType },
};
const coinStub = {
supportsTss: () => supportsTss,
allowsAccountConsolidations: () => allowsAccountConsolidations,
wallets: () => ({ get: () => Promise.resolve(walletStub) }),
};
Expand Down Expand Up @@ -108,7 +111,7 @@ describe('Consolidate account', () => {
it('should pass the apiVersion param to bitgo api consolidate/build', async () => {
const result = { success: [], failure: [] };
const body = { apiVersion: 'full' };
const { bitgoStub, consolidationStub } = createConsolidateMocks(result, true, true);
const { bitgoStub, consolidationStub } = createConsolidateMocks(result, true, 'tss');
const mockRequest = {
bitgo: bitgoStub,
decoded: {
Expand All @@ -124,6 +127,38 @@ describe('Consolidate account', () => {
consolidationStub.should.be.calledOnceWith(body);
});

it('should use on-chain signing params for a TRX on-chain wallet even though TRX supportsTss', async () => {
const result = { failure: [] };
const body = { consolidateAddresses: ['addr1'] };
const { bitgoStub, consolidationStub } = createConsolidateMocks(result, true, 'onchain');
const mockRequest = {
bitgo: bitgoStub,
decoded: { coin: 'ttrx', id: '23423423423423' },
body,
};

await handleV2ConsolidateAccount(mockRequest as express.Request & typeof mockRequest).should.be.resolvedWith(
result
);
consolidationStub.should.be.calledOnceWith(body);
});

it('should use TSS signing params for a TRX TSS wallet', async () => {
const result = { failure: [] };
const body = { consolidateAddresses: ['addr1'] };
const { bitgoStub, consolidationStub } = createConsolidateMocks(result, true, 'tss');
const mockRequest = {
bitgo: bitgoStub,
decoded: { coin: 'ttrx', id: '23423423423423' },
body,
};

await handleV2ConsolidateAccount(mockRequest as express.Request & typeof mockRequest).should.be.resolvedWith(
result
);
consolidationStub.should.be.calledOnceWith(body);
});

it('should return 202 when some transactions fail', async () => {
const result = { success: [0], failure: [0] };
const body = 'testbody';
Expand Down
15 changes: 15 additions & 0 deletions modules/express/test/unit/typedRoutes/consolidateAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ describe('Consolidate Account API Tests', function () {

const mockWallet = {
sendAccountConsolidations: sinon.stub().resolves(mockSuccessResponse),
_wallet: { multisigType: 'onchain' },
};

const mockCoin = {
Expand Down Expand Up @@ -217,6 +218,7 @@ describe('Consolidate Account API Tests', function () {

const mockWallet = {
sendAccountConsolidations: sinon.stub().resolves(mockSuccessResponse),
_wallet: { multisigType: 'onchain' },
};

const mockCoin = {
Expand Down Expand Up @@ -250,6 +252,7 @@ describe('Consolidate Account API Tests', function () {

const mockWallet = {
sendAccountConsolidations: sinon.stub().resolves(mockSuccessResponse),
_wallet: { multisigType: 'onchain' },
};

const mockCoin = {
Expand Down Expand Up @@ -286,6 +289,7 @@ describe('Consolidate Account API Tests', function () {

const mockWallet = {
sendAccountConsolidations: sinon.stub().resolves(mockSuccessResponse),
_wallet: { multisigType: 'onchain' },
};

const mockCoin = {
Expand Down Expand Up @@ -329,6 +333,7 @@ describe('Consolidate Account API Tests', function () {

const mockWallet = {
sendAccountConsolidations: sinon.stub().resolves(mockMultipleSuccess),
_wallet: { multisigType: 'onchain' },
};

const mockCoin = {
Expand Down Expand Up @@ -367,6 +372,7 @@ describe('Consolidate Account API Tests', function () {

const mockWallet = {
sendAccountConsolidations: sinon.stub().resolves(mockPartialSuccess),
_wallet: { multisigType: 'onchain' },
};

const mockCoin = {
Expand Down Expand Up @@ -410,6 +416,7 @@ describe('Consolidate Account API Tests', function () {

const mockWallet = {
sendAccountConsolidations: sinon.stub().resolves(mockAllFailed),
_wallet: { multisigType: 'onchain' },
};

const mockCoin = {
Expand Down Expand Up @@ -494,6 +501,7 @@ describe('Consolidate Account API Tests', function () {

const mockWallet = {
sendAccountConsolidations: sinon.stub().rejects(new Error('Invalid passphrase')),
_wallet: { multisigType: 'onchain' },
};

const mockCoin = {
Expand Down Expand Up @@ -523,6 +531,7 @@ describe('Consolidate Account API Tests', function () {

const mockWallet = {
sendAccountConsolidations: sinon.stub().rejects(new Error('Insufficient funds')),
_wallet: { multisigType: 'onchain' },
};

const mockCoin = {
Expand Down Expand Up @@ -621,6 +630,7 @@ describe('Consolidate Account API Tests', function () {

const mockWallet = {
sendAccountConsolidations: sinon.stub().resolves(mockSuccessResponse),
_wallet: { multisigType: 'onchain' },
};

const mockCoin = {
Expand Down Expand Up @@ -655,6 +665,7 @@ describe('Consolidate Account API Tests', function () {

const mockWallet = {
sendAccountConsolidations: sinon.stub().resolves(mockSuccessResponse),
_wallet: { multisigType: 'onchain' },
};

const mockCoin = {
Expand Down Expand Up @@ -691,6 +702,7 @@ describe('Consolidate Account API Tests', function () {

const mockWallet = {
sendAccountConsolidations: sinon.stub().resolves(mockSuccessResponse),
_wallet: { multisigType: 'onchain' },
};

const mockCoin = {
Expand Down Expand Up @@ -726,6 +738,7 @@ describe('Consolidate Account API Tests', function () {

const mockWallet = {
sendAccountConsolidations: sinon.stub().resolves(mockSuccessResponse),
_wallet: { multisigType: 'onchain' },
};

const mockCoin = {
Expand Down Expand Up @@ -756,6 +769,7 @@ describe('Consolidate Account API Tests', function () {

const mockWallet = {
sendAccountConsolidations: sinon.stub().resolves(mockSuccessResponse),
_wallet: { multisigType: 'onchain' },
};

const mockCoin = {
Expand Down Expand Up @@ -789,6 +803,7 @@ describe('Consolidate Account API Tests', function () {

const mockWallet = {
sendAccountConsolidations: sinon.stub().resolves(mockSuccessResponse),
_wallet: { multisigType: 'onchain' },
};

const mockCoin = {
Expand Down
Loading