|
1 | 1 | import { AnchorProvider, Wallet } from '@coral-xyz/anchor' |
2 | 2 | import { Connection, Keypair, PublicKey } from '@solana/web3.js' |
3 | 3 | import { BN } from 'bn.js' |
| 4 | +import { getPythClusterApiUrl } from '../cluster' |
4 | 5 | import { getPythProgramKeyForCluster, pythOracleProgram, pythOracleCoder } from '../index' |
5 | 6 |
|
6 | 7 | test('Anchor', (done) => { |
7 | 8 | jest.setTimeout(60000) |
8 | 9 | const provider = new AnchorProvider( |
9 | | - new Connection('https://api.mainnet-beta.solana.com'), |
| 10 | + new Connection(getPythClusterApiUrl('pythnet')), |
10 | 11 | new Wallet(new Keypair()), |
11 | 12 | AnchorProvider.defaultOptions(), |
12 | 13 | ) |
13 | | - const pythOracle = pythOracleProgram(getPythProgramKeyForCluster('mainnet-beta'), provider) |
| 14 | + const pythOracle = pythOracleProgram(getPythProgramKeyForCluster('pythnet'), provider) |
14 | 15 | pythOracle.methods |
15 | 16 | .initMapping() |
16 | 17 | .accounts({ fundingAccount: PublicKey.unique(), freshMappingAccount: PublicKey.unique() }) |
@@ -202,5 +203,30 @@ test('Anchor', (done) => { |
202 | 203 | expect(decoded?.data.securityAuthority.equals(new PublicKey(8))).toBeTruthy() |
203 | 204 | }) |
204 | 205 |
|
| 206 | + pythOracle.methods |
| 207 | + .setMaxLatency(1, [0, 0, 0]) |
| 208 | + .accounts({ fundingAccount: PublicKey.unique(), priceAccount: PublicKey.unique() }) |
| 209 | + .instruction() |
| 210 | + .then((instruction) => { |
| 211 | + expect(instruction.data).toStrictEqual(Buffer.from([2, 0, 0, 0, 18, 0, 0, 0, 1, 0, 0, 0])) |
| 212 | + const decoded = pythOracleCoder().instruction.decode(instruction.data) |
| 213 | + expect(decoded?.name).toBe('setMaxLatency') |
| 214 | + expect(decoded?.data.maxLatency === 1).toBeTruthy() |
| 215 | + }) |
| 216 | + |
| 217 | + pythOracle.methods |
| 218 | + .initPriceFeedIndex() |
| 219 | + .accounts({ |
| 220 | + fundingAccount: PublicKey.unique(), |
| 221 | + priceAccount: PublicKey.unique(), |
| 222 | + }) |
| 223 | + .instruction() |
| 224 | + .then((instruction) => { |
| 225 | + expect(instruction.data).toStrictEqual(Buffer.from([2, 0, 0, 0, 19, 0, 0, 0])) |
| 226 | + const decoded = pythOracleCoder().instruction.decode(instruction.data) |
| 227 | + expect(decoded?.name).toBe('initPriceFeedIndex') |
| 228 | + expect(decoded?.data).toStrictEqual({}) |
| 229 | + }) |
| 230 | + |
205 | 231 | done() |
206 | 232 | }) |
0 commit comments