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