Skip to content

Commit

Permalink
Fixes for Raptor Integration Tests
Browse files Browse the repository at this point in the history
- Store vault_signer_key for Serum Market struct for access to the vaults
- Add a BaseOrQuote enum
- Add a function to get token balance by Pubkey directly
- Other cleanup and fixes
  • Loading branch information
xiecy committed Feb 2, 2022
1 parent 60e8276 commit 9cc0e35
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 26 deletions.
7 changes: 6 additions & 1 deletion .gitignore
@@ -1,2 +1,7 @@
/target
**/target
Cargo.lock
**/test-ledger
crank_log.txt
serum_dex.so

.DS_Store
4 changes: 2 additions & 2 deletions Cargo.toml
Expand Up @@ -19,8 +19,8 @@ solana-logger = "1.9.3"
serum_dex = "0.5.0"

solana-client = "1.9.3"
solana-program = "1.7.6"
solana-sdk = "1.4.14"
solana-program = "1.9.4"
solana-sdk = "1.9.4"
spl-token = "3.2.0"
tempfile = "3.0"
borsh = "0.9.1"
22 changes: 21 additions & 1 deletion src/serum.rs
Expand Up @@ -27,6 +27,7 @@ pub struct Market<'a> {
asks: Actor<'a>,
base_vault: TokenAccount<'a>,
quote_vault: TokenAccount<'a>,
vault_signer_key: Pubkey,
base_mint: &'a Mint<'a>,
quote_mint: &'a Mint<'a>,
pub open_orders_accounts: Vec<&'a Pubkey>,
Expand Down Expand Up @@ -135,6 +136,9 @@ impl<'a> Market<'a> {
],
)?;

let vault_signer_key =
serum_dex::state::gen_vault_signer_key(vault_nonce, market.pubkey(), serum)?;

Ok(Market {
sandbox,
serum,
Expand All @@ -146,6 +150,7 @@ impl<'a> Market<'a> {
asks,
base_vault,
quote_vault,
vault_signer_key,
base_mint,
quote_mint,
open_orders_accounts: Vec::new(),
Expand Down Expand Up @@ -310,7 +315,7 @@ impl<'a> Market<'a> {

/// Returns reference to bids account
pub fn bids(&self) -> &Actor {
&self.request_queue
&self.bids
}

/// Returns reference to asks account
Expand All @@ -328,6 +333,21 @@ impl<'a> Market<'a> {
&self.quote_vault
}

/// Returns reference to this market's base mint account
pub fn base_mint(&self) -> &Mint {
&self.base_mint
}

/// Returns reference to this market's quote mint account
pub fn quote_mint(&self) -> &Mint {
&self.quote_mint
}

/// Returns reference to this market's vault signer key
pub fn vault_signer_key(&self) -> &Pubkey {
&self.vault_signer_key
}

/// Fetch the size/space of the request queue account given a number of requests
fn request_queue_size(num_requests: usize) -> usize {
let mut size: usize = 0;
Expand Down
6 changes: 6 additions & 0 deletions src/token.rs
@@ -1,10 +1,16 @@
use crate::actor::Actor;
use crate::errors::Result;
use crate::sandbox::Sandbox;
use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::program_pack::Pack;
use solana_sdk::pubkey::Pubkey;
use spl_token::{self, instruction as spl_instruction, state as spl_state};

#[derive(BorshSerialize, BorshDeserialize, Eq, PartialEq, PartialOrd)]
pub enum BaseOrQuote {
Base,
Quote,
}
/// Represents an spl_token program Mint.
pub struct Mint<'a> {
sandbox: &'a Sandbox,
Expand Down
35 changes: 13 additions & 22 deletions tests/sandbox_test.rs
@@ -1,34 +1,21 @@
mod tests {
use solana_program::account_info::AccountInfo;
use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::native_token::LAMPORTS_PER_SOL;
use std::thread;
use std::thread::sleep;
use std::time::Duration;
use std::borrow::Borrow;
use std::num::NonZeroU64;

use solarium::{
actor::Actor,
sandbox::Sandbox,
serum::{Market, Participant},
token::Mint,
token::TokenAccount,
serum::Participant,
token::{BaseOrQuote, Mint},
};

use crank::{start, Command, Opts};

use serum_dex::instruction::{consume_events, MarketInstruction};

use serum_dex::state::strip_header;

use serum_dex::{
instruction::SelfTradeBehavior,
matching::{OrderType, Side},
state as serum_state,
};

use serum_common::client::Cluster;

use std::num::NonZeroU64;

#[test]
fn integration() {
let sandbox = Sandbox::new().unwrap();
Expand Down Expand Up @@ -81,7 +68,7 @@ mod tests {
.unwrap();

// Place ask order
let taker_order = market
let _taker_order = market
.new_order(
&taker.quote(),
&taker,
Expand All @@ -98,7 +85,7 @@ mod tests {
.unwrap();
println!("Placed bid order.");

let maker_order = market
let _maker_order = market
.new_order(
&maker.base(),
&maker,
Expand Down Expand Up @@ -135,11 +122,15 @@ mod tests {
matching == a.len() && matching == b.len()
}

fn get_balance(participant: &Participant, sandbox: &Sandbox) -> String {
fn get_pubkey_balance(pubkey: &solana_program::pubkey::Pubkey, sandbox: &Sandbox) -> String {
sandbox
.client()
.get_token_account_balance(participant.base().pubkey())
.get_token_account_balance(pubkey)
.unwrap()
.amount
}

fn get_balance(participant: &Participant, sandbox: &Sandbox) -> String {
get_pubkey_balance(participant.base().pubkey(), sandbox)
}
}

0 comments on commit 9cc0e35

Please sign in to comment.