forked from smartcontractkit/solana-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chainlink-solana-demo-int-test.ts
48 lines (37 loc) · 1.6 KB
/
chainlink-solana-demo-int-test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import * as anchor from '@project-serum/anchor';
import * as fs from 'fs';
import { Program, BN } from '@project-serum/anchor';
import { ChainlinkSolanaDemo } from '../target/types/chainlink_solana_demo';
const assert = require("assert");
const CHAINLINK_PROGRAM_ID = "HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny";
// SOL/USD feed account
const CHAINLINK_FEED = "669U43LNHx7LsVj95uYksnhXUfWKDsdzVqev3V4Jpw3P";
const DIVISOR = 100000000;
describe('chainlink-solana-demo', () => {
const provider = anchor.Provider.env();
// Configure the client to use the local cluster.
anchor.setProvider(provider);
it('Query SOL/USD Price Feed!', async () => {
// Generate the program client from the saved workspace
const program = anchor.workspace.ChainlinkSolanaDemo;
//create an account to store the price data
const priceFeedAccount = anchor.web3.Keypair.generate();
// Execute the RPC.
let tx = await program.rpc.execute({
accounts: {
decimal: priceFeedAccount.publicKey,
user: provider.wallet.publicKey,
chainlinkFeed: CHAINLINK_FEED,
chainlinkProgram: CHAINLINK_PROGRAM_ID,
systemProgram: anchor.web3.SystemProgram.programId
},
options: { commitment: "confirmed" },
signers: [priceFeedAccount],
});
// Fetch the account details of the account containing the price data
const latestPrice = await program.account.decimal.fetch(priceFeedAccount.publicKey);
console.log('Price Is: ' + latestPrice.value / DIVISOR)
// Ensure the price returned is a positive value
assert.ok(latestPrice.value / DIVISOR > 0);
});
});