Skip to content

Commit 6131230

Browse files
feat: add XDC_FEATURES to xdc tokens
Ticket: COIN-7060
1 parent d41623e commit 6131230

2 files changed

Lines changed: 101 additions & 6 deletions

File tree

modules/sdk-coin-xdc/test/unit/xdcToken.ts

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'should';
22
import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test';
33
import { BitGoAPI } from '@bitgo/sdk-api';
44

5-
import { register } from '../../src';
5+
import { register, XdcToken } from '../../src';
66

77
describe('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(/Cannot use common sdk module/);
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
});

modules/statics/src/allCoinsAndTokens.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2996,31 +2996,35 @@ export const allCoinsAndTokens = [
29962996
'Law Block Token',
29972997
18,
29982998
'0x05940b2df33d6371201e7ae099ced4c363855dfe',
2999-
UnderlyingAsset['xdc:lbt']
2999+
UnderlyingAsset['xdc:lbt'],
3000+
XDC_FEATURES
30003001
),
30013002
xdcErc20(
30023003
'f03302de-b06b-4ddc-94a2-ad7e89896725',
30033004
'xdc:gama',
30043005
'Gama Token',
30053006
18,
30063007
'0x3a170c7c987f55c84f28733bfa27962d8cdd5d3b',
3007-
UnderlyingAsset['xdc:gama']
3008+
UnderlyingAsset['xdc:gama'],
3009+
XDC_FEATURES
30083010
),
30093011
xdcErc20(
30103012
'bdf602ea-3a6c-407a-8afd-33d6c04a8bc3',
30113013
'xdc:srx',
30123014
'STORX',
30133015
18,
30143016
'0x5d5f074837f5d4618b3916ba74de1bf9662a3fed',
3015-
UnderlyingAsset['xdc:srx']
3017+
UnderlyingAsset['xdc:srx'],
3018+
XDC_FEATURES
30163019
),
30173020
xdcErc20(
30183021
'd42c9497-0987-497d-97f2-8b19c539e350',
30193022
'xdc:weth',
30203023
'Wrapped Ether',
30213024
18,
30223025
'0xa7348290de5cf01772479c48d50dec791c3fc212',
3023-
UnderlyingAsset['xdc:weth']
3026+
UnderlyingAsset['xdc:weth'],
3027+
XDC_FEATURES
30243028
),
30253029

30263030
// XDC testnet tokens
@@ -3030,7 +3034,8 @@ export const allCoinsAndTokens = [
30303034
'XDC Network TMT',
30313035
6,
30323036
'0xb283ec8dad644effc5c4c50bb7bb21442ac3c2db',
3033-
UnderlyingAsset['txdc:tmt']
3037+
UnderlyingAsset['txdc:tmt'],
3038+
XDC_FEATURES
30343039
),
30353040

30363041
// MON mainnet tokens

0 commit comments

Comments
 (0)