Skip to content

Commit 2c4e106

Browse files
prajwalu142bitgobot
authored andcommitted
test(sdk-coin-xlm): add ALPHANUM12 enabletoken verification tests for TUSDC
Add three unit tests exercising the ALPHANUM12 (5-char asset code) path through verifyTransaction/verifyTrustlineTxOperations in sdk-coin-xlm. All prior test fixtures only covered ALPHANUM4 (≤4 char) asset codes; TUSDC is 5 chars and is encoded as assetTypeCreditAlphanum12 in Stellar XDR, which is a distinct code path that was previously untested. Tests added: 1. Happy path: changeTrust XDR for stellar.Asset('TUSDC', issuer) is accepted by verifyTransaction with matching enabletoken txParams. 2. Issuer mismatch: changeTrust from a different issuer is rejected with the expected "Invalid issuer on token enablement operation" error. 3. Code mismatch: changeTrust for 'USDCX' (also ALPHANUM12) while params expect 'TUSDC' is rejected with the expected code-mismatch error. These tests exercise the same issuer identified in CSHLD-1407/CSHLD-1447 (GC26PEYGETD7L6PUW2VCU3PSC7LCLRRPOSUILSHD2RT23IQUEAN4TQBQ) and confirm the SDK's XLM token verification pipeline handles ALPHANUM12 assets. Ticket: CSHLD-1447 Session-Id: bb58b0aa-c314-4212-8901-e1cfc7a3c8db Task-Id: 31db5ad2-ab59-4d9f-8c21-6acc91a05c08
1 parent 3333cb4 commit 2c4e106

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

  • modules/sdk-coin-xlm/test/unit

modules/sdk-coin-xlm/test/unit/xlm.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,75 @@ describe('XLM:', function () {
10161016
});
10171017
});
10181018

1019+
describe('ALPHANUM12 token (txlm:TUSDC) enabletoken verification', function () {
1020+
// TUSDC is a 5-char asset code — encoded as assetTypeCreditAlphanum12 in Stellar XDR.
1021+
// All prior test fixtures use 3–4 char (ALPHANUM4) codes; these tests verify that the
1022+
// verifyTransaction path handles the ALPHANUM12 encoding correctly (CSHLD-1447).
1023+
const stellarNetworkPassphrase = stellar.Networks.TESTNET;
1024+
const sourceAddress = 'GA34NPQ4M54HHZBKSDZ5B3J3BZHTXKCZD4UFO2OYZERPOASK4DAATSIB';
1025+
const tusdcIssuer = 'GC26PEYGETD7L6PUW2VCU3PSC7LCLRRPOSUILSHD2RT23IQUEAN4TQBQ';
1026+
const tusdcTokenName = `txlm:TUSDC-${tusdcIssuer}`;
1027+
const tusdcAsset = new stellar.Asset('TUSDC', tusdcIssuer);
1028+
1029+
const buildTxBase64 = (ops: stellar.xdr.Operation[]): string => {
1030+
const sourceAccount = new stellar.Account(sourceAddress, '1');
1031+
const tx = new stellar.TransactionBuilder(sourceAccount, {
1032+
fee: '100',
1033+
networkPassphrase: stellarNetworkPassphrase,
1034+
});
1035+
ops.forEach((op) => tx.addOperation(op));
1036+
return tx.setTimeout(0).build().toEnvelope().toXDR('base64');
1037+
};
1038+
1039+
it('should verify a changeTrust for a 5-char ALPHANUM12 asset (TUSDC)', async function () {
1040+
const txPrebuild = {
1041+
txBase64: buildTxBase64([stellar.Operation.changeTrust({ asset: tusdcAsset })]),
1042+
};
1043+
const txParams = {
1044+
type: 'enabletoken',
1045+
recipients: [{ tokenName: tusdcTokenName, amount: 0, address: '' }],
1046+
};
1047+
const isValid = await basecoin.verifyTransaction({
1048+
txParams,
1049+
txPrebuild,
1050+
wallet: {},
1051+
verification: { verifyTokenEnablement: true },
1052+
});
1053+
isValid.should.equal(true);
1054+
});
1055+
1056+
it('should reject a changeTrust whose issuer does not match txlm:TUSDC', async function () {
1057+
const differentIssuer = 'GCWHAO4SVB4KX3Q62QZGZUHUH2GSH3OIV7IS7Y3MPQOFGQFGBP6IYCOU';
1058+
const differentAsset = new stellar.Asset('TUSDC', differentIssuer);
1059+
const txPrebuild = {
1060+
txBase64: buildTxBase64([stellar.Operation.changeTrust({ asset: differentAsset })]),
1061+
};
1062+
const txParams = {
1063+
type: 'enabletoken',
1064+
recipients: [{ tokenName: tusdcTokenName, amount: 0, address: '' }],
1065+
};
1066+
await basecoin
1067+
.verifyTransaction({ txParams, txPrebuild, wallet: {}, verification: { verifyTokenEnablement: true } })
1068+
.should.be.rejectedWith(
1069+
`Invalid issuer on token enablement operation: expected ${tusdcIssuer}, got ${differentIssuer}`
1070+
);
1071+
});
1072+
1073+
it('should reject a changeTrust whose asset code does not match TUSDC', async function () {
1074+
const wrongAsset = new stellar.Asset('USDCX', tusdcIssuer);
1075+
const txPrebuild = {
1076+
txBase64: buildTxBase64([stellar.Operation.changeTrust({ asset: wrongAsset })]),
1077+
};
1078+
const txParams = {
1079+
type: 'enabletoken',
1080+
recipients: [{ tokenName: tusdcTokenName, amount: 0, address: '' }],
1081+
};
1082+
await basecoin
1083+
.verifyTransaction({ txParams, txPrebuild, wallet: {}, verification: { verifyTokenEnablement: true } })
1084+
.should.be.rejectedWith('Invalid token code on token enablement operation: expected TUSDC, got USDCX');
1085+
});
1086+
});
1087+
10191088
describe('Federation lookups:', function () {
10201089
describe('Look up by stellar address:', function () {
10211090
it('should fail to loop up an invalid stellar address with a bitgo.com domain', async function () {

0 commit comments

Comments
 (0)