Skip to content

Commit 2cace22

Browse files
committed
Checkpoint
1 parent 86bb029 commit 2cace22

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

src/__tests__/Anchor.test.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AnchorProvider, Wallet } from '@coral-xyz/anchor'
22
import { Connection, Keypair, PublicKey } from '@solana/web3.js'
3-
import { getPythProgramKeyForCluster, pythOracleProgram } from '../index'
3+
import { getPythProgramKeyForCluster, pythOracleProgram, PythOracleCoder } from '../index'
44

55
test('Anchor', (done) => {
66
jest.setTimeout(60000)
@@ -12,13 +12,33 @@ test('Anchor', (done) => {
1212
const pythOracle = pythOracleProgram(getPythProgramKeyForCluster('mainnet-beta'), provider)
1313
pythOracle.methods
1414
.initMapping()
15-
.accounts({ fundingAccount: new PublicKey(0) })
15+
.accounts({ fundingAccount: new PublicKey(0), freshMappingAccount: new PublicKey(1) })
1616
.instruction()
17-
.then((x) => console.log(x))
17+
.then((instruction) => {
18+
expect(instruction.data).toStrictEqual(Buffer.from([2, 0, 0, 0, 0, 0, 0, 0]))
19+
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
20+
expect(decoded?.name).toBe('initMapping')
21+
expect(decoded?.data).toStrictEqual({})
22+
})
1823
pythOracle.methods
1924
.addMapping()
20-
.accounts({ fundingAccount: new PublicKey(0) })
25+
.accounts({ fundingAccount: new PublicKey(0), curMapping: new PublicKey(1), nextMapping: new PublicKey(2) })
2126
.instruction()
22-
.then((x) => console.log(x))
27+
.then((instruction) => {
28+
expect(instruction.data).toStrictEqual(Buffer.from([2, 0, 0, 0, 1, 0, 0, 0]))
29+
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
30+
expect(decoded?.name).toBe('addMapping')
31+
expect(decoded?.data).toStrictEqual({})
32+
})
33+
pythOracle.methods
34+
.addMapping()
35+
.accounts({ fundingAccount: new PublicKey(0), curMapping: new PublicKey(1), nextMapping: new PublicKey(2) })
36+
.instruction()
37+
.then((instruction) => {
38+
expect(instruction.data).toStrictEqual(Buffer.from([2, 0, 0, 0, 1, 0, 0, 0]))
39+
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
40+
expect(decoded?.name).toBe('addMapping')
41+
expect(decoded?.data).toStrictEqual({})
42+
})
2343
done()
2444
})

src/anchor/program.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export function pythOracleProgram(programId: PublicKey, provider: AnchorProvider
77
return new Program<PythOracle>(IDL as PythOracle, programId, provider, new PythOracleCoder(IDL as Idl))
88
}
99

10+
export {PythOracleCoder} from './coder'
11+
1012
export type PythOracle = {
1113
version: '2.20.0'
1214
name: 'pyth_oracle'

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,4 +370,4 @@ export const parsePriceData = (data: Buffer, currentSlot?: number): PriceData =>
370370
export { PythConnection } from './PythConnection'
371371
export { PythHttpClient } from './PythHttpClient'
372372
export { getPythProgramKeyForCluster } from './cluster'
373-
export { pythOracleProgram } from './anchor'
373+
export { pythOracleProgram, PythOracleCoder } from './anchor'

0 commit comments

Comments
 (0)