diff --git a/src/repo/index.test.ts b/src/repo/index.test.ts new file mode 100644 index 0000000..69b1917 --- /dev/null +++ b/src/repo/index.test.ts @@ -0,0 +1,9 @@ +import test from "ava"; +import { getDirPathForTokenlist } from "."; + +test("getDirPathForTokenlist calculates the correct directory", async (t) => { + const network = 'ethereum'; + const address = '0x'; + + t.deepEqual(getDirPathForTokenlist(network, address), `/networks/ethereum/assets/${network}-tokenlist/${address}`); +}); \ No newline at end of file diff --git a/src/repo/index.ts b/src/repo/index.ts index dd49ab6..97d708b 100644 --- a/src/repo/index.ts +++ b/src/repo/index.ts @@ -67,14 +67,14 @@ export function getGithubHostedFileUrl (dir: string, fileName: string) { } export function getDirPathForNetworkCode (network: string) { - return `/networks/${network}`; + return path.join('networks', network); } export function getDirPathForTokenlist (network: string, address?: string) { - return getDirPathForNetworkCode(network) + `/assets/${network}-tokenlist` + (address ? `/${address}` : ''); + return path.join(getDirPathForNetworkCode(network),'assets',`${network}-tokenlist`, (address ? `/${address}` : '')); } -export async function addIdentifierToAsset(path: string, networkCode: string, address: string, identifierKey: string, identifierValue: string | number): Promise<{addedIdentifier: boolean}> { +export async function addIdentifierToAsset(dir: string, networkCode: string, address: string, identifierKey: string, identifierValue: string | number): Promise<{addedIdentifier: boolean}> { const ALLOWED_IDENTIFIER_KEYS_FOR_ASSETS = [ 'coinmarketcap' @@ -84,9 +84,10 @@ export async function addIdentifierToAsset(path: string, networkCode: string, ad throw new Error('Identifier key ' + identifierKey + ' is not allowed for assets'); } - const assetInfoFilePath = path + getDirPathForTokenlist(networkCode, address); + const assetInfoFilePath = path.join(dir, getDirPathForTokenlist(networkCode, address), 'info.json'); if(!fs.existsSync(assetInfoFilePath)) { + console.error('addIdentifierToAsset Cannot find asset info file for asset ' + address + ' in directory ' + dir); return { addedIdentifier: false }; } diff --git a/src/utils/tcrs/kleros-tcr.ts b/src/utils/tcrs/kleros-tcr.ts index c42dbd3..beaa3de 100644 --- a/src/utils/tcrs/kleros-tcr.ts +++ b/src/utils/tcrs/kleros-tcr.ts @@ -33,6 +33,7 @@ export async function checkIfAssetInKlerosTCR(address: string): Promise