Skip to content

Commit 6a638f0

Browse files
authored
Merge pull request #6801 from BitGo/COIN-5391
test: near token naming convention
2 parents 62ef360 + c4e3f05 commit 6a638f0

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

modules/statics/test/unit/tokenNamingConvention.ts

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { erc20Coins } from '../../src/coins/erc20Coins';
22
import { cosmosTokens } from '../../src/coins/cosmosTokens';
33
import { avaxTokens } from '../../src/coins/avaxTokens';
44
import { bscTokens } from '../../src/coins/bscTokens';
5+
import { nep141Tokens } from '../../src/coins/nep141Tokens';
56
import { NetworkType } from '../../src/networks';
67

78
describe('Token Naming Convention Tests', function () {
8-
const allTokens = [...erc20Coins, ...cosmosTokens, ...avaxTokens, ...bscTokens];
9+
const allTokens = [...erc20Coins, ...cosmosTokens, ...avaxTokens, ...bscTokens, ...nep141Tokens];
910

1011
// Helper function to filter tokens by network type
1112
function getTokensByNetworkType(networkType: NetworkType) {
@@ -162,6 +163,11 @@ describe('Token Naming Convention Tests', function () {
162163
const networkPrefix = parts[0];
163164
const tokenId = parts[1];
164165

166+
const knownNetworkExceptions = ['hteth'];
167+
if (knownNetworkExceptions.includes(networkPrefix)) {
168+
return; // Skip known exceptions
169+
}
170+
165171
// For testnet tokens, remove the 't' prefix to get the base network name
166172
let baseNetworkName: string;
167173
if (token.network.type === NetworkType.TESTNET) {
@@ -239,7 +245,7 @@ describe('Token Naming Convention Tests', function () {
239245
{ mainnet: 'eth:link', testnet: 'teth:link' }, // 18 vs 6 decimal places
240246
];
241247

242-
// Group tokens by their base token identifier
248+
// Group tokens by their base token identifier and compatible network prefixes
243249
const tokenPairs = new Map<string, { token: any; networkPrefix: string; isTestnet: boolean }[]>();
244250

245251
tokensWithColon.forEach((token) => {
@@ -248,8 +254,21 @@ describe('Token Naming Convention Tests', function () {
248254
const networkPrefix = parts[0];
249255
const tokenId = parts[1];
250256

251-
// Create a key based on just the token identifier
252-
const key = tokenId;
257+
const knownNetworkExceptions = ['hteth'];
258+
if (knownNetworkExceptions.includes(networkPrefix)) {
259+
return; // Skip known exceptions
260+
}
261+
262+
// For testnet tokens, get the equivalent mainnet prefix
263+
let baseNetworkName: string;
264+
if (token.network.type === NetworkType.TESTNET) {
265+
baseNetworkName = networkPrefix.startsWith('t') ? networkPrefix.substring(1) : networkPrefix;
266+
} else {
267+
baseNetworkName = networkPrefix;
268+
}
269+
270+
// Create a key that combines the base network name and token identifier
271+
const key = `${baseNetworkName}:${tokenId}`;
253272

254273
if (!tokenPairs.has(key)) {
255274
tokenPairs.set(key, []);
@@ -265,12 +284,19 @@ describe('Token Naming Convention Tests', function () {
265284
tokenPairs.forEach((tokens, _tokenId) => {
266285
// If there are both mainnet and testnet versions of this token
267286
if (tokens.length > 1) {
268-
const testnetTokens = tokens.filter((t: any) => t.isTestnet);
269-
const mainnetTokens = tokens.filter((t: any) => !t.isTestnet);
287+
const testnetTokens = tokens.filter(
288+
(t: { token: any; networkPrefix: string; isTestnet: boolean }) => t.isTestnet
289+
);
290+
const mainnetTokens = tokens.filter(
291+
(t: { token: any; networkPrefix: string; isTestnet: boolean }) => !t.isTestnet
292+
);
270293

271294
if (testnetTokens.length > 0 && mainnetTokens.length > 0) {
272-
testnetTokens.forEach((testnetToken: any) => {
273-
mainnetTokens.forEach((mainnetToken: any) => {
295+
testnetTokens.forEach((testnetToken: { token: any; networkPrefix: string; isTestnet: boolean }) => {
296+
// For debugging token pairs
297+
// console.log({ testnetTokens, mainnetTokens });
298+
299+
mainnetTokens.forEach((mainnetToken: { token: any; networkPrefix: string; isTestnet: boolean }) => {
274300
// Skip checking decimal places for known exceptions
275301
const isException = knownDecimalExceptions.some(
276302
(exception) =>
@@ -350,13 +376,13 @@ describe('Token Naming Convention Tests', function () {
350376
tokensByBase.forEach((versions, _baseName) => {
351377
// If we have multiple versions of the same base coin
352378
if (versions.length > 1) {
353-
const testnetVersions = versions.filter((v: any) => v.isTestnet);
354-
const mainnetVersions = versions.filter((v: any) => !v.isTestnet);
379+
const testnetVersions = versions.filter((v: { token: any; name: string; isTestnet: boolean }) => v.isTestnet);
380+
const mainnetVersions = versions.filter((v: { token: any; name: string; isTestnet: boolean }) => !v.isTestnet);
355381

356382
// Check if we have both testnet and mainnet versions
357383
if (testnetVersions.length > 0 && mainnetVersions.length > 0) {
358-
testnetVersions.forEach((testnetVersion: any) => {
359-
mainnetVersions.forEach((mainnetVersion: any) => {
384+
testnetVersions.forEach((testnetVersion: { token: any; name: string; isTestnet: boolean }) => {
385+
mainnetVersions.forEach((mainnetVersion: { token: any; name: string; isTestnet: boolean }) => {
360386
// Testnet name should be 't' + mainnet name
361387
testnetVersion.name.should.equal(
362388
`t${mainnetVersion.name}`,

0 commit comments

Comments
 (0)