Skip to content

Commit cfba04b

Browse files
authored
Merge pull request #5070 from BitGo/COIN-1958
fix(sdk) : throw error on sendmany API call when recipients > 1
2 parents 2f07c4b + a5f9630 commit cfba04b

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

modules/sdk-coin-celo/src/celo.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @prettier
33
*/
4-
import { BaseCoin, BitGoBase } from '@bitgo/sdk-core';
4+
import { BaseCoin, BitGoBase, VerifyTransactionOptions } from '@bitgo/sdk-core';
55
import { BaseCoin as StaticsBaseCoin, coins } from '@bitgo/statics';
66
import { AbstractEthLikeCoin } from '@bitgo/abstract-eth';
77
import { KeyPair, TransactionBuilder } from './lib';
@@ -28,4 +28,12 @@ export class Celo extends AbstractEthLikeCoin {
2828
protected getTransactionBuilder(): TransactionBuilder {
2929
return new TransactionBuilder(coins.get(this.getBaseChain()));
3030
}
31+
32+
async verifyTransaction(params: VerifyTransactionOptions): Promise<boolean> {
33+
const { txParams } = params;
34+
if (txParams?.recipients?.length !== 1) {
35+
throw new Error(`txParams should only have 1 recipient but ${txParams?.recipients?.length} found`);
36+
}
37+
return true;
38+
}
3139
}

modules/sdk-coin-celo/test/unit/celo.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test';
22
import { BitGoAPI } from '@bitgo/sdk-api';
33
import { Celo, Tcelo } from '../../src';
4+
import { Wallet } from '@bitgo/sdk-core';
45

56
describe('Celo Gold', function () {
67
let bitgo: TestBitGoAPI;
8+
let basecoin;
79

810
before(function () {
911
bitgo = TestBitGo.decorate(BitGoAPI, { env: 'mock' });
1012
bitgo.safeRegister('tcelo', Tcelo.createInstance);
1113
bitgo.safeRegister('celo', Celo.createInstance);
1214
bitgo.initializeTestVars();
15+
basecoin = bitgo.coin('celo');
1316
});
1417

1518
it('should instantiate the coin', function () {
@@ -19,4 +22,25 @@ describe('Celo Gold', function () {
1922
localBasecoin = bitgo.coin('celo');
2023
localBasecoin.should.be.an.instanceof(Celo);
2124
});
25+
26+
describe('Verify Transaction', function () {
27+
const address1 = '5Ge59qRnZa8bxyhVFE6BDoY3kuhSrNVETRxXYLty1Hh6XTaf';
28+
const address2 = '5DiMLZugmcKEH3igPZP367FqummZkWeW5Z6zDCHLfxRjnPXe';
29+
it('should reject a txPrebuild with more than one recipient', async function () {
30+
const wallet = new Wallet(bitgo, basecoin, {});
31+
32+
const txParams = {
33+
recipients: [
34+
{ amount: '1000000000000', address: address1 },
35+
{ amount: '2500000000000', address: address2 },
36+
],
37+
wallet: wallet,
38+
walletPassphrase: 'fakeWalletPassphrase',
39+
};
40+
41+
await basecoin
42+
.verifyTransaction({ txParams })
43+
.should.be.rejectedWith('txParams should only have 1 recipient but 2 found');
44+
});
45+
});
2246
});

modules/sdk-coin-xtz/src/xtz.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ export class Xtz extends BaseCoin {
104104
}
105105

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

modules/sdk-coin-xtz/test/unit/xtz.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
unsignedHex,
1111
unsignedTransactionWithTwoTransfersHex,
1212
} from '../fixtures';
13+
import { Wallet } from '@bitgo/sdk-core';
1314

1415
const bitgo: TestBitGoAPI = TestBitGo.decorate(BitGoAPI, { env: 'test' });
1516
bitgo.safeRegister('xtz', Xtz.createInstance);
@@ -199,4 +200,25 @@ describe('Tezos:', function () {
199200
isValid.should.equal(false);
200201
});
201202
});
203+
204+
describe('Verify Transaction', function () {
205+
const address1 = '5Ge59qRnZa8bxyhVFE6BDoY3kuhSrNVETRxXYLty1Hh6XTaf';
206+
const address2 = '5DiMLZugmcKEH3igPZP367FqummZkWeW5Z6zDCHLfxRjnPXe';
207+
it('should reject a txPrebuild with more than one recipient', async function () {
208+
const wallet = new Wallet(bitgo, basecoin, {});
209+
210+
const txParams = {
211+
recipients: [
212+
{ amount: '1000000000000', address: address1 },
213+
{ amount: '2500000000000', address: address2 },
214+
],
215+
wallet: wallet,
216+
walletPassphrase: 'fakeWalletPassphrase',
217+
};
218+
219+
await basecoin
220+
.verifyTransaction({ txParams })
221+
.should.be.rejectedWith('txParams should only have 1 recipient but 2 found');
222+
});
223+
});
202224
});

0 commit comments

Comments
 (0)