Skip to content

Commit

Permalink
update test (add more later) + remove console log
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Lefebvre committed Oct 25, 2023
1 parent ccbb353 commit 65ff3e8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
47 changes: 39 additions & 8 deletions src/queries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
5 changes: 0 additions & 5 deletions src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand All @@ -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 = [
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 65ff3e8

Please sign in to comment.