1
1
import { AnchorProvider , Wallet } from '@coral-xyz/anchor'
2
2
import { Connection , Keypair , PublicKey } from '@solana/web3.js'
3
- import { getPythProgramKeyForCluster , pythOracleProgram } from '../index'
3
+ import { getPythProgramKeyForCluster , pythOracleProgram , PythOracleCoder } from '../index'
4
4
5
5
test ( 'Anchor' , ( done ) => {
6
6
jest . setTimeout ( 60000 )
@@ -12,13 +12,33 @@ test('Anchor', (done) => {
12
12
const pythOracle = pythOracleProgram ( getPythProgramKeyForCluster ( 'mainnet-beta' ) , provider )
13
13
pythOracle . methods
14
14
. initMapping ( )
15
- . accounts ( { fundingAccount : new PublicKey ( 0 ) } )
15
+ . accounts ( { fundingAccount : new PublicKey ( 0 ) , freshMappingAccount : new PublicKey ( 1 ) } )
16
16
. 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
+ } )
18
23
pythOracle . methods
19
24
. addMapping ( )
20
- . accounts ( { fundingAccount : new PublicKey ( 0 ) } )
25
+ . accounts ( { fundingAccount : new PublicKey ( 0 ) , curMapping : new PublicKey ( 1 ) , nextMapping : new PublicKey ( 2 ) } )
21
26
. 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
+ } )
23
43
done ( )
24
44
} )
0 commit comments