Skip to content

Commit 64dd772

Browse files
committed
swap out bankrun for litesvm in rust-sdk whirlpool tests
1 parent d99ce7f commit 64dd772

File tree

16 files changed

+3601
-2884
lines changed

16 files changed

+3601
-2884
lines changed

docs/rust/Cargo.lock

Lines changed: 1393 additions & 106 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/rust-sdk/whirlpool_repositioning_bot/Cargo.lock

Lines changed: 1371 additions & 94 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust-sdk/whirlpool/Cargo.lock

Lines changed: 459 additions & 2467 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust-sdk/whirlpool/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ bs58 = { version = "^0.5.1", default-features = false }
4545

4646
[dev-dependencies]
4747
serial_test = { version = "^3.1" }
48-
solana-program-test = { version = "^3" }
48+
litesvm = { version = "^0.8" }
49+
litesvm-token = "0.8.1"
4950
solana-version = { version = "^3" }
51+
solana-clock = { version = "^3" }
52+
solana-sysvar = { version = "^3" }
53+
agave-feature-set = { version = "^3.0" }
5054
async-trait = { version = "^0.1" }
5155
base64 = { version = "^0.20" }
5256
toml = { version = "^0.7" }

rust-sdk/whirlpool/src/account.rs

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
use serde::Deserialize;
22
use serde_json::from_value;
3-
use solana_account_decoder::UiAccountData;
3+
use solana_account_decoder::{UiAccountData, UiAccountEncoding};
44
use solana_client::{nonblocking::rpc_client::RpcClient, rpc_request::TokenAccountsFilter};
55
use solana_pubkey::Pubkey;
66
use solana_rent::Rent;
77
use solana_sysvar_id::SysvarId;
88
use std::{error::Error, str::FromStr};
99

