Skip to content

Commit

Permalink
Merge pull request #5042 from BitGo/COIN-1959-STX-error-fix
Browse files Browse the repository at this point in the history
feat(sdk-coin-stx): added check for multiple reciepents
  • Loading branch information
mohd-kashif authored Oct 24, 2024
2 parents 7648bd5 + 58321c0 commit 74687ec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion modules/sdk-coin-stx/src/stx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ export class Stx extends BaseCoin {
}

async verifyTransaction(params: VerifyTransactionOptions): Promise<boolean> {
// TODO: Implement when available on the SDK.
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-stx/test/unit/stx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { coins } from '@bitgo/statics';
import * as testData from '../fixtures';
import { Stx, Tstx, StxLib } from '../../src';
import assert from 'assert';
import { Wallet } from '@bitgo/sdk-core';

const { KeyPair } = StxLib;

Expand Down Expand Up @@ -284,4 +285,25 @@ describe('STX:', function () {
bufferTx.should.be.deepEqual(Buffer.from(testData.unsignedTxForExplainTransfer));
});
});

describe('Verify Transaction', function () {
const address1 = '0x174cfd823af8ce27ed0afee3fcf3c3ba259116be';
const address2 = '0x7e85bdc27c050e3905ebf4b8e634d9ad6edd0de6';
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 74687ec

Please sign in to comment.