From 452568b0a61732018db5962e78027c330aeb08b1 Mon Sep 17 00:00:00 2001 From: Ali Behjati Date: Tue, 27 Aug 2024 11:47:22 +0200 Subject: [PATCH] fix: update tests to use pythnet/pythtest --- src/__tests__/Anchor.test.ts | 5 +++-- src/__tests__/Example.test.ts | 6 +++--- src/__tests__/Mapping.test.ts | 6 +++--- src/__tests__/Price.test.ts | 5 +++-- src/__tests__/Product.ETH.test.ts | 6 +++--- src/__tests__/Product.test.ts | 5 +++-- src/__tests__/PythNetworkRestClient.test.ts | 15 ++++++++------- src/cluster.ts | 2 +- 8 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/__tests__/Anchor.test.ts b/src/__tests__/Anchor.test.ts index 1f988d0..d639aca 100644 --- a/src/__tests__/Anchor.test.ts +++ b/src/__tests__/Anchor.test.ts @@ -1,16 +1,17 @@ import { AnchorProvider, Wallet } from '@coral-xyz/anchor' import { Connection, Keypair, PublicKey } from '@solana/web3.js' import { BN } from 'bn.js' +import { getPythClusterApiUrl } from '../cluster' import { getPythProgramKeyForCluster, pythOracleProgram, pythOracleCoder } from '../index' test('Anchor', (done) => { jest.setTimeout(60000) const provider = new AnchorProvider( - new Connection('https://api.mainnet-beta.solana.com'), + new Connection(getPythClusterApiUrl('pythnet')), new Wallet(new Keypair()), AnchorProvider.defaultOptions(), ) - const pythOracle = pythOracleProgram(getPythProgramKeyForCluster('mainnet-beta'), provider) + const pythOracle = pythOracleProgram(getPythProgramKeyForCluster('pythnet'), provider) pythOracle.methods .initMapping() .accounts({ fundingAccount: PublicKey.unique(), freshMappingAccount: PublicKey.unique() }) diff --git a/src/__tests__/Example.test.ts b/src/__tests__/Example.test.ts index ca9803e..b9d1399 100644 --- a/src/__tests__/Example.test.ts +++ b/src/__tests__/Example.test.ts @@ -1,7 +1,7 @@ -import { clusterApiUrl, Connection, PublicKey } from '@solana/web3.js' -import { parseMappingData, parsePriceData, parseProductData } from '../index' +import { Connection, PublicKey } from '@solana/web3.js' +import { getPythClusterApiUrl, parseMappingData, parsePriceData, parseProductData } from '../index' -const SOLANA_CLUSTER_URL = clusterApiUrl('devnet') +const SOLANA_CLUSTER_URL = getPythClusterApiUrl('pythtest-crosschain') const ORACLE_MAPPING_PUBLIC_KEY = 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2' test('Mapping', (done) => { diff --git a/src/__tests__/Mapping.test.ts b/src/__tests__/Mapping.test.ts index eaef299..c4bb3c6 100644 --- a/src/__tests__/Mapping.test.ts +++ b/src/__tests__/Mapping.test.ts @@ -1,9 +1,9 @@ -import { clusterApiUrl, Connection, PublicKey } from '@solana/web3.js' -import { parseMappingData, Magic, Version } from '../index' +import { Connection, PublicKey } from '@solana/web3.js' +import { parseMappingData, Magic, Version, getPythClusterApiUrl } from '../index' test('Mapping', (done) => { jest.setTimeout(60000) - const url = clusterApiUrl('devnet') + const url = getPythClusterApiUrl('pythtest-crosschain') const oraclePublicKey = 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2' const connection = new Connection(url) const publicKey = new PublicKey(oraclePublicKey) diff --git a/src/__tests__/Price.test.ts b/src/__tests__/Price.test.ts index 94cbf16..af0326c 100644 --- a/src/__tests__/Price.test.ts +++ b/src/__tests__/Price.test.ts @@ -1,5 +1,6 @@ -import { clusterApiUrl, Connection, PublicKey } from '@solana/web3.js' +import { Connection, PublicKey } from '@solana/web3.js' import { + getPythClusterApiUrl, Magic, MAX_SLOT_DIFFERENCE, parseMappingData, @@ -11,7 +12,7 @@ import { test('Price', (done) => { jest.setTimeout(60000) - const url = clusterApiUrl('devnet') + const url = getPythClusterApiUrl('pythtest-crosschain') const oraclePublicKey = 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2' const connection = new Connection(url) const publicKey = new PublicKey(oraclePublicKey) diff --git a/src/__tests__/Product.ETH.test.ts b/src/__tests__/Product.ETH.test.ts index a3af53f..7bc8629 100644 --- a/src/__tests__/Product.ETH.test.ts +++ b/src/__tests__/Product.ETH.test.ts @@ -1,9 +1,9 @@ -import { clusterApiUrl, Connection, PublicKey } from '@solana/web3.js' -import { Magic, parseProductData, Version } from '../index' +import { Connection, PublicKey } from '@solana/web3.js' +import { getPythClusterApiUrl, Magic, parseProductData, Version } from '../index' test('Product', (done) => { jest.setTimeout(60000) - const url = clusterApiUrl('devnet') + const url = getPythClusterApiUrl('pythtest-crosschain') const ethProductKey = '2ciUuGZiee5macAMeQ7bHGTJtwcYTgnt6jdmQnnKZrfu' const connection = new Connection(url) const publicKey = new PublicKey(ethProductKey) diff --git a/src/__tests__/Product.test.ts b/src/__tests__/Product.test.ts index 0354055..9d27268 100644 --- a/src/__tests__/Product.test.ts +++ b/src/__tests__/Product.test.ts @@ -1,9 +1,10 @@ -import { clusterApiUrl, Connection, PublicKey } from '@solana/web3.js' +import { Connection, PublicKey } from '@solana/web3.js' +import { getPythClusterApiUrl } from '../cluster' import { parseMappingData, parseProductData, Magic, Version } from '../index' test('Product', (done) => { jest.setTimeout(60000) - const url = clusterApiUrl('devnet') + const url = getPythClusterApiUrl('pythtest-crosschain') const oraclePublicKey = 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2' const connection = new Connection(url) const publicKey = new PublicKey(oraclePublicKey) diff --git a/src/__tests__/PythNetworkRestClient.test.ts b/src/__tests__/PythNetworkRestClient.test.ts index a524e79..abd1240 100644 --- a/src/__tests__/PythNetworkRestClient.test.ts +++ b/src/__tests__/PythNetworkRestClient.test.ts @@ -1,11 +1,12 @@ -import { clusterApiUrl, Connection, PublicKey, SystemProgram } from '@solana/web3.js' +import { Connection, PublicKey, SystemProgram } from '@solana/web3.js' import { getPythProgramKeyForCluster, parseProductData, PythHttpClient } from '..' +import { getPythClusterApiUrl } from '../cluster' test('PythHttpClientCall: getData', (done) => { - jest.setTimeout(20000) + jest.setTimeout(60000) try { - const programKey = getPythProgramKeyForCluster('testnet') - const currentConnection = new Connection(clusterApiUrl('testnet')) + const programKey = getPythProgramKeyForCluster('pythtest-conformance') + const currentConnection = new Connection(getPythClusterApiUrl('pythtest-conformance')) const pyth_client = new PythHttpClient(currentConnection, programKey) pyth_client.getData().then( (result) => { @@ -30,7 +31,7 @@ test('PythHttpClientCall: getAssetPricesFromAccounts for one account', (done) => const solUSDKey = new PublicKey('7VJsBtJzgTftYzEeooSDYyjKXvYRWJHdwvbwfBvTg9K') try { const programKey = getPythProgramKeyForCluster('testnet') - const currentConnection = new Connection(clusterApiUrl('testnet')) + const currentConnection = new Connection(getPythClusterApiUrl('pythtest-conformance')) const pyth_client = new PythHttpClient(currentConnection, programKey) pyth_client .getAssetPricesFromAccounts([solUSDKey]) @@ -66,7 +67,7 @@ test('PythHttpClientCall: getAssetPricesFromAccounts for multiple accounts', (do try { const programKey = getPythProgramKeyForCluster('testnet') - const currentConnection = new Connection(clusterApiUrl('testnet')) + const currentConnection = new Connection(getPythClusterApiUrl('pythtest-conformance')) const pyth_client = new PythHttpClient(currentConnection, programKey) pyth_client .getAssetPricesFromAccounts([solUSDKey, bonkUSDKey, usdcUSDKey]) @@ -106,7 +107,7 @@ test('PythHttpClientCall: getAssetPricesFromAccounts should throw for invalid ac try { const programKey = getPythProgramKeyForCluster('testnet') - const currentConnection = new Connection(clusterApiUrl('testnet')) + const currentConnection = new Connection(getPythClusterApiUrl('pythtest-conformance')) const pyth_client = new PythHttpClient(currentConnection, programKey) pyth_client .getAssetPricesFromAccounts([solUSDKey, systemProgram, usdcUSDKey]) diff --git a/src/cluster.ts b/src/cluster.ts index fd09c0d..cefdf19 100644 --- a/src/cluster.ts +++ b/src/cluster.ts @@ -32,7 +32,7 @@ export function getPythClusterApiUrl(cluster: PythCluster): string { if (cluster === 'pythtest-conformance' || cluster === 'pythtest-crosschain') { return 'https://api.pythtest.pyth.network' } else if (cluster === 'pythnet') { - return 'https://pythnet.rpcpool.com' + return 'https://api2.pythnet.pyth.network' } else if (cluster === 'localnet') { return 'http://localhost:8899' } else {