From 65ff3e8d14b8c6a88935b6eb19016d7dc886bb5e Mon Sep 17 00:00:00 2001 From: Mathieu Lefebvre Date: Wed, 25 Oct 2023 13:25:56 -0400 Subject: [PATCH] update test (add more later) + remove console log --- src/queries.spec.ts | 47 +++++++++++++++++++++++++++++++++++++-------- src/queries.ts | 5 ----- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/queries.spec.ts b/src/queries.spec.ts index f4fb99e..5304e13 100644 --- a/src/queries.spec.ts +++ b/src/queries.spec.ts @@ -5,20 +5,51 @@ import { getContracts, getChain, getTotalSupply, getBalanceChanges } from "./que const chain = "eth"; const address = 'dac17f958d2ee523a2206206994597c13d831ec7' - +const limit = 1; test("getContracts", () => { - expect(getContracts(new URLSearchParams({ chain, address }))) - .toBe(`SELECT * FROM Contracts JOIN blocks ON blocks.block_id = Contracts.block_id WHERE (chain == '${chain}' AND address == '${address}') ORDER BY block_number DESC LIMIT 1`); + expect(getContracts(new URLSearchParams({ chain, address })).replace(/\s+/g, '')) + .toBe(`SELECT * FROM Contracts JOIN blocks ON blocks.block_id = Contracts.block_id WHERE(chain == '${chain}' AND address == '${address}') ORDER BY block_number DESC LIMIT 1 `.replace(/\s+/g, '')); }); test("getTotalSupply", () => { - expect(getTotalSupply(new URLSearchParams({ chain, address }))) - .toBe(`SELECT * FROM TotalSupply JOIN blocks ON blocks.block_id = TotalSupply.block_id WHERE (chain == '${chain}' AND address == '${address}') ORDER BY block_number DESC LIMIT 1`); + expect(getTotalSupply(new URLSearchParams({ chain, address })).replace(/\s+/g, '')) + .toBe(`SELECT + TotalSupply.address as address, + TotalSupply.supply as supply, + TotalSupply.id as id, + block_number, + TotalSupply.module_hash as module_hash, + TotalSupply.chain as chain, + Contracts.name as name, + Contracts.symbol as symbol, + Contracts.decimals as decimals, + timestamp, + FROM TotalSupply + JOIN blocks ON blocks.block_id = TotalSupply.block_id + LEFT JOIN Contracts ON Contracts.address = TotalSupply.address + WHERE(TotalSupply.chain == '${chain}' AND TotalSupply.address == '${address}') + ORDER BY block_number + DESC LIMIT 1 `.replace(/\s+/g, '')); }); - test("getBalanceChanges", () => { - expect(getBalanceChanges(new URLSearchParams({ chain, owner: address }))) - .toBe(`SELECT * FROM balance_changes JOIN blocks ON blocks.block_id = balance_changes.block_id WHERE (chain == '${chain}' AND owner == '${address}') ORDER BY block_number DESC LIMIT 1`); + expect(getBalanceChanges(new URLSearchParams({ chain, owner: address })).replace(/\s+/g, '')) + .toBe(`SELECT balance_changes.contract as contract, + Contracts.name as name, + Contracts.symbol as symbol, + Contracts.decimals as decimals, + balance_changes.owner as owner, + balance_changes.old_balance as old_balance, + balance_changes.new_balance as new_balance, + balance_changes.transaction_id as transaction_id, + balance_changes.id as id, + balance_changes.module_hash as module_hash, + balance_changes.chain as chain, + block_number, + timestamp + FROM balance_changes + JOIN blocks ON blocks.block_id = balance_changes.block_id + LEFT JOIN Contracts ON Contracts.address = balance_changes.contract + WHERE(chain == '${chain}' AND owner == '${address}') ORDER BY block_number DESC LIMIT 1 `.replace(/\s+/g, '')) }); test("getChain", () => { diff --git a/src/queries.ts b/src/queries.ts index b2c0310..d7680a3 100644 --- a/src/queries.ts +++ b/src/queries.ts @@ -24,7 +24,6 @@ export function getTotalSupply(searchParams: URLSearchParams) { timestamp, FROM ${table} `; - console.log(query); // JOIN block table query += ` JOIN blocks ON blocks.block_id = ${table}.block_id`; query += ` LEFT JOIN Contracts ON ${contractTable}.address = ${table}.address`; @@ -33,7 +32,6 @@ export function getTotalSupply(searchParams: URLSearchParams) { // equals if (chain) where.push(`${table}.chain == '${chain}'`); - console.log(address); if (address) where.push(`${table}.address == '${address}'`); const operators = [ @@ -62,7 +60,6 @@ export function getTotalSupply(searchParams: URLSearchParams) { query += ` ORDER BY block_number ${sort_by ?? DEFAULT_SORT_BY} ` query += ` LIMIT ${limit} ` - console.log(query); return query; } @@ -168,8 +165,6 @@ export function getBalanceChanges(searchParams: URLSearchParams) { const sort_by = searchParams.get("sort_by"); query += ` ORDER BY block_number ${sort_by ?? DEFAULT_SORT_BY} ` query += ` LIMIT ${limit} ` - - console.log(query) return query; }