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
35 changes: 35 additions & 0 deletions modules/bitgo/test/v2/unit/accountConsolidations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,46 @@ describe('Account Consolidations:', function () {

consolidations.success.length.should.equal(1);
consolidations.failure.length.should.equal(1);
consolidations.failure[0].should.have.property('message');
consolidations.failure[0].should.have.property('name');

scopeWithSuccess.isDone().should.be.True();
scopeWithError.isDone().should.be.True();
scopeBuild.isDone().should.be.True();
});

it('should return serializable error objects in the failure array', async function () {
const scopeBuild = nock(bgUrl)
.post(`/api/v2/${wallet.coin()}/wallet/${wallet.id()}/consolidateAccount/build`)
.query({})
.reply(200, fixtures.buildAccountConsolidation);

sinon.stub(wallet, 'getKeychainsAndValidatePassphrase').resolves([]);

const firstError = new Error('unable to decrypt keychain with the given wallet passphrase');
firstError.name = 'KeyDecryptionError';
const secondError = new Error('insufficient funds');
secondError.name = 'InsufficientFundsError';

sinon.stub(wallet, 'sendAccountConsolidation').onCall(0).rejects(firstError).onCall(1).rejects(secondError);

const consolidations = await wallet.sendAccountConsolidations();

consolidations.failure.length.should.equal(2);

// failure entries must be plain serializable objects, not Error instances
(consolidations.failure[0] instanceof Error).should.be.False();
consolidations.failure[0].message.should.equal('unable to decrypt keychain with the given wallet passphrase');
consolidations.failure[0].name.should.equal('KeyDecryptionError');
JSON.stringify(consolidations.failure[0]).should.not.equal('{}');

(consolidations.failure[1] instanceof Error).should.be.False();
consolidations.failure[1].message.should.equal('insufficient funds');
consolidations.failure[1].name.should.equal('InsufficientFundsError');
JSON.stringify(consolidations.failure[1]).should.not.equal('{}');

scopeBuild.isDone().should.be.True();
});
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-core/src/bitgo/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3389,7 +3389,7 @@ export class Wallet implements IWallet {
}
}
const successfulTxs: any[] = [];
const failedTxs = new Array<Error>();
const failedTxs: { message: string; name: string }[] = [];
for (const unsignedBuild of unsignedBuilds) {
// fold any of the parameters we used to build this transaction into the unsignedBuild
const unsignedBuildWithOptions: PrebuildAndSignTransactionOptions = Object.assign({}, params);
Expand All @@ -3399,7 +3399,7 @@ export class Wallet implements IWallet {
const sendTx = await this.sendAccountConsolidation(unsignedBuildWithOptions);
successfulTxs.push(sendTx);
} catch (e) {
failedTxs.push(e);
failedTxs.push({ message: e.message, name: e.name });
}
}

Expand Down
Loading