Skip to content

Commit

Permalink
Fix comma
Browse files Browse the repository at this point in the history
ref: #13
  • Loading branch information
DenisCarriere committed Oct 26, 2023
1 parent 79c42f6 commit 84cc566
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
36 changes: 24 additions & 12 deletions src/queries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ const transaction_id = "ab3612eed62a184eed2ae86bcad766183019cf40f82e5316f4d7c4e6
// Test Contract
test("getContracts", () => {
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, ''));
.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 Contract with optionals options
test("getContracts Optional", () => {
expect(getContracts(new URLSearchParams({ chain, address, symbol, greater_or_equals_by_timestamp, less_or_equals_by_timestamp, name, limit })).replace(/\s+/g, ''))
.toBe(`SELECT * FROM Contracts JOIN blocks ON blocks.block_id = Contracts.block_id WHERE(chain == '${chain}' AND address == '${address}' AND symbol == '${symbol}' AND name =='${name}' AND toUnixTimestamp(timestamp) >= ${greater_or_equals_by_timestamp} AND toUnixTimestamp(timestamp) <= ${less_or_equals_by_timestamp}) ORDER BY block_number DESC LIMIT ${limit} `.replace(/\s+/g, ''));
.toBe(`SELECT * FROM Contracts
JOIN blocks ON blocks.block_id = Contracts.block_id
WHERE (chain == '${chain}' AND address == '${address}' AND symbol == '${symbol}' AND name =='${name}' AND toUnixTimestamp(timestamp) >= ${greater_or_equals_by_timestamp} AND toUnixTimestamp(timestamp) <= ${less_or_equals_by_timestamp})
ORDER BY block_number DESC
LIMIT ${limit}`.replace(/\s+/g, ''));
});


Expand All @@ -38,13 +46,13 @@ test("getTotalSupply", () => {
Contracts.name as name,
Contracts.symbol as symbol,
Contracts.decimals as decimals,
timestamp,
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, ''));
WHERE (TotalSupply.chain == '${chain}' AND TotalSupply.address == '${address}')
ORDER BY block_number DESC
LIMIT 1`.replace(/\s+/g, ''));
});

// Test TotalSupply
Expand All @@ -60,13 +68,13 @@ test("getTotalSupply optional", () => {
Contracts.name as name,
Contracts.symbol as symbol,
Contracts.decimals as decimals,
timestamp,
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}' AND toUnixTimestamp(timestamp) >= ${greater_or_equals_by_timestamp} AND toUnixTimestamp(timestamp) <= ${less_or_equals_by_timestamp} AND symbol == '${symbol}' AND name == '${name}')
ORDER BY block_number
DESC LIMIT ${limit} `.replace(/\s+/g, ''));
WHERE (TotalSupply.chain == '${chain}' AND TotalSupply.address == '${address}' AND toUnixTimestamp(timestamp) >= ${greater_or_equals_by_timestamp} AND toUnixTimestamp(timestamp) <= ${less_or_equals_by_timestamp} AND symbol == '${symbol}' AND name == '${name}')
ORDER BY block_number DESC
LIMIT ${limit} `.replace(/\s+/g, ''));
});

// Test BalanceChanges
Expand All @@ -88,7 +96,9 @@ test("getBalanceChanges", () => {
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, ''))
WHERE (chain == '${chain}' AND owner == '${address}')
ORDER BY block_number DESC
LIMIT 1 `.replace(/\s+/g, ''))
});


Expand All @@ -111,7 +121,9 @@ test("getBalanceChanges Optional", () => {
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}' AND balance_changes.transaction_id == '${transaction_id}' AND toUnixTimestamp(timestamp) >= ${greater_or_equals_by_timestamp} AND toUnixTimestamp(timestamp) <= ${less_or_equals_by_timestamp}) ORDER BY block_number DESC LIMIT ${limit} `.replace(/\s+/g, ''))
WHERE (chain == '${chain}' AND owner == '${address}' AND balance_changes.transaction_id == '${transaction_id}' AND toUnixTimestamp(timestamp) >= ${greater_or_equals_by_timestamp} AND toUnixTimestamp(timestamp) <= ${less_or_equals_by_timestamp})
ORDER BY block_number DESC
LIMIT ${limit}`.replace(/\s+/g, ''))
});


Expand Down
2 changes: 1 addition & 1 deletion src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function getTotalSupply(searchParams: URLSearchParams) {
${contractTable}.name as name,
${contractTable}.symbol as symbol,
${contractTable}.decimals as decimals,
timestamp,
timestamp
FROM ${table} `;

// JOIN block table
Expand Down

0 comments on commit 84cc566

Please sign in to comment.