Skip to content

Commit

Permalink
fix(sdk): throw error on sendmany API call when recipients greater th…
Browse files Browse the repository at this point in the history
…an 1

TICKET: COIN-1958
  • Loading branch information
nvrakesh06 committed Oct 28, 2024
1 parent c323e7e commit 5f4aa1d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
10 changes: 9 additions & 1 deletion modules/sdk-coin-celo/src/celo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @prettier
*/
import { BaseCoin, BitGoBase } from '@bitgo/sdk-core';
import { BaseCoin, BitGoBase, VerifyTransactionOptions } from '@bitgo/sdk-core';
import { BaseCoin as StaticsBaseCoin, coins } from '@bitgo/statics';
import { AbstractEthLikeCoin } from '@bitgo/abstract-eth';
import { KeyPair, TransactionBuilder } from './lib';
Expand All @@ -28,4 +28,12 @@ export class Celo extends AbstractEthLikeCoin {
protected getTransactionBuilder(): TransactionBuilder {
return new TransactionBuilder(coins.get(this.getBaseChain()));
}

async verifyTransaction(params: VerifyTransactionOptions): Promise<boolean> {
const { txParams } = params;
if (txParams?.recipients?.length !== 1) {
throw new Error(`txParams should only have 1 recipient but ${txParams?.recipients?.length} found`);
}
return true;
}
}
24 changes: 24 additions & 0 deletions modules/sdk-coin-celo/test/unit/celo.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test';
import { BitGoAPI } from '@bitgo/sdk-api';
import { Celo, Tcelo } from '../../src';
import { Wallet } from '@bitgo/sdk-core';

describe('Celo Gold', function () {
let bitgo: TestBitGoAPI;
let basecoin;

before(function () {
bitgo = TestBitGo.decorate(BitGoAPI, { env: 'mock' });
bitgo.safeRegister('tcelo', Tcelo.createInstance);
bitgo.safeRegister('celo', Celo.createInstance);
bitgo.initializeTestVars();
basecoin = bitgo.coin('celo');
});

it('should instantiate the coin', function () {
Expand All @@ -19,4 +22,25 @@ describe('Celo Gold', function () {
localBasecoin = bitgo.coin('celo');
localBasecoin.should.be.an.instanceof(Celo);
});

describe('Verify Transaction', function () {
const address1 = '5Ge59qRnZa8bxyhVFE6BDoY3kuhSrNVETRxXYLty1Hh6XTaf';
const address2 = '5DiMLZugmcKEH3igPZP367FqummZkWeW5Z6zDCHLfxRjnPXe';
it('should reject a txPrebuild with more than one recipient', async function () {
const wallet = new Wallet(bitgo, basecoin, {});

const txParams = {
recipients: [
{ amount: '1000000000000', address: address1 },
{ amount: '2500000000000', address: address2 },
],
wallet: wallet,
walletPassphrase: 'fakeWalletPassphrase',
};

await basecoin
.verifyTransaction({ txParams })
.should.be.rejectedWith('txParams should only have 1 recipient but 2 found');
});
});
});
4 changes: 4 additions & 0 deletions modules/sdk-coin-xtz/src/xtz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ export class Xtz extends BaseCoin {
}

async verifyTransaction(params: VerifyTransactionOptions): Promise<boolean> {
const { txParams } = params;
if (txParams?.recipients?.length !== 1) {
throw new Error(`txParams should only have 1 recipient but ${txParams?.recipients?.length} found`);
}
return true;
}

Expand Down
22 changes: 22 additions & 0 deletions modules/sdk-coin-xtz/test/unit/xtz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
unsignedHex,
unsignedTransactionWithTwoTransfersHex,
} from '../fixtures';
import { Wallet } from '@bitgo/sdk-core';

const bitgo: TestBitGoAPI = TestBitGo.decorate(BitGoAPI, { env: 'test' });
bitgo.safeRegister('xtz', Xtz.createInstance);
Expand Down Expand Up @@ -199,4 +200,25 @@ describe('Tezos:', function () {
isValid.should.equal(false);
});
});

describe('Verify Transaction', function () {
const address1 = '5Ge59qRnZa8bxyhVFE6BDoY3kuhSrNVETRxXYLty1Hh6XTaf';
const address2 = '5DiMLZugmcKEH3igPZP367FqummZkWeW5Z6zDCHLfxRjnPXe';
it('should reject a txPrebuild with more than one recipient', async function () {
const wallet = new Wallet(bitgo, basecoin, {});

const txParams = {
recipients: [
{ amount: '1000000000000', address: address1 },
{ amount: '2500000000000', address: address2 },
],
wallet: wallet,
walletPassphrase: 'fakeWalletPassphrase',
};

await basecoin
.verifyTransaction({ txParams })
.should.be.rejectedWith('txParams should only have 1 recipient but 2 found');
});
});
});

0 comments on commit 5f4aa1d

Please sign in to comment.