@@ -21,6 +21,27 @@ describe('TRON:', function () {
2121
2222 let basecoin ;
2323
24+ // Test data from wallet 693b011a3ec26986f569b02140c7627e
25+ const testWalletData = {
26+ rootAddress : 'TAf36b36eqoMCzJJm3jwSsP81UvkMxrPbi' ,
27+ receiveAddress : 'TFaD6DeKFMcBuGuDD7LbbqxTnKunhXfdya' ,
28+ receiveAddressIndex : 2 ,
29+ keychains : [
30+ {
31+ id : '693b0110271fc3f5749754097793bb8d' ,
32+ pub : 'xpub661MyMwAqRbcFsVAdZyN2m8p21WHXg8NRNkqKApyS5gwmFsPdRTrmHYCnzR9vYe8DQ4uWGCBcAAsWE3r97HsFS3K2faZ2ejXNhHxdEoAEWC' ,
33+ } ,
34+ {
35+ id : '693b011065b9c4674825ce1f849b7bef' ,
36+ pub : 'xpub661MyMwAqRbcErKpZr9ztTFJk6fzXWatMFgRnpXfsjybWBfE9847EVGrHHBsGP8fcnzJmJuevAbPUEpjHTjEEWfYUWNMEDahvssQein848o' ,
37+ } ,
38+ {
39+ id : '693b01117c41846abb04818815b89b6c' ,
40+ pub : 'xpub661MyMwAqRbcFqZd7XU9DFW4f29VJzQt7UCA51ypaWa5ymhQ2pRZDTgViw3vZ56PqZ8dj1cracN3fAWhaiG1QKj9mvyt9Cba4nM2tPibNKw' ,
41+ } ,
42+ ] ,
43+ } ;
44+
2445 before ( function ( ) {
2546 basecoin = bitgo . coin ( 'ttrx' ) ;
2647 } ) ;
@@ -612,4 +633,113 @@ describe('TRON:', function () {
612633 assert . equal ( Utils . getBase58AddressFromHex ( value1 . to_address ) , TestRecoverData . baseAddress ) ;
613634 } ) ;
614635 } ) ;
636+
637+ describe ( 'isWalletAddress' , ( ) => {
638+ it ( 'should verify root address (index 0)' , async function ( ) {
639+ const result = await basecoin . isWalletAddress ( {
640+ address : testWalletData . rootAddress ,
641+ keychains : testWalletData . keychains ,
642+ index : 0 ,
643+ } ) ;
644+ assert . equal ( result , true ) ;
645+ } ) ;
646+
647+ it ( 'should verify receive address (index > 0)' , async function ( ) {
648+ const result = await basecoin . isWalletAddress ( {
649+ address : testWalletData . receiveAddress ,
650+ keychains : testWalletData . keychains ,
651+ index : testWalletData . receiveAddressIndex ,
652+ chain : 0 ,
653+ } ) ;
654+ assert . equal ( result , true ) ;
655+ } ) ;
656+
657+ it ( 'should verify address with index in coinSpecific' , async function ( ) {
658+ const result = await basecoin . isWalletAddress ( {
659+ address : testWalletData . rootAddress ,
660+ keychains : testWalletData . keychains ,
661+ coinSpecific : { index : 0 } ,
662+ } ) ;
663+ assert . equal ( result , true ) ;
664+ } ) ;
665+
666+ it ( 'should verify address with string index' , async function ( ) {
667+ const result = await basecoin . isWalletAddress ( {
668+ address : testWalletData . rootAddress ,
669+ keychains : testWalletData . keychains ,
670+ index : '0' ,
671+ } ) ;
672+ assert . equal ( result , true ) ;
673+ } ) ;
674+
675+ it ( 'should return false for wrong address at index 0' , async function ( ) {
676+ const result = await basecoin . isWalletAddress ( {
677+ address : testWalletData . receiveAddress , // wrong address for index 0
678+ keychains : testWalletData . keychains ,
679+ index : 0 ,
680+ } ) ;
681+ assert . equal ( result , false ) ;
682+ } ) ;
683+
684+ it ( 'should return false for wrong address at receive index' , async function ( ) {
685+ const result = await basecoin . isWalletAddress ( {
686+ address : testWalletData . rootAddress , // wrong address for index 1
687+ keychains : testWalletData . keychains ,
688+ index : testWalletData . receiveAddressIndex ,
689+ chain : 0 ,
690+ } ) ;
691+ assert . equal ( result , false ) ;
692+ } ) ;
693+
694+ it ( 'should throw for invalid address' , async function ( ) {
695+ await assert . rejects (
696+ basecoin . isWalletAddress ( {
697+ address : 'invalid-address' ,
698+ keychains : testWalletData . keychains ,
699+ index : 0 ,
700+ } ) ,
701+ {
702+ message : 'Invalid address: invalid-address' ,
703+ }
704+ ) ;
705+ } ) ;
706+
707+ it ( 'should throw for missing index' , async function ( ) {
708+ await assert . rejects (
709+ basecoin . isWalletAddress ( {
710+ address : testWalletData . rootAddress ,
711+ keychains : testWalletData . keychains ,
712+ } ) ,
713+ {
714+ message : 'Invalid or missing index for address verification' ,
715+ }
716+ ) ;
717+ } ) ;
718+
719+ it ( 'should throw for missing bitgo key on root address verification' , async function ( ) {
720+ await assert . rejects (
721+ basecoin . isWalletAddress ( {
722+ address : testWalletData . rootAddress ,
723+ keychains : testWalletData . keychains . slice ( 0 , 2 ) , // only user and backup keys
724+ index : 0 ,
725+ } ) ,
726+ {
727+ message : 'BitGo public key required for root address verification' ,
728+ }
729+ ) ;
730+ } ) ;
731+
732+ it ( 'should throw for missing user key on receive address verification' , async function ( ) {
733+ await assert . rejects (
734+ basecoin . isWalletAddress ( {
735+ address : testWalletData . receiveAddress ,
736+ keychains : [ ] , // no keys
737+ index : testWalletData . receiveAddressIndex ,
738+ } ) ,
739+ {
740+ message : 'User public key required for receive address verification' ,
741+ }
742+ ) ;
743+ } ) ;
744+ } ) ;
615745} ) ;
0 commit comments