Skip to content

Commit

Permalink
fix: update tests to use pythnet/pythtest
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-bahjati committed Aug 27, 2024
1 parent 70eced3 commit 452568b
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 23 deletions.
5 changes: 3 additions & 2 deletions src/__tests__/Anchor.test.ts
Original file line number Diff line number Diff line change
@@ -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() })
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/Example.test.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/Mapping.test.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/__tests__/Price.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/Product.ETH.test.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/__tests__/Product.test.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
15 changes: 8 additions & 7 deletions src/__tests__/PythNetworkRestClient.test.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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])
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion src/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 452568b

Please sign in to comment.