Tests: Helper for create + fund
This commit is contained in:
parent
7d508e5df5
commit
d6d66402f7
|
@ -5,7 +5,7 @@ use solana_sdk::signature::Keypair;
|
|||
|
||||
use super::mango_client::*;
|
||||
use super::solana::SolanaCookie;
|
||||
use super::{send_tx, MintCookie};
|
||||
use super::{send_tx, ClonableKeypair, MintCookie, UserCookie};
|
||||
|
||||
pub struct GroupWithTokensConfig<'a> {
|
||||
pub admin: &'a Keypair,
|
||||
|
@ -137,3 +137,48 @@ impl<'a> GroupWithTokensConfig<'a> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn create_funded_account(
|
||||
solana: &SolanaCookie,
|
||||
group: Pubkey,
|
||||
owner: &Keypair,
|
||||
account_num: u32,
|
||||
payer: &UserCookie,
|
||||
mints: &[MintCookie],
|
||||
amounts: u64,
|
||||
bank_index: usize,
|
||||
) -> Pubkey {
|
||||
let account = send_tx(
|
||||
solana,
|
||||
AccountCreateInstruction {
|
||||
account_num,
|
||||
token_count: 16,
|
||||
serum3_count: 8,
|
||||
perp_count: 8,
|
||||
perp_oo_count: 8,
|
||||
group,
|
||||
owner,
|
||||
payer: &payer.key,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.account;
|
||||
|
||||
for mint in mints {
|
||||
send_tx(
|
||||
solana,
|
||||
TokenDepositInstruction {
|
||||
amount: amounts,
|
||||
account,
|
||||
token_account: payer.token_accounts[mint.index],
|
||||
token_authority: payer.key.clone(),
|
||||
bank_index,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
account
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ use solana_sdk::{
|
|||
use mango_v4::state::*;
|
||||
use program_test::*;
|
||||
|
||||
use mango_setup::*;
|
||||
|
||||
mod program_test;
|
||||
|
||||
#[tokio::test]
|
||||
|
@ -27,7 +29,7 @@ async fn test_bankrupt_tokens_socialize_loss() -> Result<(), TransportError> {
|
|||
// SETUP: Create a group and an account to fill the vaults
|
||||
//
|
||||
|
||||
let mango_setup::GroupWithTokens { group, tokens, .. } = mango_setup::GroupWithTokensConfig {
|
||||
let GroupWithTokens { group, tokens, .. } = GroupWithTokensConfig {
|
||||
admin,
|
||||
payer,
|
||||
mints,
|
||||
|
@ -40,37 +42,18 @@ async fn test_bankrupt_tokens_socialize_loss() -> Result<(), TransportError> {
|
|||
let collateral_token2 = &tokens[3];
|
||||
|
||||
// deposit some funds, to the vaults aren't empty
|
||||
let vault_account = send_tx(
|
||||
solana,
|
||||
AccountCreateInstruction {
|
||||
account_num: 2,
|
||||
token_count: 16,
|
||||
serum3_count: 8,
|
||||
perp_count: 8,
|
||||
perp_oo_count: 8,
|
||||
group,
|
||||
owner,
|
||||
payer,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.account;
|
||||
let vault_amount = 100000;
|
||||
for &token_account in payer_mint_accounts {
|
||||
send_tx(
|
||||
solana,
|
||||
TokenDepositInstruction {
|
||||
amount: vault_amount,
|
||||
account: vault_account,
|
||||
token_account,
|
||||
token_authority: payer.clone(),
|
||||
bank_index: 1,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
let vault_account = create_funded_account(
|
||||
&solana,
|
||||
group,
|
||||
owner,
|
||||
2,
|
||||
&context.users[1],
|
||||
mints,
|
||||
vault_amount,
|
||||
1,
|
||||
)
|
||||
.await;
|
||||
|
||||
// also add a tiny amount to bank0 for borrow_token1, so we can test multi-bank socialized loss
|
||||
send_tx(
|
||||
|
|
|
@ -6,6 +6,8 @@ use solana_sdk::{signature::Keypair, signature::Signer, transport::TransportErro
|
|||
use mango_v4::state::*;
|
||||
use program_test::*;
|
||||
|
||||
use mango_setup::*;
|
||||
|
||||
mod program_test;
|
||||
|
||||
#[tokio::test]
|
||||
|
@ -24,7 +26,7 @@ async fn test_delegate() -> Result<(), TransportError> {
|
|||
// SETUP: Create a group, register a token (mint0), create an account
|
||||
//
|
||||
|
||||
let mango_setup::GroupWithTokens { group, tokens, .. } = mango_setup::GroupWithTokensConfig {
|
||||
let GroupWithTokens { group, tokens, .. } = GroupWithTokensConfig {
|
||||
admin,
|
||||
payer,
|
||||
mints,
|
||||
|
@ -33,36 +35,8 @@ async fn test_delegate() -> Result<(), TransportError> {
|
|||
.await;
|
||||
let bank = tokens[0].bank;
|
||||
|
||||
let account = send_tx(
|
||||
solana,
|
||||
AccountCreateInstruction {
|
||||
account_num: 0,
|
||||
token_count: 16,
|
||||
serum3_count: 8,
|
||||
perp_count: 8,
|
||||
perp_oo_count: 8,
|
||||
group,
|
||||
owner,
|
||||
payer,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.account;
|
||||
|
||||
// deposit
|
||||
send_tx(
|
||||
solana,
|
||||
TokenDepositInstruction {
|
||||
amount: 100,
|
||||
account,
|
||||
token_account: payer_mint0_account,
|
||||
token_authority: payer.clone(),
|
||||
bank_index: 0,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let account =
|
||||
create_funded_account(&solana, group, owner, 0, &context.users[1], mints, 100, 0).await;
|
||||
|
||||
//
|
||||
// TEST: Edit account - Set delegate
|
||||
|
|
|
@ -7,6 +7,8 @@ use solana_sdk::{signature::Keypair, transport::TransportError};
|
|||
|
||||
use program_test::*;
|
||||
|
||||
use mango_setup::*;
|
||||
|
||||
mod program_test;
|
||||
|
||||
// Try to reach compute limits in health checks by having many different tokens in an account
|
||||
|
@ -19,13 +21,12 @@ async fn test_health_compute_tokens() -> Result<(), TransportError> {
|
|||
let owner = &context.users[0].key;
|
||||
let payer = &context.users[1].key;
|
||||
let mints = &context.mints[0..10];
|
||||
let payer_mint_accounts = &context.users[1].token_accounts[0..mints.len()];
|
||||
|
||||
//
|
||||
// SETUP: Create a group and an account
|
||||
//
|
||||
|
||||
let mango_setup::GroupWithTokens { group, .. } = mango_setup::GroupWithTokensConfig {
|
||||
let GroupWithTokens { group, .. } = GroupWithTokensConfig {
|
||||
admin,
|
||||
payer,
|
||||
mints,
|
||||
|
@ -33,43 +34,8 @@ async fn test_health_compute_tokens() -> Result<(), TransportError> {
|
|||
.create(solana)
|
||||
.await;
|
||||
|
||||
let account = send_tx(
|
||||
solana,
|
||||
AccountCreateInstruction {
|
||||
account_num: 0,
|
||||
token_count: 16,
|
||||
serum3_count: 8,
|
||||
perp_count: 8,
|
||||
perp_oo_count: 8,
|
||||
group,
|
||||
owner,
|
||||
payer,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.account;
|
||||
|
||||
//
|
||||
// TEST: Deposit user funds for all the mints
|
||||
// each deposit will end with a health check
|
||||
//
|
||||
for &token_account in payer_mint_accounts {
|
||||
let deposit_amount = 1000;
|
||||
|
||||
send_tx(
|
||||
solana,
|
||||
TokenDepositInstruction {
|
||||
amount: deposit_amount,
|
||||
account,
|
||||
token_account,
|
||||
token_authority: payer.clone(),
|
||||
bank_index: 0,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
// each deposit ends with a health check
|
||||
create_funded_account(&solana, group, owner, 0, &context.users[1], mints, 1000, 0).await;
|
||||
|
||||
// TODO: actual explicit CU comparisons.
|
||||
// On 2022-5-25 the final deposit costs 36905 CU and each new token increases it by roughly 1600 CU
|
||||
|
@ -216,36 +182,17 @@ async fn test_health_compute_perp() -> Result<(), TransportError> {
|
|||
.create(solana)
|
||||
.await;
|
||||
|
||||
let account = send_tx(
|
||||
solana,
|
||||
AccountCreateInstruction {
|
||||
account_num: 0,
|
||||
token_count: 16,
|
||||
serum3_count: 8,
|
||||
perp_count: 8,
|
||||
perp_oo_count: 8,
|
||||
group,
|
||||
owner,
|
||||
payer,
|
||||
},
|
||||
let account = create_funded_account(
|
||||
&solana,
|
||||
group,
|
||||
owner,
|
||||
0,
|
||||
&context.users[1],
|
||||
&mints[..1],
|
||||
1000,
|
||||
0,
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.account;
|
||||
|
||||
// Give the account some quote currency
|
||||
send_tx(
|
||||
solana,
|
||||
TokenDepositInstruction {
|
||||
amount: 1000,
|
||||
account,
|
||||
token_account: payer_mint_accounts[0],
|
||||
token_authority: payer.clone(),
|
||||
bank_index: 0,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
.await;
|
||||
|
||||
//
|
||||
// SETUP: Create perp markets
|
||||
|
|
|
@ -7,6 +7,8 @@ use mango_v4::state::MangoAccount;
|
|||
|
||||
use program_test::*;
|
||||
|
||||
use mango_setup::*;
|
||||
|
||||
mod program_test;
|
||||
|
||||
#[tokio::test]
|
||||
|
@ -24,7 +26,7 @@ async fn test_health_wrap() -> Result<(), TransportError> {
|
|||
// SETUP: Create a group, account, register a token (mint0)
|
||||
//
|
||||
|
||||
let mango_setup::GroupWithTokens { group, tokens, .. } = mango_setup::GroupWithTokensConfig {
|
||||
let GroupWithTokens { group, tokens, .. } = GroupWithTokensConfig {
|
||||
admin,
|
||||
payer,
|
||||
mints,
|
||||
|
@ -33,35 +35,7 @@ async fn test_health_wrap() -> Result<(), TransportError> {
|
|||
.await;
|
||||
|
||||
// SETUP: Create an account with deposits, so the second account can borrow more than it has
|
||||
let setup_account = send_tx(
|
||||
solana,
|
||||
AccountCreateInstruction {
|
||||
account_num: 0,
|
||||
token_count: 8,
|
||||
serum3_count: 0,
|
||||
perp_count: 0,
|
||||
perp_oo_count: 0,
|
||||
group,
|
||||
owner,
|
||||
payer,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.account;
|
||||
|
||||
send_tx(
|
||||
solana,
|
||||
TokenDepositInstruction {
|
||||
amount: 1000,
|
||||
account: setup_account,
|
||||
token_account: payer_mint_accounts[0],
|
||||
token_authority: payer.clone(),
|
||||
bank_index: 0,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
create_funded_account(&solana, group, owner, 0, &context.users[1], mints, 1000, 0).await;
|
||||
|
||||
// SETUP: Make a second account
|
||||
let account = send_tx(
|
||||
|
|
|
@ -7,6 +7,8 @@ use solana_sdk::{signature::Keypair, transport::TransportError};
|
|||
use mango_v4::instructions::{Serum3OrderType, Serum3SelfTradeBehavior, Serum3Side};
|
||||
use program_test::*;
|
||||
|
||||
use mango_setup::*;
|
||||
|
||||
mod program_test;
|
||||
|
||||
#[tokio::test]
|
||||
|
@ -26,7 +28,7 @@ async fn test_liq_tokens_force_cancel() -> Result<(), TransportError> {
|
|||
// SETUP: Create a group and an account to fill the vaults
|
||||
//
|
||||
|
||||
let mango_setup::GroupWithTokens { group, tokens, .. } = mango_setup::GroupWithTokensConfig {
|
||||
let GroupWithTokens { group, tokens, .. } = GroupWithTokensConfig {
|
||||
admin,
|
||||
payer,
|
||||
mints,
|
||||
|
@ -37,36 +39,7 @@ async fn test_liq_tokens_force_cancel() -> Result<(), TransportError> {
|
|||
let quote_token = &tokens[1];
|
||||
|
||||
// deposit some funds, to the vaults aren't empty
|
||||
let vault_account = send_tx(
|
||||
solana,
|
||||
AccountCreateInstruction {
|
||||
account_num: 2,
|
||||
token_count: 16,
|
||||
serum3_count: 8,
|
||||
perp_count: 8,
|
||||
perp_oo_count: 8,
|
||||
group,
|
||||
owner,
|
||||
payer,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.account;
|
||||
for &token_account in payer_mint_accounts {
|
||||
send_tx(
|
||||
solana,
|
||||
TokenDepositInstruction {
|
||||
amount: 10000,
|
||||
account: vault_account,
|
||||
token_account,
|
||||
token_authority: payer.clone(),
|
||||
bank_index: 0,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
create_funded_account(&solana, group, owner, 0, &context.users[1], mints, 10000, 0).await;
|
||||
|
||||
//
|
||||
// SETUP: Create serum market
|
||||
|
@ -96,36 +69,18 @@ async fn test_liq_tokens_force_cancel() -> Result<(), TransportError> {
|
|||
//
|
||||
// SETUP: Make an account and deposit some quote
|
||||
//
|
||||
let account = send_tx(
|
||||
solana,
|
||||
AccountCreateInstruction {
|
||||
account_num: 0,
|
||||
token_count: 16,
|
||||
serum3_count: 8,
|
||||
perp_count: 8,
|
||||
perp_oo_count: 8,
|
||||
group,
|
||||
owner,
|
||||
payer,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.account;
|
||||
|
||||
let deposit_amount = 1000;
|
||||
send_tx(
|
||||
solana,
|
||||
TokenDepositInstruction {
|
||||
amount: deposit_amount,
|
||||
account,
|
||||
token_account: payer_mint_accounts[1],
|
||||
token_authority: payer.clone(),
|
||||
bank_index: 0,
|
||||
},
|
||||
let account = create_funded_account(
|
||||
&solana,
|
||||
group,
|
||||
owner,
|
||||
1,
|
||||
&context.users[1],
|
||||
&mints[1..2],
|
||||
deposit_amount,
|
||||
0,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
.await;
|
||||
|
||||
//
|
||||
// SETUP: Create an open orders account and an order
|
||||
|
|
|
@ -6,6 +6,8 @@ use solana_sdk::signature::Signer;
|
|||
|
||||
use program_test::*;
|
||||
|
||||
use mango_setup::*;
|
||||
|
||||
mod program_test;
|
||||
|
||||
// This is an unspecific happy-case test that just runs a few instructions to check
|
||||
|
@ -21,7 +23,6 @@ async fn test_margin_trade() -> Result<(), BanksClientError> {
|
|||
let payer = &context.users[1].key;
|
||||
let mints = &context.mints[0..2];
|
||||
let payer_mint0_account = context.users[1].token_accounts[0];
|
||||
let payer_mint1_account = context.users[1].token_accounts[1];
|
||||
let loan_origination_fee = 0.0005;
|
||||
|
||||
// higher resolution that the loan_origination_fee for one token
|
||||
|
@ -31,7 +32,7 @@ async fn test_margin_trade() -> Result<(), BanksClientError> {
|
|||
// SETUP: Create a group, account, register a token (mint0)
|
||||
//
|
||||
|
||||
let mango_setup::GroupWithTokens { group, tokens, .. } = mango_setup::GroupWithTokensConfig {
|
||||
let GroupWithTokens { group, tokens, .. } = GroupWithTokensConfig {
|
||||
admin,
|
||||
payer,
|
||||
mints,
|
||||
|
@ -45,48 +46,17 @@ async fn test_margin_trade() -> Result<(), BanksClientError> {
|
|||
// provide some funds for tokens, so the test user can borrow
|
||||
//
|
||||
let provided_amount = 1000;
|
||||
|
||||
let provider_account = send_tx(
|
||||
solana,
|
||||
AccountCreateInstruction {
|
||||
account_num: 1,
|
||||
token_count: 16,
|
||||
serum3_count: 8,
|
||||
perp_count: 8,
|
||||
perp_oo_count: 8,
|
||||
group,
|
||||
owner,
|
||||
payer,
|
||||
},
|
||||
create_funded_account(
|
||||
&solana,
|
||||
group,
|
||||
owner,
|
||||
1,
|
||||
&context.users[1],
|
||||
mints,
|
||||
provided_amount,
|
||||
0,
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.account;
|
||||
|
||||
send_tx(
|
||||
solana,
|
||||
TokenDepositInstruction {
|
||||
amount: provided_amount,
|
||||
account: provider_account,
|
||||
token_account: payer_mint0_account,
|
||||
token_authority: payer.clone(),
|
||||
bank_index: 0,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
send_tx(
|
||||
solana,
|
||||
TokenDepositInstruction {
|
||||
amount: provided_amount,
|
||||
account: provider_account,
|
||||
token_account: payer_mint1_account,
|
||||
token_authority: payer.clone(),
|
||||
bank_index: 0,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
.await;
|
||||
|
||||
//
|
||||
// create thes test user account
|
||||
|
|
|
@ -7,6 +7,8 @@ use program_test::*;
|
|||
use solana_program_test::*;
|
||||
use solana_sdk::{signature::Keypair, signer::Signer, transport::TransportError};
|
||||
|
||||
use mango_setup::*;
|
||||
|
||||
mod program_test;
|
||||
|
||||
#[tokio::test]
|
||||
|
@ -18,13 +20,12 @@ async fn test_perp() -> Result<(), TransportError> {
|
|||
let owner = &context.users[0].key;
|
||||
let payer = &context.users[1].key;
|
||||
let mints = &context.mints[0..2];
|
||||
let payer_mint_accounts = &context.users[1].token_accounts[0..=2];
|
||||
|
||||
//
|
||||
// SETUP: Create a group and an account
|
||||
//
|
||||
|
||||
let mango_setup::GroupWithTokens { group, tokens, .. } = mango_setup::GroupWithTokensConfig {
|
||||
let GroupWithTokens { group, tokens, .. } = GroupWithTokensConfig {
|
||||
admin,
|
||||
payer,
|
||||
mints,
|
||||
|
@ -32,102 +33,29 @@ async fn test_perp() -> Result<(), TransportError> {
|
|||
.create(solana)
|
||||
.await;
|
||||
|
||||
let account_0 = send_tx(
|
||||
solana,
|
||||
AccountCreateInstruction {
|
||||
account_num: 0,
|
||||
token_count: 16,
|
||||
serum3_count: 8,
|
||||
perp_count: 8,
|
||||
perp_oo_count: 8,
|
||||
group,
|
||||
owner,
|
||||
payer,
|
||||
},
|
||||
let deposit_amount = 1000;
|
||||
let account_0 = create_funded_account(
|
||||
&solana,
|
||||
group,
|
||||
owner,
|
||||
0,
|
||||
&context.users[1],
|
||||
mints,
|
||||
deposit_amount,
|
||||
0,
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.account;
|
||||
|
||||
let account_1 = send_tx(
|
||||
solana,
|
||||
AccountCreateInstruction {
|
||||
account_num: 1,
|
||||
token_count: 16,
|
||||
serum3_count: 8,
|
||||
perp_count: 8,
|
||||
perp_oo_count: 8,
|
||||
group,
|
||||
owner,
|
||||
payer,
|
||||
},
|
||||
.await;
|
||||
let account_1 = create_funded_account(
|
||||
&solana,
|
||||
group,
|
||||
owner,
|
||||
1,
|
||||
&context.users[1],
|
||||
mints,
|
||||
deposit_amount,
|
||||
0,
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.account;
|
||||
|
||||
//
|
||||
// SETUP: Deposit user funds
|
||||
//
|
||||
{
|
||||
let deposit_amount = 1000;
|
||||
|
||||
send_tx(
|
||||
solana,
|
||||
TokenDepositInstruction {
|
||||
amount: deposit_amount,
|
||||
account: account_0,
|
||||
token_account: payer_mint_accounts[0],
|
||||
token_authority: payer.clone(),
|
||||
bank_index: 0,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
send_tx(
|
||||
solana,
|
||||
TokenDepositInstruction {
|
||||
amount: deposit_amount,
|
||||
account: account_0,
|
||||
token_account: payer_mint_accounts[1],
|
||||
token_authority: payer.clone(),
|
||||
bank_index: 0,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
{
|
||||
let deposit_amount = 1000;
|
||||
|
||||
send_tx(
|
||||
solana,
|
||||
TokenDepositInstruction {
|
||||
amount: deposit_amount,
|
||||
account: account_1,
|
||||
token_account: payer_mint_accounts[0],
|
||||
token_authority: payer.clone(),
|
||||
bank_index: 0,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
send_tx(
|
||||
solana,
|
||||
TokenDepositInstruction {
|
||||
amount: deposit_amount,
|
||||
account: account_1,
|
||||
token_account: payer_mint_accounts[1],
|
||||
token_authority: payer.clone(),
|
||||
bank_index: 0,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
.await;
|
||||
|
||||
//
|
||||
// TEST: Create a perp market
|
||||
|
|
|
@ -6,6 +6,8 @@ use solana_sdk::signature::Keypair;
|
|||
|
||||
use program_test::*;
|
||||
|
||||
use crate::mango_setup::*;
|
||||
|
||||
mod program_test;
|
||||
|
||||
// Check opening and closing positions
|
||||
|
@ -50,43 +52,18 @@ async fn test_position_lifetime() -> Result<()> {
|
|||
.unwrap()
|
||||
.account;
|
||||
|
||||
let funding_account = send_tx(
|
||||
solana,
|
||||
AccountCreateInstruction {
|
||||
account_num: 1,
|
||||
token_count: 16,
|
||||
serum3_count: 8,
|
||||
perp_count: 8,
|
||||
perp_oo_count: 8,
|
||||
group,
|
||||
owner,
|
||||
payer,
|
||||
},
|
||||
let funding_amount = 1000000;
|
||||
create_funded_account(
|
||||
&solana,
|
||||
group,
|
||||
owner,
|
||||
1,
|
||||
&context.users[1],
|
||||
mints,
|
||||
funding_amount,
|
||||
0,
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.account;
|
||||
|
||||
//
|
||||
// SETUP: Put some tokens into the funding account to allow borrowing
|
||||
//
|
||||
{
|
||||
let funding_amount = 1000000;
|
||||
for &payer_token in payer_mint_accounts {
|
||||
send_tx(
|
||||
solana,
|
||||
TokenDepositInstruction {
|
||||
amount: funding_amount,
|
||||
account: funding_account,
|
||||
token_account: payer_token,
|
||||
token_authority: payer.clone(),
|
||||
bank_index: 0,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
.await;
|
||||
|
||||
//
|
||||
// TEST: Deposit and withdraw tokens for all mints
|
||||
|
|
|
@ -8,6 +8,8 @@ use program_test::*;
|
|||
|
||||
mod program_test;
|
||||
|
||||
use mango_setup::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_serum() -> Result<(), TransportError> {
|
||||
let mut test_builder = TestContextBuilder::new();
|
||||
|
@ -19,13 +21,12 @@ async fn test_serum() -> Result<(), TransportError> {
|
|||
let owner = &context.users[0].key;
|
||||
let payer = &context.users[1].key;
|
||||
let mints = &context.mints[0..2];
|
||||
let payer_mint_accounts = &context.users[1].token_accounts[0..=2];
|
||||
|
||||
//
|
||||
// SETUP: Create a group and an account
|
||||
//
|
||||
|
||||
let mango_setup::GroupWithTokens { group, tokens, .. } = mango_setup::GroupWithTokensConfig {
|
||||
let GroupWithTokens { group, tokens, .. } = GroupWithTokensConfig {
|
||||
admin,
|
||||
payer,
|
||||
mints,
|
||||
|
@ -35,22 +36,18 @@ async fn test_serum() -> Result<(), TransportError> {
|
|||
let base_token = &tokens[0];
|
||||
let quote_token = &tokens[1];
|
||||
|
||||
let account = send_tx(
|
||||
solana,
|
||||
AccountCreateInstruction {
|
||||
account_num: 0,
|
||||
token_count: 16,
|
||||
serum3_count: 8,
|
||||
perp_count: 8,
|
||||
perp_oo_count: 8,
|
||||
group,
|
||||
owner,
|
||||
payer,
|
||||
},
|
||||
let deposit_amount = 1000;
|
||||
let account = create_funded_account(
|
||||
&solana,
|
||||
group,
|
||||
owner,
|
||||
0,
|
||||
&context.users[1],
|
||||
mints,
|
||||
deposit_amount,
|
||||
0,
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.account;
|
||||
.await;
|
||||
|
||||
//
|
||||
// SETUP: Create serum market
|
||||
|
@ -60,39 +57,6 @@ async fn test_serum() -> Result<(), TransportError> {
|
|||
.list_spot_market(&base_token.mint, "e_token.mint)
|
||||
.await;
|
||||
|
||||
//
|
||||
// SETUP: Deposit user funds
|
||||
//
|
||||
{
|
||||
let deposit_amount = 1000;
|
||||
|
||||
send_tx(
|
||||
solana,
|
||||
TokenDepositInstruction {
|
||||
amount: deposit_amount,
|
||||
account,
|
||||
token_account: payer_mint_accounts[0],
|
||||
token_authority: payer.clone(),
|
||||
bank_index: 0,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
send_tx(
|
||||
solana,
|
||||
TokenDepositInstruction {
|
||||
amount: deposit_amount,
|
||||
account,
|
||||
token_account: payer_mint_accounts[1],
|
||||
token_authority: payer.clone(),
|
||||
bank_index: 0,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
//
|
||||
// TEST: Register a serum market
|
||||
//
|
||||
|
|
|
@ -4,6 +4,7 @@ use mango_v4::state::*;
|
|||
use solana_program_test::*;
|
||||
use solana_sdk::{signature::Keypair, transport::TransportError};
|
||||
|
||||
use mango_setup::*;
|
||||
use program_test::*;
|
||||
|
||||
mod program_test;
|
||||
|
@ -17,13 +18,12 @@ async fn test_token_update_index_and_rate() -> Result<(), TransportError> {
|
|||
let owner = &context.users[0].key;
|
||||
let payer = &context.users[1].key;
|
||||
let mints = &context.mints[0..2];
|
||||
let payer_mint_accounts = &context.users[1].token_accounts[0..2];
|
||||
|
||||
//
|
||||
// SETUP: Create a group and an account to fill the vaults
|
||||
//
|
||||
|
||||
let mango_setup::GroupWithTokens { group, tokens, .. } = mango_setup::GroupWithTokensConfig {
|
||||
let GroupWithTokens { group, tokens, .. } = GroupWithTokensConfig {
|
||||
admin,
|
||||
payer,
|
||||
mints,
|
||||
|
@ -32,66 +32,18 @@ async fn test_token_update_index_and_rate() -> Result<(), TransportError> {
|
|||
.await;
|
||||
|
||||
// deposit some funds, to the vaults aren't empty
|
||||
let deposit_account = send_tx(
|
||||
solana,
|
||||
AccountCreateInstruction {
|
||||
account_num: 0,
|
||||
token_count: 16,
|
||||
serum3_count: 8,
|
||||
perp_count: 8,
|
||||
perp_oo_count: 8,
|
||||
group,
|
||||
owner,
|
||||
payer,
|
||||
},
|
||||
create_funded_account(&solana, group, owner, 0, &context.users[1], mints, 10000, 0).await;
|
||||
let withdraw_account = create_funded_account(
|
||||
&solana,
|
||||
group,
|
||||
owner,
|
||||
1,
|
||||
&context.users[1],
|
||||
&mints[1..2],
|
||||
100000,
|
||||
0,
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.account;
|
||||
for &token_account in payer_mint_accounts {
|
||||
send_tx(
|
||||
solana,
|
||||
TokenDepositInstruction {
|
||||
amount: 10000,
|
||||
account: deposit_account,
|
||||
token_account,
|
||||
token_authority: payer.clone(),
|
||||
bank_index: 0,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let withdraw_account = send_tx(
|
||||
solana,
|
||||
AccountCreateInstruction {
|
||||
account_num: 1,
|
||||
token_count: 16,
|
||||
serum3_count: 8,
|
||||
perp_count: 8,
|
||||
perp_oo_count: 8,
|
||||
group,
|
||||
owner,
|
||||
payer,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.account;
|
||||
|
||||
send_tx(
|
||||
solana,
|
||||
TokenDepositInstruction {
|
||||
amount: 100000,
|
||||
account: withdraw_account,
|
||||
token_account: payer_mint_accounts[1],
|
||||
token_authority: payer.clone(),
|
||||
bank_index: 0,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
.await;
|
||||
|
||||
send_tx(
|
||||
solana,
|
||||
|
|
Loading…
Reference in New Issue