@@ -2,7 +2,7 @@ import 'should';
22import { TestBitGo , TestBitGoAPI } from '@bitgo/sdk-test' ;
33import { BitGoAPI } from '@bitgo/sdk-api' ;
44
5- import { register } from '../../src' ;
5+ import { register , XdcToken } from '../../src' ;
66
77describe ( 'XDC Token:' , function ( ) {
88 let bitgo : TestBitGoAPI ;
@@ -27,4 +27,94 @@ describe('XDC Token:', function () {
2727 xdcTokenCoin . network . should . equal ( 'Mainnet' ) ;
2828 xdcTokenCoin . decimalPlaces . should . equal ( 6 ) ;
2929 } ) ;
30+
31+ describe ( 'Token Registration and TransactionBuilder' , function ( ) {
32+ const mainnetTokens = [ 'xdc:usdc' , 'xdc:lbt' , 'xdc:gama' , 'xdc:srx' , 'xdc:weth' ] ;
33+ const testnetTokens = [ 'txdc:tmt' ] ;
34+
35+ describe ( 'Mainnet tokens' , function ( ) {
36+ mainnetTokens . forEach ( ( tokenName ) => {
37+ it ( `${ tokenName } should be registered as XdcToken` , function ( ) {
38+ const token = bitgo . coin ( tokenName ) ;
39+ token . should . be . instanceOf ( XdcToken ) ;
40+ } ) ;
41+
42+ it ( `${ tokenName } should create TransactionBuilder without error` , function ( ) {
43+ const token = bitgo . coin ( tokenName ) as XdcToken ;
44+ // @ts -expect-error - accessing protected method for testing
45+ ( ( ) => token . getTransactionBuilder ( ) ) . should . not . throw ( ) ;
46+ } ) ;
47+
48+ it ( `${ tokenName } should use XDC-specific TransactionBuilder` , function ( ) {
49+ const token = bitgo . coin ( tokenName ) as XdcToken ;
50+ // @ts -expect-error - accessing protected method for testing
51+ const builder = token . getTransactionBuilder ( ) ;
52+ builder . should . have . property ( '_common' ) ;
53+ // Verify it's using XDC's getCommon, not EVM's
54+ // XDC's TransactionBuilder should create successfully without SHARED_EVM_SDK feature
55+ builder . constructor . name . should . equal ( 'TransactionBuilder' ) ;
56+ } ) ;
57+ } ) ;
58+ } ) ;
59+
60+ describe ( 'Testnet tokens' , function ( ) {
61+ testnetTokens . forEach ( ( tokenName ) => {
62+ it ( `${ tokenName } should be registered as XdcToken` , function ( ) {
63+ const token = bitgo . coin ( tokenName ) ;
64+ token . should . be . instanceOf ( XdcToken ) ;
65+ } ) ;
66+
67+ it ( `${ tokenName } should create TransactionBuilder without error` , function ( ) {
68+ const token = bitgo . coin ( tokenName ) as XdcToken ;
69+ // @ts -expect-error - accessing protected method for testing
70+ ( ( ) => token . getTransactionBuilder ( ) ) . should . not . throw ( ) ;
71+ } ) ;
72+
73+ it ( `${ tokenName } should use XDC-specific TransactionBuilder` , function ( ) {
74+ const token = bitgo . coin ( tokenName ) as XdcToken ;
75+ // @ts -expect-error - accessing protected method for testing
76+ const builder = token . getTransactionBuilder ( ) ;
77+ builder . should . have . property ( '_common' ) ;
78+ builder . constructor . name . should . equal ( 'TransactionBuilder' ) ;
79+ } ) ;
80+
81+ it ( `${ tokenName } should have correct base chain` , function ( ) {
82+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
83+ const token : any = bitgo . coin ( tokenName ) ;
84+ token . getBaseChain ( ) . should . equal ( 'txdc' ) ;
85+ } ) ;
86+
87+ it ( `${ tokenName } should not throw "Cannot use common sdk module" error` , function ( ) {
88+ const token = bitgo . coin ( tokenName ) as XdcToken ;
89+ let errorThrown = false ;
90+ let errorMessage = '' ;
91+
92+ try {
93+ // @ts -expect-error - accessing protected method for testing
94+ const builder = token . getTransactionBuilder ( ) ;
95+ // Try to use the builder to ensure it's fully functional
96+ // @ts -expect-error - type expects TransactionType enum
97+ builder . type ( 'Send' ) ;
98+ } catch ( e ) {
99+ errorThrown = true ;
100+ errorMessage = ( e as Error ) . message ;
101+ }
102+
103+ errorThrown . should . equal ( false ) ;
104+ errorMessage . should . not . match ( / C a n n o t u s e c o m m o n s d k m o d u l e / ) ;
105+ } ) ;
106+ } ) ;
107+ } ) ;
108+
109+ it ( 'should verify all XDC tokens use XdcToken class, not EthLikeErc20Token' , function ( ) {
110+ const allTokens = [ ...mainnetTokens , ...testnetTokens ] ;
111+
112+ allTokens . forEach ( ( tokenName ) => {
113+ const token = bitgo . coin ( tokenName ) ;
114+ token . should . be . instanceOf ( XdcToken ) ;
115+ token . constructor . name . should . equal ( 'XdcToken' ) ;
116+ token . constructor . name . should . not . equal ( 'EthLikeErc20Token' ) ;
117+ } ) ;
118+ } ) ;
119+ } ) ;
30120} ) ;
0 commit comments