-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Script to compare results with prod, improve all-token-balance-…
…history and swap endpoint, return -token-balance-history endpoint.
- Loading branch information
1 parent
d52e404
commit 5730090
Showing
8 changed files
with
398 additions
and
328 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import axios, { AxiosResponse } from 'axios'; | ||
import chalk from 'chalk'; | ||
|
||
const PROD_URL = 'https://ref-sdk-api.fly.dev'; | ||
const LOCAL_URL = 'http://localhost:3000'; | ||
|
||
type QueryParams = { | ||
token?: string; | ||
account?: string; | ||
account_id?: string; | ||
token_id?: string; | ||
treasuryDaoID?: string; | ||
tokenIn?: string; | ||
tokenOut?: string; | ||
amountIn?: string; | ||
slippage?: string; | ||
[key: string]: string | undefined; | ||
}; | ||
|
||
interface EndpointResponse { | ||
data: unknown; | ||
status: number; | ||
} | ||
|
||
const endpoints = [ | ||
// '/api/token-metadata', | ||
// '/api/whitelist-tokens', I made some changes to whitelist-tokens so they differ | ||
'/api/swap', | ||
'/api/near-price', | ||
'/api/ft-tokens', | ||
// '/api/all-token-balance-history', | ||
// '/api/transactions-transfer-history' | ||
] as const; | ||
|
||
type Endpoint = typeof endpoints[number]; | ||
|
||
async function compareEndpoints(endpoint: Endpoint, queryParams: QueryParams = {}): Promise<void> { | ||
console.log(chalk.blue(`\nTesting ${endpoint}`)); | ||
console.log(chalk.blue('Query params:', JSON.stringify(queryParams, null, 2))); | ||
|
||
try { | ||
const prodUrl = `${PROD_URL}${endpoint}`; | ||
const localUrl = `${LOCAL_URL}${endpoint}`; | ||
|
||
console.log(chalk.blue(`Making requests to:`)); | ||
console.log(chalk.blue(`PROD: ${prodUrl}`)); | ||
console.log(chalk.blue(`LOCAL: ${localUrl}`)); | ||
|
||
let prodRes: AxiosResponse | null = null; | ||
let localRes: AxiosResponse | null = null; | ||
|
||
try { | ||
prodRes = await axios.get(prodUrl, { params: queryParams }); | ||
console.log(chalk.green('✓ Production request successful')); | ||
} catch (error) { | ||
console.log(chalk.red('✗ Production request failed:')); | ||
if (axios.isAxiosError(error)) { | ||
console.log(chalk.red(`Status: ${error.response?.status}`)); | ||
console.log(chalk.red(`Error: ${error.message}`)); | ||
console.log(chalk.red(`Response data:`, JSON.stringify(error.response?.data, null, 2))); | ||
} | ||
} | ||
|
||
try { | ||
localRes = await axios.get(localUrl, { params: queryParams }); | ||
console.log(chalk.green('✓ Local request successful')); | ||
} catch (error) { | ||
console.log(chalk.red('✗ Local request failed:')); | ||
if (axios.isAxiosError(error)) { | ||
console.log(chalk.red(`Status: ${error.response?.status}`)); | ||
console.log(chalk.red(`Error: ${error.message}`)); | ||
console.log(chalk.red(`Response data:`, JSON.stringify(error.response?.data, null, 2))); | ||
} | ||
} | ||
|
||
if (!prodRes || !localRes) { | ||
return; | ||
} | ||
|
||
const prodData = JSON.stringify(prodRes.data, null, 2); | ||
const localData = JSON.stringify(localRes.data, null, 2); | ||
|
||
if (prodData === localData) { | ||
console.log(chalk.green('✓ Responses match')); | ||
} else { | ||
const prodLines = prodData.split('\n'); | ||
const localLines = localData.split('\n'); | ||
const diffCount = prodLines.reduce((count, line, index) => | ||
count + (line !== localLines[index] ? 1 : 0), 0); | ||
|
||
console.log(chalk.red(`✗ Responses differ (${diffCount} lines):`)); | ||
console.log('\nDifferences:'); | ||
|
||
prodLines.forEach((line, index) => { | ||
if (line !== localLines[index]) { | ||
console.log(chalk.red(`Line ${index + 1}:`)); | ||
console.log(chalk.yellow(`Prod: ${line}`)); | ||
console.log(chalk.yellow(`Local: ${localLines[index] || '(missing)'}`)); | ||
console.log(); | ||
} | ||
}); | ||
} | ||
} catch (error) { | ||
console.log(chalk.red(`Error in comparison:`)); | ||
console.log(chalk.red(error instanceof Error ? error.stack : String(error))); | ||
} | ||
} | ||
|
||
async function runTests(queryParams: QueryParams): Promise<void> { | ||
console.log(chalk.cyan('Starting endpoint comparison tests...')); | ||
console.log(chalk.cyan('Using query parameters:')); | ||
console.log(queryParams); | ||
|
||
for (const endpoint of endpoints) { | ||
await compareEndpoints(endpoint, queryParams); | ||
} | ||
} | ||
|
||
// Usage example: | ||
// Replace this object with your desired query parameters | ||
const queryParams: QueryParams = { | ||
token: 'near', | ||
account: 'testing-treasury.sputnik-dao.near', | ||
account_id: 'testing-treasury.sputnik-dao.near', | ||
token_id: 'near', | ||
treasuryDaoID: 'testing-treasury.sputnik-dao.near', | ||
tokenIn: 'near', | ||
tokenOut: 'wrap.near', | ||
amountIn: '1000000000000000000000000', // 1 NEAR (24 decimals) | ||
slippage: '0.01' | ||
}; | ||
|
||
runTests(queryParams); |
Oops, something went wrong.