10+
#[cfg(test)]
11+
use base64;
12+
1013
#[derive(Debug, Clone)]
1114
pub struct ParsedTokenAccount {
1215
pub pubkey: Pubkey,
@@ -42,19 +45,40 @@ pub(crate) async fn get_token_accounts_for_owner(
4245

4346
let mut token_accounts: Vec<ParsedTokenAccount> = Vec::new();
4447
for account in accounts {
45-
if let UiAccountData::Json(data) = account.account.data {
46-
let token_program = match data.program.as_str() {
47-
"spl-token" => &spl_token_interface::ID.to_string(),
48-
"spl-token-2022" => &spl_token_2022_interface::ID.to_string(),
49-
pubkey => pubkey,
50-
};
51-
let token: Parsed = from_value(data.parsed)?;
52-
token_accounts.push(ParsedTokenAccount {
53-
pubkey: Pubkey::from_str(&account.pubkey)?,
54-
token_program: Pubkey::from_str(token_program)?,
55-
mint: Pubkey::from_str(&token.info.mint)?,
56-
amount: token.info.token_amount.amount.parse::<u64>()?,
57-
});
48+
match account.account.data {
49+
UiAccountData::Json(data) => {
50+
let token_program = match data.program.as_str() {
51+
"spl-token" => &spl_token_interface::ID.to_string(),
52+
"spl-token-2022" => &spl_token_2022_interface::ID.to_string(),
53+
pubkey => pubkey,
54+
};
55+
let token: Parsed = from_value(data.parsed)?;
56+
token_accounts.push(ParsedTokenAccount {
57+
pubkey: Pubkey::from_str(&account.pubkey)?,
58+
token_program: Pubkey::from_str(token_program)?,
59+
mint: Pubkey::from_str(&token.info.mint)?,
60+
amount: token.info.token_amount.amount.parse::<u64>()?,
61+
});
62+
}
63+
#[cfg(test)]
64+
UiAccountData::Binary(data, encoding)
65+
if matches!(encoding, UiAccountEncoding::Base64) =>
66+
{
67+
let bytes = base64::decode(&data)?;
68+
if bytes.len() >= 72 {
69+
let mint_bytes: [u8; 32] = bytes[0..32].try_into()?;
70+
let _owner_bytes: [u8; 32] = bytes[32..64].try_into()?;
71+
let amount_bytes: [u8; 8] = bytes[64..72].try_into()?;
72+
73+
token_accounts.push(ParsedTokenAccount {
74+
pubkey: Pubkey::from_str(&account.pubkey)?,
75+
token_program: Pubkey::from_str(&account.account.owner)?,
76+
mint: Pubkey::new_from_array(mint_bytes),
77+
amount: u64::from_le_bytes(amount_bytes),
78+
});
79+
}
80+
}
81+
_ => {}
5882
}
5983
}
6084
Ok(token_accounts)

rust-sdk/whirlpool/src/create_pool.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ mod tests {
323323
#[tokio::test]
324324
#[serial]
325325
async fn test_error_if_no_funder() {
326-
let ctx = RpcContext::new().await;
326+
let ctx = RpcContext::new();
327327
let mint_a = setup_mint(&ctx).await.unwrap();
328328
let mint_b = setup_mint(&ctx).await.unwrap();
329329

@@ -336,7 +336,7 @@ mod tests {
336336
#[tokio::test]
337337
#[serial]
338338
async fn test_error_if_tokens_not_ordered() {
339-
let ctx = RpcContext::new().await;
339+
let ctx = RpcContext::new();
340340
let mint_a = setup_mint(&ctx).await.unwrap();
341341
let mint_b = setup_mint(&ctx).await.unwrap();
342342

@@ -356,7 +356,7 @@ mod tests {
356356
#[tokio::test]
357357
#[serial]
358358
async fn test_create_splash_pool() {
359-
let ctx = RpcContext::new().await;
359+
let ctx = RpcContext::new();
360360
let mint_a = setup_mint(&ctx).await.unwrap();
361361
let mint_b = setup_mint(&ctx).await.unwrap();
362362
let price = 10.0;
@@ -407,7 +407,7 @@ mod tests {
407407
#[tokio::test]
408408
#[serial]
409409
async fn test_create_splash_pool_with_one_te_token() {
410-
let ctx = RpcContext::new().await;
410+
let ctx = RpcContext::new();
411411
let mint = setup_mint(&ctx).await.unwrap();
412412
let mint_te = setup_mint_te(&ctx, &[]).await.unwrap();
413413
let price = 10.0;
@@ -458,7 +458,7 @@ mod tests {
458458
#[tokio::test]
459459
#[serial]
460460
async fn test_create_splash_pool_with_two_te_tokens() {
461-
let ctx = RpcContext::new().await;
461+
let ctx = RpcContext::new();
462462
let mint_te_a = setup_mint_te(&ctx, &[]).await.unwrap();
463463
let mint_te_b = setup_mint_te(&ctx, &[]).await.unwrap();
464464
let price = 10.0;
@@ -509,7 +509,7 @@ mod tests {
509509
#[tokio::test]
510510
#[serial]
511511
async fn test_create_splash_pool_with_transfer_fee() {
512-
let ctx = RpcContext::new().await;
512+
let ctx = RpcContext::new();
513513
let mint = setup_mint(&ctx).await.unwrap();
514514
let mint_te_fee = setup_mint_te_fee(&ctx).await.unwrap();
515515
let price = 10.0;
@@ -560,7 +560,7 @@ mod tests {
560560
#[tokio::test]
561561
#[serial]
562562
async fn test_create_concentrated_liquidity_pool() {
563-
let ctx = RpcContext::new().await;
563+
let ctx = RpcContext::new();
564564
let mint_a = setup_mint(&ctx).await.unwrap();
565565
let mint_b = setup_mint(&ctx).await.unwrap();
566566
let price = 10.0;
@@ -612,7 +612,7 @@ mod tests {
612612
#[tokio::test]
613613
#[serial]
614614
async fn test_create_concentrated_liquidity_pool_with_one_te_token() {
615-
let ctx = RpcContext::new().await;
615+
let ctx = RpcContext::new();
616616
let mint = setup_mint(&ctx).await.unwrap();
617617
let mint_te = setup_mint_te(&ctx, &[]).await.unwrap();
618618
let price = 10.0;
@@ -664,7 +664,7 @@ mod tests {
664664
#[tokio::test]
665665
#[serial]
666666
async fn test_create_concentrated_liquidity_pool_with_two_te_tokens() {
667-
let ctx = RpcContext::new().await;
667+
let ctx = RpcContext::new();
668668
let mint_te_a = setup_mint_te(&ctx, &[]).await.unwrap();
669669
let mint_te_b = setup_mint_te(&ctx, &[]).await.unwrap();
670670
let price = 10.0;
@@ -716,7 +716,7 @@ mod tests {
716716
#[tokio::test]
717717
#[serial]
718718
async fn test_create_concentrated_liquidity_pool_with_transfer_fee() {
719-
let ctx = RpcContext::new().await;
719+
let ctx = RpcContext::new();
720720
let mint = setup_mint(&ctx).await.unwrap();
721721
let mint_te_fee = setup_mint_te_fee(&ctx).await.unwrap();
722722
let price = 10.0;
@@ -768,7 +768,7 @@ mod tests {
768768
#[tokio::test]
769769
#[serial]
770770
async fn test_create_concentrated_liquidity_pool_with_scaled_ui_amount() {
771-
let ctx = RpcContext::new().await;
771+
let ctx = RpcContext::new();
772772
let mint = setup_mint(&ctx).await.unwrap();
773773
let mint_te_sua = setup_mint_te_sua(&ctx).await.unwrap();
774774
let price = 10.0;

rust-sdk/whirlpool/src/decrease_liquidity.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ mod tests {
650650
use solana_client::nonblocking::rpc_client::RpcClient;
651651
use solana_keypair::{Keypair, Signer};
652652
use solana_program_pack::Pack;
653-
use solana_program_test::tokio;
653+
654654
use solana_pubkey::Pubkey;
655655
use spl_token_2022_interface::{
656656
extension::StateWithExtensionsOwned, state::Account as TokenAccount2022,
@@ -843,7 +843,7 @@ mod tests {
843843
) {
844844
let rt = tokio::runtime::Runtime::new().unwrap();
845845
rt.block_on(async {
846-
let ctx = RpcContext::new().await;
846+
let ctx = RpcContext::new();
847847

848848
let minted = setup_all_mints(&ctx).await.unwrap();
849849
let user_atas = setup_all_atas(&ctx, &minted).await.unwrap();
@@ -932,7 +932,7 @@ mod tests {
932932
#[case] lower_tick: i32,
933933
#[case] upper_tick: i32,
934934
) -> Result<(), Box<dyn Error>> {
935-
let ctx = RpcContext::new().await;
935+
let ctx = RpcContext::new();
936936
let minted = setup_all_mints(&ctx).await?;
937937
let user_atas = setup_all_atas(&ctx, &minted).await?;
938938

@@ -1058,7 +1058,7 @@ mod tests {
10581058
#[tokio::test]
10591059
#[serial]
10601060
async fn test_close_position_fails_if_missing_mint() -> Result<(), Box<dyn Error>> {
1061-
let ctx = RpcContext::new().await;
1061+
let ctx = RpcContext::new();
10621062

10631063
let bogus_mint = Pubkey::new_unique();
10641064

rust-sdk/whirlpool/src/e2e.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
use std::error::Error;
22

33
use orca_whirlpools_client::{get_position_address, Position, Whirlpool};
4-
use serial_test::serial;
54
use solana_keypair::Signer;
65
use solana_program_pack::Pack;
7-
use solana_program_test::tokio::{self};
86
use solana_pubkey::Pubkey;
97
use spl_token_2022_interface::state::Account;
8+
use tokio::{self};
109

1110
use crate::{
1211
close_position_instructions, create_concentrated_liquidity_pool_instructions,
1312
create_splash_pool_instructions, decrease_liquidity_instructions,
1413
harvest_position_instructions, increase_liquidity_instructions,
15-
open_full_range_position_instructions_with_params, swap_instructions,
14+
open_full_range_position_instructions, swap_instructions,
1615
tests::{setup_ata_with_amount, setup_mint_with_decimals, RpcContext},
17-
DecreaseLiquidityParam, IncreaseLiquidityParam, OpenPositionParams, SwapQuote, SwapType,
18-
SPLASH_POOL_TICK_SPACING,
16+
DecreaseLiquidityParam, IncreaseLiquidityParam, SwapQuote, SwapType, SPLASH_POOL_TICK_SPACING,
1917
};
2018

2119
struct TestContext {
@@ -28,7 +26,7 @@ struct TestContext {
2826

2927
impl TestContext {
3028
pub async fn new() -> Result<Self, Box<dyn Error>> {
31-
let ctx = RpcContext::new().await;
29+
let ctx = RpcContext::new();
3230
let mint_a = setup_mint_with_decimals(&ctx, 9).await?;
3331
let mint_b = setup_mint_with_decimals(&ctx, 9).await?;
3432
let ata_a = setup_ata_with_amount(&ctx, mint_a, 500_000_000_000).await?;
@@ -102,15 +100,12 @@ impl TestContext {
102100
let token_a_before = Account::unpack(&infos_before[0].as_ref().unwrap().data)?;
103101
let token_b_before = Account::unpack(&infos_before[1].as_ref().unwrap().data)?;
104102

105-
let position = open_full_range_position_instructions_with_params(
103+
let position = open_full_range_position_instructions(
106104
&self.ctx.rpc,
107105
pool,
108106
IncreaseLiquidityParam::Liquidity(1000000000),
109107
None,
110108
Some(self.ctx.signer.pubkey()),
111-
OpenPositionParams {
112-
with_token_metadata_extension: false,
113-
},
114109
)
115110
.await?;
116111

@@ -524,7 +519,6 @@ impl TestContext {
524519
}
525520

526521
#[tokio::test]
527-
#[serial]
528522
async fn test_splash_pool() {
529523
let ctx = TestContext::new().await.unwrap();
530524
let pool = ctx.init_splash_pool().await.unwrap();
@@ -544,7 +538,6 @@ async fn test_splash_pool() {
544538
}
545539

546540
#[tokio::test]
547-
#[serial]
548541
async fn test_concentrated_liquidity_pool() {
549542
let ctx = TestContext::new().await.unwrap();
550543
let pool = ctx.init_concentrated_liquidity_pool().await.unwrap();

rust-sdk/whirlpool/src/harvest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ mod tests {
341341
use solana_client::nonblocking::rpc_client::RpcClient;
342342
use solana_keypair::{Keypair, Signer};
343343
use solana_program_pack::Pack;
344-
use solana_program_test::tokio;
344+
345345
use solana_pubkey::Pubkey;
346346
use spl_token_2022_interface::{
347347
extension::StateWithExtensionsOwned, state::Account as TokenAccount2022,
@@ -513,7 +513,7 @@ mod tests {
513513
) {
514514
let rt = tokio::runtime::Runtime::new().unwrap();
515515
rt.block_on(async {
516-
let ctx = RpcContext::new().await;
516+
let ctx = RpcContext::new();
517517

518518
let minted = setup_all_mints(&ctx).await.unwrap();
519519
let user_atas = setup_all_atas(&ctx, &minted).await.unwrap();

0 commit comments

Comments
 (0)