From 2e5d0593d2828d82a68b6774b1d85a4de8811008 Mon Sep 17 00:00:00 2001 From: Viki Val Date: Wed, 22 Mar 2023 23:55:20 +0100 Subject: [PATCH] :tada: Remarkable validator --- validate/graph.ts | 54 +++++++++++++++++++++++++++++++ validate/main.ts | 5 +++ validate/tests/collection.test.ts | 13 ++++++++ 3 files changed, 72 insertions(+) create mode 100644 validate/graph.ts create mode 100644 validate/main.ts create mode 100644 validate/tests/collection.test.ts diff --git a/validate/graph.ts b/validate/graph.ts new file mode 100644 index 0000000..12ec73f --- /dev/null +++ b/validate/graph.ts @@ -0,0 +1,54 @@ +// const GRAPHQL_URL = 'https://app.gc.subsquid.io/beta/rubick/009-rc0/graphql' +const RMRK_GRAPHQL_URL = 'https://gql-rmrk2-prod.graphcdn.app' + +import { + getClient, + graphFetch +} from 'https://esm.sh/@kodadot1/uniquery@0.2.2-rc.0' +import { query } from 'https://esm.sh/gql-query-builder@3.8.0' + +const client = getClient('rmrk2') + +export async function getKodaCollection(id: string): Promise { + const collection = client.collectionById(id, ['id', 'symbol', 'blockNumber', 'max', 'issuer', 'metadata', 'name', 'supply' ] as any) + const result = await client.fetch<{ data: any }>(collection) + return result.data.collection +} + +export async function getSingularCollection(id: string): Promise { + const q = query({ + operation: { + alias: 'collection', + name: 'collections_by_pk', + }, + fields: [ + 'id', + 'symbol', + 'blockNumber: block', + 'max', + 'issuer', + 'metadata', + 'name: metadata_name', + { 'count: nfts_aggregate': [ + { 'aggregate': [ + 'value :count' + ] } + ] } + ], + variables: { + id: { + type: 'String', + name: 'id', + required: true, + value: id, + } + }, + }) + + const result = await graphFetch<{ data: any }>(RMRK_GRAPHQL_URL, q) + const { data: { collection } } = result + const x = { ...collection, blockNumber: String(collection.blockNumber), supply: collection.count.aggregate.value } + delete x['count'] + return x +} + diff --git a/validate/main.ts b/validate/main.ts new file mode 100644 index 0000000..5ba0b1e --- /dev/null +++ b/validate/main.ts @@ -0,0 +1,5 @@ +import { parse } from "https://deno.land/std@0.180.0/flags/mod.ts" + +const flags = parse(Deno.args, { + string: ["entity", "id"], +}); \ No newline at end of file diff --git a/validate/tests/collection.test.ts b/validate/tests/collection.test.ts new file mode 100644 index 0000000..e1cbadc --- /dev/null +++ b/validate/tests/collection.test.ts @@ -0,0 +1,13 @@ +import { assertEquals } from "https://deno.land/std@0.180.0/testing/asserts.ts"; +import { getKodaCollection, getSingularCollection } from "../graph.ts"; + +Deno.test("Collection should be equal", async () => { + const id = '5412791fffe83a9b05-AW7TG' + const koda = await getKodaCollection(id) + const singular = await getSingularCollection(id) + + console.log(koda) + console.log(singular) + + assertEquals(koda, singular) +}); \ No newline at end of file