@@ -150,4 +150,86 @@ describe('Wallet - Token Approval', function () {
150150 await wallet . buildErc20TokenApproval ( 'USDC' , 'passphrase123' ) . should . be . rejectedWith ( 'signing error' ) ;
151151 } ) ;
152152 } ) ;
153+
154+ describe ( 'sendTokenEnablement' , function ( ) {
155+ let teWallet : Wallet ;
156+ let teBaseCoin : any ;
157+ let teBitGo : any ;
158+
159+ beforeEach ( function ( ) {
160+ teBitGo = {
161+ post : sinon . stub ( ) ,
162+ get : sinon . stub ( ) ,
163+ setRequestTracer : sinon . stub ( ) ,
164+ } ;
165+
166+ teBaseCoin = {
167+ getFamily : sinon . stub ( ) . returns ( 'txrp' ) ,
168+ getFullName : sinon . stub ( ) . returns ( 'Testnet XRP' ) ,
169+ url : sinon . stub ( ) ,
170+ keychains : sinon . stub ( ) ,
171+ supportsTss : sinon . stub ( ) . returns ( false ) ,
172+ getMPCAlgorithm : sinon . stub ( ) ,
173+ getTokenEnablementConfig : sinon . stub ( ) . returns ( { requiresTokenEnablement : true } ) ,
174+ } ;
175+
176+ // custodial wallet so the path after validation calls initiateTransaction
177+ const walletData = {
178+ id : 'te-wallet-id' ,
179+ coin : 'txrp' ,
180+ type : 'custodial' ,
181+ keys : [ 'user-key' , 'backup-key' , 'bitgo-key' ] ,
182+ } ;
183+
184+ teWallet = new Wallet ( teBitGo , teBaseCoin , walletData ) ;
185+ } ) ;
186+
187+ it ( 'should throw "Invalid build of token enablement." when prebuildTx is a string' , async function ( ) {
188+ await teWallet
189+ . sendTokenEnablement ( { prebuildTx : 'raw-hex-string' as any } )
190+ . should . be . rejectedWith ( 'Invalid build of token enablement.' ) ;
191+ } ) ;
192+
193+ it ( 'should throw "Invalid build of token enablement." when buildParams.type is undefined' , async function ( ) {
194+ await teWallet
195+ . sendTokenEnablement ( { prebuildTx : { buildParams : { } } as any } )
196+ . should . be . rejectedWith ( 'Invalid build of token enablement.' ) ;
197+ } ) ;
198+
199+ it ( 'should throw "Invalid build of token enablement." when buildParams.type is an unrecognised type' , async function ( ) {
200+ await teWallet
201+ . sendTokenEnablement ( { prebuildTx : { buildParams : { type : 'transfer' } } as any } )
202+ . should . be . rejectedWith ( 'Invalid build of token enablement.' ) ;
203+ } ) ;
204+
205+ it ( 'should pass validation and proceed when buildParams.type is "enabletoken"' , async function ( ) {
206+ const initiateStub = sinon . stub ( teWallet as any , 'initiateTransaction' ) . resolves ( { txid : 'abc123' } ) ;
207+
208+ const result = await teWallet . sendTokenEnablement ( {
209+ prebuildTx : { buildParams : { type : 'enabletoken' } } as any ,
210+ } ) ;
211+
212+ result . should . eql ( { txid : 'abc123' } ) ;
213+ sinon . assert . calledOnce ( initiateStub ) ;
214+ } ) ;
215+
216+ it ( 'should pass validation and proceed when buildParams.type is "enableMpt"' , async function ( ) {
217+ const initiateStub = sinon . stub ( teWallet as any , 'initiateTransaction' ) . resolves ( { txid : 'mpt456' } ) ;
218+
219+ const result = await teWallet . sendTokenEnablement ( {
220+ prebuildTx : { buildParams : { type : 'enableMpt' } } as any ,
221+ } ) ;
222+
223+ result . should . eql ( { txid : 'mpt456' } ) ;
224+ sinon . assert . calledOnce ( initiateStub ) ;
225+ } ) ;
226+
227+ it ( 'should throw when the coin does not require token enablement' , async function ( ) {
228+ teBaseCoin . getTokenEnablementConfig . returns ( { requiresTokenEnablement : false } ) ;
229+
230+ await teWallet
231+ . sendTokenEnablement ( { prebuildTx : { buildParams : { type : 'enableMpt' } } as any } )
232+ . should . be . rejectedWith ( / d o e s n o t r e q u i r e t o k e n e n a b l e m e n t t r a n s a c t i o n s / ) ;
233+ } ) ;
234+ } ) ;
153235} ) ;
0 commit comments