From aa3c85cfc6fee46a3c3d511e3245fb184464cc77 Mon Sep 17 00:00:00 2001 From: Amadeo Pellicce Date: Tue, 20 Sep 2022 10:22:37 +0200 Subject: [PATCH 1/3] adding getNetworksWithAssets API --- src/networks/index.test.ts | 11 ++++++++++- src/networks/index.ts | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/networks/index.test.ts b/src/networks/index.test.ts index 78ad498..5d7f797 100644 --- a/src/networks/index.test.ts +++ b/src/networks/index.test.ts @@ -1,5 +1,5 @@ import test from "ava"; -import { getAssetMapping, getNetworks } from "."; +import { getAssetMapping, getNetworks, getNetworksWithAssets } from "."; test("networks includes ethereum", async (t) => { const networks = await getNetworks(); @@ -11,3 +11,12 @@ test("Mappings can be read successfully", async (t) => { t.truthy(mappings.length > 0); }); +test("networks with assets includes polygon", async (t) => { + const networks = await getNetworksWithAssets(); + t.truthy(networks.find((n) => n.name === "Polygon")); +}); + +test("networks with assets does not include Bitcoin", async (t) => { + const networks = await getNetworksWithAssets(); + t.falsy(networks.find((n) => n.name === "Bitcoin")); +}); \ No newline at end of file diff --git a/src/networks/index.ts b/src/networks/index.ts index 66aeaa1..73c28ac 100644 --- a/src/networks/index.ts +++ b/src/networks/index.ts @@ -37,6 +37,44 @@ export async function getNetworks(dir?: string): Promise { } } +export async function getNetworksWithAssets(dir?: string): Promise { + if (!dir) { + dir = DEFAULT_REPO_DISK_LOCATION; + } + + const res: Network[] = []; + + try { + await cloneOrPullRepoAndUpdateSubmodules(REPO_CLONE_URL, dir, true, "master"); + + const directories = await getDirectories(dir); + + directories.forEach((directory) => { + const split = directory.split("/"); + const baseDirIsNetworkDir = split[split.length - 2] === "networks"; + const dirIsGitDir = directory.includes(".git") + + if (baseDirIsNetworkDir && !dirIsGitDir) { + const networkName = split[split.length - 1]; + + const networkHasAssets = fs.existsSync(`${directory}/assets/${networkName}-tokenlist`); + + if(networkHasAssets) { + res.push(readAndParseJson(`${directory}/info.json`)); + } + } + }); + + if (res.length === 0) { + throw new Error(`getNetworks No networks found in ${dir}`); + } + + return res; + } catch (err) { + throw err; + } +} + export async function getAssetsForNetwork(network: string, dir?: string): Promise { if (!dir) { dir = DEFAULT_REPO_DISK_LOCATION; From 108203536937602f760591c7d37ac7935705923b Mon Sep 17 00:00:00 2001 From: Amadeo Pellicce Date: Tue, 20 Sep 2022 10:22:49 +0200 Subject: [PATCH 2/3] fixing failing tests with git API --- src/utils/git.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/git.test.ts b/src/utils/git.test.ts index d3a5ec4..5397057 100644 --- a/src/utils/git.test.ts +++ b/src/utils/git.test.ts @@ -1,6 +1,6 @@ import test from "ava"; import fs from "fs"; -import { cloneOrPullRepoAndUpdateSubmodules, getCommitId } from "./git"; +import { cloneOrPullRepoAndUpdateSubmodules, commit, getCommitId } from "./git"; const REPO_CLONE_URL = "git@github.com:map3xyz/assets.git"; const DEFAULT_REPO_DISK_LOCATION = "./tmp/map3xyz-assets"; @@ -21,7 +21,7 @@ test("we are able to get the commit id of a tag", async (t) => { try { await cloneOrPullRepoAndUpdateSubmodules(REPO_CLONE_URL, DEFAULT_REPO_DISK_LOCATION, true, "master"); const commitId = await getCommitId(DEFAULT_REPO_DISK_LOCATION, "HEAD"); - t.true(commitId.length === 16); + t.true(commitId.length === 16 || commitId.length === 8); } catch (err) { t.fail(err.message); } From af7e07b4f136c26039bd1a7e769d2af3ec1682d5 Mon Sep 17 00:00:00 2001 From: Amadeo Pellicce Date: Tue, 20 Sep 2022 10:23:56 +0200 Subject: [PATCH 3/3] 1.0.136 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9e7dfb2..a19c9e6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@map3xyz/assets-helper", - "version": "1.0.135", + "version": "1.0.136", "description": "A library for maintaining the assets repo.", "author": "pellicceama", "keywords": [