File tree Expand file tree Collapse file tree 3 files changed +51
-7
lines changed
Expand file tree Collapse file tree 3 files changed +51
-7
lines changed Original file line number Diff line number Diff line change @@ -1652,6 +1652,48 @@ describe('V2 Wallet:', function () {
16521652 } ) ;
16531653 } ) ;
16541654 } ) ;
1655+ describe ( 'max recipient' , function ( ) {
1656+ const address = '5b34252f1bf349930e34020a' ;
1657+ const recipients = [
1658+ {
1659+ address,
1660+ amount : 'max' ,
1661+ } ,
1662+ ] ;
1663+ let basecoin ;
1664+ let wallet ;
1665+
1666+ before ( async function ( ) {
1667+ basecoin = bitgo . coin ( 'tbtc' ) ;
1668+ const walletData = {
1669+ id : '5b34252f1bf349930e34020a' ,
1670+ coin : 'tbtc' ,
1671+ keys : [ '5b3424f91bf349930e340175' ] ,
1672+ } ;
1673+ wallet = new Wallet ( bitgo , basecoin , walletData ) ;
1674+ } ) ;
1675+
1676+ it ( 'should pass maxFeeRate parameter when building transactions' , async function ( ) {
1677+ const path = `/api/v2/${ wallet . coin ( ) } /wallet/${ wallet . id ( ) } /tx/build` ;
1678+ const response = nock ( bgUrl )
1679+ . post (
1680+ path ,
1681+ _ . matches ( {
1682+ recipients,
1683+ } )
1684+ ) // use _.matches to do a partial match on request body object instead of strict matching
1685+ . reply ( 200 ) ;
1686+
1687+ try {
1688+ await wallet . prebuildTransaction ( { recipients } ) ;
1689+ } catch ( e ) {
1690+ // the prebuildTransaction method will probably throw an exception for not having all of the correct nocks
1691+ // we only care about /tx/build and whether maxFeeRate is an allowed parameter
1692+ }
1693+
1694+ response . isDone ( ) . should . be . true ( ) ;
1695+ } ) ;
1696+ } ) ;
16551697
16561698 describe ( 'maxFeeRate verification' , function ( ) {
16571699 const address = '5b34252f1bf349930e34020a' ;
Original file line number Diff line number Diff line change @@ -226,12 +226,14 @@ export abstract class BaseCoin implements IBaseCoin {
226226 }
227227
228228 checkRecipient ( recipient : { address : string ; amount : string | number } ) : void {
229- const amount = new BigNumber ( recipient . amount ) ;
230- if ( amount . isNegative ( ) ) {
231- throw new Error ( 'invalid argument for amount - positive number greater than zero or numeric string expected' ) ;
232- }
233- if ( ! this . valuelessTransferAllowed ( ) && amount . isZero ( ) ) {
234- throw new Error ( 'invalid argument for amount - positive number greater than zero or numeric string expected' ) ;
229+ if ( recipient . amount !== 'max' ) {
230+ const amount = new BigNumber ( recipient . amount ) ;
231+ if ( amount . isNegative ( ) ) {
232+ throw new Error ( 'invalid argument for amount - positive number greater than zero or numeric string expected' ) ;
233+ }
234+ if ( ! this . valuelessTransferAllowed ( ) && amount . isZero ( ) ) {
235+ throw new Error ( 'invalid argument for amount - positive number greater than zero or numeric string expected' ) ;
236+ }
235237 }
236238 }
237239
Original file line number Diff line number Diff line change @@ -2483,7 +2483,7 @@ export class Wallet implements IWallet {
24832483 this . bitgo . setRequestTracer ( reqId ) ;
24842484 const coin = this . baseCoin ;
24852485 if ( _ . isObject ( params . recipients ) ) {
2486- params . recipients . map ( function ( recipient ) {
2486+ params . recipients . forEach ( function ( recipient ) {
24872487 coin . checkRecipient ( recipient ) ;
24882488 } ) ;
24892489 }
You can’t perform that action at this time.
0 commit comments