@@ -654,21 +654,28 @@ describe('V2 Wallet:', function () {
654654
655655 it ( 'should send wrapParams to /tx/build when prebuilding wrapApprove on an onchain multi-sig wallet' , async function ( ) {
656656 const wrapParams = { tokenName : 'hteth:cusdt' , amount : '1000000' } ;
657+ const callerParams : { type : string ; wrapParams : { tokenName : string ; amount : string } ; recipients ?: unknown } = {
658+ type : 'wrapApprove' ,
659+ wrapParams,
660+ } ;
657661 const buildNock = nock ( bgUrl )
658662 . post ( `/api/v2/${ ethWallet . coin ( ) } /wallet/${ ethWallet . id ( ) } /tx/build` , ( body ) => {
659663 body . type . should . equal ( 'wrapApprove' ) ;
660664 body . wrapParams . should . deepEqual ( wrapParams ) ;
661- should . not . exist ( body . recipients ) ;
665+ body . recipients . should . deepEqual ( [ ] ) ;
662666 return true ;
663667 } )
664668 . reply ( 200 , { txHex : '0xfaketxhex' , feeInfo : { fee : '1000' } } ) ;
665669
666670 try {
667- await ethWallet . prebuildTransaction ( { type : 'wrapApprove' , wrapParams } ) ;
671+ await ethWallet . prebuildTransaction ( callerParams ) ;
668672 } catch ( e ) {
669673 // post-processing of the fake prebuild may fail; the contract under test is the request body
670674 }
671675 buildNock . isDone ( ) . should . be . true ( ) ;
676+ // the caller's params must stay untouched: they flow into prebuildAndSignTransaction
677+ // (prebuildTx + sign flows), where a truthy recipients trips the prebuildTx check
678+ should . not . exist ( callerParams . recipients ) ;
672679 } ) ;
673680
674681 it ( 'should send unwrapParams to /tx/build when prebuilding unwrap on an onchain multi-sig wallet' , async function ( ) {
@@ -677,7 +684,7 @@ describe('V2 Wallet:', function () {
677684 . post ( `/api/v2/${ ethWallet . coin ( ) } /wallet/${ ethWallet . id ( ) } /tx/build` , ( body ) => {
678685 body . type . should . equal ( 'unwrap' ) ;
679686 body . unwrapParams . should . deepEqual ( unwrapParams ) ;
680- should . not . exist ( body . recipients ) ;
687+ body . recipients . should . deepEqual ( [ ] ) ;
681688 return true ;
682689 } )
683690 . reply ( 200 , { txHex : '0xfaketxhex' , feeInfo : { fee : '1000' } } ) ;
@@ -690,6 +697,40 @@ describe('V2 Wallet:', function () {
690697 buildNock . isDone ( ) . should . be . true ( ) ;
691698 } ) ;
692699
700+ it ( 'should send empty recipients to /tx/build when prebuilding wrap (request-shape contract)' , async function ( ) {
701+ const buildNock = nock ( bgUrl )
702+ . post ( `/api/v2/${ ethWallet . coin ( ) } /wallet/${ ethWallet . id ( ) } /tx/build` , ( body ) => {
703+ body . type . should . equal ( 'wrap' ) ;
704+ body . recipients . should . deepEqual ( [ ] ) ;
705+ return true ;
706+ } )
707+ . reply ( 200 , { txHex : '0xfaketxhex' , feeInfo : { fee : '1000' } } ) ;
708+
709+ try {
710+ await ethWallet . prebuildTransaction ( { type : 'wrap' } ) ;
711+ } catch ( e ) {
712+ // the server rejects direct wrap builds; the contract under test is the request body
713+ }
714+ buildNock . isDone ( ) . should . be . true ( ) ;
715+ } ) ;
716+
717+ it ( 'should send empty recipients to /tx/build when prebuilding finalizeUnwrap (request-shape contract)' , async function ( ) {
718+ const buildNock = nock ( bgUrl )
719+ . post ( `/api/v2/${ ethWallet . coin ( ) } /wallet/${ ethWallet . id ( ) } /tx/build` , ( body ) => {
720+ body . type . should . equal ( 'finalizeUnwrap' ) ;
721+ body . recipients . should . deepEqual ( [ ] ) ;
722+ return true ;
723+ } )
724+ . reply ( 200 , { txHex : '0xfaketxhex' , feeInfo : { fee : '1000' } } ) ;
725+
726+ try {
727+ await ethWallet . prebuildTransaction ( { type : 'finalizeUnwrap' } ) ;
728+ } catch ( e ) {
729+ // the server rejects direct finalizeUnwrap builds; the contract under test is the request body
730+ }
731+ buildNock . isDone ( ) . should . be . true ( ) ;
732+ } ) ;
733+
693734 it ( 'should not pass recipients in sendMany when transaction type is finalizeUnwrap' , async function ( ) {
694735 const recipients = [
695736 {
@@ -724,6 +765,37 @@ describe('V2 Wallet:', function () {
724765 caught ! . message . should . equal ( 'cannot provide recipients for transaction type wrapApprove' ) ;
725766 caught ! . code ! . should . equal ( 'recipients_not_allowed_for_fillnonce_and_acceleration_tx_type' ) ;
726767 } ) ;
768+
769+ it ( 'allows an empty recipients array when prebuilding wrapApprove (server-derived shape)' , async function ( ) {
770+ const nockKeychain = nock ( bgUrl ) . get ( `/api/v2/${ ethWallet . coin ( ) } /key/${ ethWallet . keyIds ( ) [ 0 ] } ` ) . reply ( 200 , {
771+ id : '598f606cd8fc24710d2ebad89dce86c2' ,
772+ pub : 'xpub661MyMwAqRbcFXDcWD2vxuebcT1ZpTF4Vke6qmMW8yzddwNYpAPjvYEEL5jLfyYXW2fuxtAxY8TgjPUJLcf1C8qz9N6VgZxArKX4EwB8rH5' ,
773+ ethAddress : '0x26a163ba9739529720c0914c583865dec0d37278' ,
774+ source : 'user' ,
775+ encryptedPrv :
776+ '{"iv":"15FsbDVI1zG9OggD8YX+Hg==","v":1,"iter":10000,"ks":256,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"hHbNH3Sz/aU=","ct":"WoNVKz7afiRxXI2w/YkzMdMyoQg/B15u1Q8aQgi96jJZ9wk6TIaSEc6bXFH3AHzD9MdJCWJQUpRhoQc/rgytcn69scPTjKeeyVMElGCxZdFVS/psQcNE+lue3//2Zlxj+6t1NkvYO+8yAezSMRBK5OdftXEjNQI="}' ,
777+ coinSpecific : { } ,
778+ } ) ;
779+
780+ // the guard must let the empty-array shape through; the failure below is the passphrase check
781+ await ethWallet
782+ . prebuildAndSignTransaction ( { type : 'wrapApprove' , recipients : [ ] , walletPassphrase : 'wrongPassphrase' } )
783+ . should . be . rejectedWith ( 'unable to decrypt keychain with the given wallet passphrase' ) ;
784+ nockKeychain . isDone ( ) . should . be . true ( ) ;
785+ } ) ;
786+
787+ it ( 'still rejects an empty recipients array for fillNonce (guard regression)' , async function ( ) {
788+ let caught : ( Error & { code ?: string } ) | undefined ;
789+ try {
790+ await ethWallet . prebuildAndSignTransaction ( { type : 'fillNonce' , recipients : [ ] } ) ;
791+ } catch ( e ) {
792+ caught = e ;
793+ }
794+
795+ should . exist ( caught ) ;
796+ caught ! . message . should . equal ( 'cannot provide recipients for transaction type fillNonce' ) ;
797+ caught ! . code ! . should . equal ( 'recipients_not_allowed_for_fillnonce_and_acceleration_tx_type' ) ;
798+ } ) ;
727799 } ) ;
728800
729801 describe ( 'OFC Create Address' , ( ) => {
0 commit comments