serializing and deserializing config file correctly
This commit is contained in:
parent
de5cc1c827
commit
9ff685674a
|
@ -183,9 +183,9 @@ async function configure(
|
||||||
|
|
||||||
let userData: User [] = users.map((user, i) => {
|
let userData: User [] = users.map((user, i) => {
|
||||||
return {
|
return {
|
||||||
keypair: user,
|
secret: Array.from(user.secretKey),
|
||||||
openOrders: userOpenOrders[i],
|
open_orders: userOpenOrders[i],
|
||||||
token: tokenAccounts[i],
|
token_data: tokenAccounts[i],
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -195,10 +195,10 @@ async function configure(
|
||||||
let accounts = await configure_accounts(connection, authority, numberOfAccountsToBeCreated, programIds);
|
let accounts = await configure_accounts(connection, authority, numberOfAccountsToBeCreated, programIds);
|
||||||
|
|
||||||
// adding known accounts
|
// adding known accounts
|
||||||
const marketAccountsList = markets.map(market => [market.asks, market.bids, market.marketPk, market.oracle, market.quoteVault, market.baseVault, market.baseMint, market.quoteMint] ).flat();
|
const marketAccountsList = markets.map(market => [market.asks, market.bids, market.market_pk, market.oracle, market.quote_vault, market.base_vault, market.base_mint, market.quote_mint] ).flat();
|
||||||
const userAccountsList = userData.map(user => {
|
const userAccountsList = userData.map(user => {
|
||||||
const allOpenOrdersAccounts = user.openOrders.map(x=>x.openOrders).flat();
|
const allOpenOrdersAccounts = user.open_orders.map(x=>x.open_orders).flat();
|
||||||
const allTokenAccounts = user.token.map(x => x.tokenAccount);
|
const allTokenAccounts = user.token_data.map(x => x.token_account);
|
||||||
return allOpenOrdersAccounts.concat(allTokenAccounts)
|
return allOpenOrdersAccounts.concat(allTokenAccounts)
|
||||||
}).flat()
|
}).flat()
|
||||||
accounts = accounts.concat(marketAccountsList).concat(userAccountsList);
|
accounts = accounts.concat(marketAccountsList).concat(userAccountsList);
|
||||||
|
|
|
@ -5,9 +5,9 @@ import * as splToken from '@solana/spl-token'
|
||||||
import { OpenOrders } from "../openbook-v2/configure_openbook";
|
import { OpenOrders } from "../openbook-v2/configure_openbook";
|
||||||
|
|
||||||
export interface User {
|
export interface User {
|
||||||
keypair: Keypair,
|
secret: number[],
|
||||||
token : TokenAccountData[],
|
token_data : TokenAccountData[],
|
||||||
openOrders: OpenOrders[],
|
open_orders: OpenOrders[],
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createUser(connection: Connection, authority: Keypair, balancePerPayer: number): Promise<Keypair> {
|
export async function createUser(connection: Connection, authority: Keypair, balancePerPayer: number): Promise<Keypair> {
|
||||||
|
@ -27,7 +27,7 @@ export async function createUser(connection: Connection, authority: Keypair, bal
|
||||||
|
|
||||||
interface TokenAccountData {
|
interface TokenAccountData {
|
||||||
mint: PublicKey,
|
mint: PublicKey,
|
||||||
tokenAccount: PublicKey
|
token_account: PublicKey
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function mintUser(connection: Connection, authority: Keypair, mints: PublicKey[], mintUtils: MintUtils, user: PublicKey, amount: number) : Promise<TokenAccountData[]> {
|
export async function mintUser(connection: Connection, authority: Keypair, mints: PublicKey[], mintUtils: MintUtils, user: PublicKey, amount: number) : Promise<TokenAccountData[]> {
|
||||||
|
@ -37,7 +37,7 @@ export async function mintUser(connection: Connection, authority: Keypair, mints
|
||||||
await splToken.mintTo(connection, authority, mint, tokenAccount, authority, amount);
|
await splToken.mintTo(connection, authority, mint, tokenAccount, authority, amount);
|
||||||
return {
|
return {
|
||||||
mint: mint,
|
mint: mint,
|
||||||
tokenAccount: tokenAccount
|
token_account: tokenAccount
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { BN, Program, web3 } from "@project-serum/anchor";
|
||||||
|
|
||||||
export interface OpenOrders {
|
export interface OpenOrders {
|
||||||
market: PublicKey,
|
market: PublicKey,
|
||||||
openOrders: PublicKey
|
open_orders: PublicKey
|
||||||
}
|
}
|
||||||
|
|
||||||
export class OpenbookConfigurator {
|
export class OpenbookConfigurator {
|
||||||
|
@ -39,26 +39,26 @@ export class OpenbookConfigurator {
|
||||||
const openOrders = await Promise.all(
|
const openOrders = await Promise.all(
|
||||||
markets.map(async(market) => {
|
markets.map(async(market) => {
|
||||||
let accountIndex = new BN(0);
|
let accountIndex = new BN(0);
|
||||||
let [openOrders, _tmp] = PublicKey.findProgramAddressSync([Buffer.from("OpenOrders"), user.publicKey.toBuffer(), market.marketPk.toBuffer(), accountIndex.toBuffer("le", 4)], this.openbookProgramId)
|
let [openOrders, _tmp] = PublicKey.findProgramAddressSync([Buffer.from("OpenOrders"), user.publicKey.toBuffer(), market.market_pk.toBuffer(), accountIndex.toBuffer("le", 4)], this.openbookProgramId)
|
||||||
|
|
||||||
await program.methods.initOpenOrders(
|
await program.methods.initOpenOrders(
|
||||||
0,
|
0,
|
||||||
64
|
64
|
||||||
).accounts({
|
).accounts({
|
||||||
openOrdersAccount: openOrders,
|
openOrdersAccount: openOrders,
|
||||||
market: market.marketPk,
|
market: market.market_pk,
|
||||||
owner: user.publicKey,
|
owner: user.publicKey,
|
||||||
payer: this.anchorProvider.publicKey,
|
payer: this.anchorProvider.publicKey,
|
||||||
systemProgram: web3.SystemProgram.programId,
|
systemProgram: web3.SystemProgram.programId,
|
||||||
}).signers([user]).rpc();
|
}).signers([user]).rpc();
|
||||||
return [market.marketPk, openOrders]
|
return [market.market_pk, openOrders]
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
return openOrders.map(x=> {
|
return openOrders.map(x=> {
|
||||||
return {
|
return {
|
||||||
market : x[0],
|
market : x[0],
|
||||||
openOrders : x[1],
|
open_orders : x[1],
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,16 +10,16 @@ import { TestProvider } from '../anchor_utils';
|
||||||
export interface Market {
|
export interface Market {
|
||||||
name: string,
|
name: string,
|
||||||
admin : number[],
|
admin : number[],
|
||||||
marketPk: PublicKey
|
market_pk: PublicKey
|
||||||
oracle: PublicKey,
|
oracle: PublicKey,
|
||||||
asks: PublicKey,
|
asks: PublicKey,
|
||||||
bids: PublicKey,
|
bids: PublicKey,
|
||||||
eventQueue: PublicKey,
|
event_queue: PublicKey,
|
||||||
baseVault: PublicKey,
|
base_vault: PublicKey,
|
||||||
quoteVault: PublicKey,
|
quote_vault: PublicKey,
|
||||||
baseMint: PublicKey,
|
base_mint: PublicKey,
|
||||||
quoteMint: PublicKey,
|
quote_mint: PublicKey,
|
||||||
marketIndex: number,
|
market_index: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createMarket(anchorProvider: TestProvider, mintUtils: MintUtils, adminKp: Keypair, openbookProgramId: PublicKey, baseMint: PublicKey, quoteMint: PublicKey, index: number): Promise<Market> {
|
export async function createMarket(anchorProvider: TestProvider, mintUtils: MintUtils, adminKp: Keypair, openbookProgramId: PublicKey, baseMint: PublicKey, quoteMint: PublicKey, index: number): Promise<Market> {
|
||||||
|
@ -85,13 +85,13 @@ export async function createMarket(anchorProvider: TestProvider, mintUtils: Mint
|
||||||
name,
|
name,
|
||||||
bids,
|
bids,
|
||||||
asks,
|
asks,
|
||||||
eventQueue,
|
event_queue: eventQueue,
|
||||||
baseMint,
|
base_mint: baseMint,
|
||||||
baseVault,
|
base_vault: baseVault,
|
||||||
marketIndex,
|
market_index: index,
|
||||||
marketPk,
|
market_pk: marketPk,
|
||||||
oracle: oracleId,
|
oracle: oracleId,
|
||||||
quoteMint,
|
quote_mint: quoteMint,
|
||||||
quoteVault,
|
quote_vault: quoteVault,
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,6 +6,7 @@ SCRIPT_DIR=$( dirname -- "$0"; )
|
||||||
OPENBOOK_PID=$(solana address -k $SCRIPT_DIR/configure/programs/openbook_v2-keypair.json)
|
OPENBOOK_PID=$(solana address -k $SCRIPT_DIR/configure/programs/openbook_v2-keypair.json)
|
||||||
echo "Openbook PID $OPENBOOK_PID"
|
echo "Openbook PID $OPENBOOK_PID"
|
||||||
cd $SCRIPT_DIR/thirdparty/openbook-v2
|
cd $SCRIPT_DIR/thirdparty/openbook-v2
|
||||||
|
git pull
|
||||||
git submodule update --init
|
git submodule update --init
|
||||||
|
|
||||||
sed 's@BfxZj7ckfRGHxByn7aHgH2puyXhfjAUvULtRjJo4rd8X@'"$OPENBOOK_PID"'@' programs/openbook-v2/src/lib.rs > programs/openbook-v2/src/lib-tmp.rs
|
sed 's@BfxZj7ckfRGHxByn7aHgH2puyXhfjAUvULtRjJo4rd8X@'"$OPENBOOK_PID"'@' programs/openbook-v2/src/lib.rs > programs/openbook-v2/src/lib-tmp.rs
|
||||||
|
|
|
@ -7,18 +7,55 @@ pub struct ProgramData {
|
||||||
pub program_id: String,
|
pub program_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct User {
|
||||||
|
secret: Vec<u8>,
|
||||||
|
token_data: Vec<TokenAccountData>,
|
||||||
|
open_orders: Vec<OpenOrders>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct TokenAccountData {
|
||||||
|
mint: String,
|
||||||
|
token_account: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct OpenOrders {
|
||||||
|
market: String,
|
||||||
|
open_orders: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct Market {
|
||||||
|
name: String,
|
||||||
|
admin : Vec<u8>,
|
||||||
|
market_pk: String,
|
||||||
|
oracle: String,
|
||||||
|
asks: String,
|
||||||
|
bids: String,
|
||||||
|
event_queue: String,
|
||||||
|
base_vault: String,
|
||||||
|
quote_vault: String,
|
||||||
|
base_mint: String,
|
||||||
|
quote_mint: String,
|
||||||
|
market_index: u32,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub programs: Vec<ProgramData>,
|
pub programs: Vec<ProgramData>,
|
||||||
pub known_accounts: Vec<String>,
|
pub known_accounts: Vec<String>,
|
||||||
pub payers: Vec<Vec<u8>>,
|
pub users: Vec<User>,
|
||||||
|
pub mints: Vec<String>,
|
||||||
|
pub markets: Vec<Market>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn get_payers(&self) -> Vec<Keypair> {
|
pub fn get_payers(&self) -> Vec<Keypair> {
|
||||||
self.payers
|
self.users
|
||||||
.iter()
|
.iter()
|
||||||
.map(|x| Keypair::from_bytes(x.as_slice()).unwrap())
|
.map(|x| Keypair::from_bytes(x.secret.as_slice()).unwrap())
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,8 @@ mod cli;
|
||||||
mod config;
|
mod config;
|
||||||
mod solana_runtime;
|
mod solana_runtime;
|
||||||
mod test_registry;
|
mod test_registry;
|
||||||
|
|
||||||
use cli::Args;
|
use cli::Args;
|
||||||
use config::Config;
|
use config::Config;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use test_registry::TestRegistry;
|
use test_registry::TestRegistry;
|
||||||
|
|
||||||
|
@ -21,8 +19,8 @@ async fn main() -> anyhow::Result<()> {
|
||||||
let config_json: Config =
|
let config_json: Config =
|
||||||
serde_json::from_str(contents.as_str()).expect("Config file not valid");
|
serde_json::from_str(contents.as_str()).expect("Config file not valid");
|
||||||
|
|
||||||
if config_json.payers.is_empty() {
|
if config_json.users.is_empty() {
|
||||||
log::error!("config file is missing payers");
|
log::error!("Config file is missing payers");
|
||||||
return Err(anyhow::Error::msg("No payers"));
|
return Err(anyhow::Error::msg("No payers"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,4 +28,4 @@ async fn main() -> anyhow::Result<()> {
|
||||||
registry.register_all();
|
registry.register_all();
|
||||||
registry.start_testing(args, config_json).await;
|
registry.start_testing(args, config_json).await;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
|
@ -93,7 +93,7 @@ impl TestingTask for AccountsFetchingTests {
|
||||||
for i in 0..accounts_to_fetch.len() {
|
for i in 0..accounts_to_fetch.len() {
|
||||||
if hash_set_known.contains(&accounts_to_fetch[i]) {
|
if hash_set_known.contains(&accounts_to_fetch[i]) {
|
||||||
if res[i].is_none() {
|
if res[i].is_none() {
|
||||||
println!("unable to fetch known account");
|
println!("unable to fetch known account {}", accounts_to_fetch[i]);
|
||||||
}
|
}
|
||||||
} else if res[i].is_some() {
|
} else if res[i].is_some() {
|
||||||
println!("fetched unknown account should not be possible");
|
println!("fetched unknown account should not be possible");
|
||||||
|
|
Loading…
Reference in New Issue