Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: test errors #78

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,5 @@ pnpm-lock.yaml
package-lock.json

.DS_Store

.vscode
9 changes: 0 additions & 9 deletions jest.config.js

This file was deleted.

7 changes: 5 additions & 2 deletions src/chains/supportedChains.evm.int.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createPublicClient, http } from 'viem'
import { describe, expect, test } from 'vitest'
import { supportedEVMChains } from './supportedChains.evm'
import { isSameUrl } from './utils'

describe.concurrent('EVM chains RPC check', () => {
const rpcUrls = supportedEVMChains.flatMap((chain) =>
Expand Down Expand Up @@ -39,8 +40,10 @@ describe.concurrent('EVM chains block explorer check', () => {
{ timeout: 10_000, retry: 3 },
async ({ blockExplorerUrl }) => {
const response = await fetch(blockExplorerUrl)
expect(response.url).toBe(blockExplorerUrl)
expect(response.ok).toBe(true)

// Ensure the / is removed from the end of the URL
expect(isSameUrl(blockExplorerUrl, response.url)).toBeTruthy()
expect(response.ok).toBeTruthy()
expect(response.status).toBe(200)
}
)
Expand Down
18 changes: 15 additions & 3 deletions src/chains/supportedChains.svm.int.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Connection, PublicKey } from '@solana/web3.js'
import { describe, expect, test } from 'vitest'
import { supportedSolanaChains } from './supportedChains.svm'
import { isSameUrl } from './utils'

const TokenProgramAddress = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
const WalletAddress = '6AUWsSCRFSCbrHKH9s84wfzJXtD6mNzAHs11x6pGEcmJ'
Expand All @@ -22,8 +23,19 @@
const accountPublicKey = new PublicKey(WalletAddress)
const tokenProgramPublicKey = new PublicKey(TokenProgramAddress)
const [blockHeight, slot, balance, tokenAccountsByOwner] =
// connection.getBlockHeight() with https://solana-rpc.publicnode.com will result in 500 error
await Promise.allSettled([
connection.getBlockHeight(),
fetch(rpcUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getBlockHeight',
}),
}),
connection.getSlot(),
connection.getBalance(accountPublicKey),
connection.getParsedTokenAccountsByOwner(accountPublicKey, {
Expand Down Expand Up @@ -52,8 +64,8 @@
{ timeout: 10_000, retry: 3 },
async ({ blockExplorerUrl }) => {
const response = await fetch(blockExplorerUrl)
expect(response.url).toBe(blockExplorerUrl)
expect(response.ok).toBe(true)
expect(isSameUrl(blockExplorerUrl, response.url)).toBeTruthy()
expect(response.ok).toBeTruthy()

Check failure on line 68 in src/chains/supportedChains.svm.int.spec.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

src/chains/supportedChains.svm.int.spec.ts > SVM chains block explorer check > block explorer should be alive 'Solana' - 1151111081099710 - 'https://solscan.io/'

AssertionError: expected false to be truthy ❯ src/chains/supportedChains.svm.int.spec.ts:68:27

Check failure on line 68 in src/chains/supportedChains.svm.int.spec.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

src/chains/supportedChains.svm.int.spec.ts > SVM chains block explorer check > block explorer should be alive 'Solana' - 1151111081099710 - 'https://solscan.io/'

AssertionError: expected false to be truthy ❯ src/chains/supportedChains.svm.int.spec.ts:68:27

Check failure on line 68 in src/chains/supportedChains.svm.int.spec.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

src/chains/supportedChains.svm.int.spec.ts > SVM chains block explorer check > block explorer should be alive 'Solana' - 1151111081099710 - 'https://solscan.io/'

AssertionError: expected false to be truthy ❯ src/chains/supportedChains.svm.int.spec.ts:68:27

Check failure on line 68 in src/chains/supportedChains.svm.int.spec.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

src/chains/supportedChains.svm.int.spec.ts > SVM chains block explorer check > block explorer should be alive 'Solana' - 1151111081099710 - 'https://solscan.io/'

AssertionError: expected false to be truthy ❯ src/chains/supportedChains.svm.int.spec.ts:68:27
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm what is ok in that case? Because 'false' is truthy, so do we really want this behaviour?

Copy link
Collaborator Author

@myz1237 myz1237 Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • To be honest, I do not wanna this test cases for solana, evm and utxo, since the test really calls external service, which are unstable, that's the reason why we fail at most of time.

Any input @chybisov You added these tests, is it fine to remove it and just check if the url is legal or not?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chybisov Do we wanna remove it? Otherwise the test does not work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solana explorers should pass tests fine, there were some issues with Bitcoin ones. Would you like to remove these checks completely?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I wanna remove them completely, and just ensure the rpc and explorer array are not empty.
Normally, we add multiple rpcs, some of them may be invalid, or we are blocked. Same to explorer, the explorer could refuse our request, which are unstable.
what do you think of it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed all tests about the block explorer links

expect(response.status).toBe(200)
}
)
Expand Down
3 changes: 2 additions & 1 deletion src/chains/supportedChains.utxo.int.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, test } from 'vitest'
import { supportedUXTOChains } from './supportedChains.utxo'
import { isSameUrl } from './utils'

describe.concurrent('UTXO chains RPC check', () => {
const rpcUrls = supportedUXTOChains.flatMap((chain) =>
Expand Down Expand Up @@ -48,7 +49,7 @@ describe.concurrent('UTXO chains block explorer check', () => {
{ timeout: 10_000, retry: 3 },
async ({ blockExplorerUrl }) => {
const response = await fetch(blockExplorerUrl)
expect(response.url).toBe(blockExplorerUrl)
expect(isSameUrl(blockExplorerUrl, response.url)).toBeTruthy()
expect(response.ok).toBe(true)
expect(response.status).toBe(200)
}
Expand Down
4 changes: 4 additions & 0 deletions src/chains/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export const prefixChainId = (chainId: number): string => {
return '0x' + chainId.toString(16)
}

// Used in test only, check if the URL is the same without the trailing slash
export const isSameUrl = (url1: string, url2: string): boolean =>
url1.replace(/\/$/, '') === url2.replace(/\/$/, '')
2 changes: 1 addition & 1 deletion src/coins/coins.int.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe.concurrent('Coin logo test', { timeout: 30_000 }, () => {
...Object.values(wrappedTokens).map((token: StaticToken) => token.logoURI!)
)

test.each([...new Set(allImages)])(
test.each(Array.from(new Set(allImages)))(
myz1237 marked this conversation as resolved.
Show resolved Hide resolved
'check that logoURI %s is valid',
async (image) => {
expect(image.startsWith('https://')).toBeTruthy()
Expand Down
Loading