|
| 1 | +import * as should from 'should'; |
| 2 | +import { ofcCoins } from '../../src/coins/ofcCoins'; |
| 3 | +import { NetworkType } from '../../src/networks'; |
| 4 | + |
| 5 | +describe('OFC Token Naming Convention Tests', function () { |
| 6 | + it('should have all testnet tokens on test network and mainnet tokens on main network', function () { |
| 7 | + // Known exceptions for testnet tokens that don't follow the typical naming pattern |
| 8 | + const testnetExceptions = ['ofcgteth', 'ofchteth', 'ofchooditeth']; |
| 9 | + |
| 10 | + ofcCoins.forEach((token) => { |
| 11 | + if (token.network.type === NetworkType.TESTNET) { |
| 12 | + // Skip checking naming convention for known exceptions |
| 13 | + if (testnetExceptions.includes(token.name)) { |
| 14 | + return; |
| 15 | + } |
| 16 | + |
| 17 | + // All testnet tokens should start with 'ofct' |
| 18 | + token.name.startsWith('ofct').should.be.true(`Testnet token ${token.name} should start with 'ofct'`); |
| 19 | + } else if (token.network.type === NetworkType.MAINNET) { |
| 20 | + // All mainnet tokens should start with 'ofc' |
| 21 | + token.name.startsWith('ofc').should.be.true(`Mainnet token ${token.name} should start with 'ofc'`); |
| 22 | + |
| 23 | + // Special case handling for tokens where the asset name starts with 't' |
| 24 | + // (e.g., ofctia for TIA/Celestia), these should be exempt from the 'ofct' check |
| 25 | + const assetName = token.asset.toString().toLowerCase(); |
| 26 | + const isSpecialCase = assetName.startsWith('t'); |
| 27 | + |
| 28 | + if (!isSpecialCase) { |
| 29 | + token.name.startsWith('ofct').should.be.false(`Mainnet token ${token.name} should not start with 'ofct'`); |
| 30 | + } |
| 31 | + } |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should have consistent fullName format for testnet tokens', function () { |
| 36 | + const testnetTokens = ofcCoins.filter((token) => token.network.type === NetworkType.TESTNET); |
| 37 | + |
| 38 | + testnetTokens.forEach((token) => { |
| 39 | + // All tokens should have a fullName defined |
| 40 | + should.exist(token.fullName, `Token ${token.name} is missing a fullName`); |
| 41 | + |
| 42 | + // Known exceptions that don't follow the "Test" or "Testnet" pattern |
| 43 | + const knownExceptions = [ |
| 44 | + 'ofcttrx:usdt', // "Tether USD" |
| 45 | + 'ofcttrx:usd1', // "USD1 Token" |
| 46 | + 'ofcttrx:stgusd1', // "Staging USD1 Token" |
| 47 | + 'ofctxrp:rlusd', // "RLUSD" |
| 48 | + 'ofctxrp:xsgd', // "XSGB" |
| 49 | + 'ofctpolygon:usdc', // "USD Coin" |
| 50 | + 'ofctpolygon:usdt', // "Tether USD" |
| 51 | + 'ofctpolygon:xsgd', // "XSGD" |
| 52 | + 'ofctnear:usdc', // "USD Coin" |
| 53 | + ]; |
| 54 | + |
| 55 | + if (!knownExceptions.includes(token.name)) { |
| 56 | + const fullName = token.fullName.toLowerCase(); |
| 57 | + const hasTestIndicator = |
| 58 | + fullName.startsWith('test ') || fullName.startsWith('testnet ') || fullName.includes('test'); |
| 59 | + |
| 60 | + hasTestIndicator.should.be.true( |
| 61 | + `Testnet token ${token.name} has fullName "${token.fullName}" which should include "test" or "testnet"` |
| 62 | + ); |
| 63 | + } |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should maintain network consistency between mainnet and testnet token pairs', function () { |
| 68 | + // Test for network tokens (those with a colon in the name) |
| 69 | + const mainnetNetworkTokens = ofcCoins.filter((token) => token.network.type === NetworkType.MAINNET); |
| 70 | + |
| 71 | + mainnetNetworkTokens.forEach((mainToken) => { |
| 72 | + // Replace 'ofc' with 'ofct' to get expected testnet token name |
| 73 | + const expectedTestTokenName = mainToken.name.replace(/^ofc/, 'ofct'); |
| 74 | + |
| 75 | + // Find the matching testnet token if it exists |
| 76 | + const testToken = ofcCoins.find((token) => token.name === expectedTestTokenName); |
| 77 | + |
| 78 | + if (testToken) { |
| 79 | + testToken.network.type.should.equal( |
| 80 | + NetworkType.TESTNET, |
| 81 | + `Token ${expectedTestTokenName} should be on testnet network` |
| 82 | + ); |
| 83 | + } |
| 84 | + }); |
| 85 | + }); |
| 86 | + |
| 87 | + it('should maintain matching decimal places between mainnet and testnet pairs when possible', function () { |
| 88 | + // Known exceptions where mainnet and testnet tokens intentionally have different decimal places |
| 89 | + const knownDecimalExceptions = [ |
| 90 | + { mainnet: 'ofcdot', testnet: 'ofctdot' }, // 10 vs 12 decimal places |
| 91 | + { mainnet: 'ofcsol:usdt', testnet: 'ofctsol:usdt' }, // 6 vs 9 decimal places |
| 92 | + { mainnet: 'ofcsol:usdc', testnet: 'ofctsol:usdc' }, // 6 vs 9 decimal places |
| 93 | + { mainnet: 'ofcsol:srm', testnet: 'ofctsol:srm' }, // 6 vs 9 decimal places |
| 94 | + { mainnet: 'ofcsol:slnd', testnet: 'ofctsol:slnd' }, // 6 vs 9 decimal places |
| 95 | + { mainnet: 'ofcsol:ray', testnet: 'ofctsol:ray' }, // 6 vs 9 decimal places |
| 96 | + { mainnet: 'ofcsol:orca', testnet: 'ofctsol:orca' }, // 6 vs 9 decimal places |
| 97 | + ]; |
| 98 | + |
| 99 | + const mainnetBasicTokens = ofcCoins.filter((token) => token.network.type === NetworkType.MAINNET); |
| 100 | + |
| 101 | + mainnetBasicTokens.forEach((mainToken) => { |
| 102 | + const mainTokenName = mainToken.name; |
| 103 | + const expectedTestTokenName = mainTokenName.replace(/^ofc/, 'ofct'); |
| 104 | + |
| 105 | + // Skip known exceptions where decimal places are intentionally different |
| 106 | + const isException = knownDecimalExceptions.some((exception) => exception.mainnet === mainTokenName); |
| 107 | + |
| 108 | + if (isException) { |
| 109 | + return; |
| 110 | + } |
| 111 | + |
| 112 | + // Find the matching testnet token if it exists |
| 113 | + const testToken = ofcCoins.find((token) => token.name === expectedTestTokenName); |
| 114 | + |
| 115 | + if (testToken) { |
| 116 | + testToken.decimalPlaces.should.equal( |
| 117 | + mainToken.decimalPlaces, |
| 118 | + `Token ${mainToken.name} has ${mainToken.decimalPlaces} decimal places, but its testnet counterpart ${testToken.name} has ${testToken.decimalPlaces}` |
| 119 | + ); |
| 120 | + } |
| 121 | + }); |
| 122 | + }); |
| 123 | +}); |
0 commit comments