@@ -232,6 +232,78 @@ describe('TRON:', function () {
232232 assert . equal ( Utils . getBase58AddressFromHex ( value . to_address ) , TestRecoverData . recoveryDestination ) ;
233233 } ) ;
234234
235+ it ( 'should recover trx from base address to recovery address with scan passed as valid integer string' , async function ( ) {
236+ mock . method ( Trx . prototype as any , 'getAccountBalancesFromNode' , ( ...args ) => {
237+ if ( args . length > 0 && args [ 0 ] === TestRecoverData . baseAddress ) {
238+ return Promise . resolve ( baseAddressBalance ( 3000000 ) ) ;
239+ }
240+
241+ return undefined ;
242+ } ) ;
243+
244+ const baseAddrHex = Utils . getHexAddressFromBase58Address ( TestRecoverData . baseAddress ) ;
245+ const destinationHex = Utils . getHexAddressFromBase58Address ( TestRecoverData . recoveryDestination ) ;
246+
247+ mock . method ( Trx . prototype as any , 'getBuildTransaction' , ( ...args ) => {
248+ if ( args . length > 0 && args [ 0 ] === destinationHex && args [ 1 ] === baseAddrHex && args [ 2 ] === 900000 ) {
249+ return Promise . resolve ( creationTransaction ( baseAddrHex , destinationHex , 900000 ) ) ;
250+ }
251+
252+ return undefined ;
253+ } ) ;
254+
255+ const res = await basecoin . recover ( {
256+ userKey : TestRecoverData . userKey ,
257+ backupKey : TestRecoverData . backupKey ,
258+ bitgoKey : TestRecoverData . bitgoKey ,
259+ recoveryDestination : TestRecoverData . recoveryDestination ,
260+ scan : '10' ,
261+ } ) ;
262+ assert . notEqual ( res . length , 0 ) ;
263+ assert . ok ( Object . prototype . hasOwnProperty . call ( res , 'txHex' ) ) ;
264+ assert . ok ( Object . prototype . hasOwnProperty . call ( res , 'feeInfo' ) ) ;
265+ const rawData = JSON . parse ( res . txHex ) . raw_data ;
266+ assert . ok ( Object . prototype . hasOwnProperty . call ( rawData , 'contract' ) ) ;
267+ const value = rawData . contract [ 0 ] . parameter . value ;
268+ assert . equal ( value . amount , 900000 ) ;
269+ assert . equal ( Utils . getBase58AddressFromHex ( value . owner_address ) , TestRecoverData . baseAddress ) ;
270+ assert . equal ( Utils . getBase58AddressFromHex ( value . to_address ) , TestRecoverData . recoveryDestination ) ;
271+ } ) ;
272+
273+ it ( 'should fail recover trx from base address to recovery address with scan passed as valid integer string' , async function ( ) {
274+ mock . method ( Trx . prototype as any , 'getAccountBalancesFromNode' , ( ...args ) => {
275+ if ( args . length > 0 && args [ 0 ] === TestRecoverData . baseAddress ) {
276+ return Promise . resolve ( baseAddressBalance ( 3000000 ) ) ;
277+ }
278+
279+ return undefined ;
280+ } ) ;
281+
282+ const baseAddrHex = Utils . getHexAddressFromBase58Address ( TestRecoverData . baseAddress ) ;
283+ const destinationHex = Utils . getHexAddressFromBase58Address ( TestRecoverData . recoveryDestination ) ;
284+
285+ mock . method ( Trx . prototype as any , 'getBuildTransaction' , ( ...args ) => {
286+ if ( args . length > 0 && args [ 0 ] === destinationHex && args [ 1 ] === baseAddrHex && args [ 2 ] === 900000 ) {
287+ return Promise . resolve ( creationTransaction ( baseAddrHex , destinationHex , 900000 ) ) ;
288+ }
289+
290+ return undefined ;
291+ } ) ;
292+
293+ await assert . rejects (
294+ basecoin . recover ( {
295+ userKey : TestRecoverData . userKey ,
296+ backupKey : TestRecoverData . backupKey ,
297+ bitgoKey : TestRecoverData . bitgoKey ,
298+ recoveryDestination : TestRecoverData . recoveryDestination ,
299+ scan : 'abc' ,
300+ } ) ,
301+ {
302+ message : 'Invalid scanning factor' ,
303+ }
304+ ) ;
305+ } ) ;
306+
235307 it ( 'should recover trx from receive address to base address' , async function ( ) {
236308 mock . method ( Trx . prototype as any , 'getAccountBalancesFromNode' , ( ...args ) => {
237309 if ( args . length > 0 && args [ 0 ] === TestRecoverData . baseAddress ) {
0 commit comments