Skip to content

Commit 853ec39

Browse files
committed
integration tests'
1 parent 4e75bca commit 853ec39

File tree

8 files changed

+332
-9
lines changed

8 files changed

+332
-9
lines changed

clients/js/jito_tip_router/accounts/trackedMints.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function getTrackedMintsEncoder(): Encoder<TrackedMintsArgs> {
6363
['ncn', getAddressEncoder()],
6464
['bump', getU8Encoder()],
6565
['reserved', getArrayEncoder(getU8Encoder(), { size: 7 })],
66-
['stMintList', getArrayEncoder(getMintEntryEncoder(), { size: 2 })],
66+
['stMintList', getArrayEncoder(getMintEntryEncoder(), { size: 16 })],
6767
]);
6868
}
6969

@@ -73,7 +73,7 @@ export function getTrackedMintsDecoder(): Decoder<TrackedMints> {
7373
['ncn', getAddressDecoder()],
7474
['bump', getU8Decoder()],
7575
['reserved', getArrayDecoder(getU8Decoder(), { size: 7 })],
76-
['stMintList', getArrayDecoder(getMintEntryDecoder(), { size: 2 })],
76+
['stMintList', getArrayDecoder(getMintEntryDecoder(), { size: 16 })],
7777
]);
7878
}
7979

clients/rust/jito_tip_router/src/generated/accounts/tracked_mints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct TrackedMints {
2020
pub ncn: Pubkey,
2121
pub bump: u8,
2222
pub reserved: [u8; 7],
23-
pub st_mint_list: [MintEntry; 2],
23+
pub st_mint_list: [MintEntry; 16],
2424
}
2525

2626
impl TrackedMints {

core/src/tracked_mints.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub struct TrackedMints {
3939
pub ncn: Pubkey,
4040
pub bump: u8,
4141
pub reserved: [u8; 7],
42-
pub st_mint_list: [MintEntry; 2],
42+
pub st_mint_list: [MintEntry; 16], // TODO extend to 64; figure out serde issue
4343
}
4444

4545
impl Discriminator for TrackedMints {
@@ -52,7 +52,7 @@ impl TrackedMints {
5252
ncn,
5353
bump,
5454
reserved: [0; 7],
55-
st_mint_list: [MintEntry::default(); 2],
55+
st_mint_list: [MintEntry::default(); 16],
5656
}
5757
}
5858

idl/jito_tip_router.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@
418418
{
419419
"defined": "MintEntry"
420420
},
421-
2
421+
16
422422
]
423423
}
424424
}

integration_tests/tests/fixtures/tip_router_client.rs

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ use jito_bytemuck::AccountDeserialize;
22
use jito_restaking_core::config::Config;
33
use jito_tip_router_client::{
44
instructions::{
5-
AdminUpdateWeightTableBuilder, InitializeNCNConfigBuilder, InitializeWeightTableBuilder,
6-
SetConfigFeesBuilder, SetNewAdminBuilder,
5+
AdminUpdateWeightTableBuilder, InitializeNCNConfigBuilder, InitializeTrackedMintsBuilder,
6+
InitializeWeightTableBuilder, RegisterMintBuilder, SetConfigFeesBuilder,
7+
SetNewAdminBuilder,
78
},
89
types::ConfigAdminRole,
910
};
1011
use jito_tip_router_core::{
11-
error::TipRouterError, ncn_config::NcnConfig, weight_table::WeightTable,
12+
error::TipRouterError, ncn_config::NcnConfig, tracked_mints::TrackedMints,
13+
weight_table::WeightTable,
1214
};
1315
use solana_program::{
1416
instruction::InstructionError, native_token::sol_to_lamports, pubkey::Pubkey,
@@ -64,6 +66,14 @@ impl TipRouterClient {
6466
Ok(())
6567
}
6668

69+
pub async fn setup_tip_router(&mut self, ncn_root: &NcnRoot) -> TestResult<()> {
70+
self.do_initialize_config(ncn_root.ncn_pubkey, &ncn_root.ncn_admin)
71+
.await?;
72+
self.do_initialize_tracked_mints(ncn_root.ncn_pubkey)
73+
.await?;
74+
Ok(())
75+
}
76+
6777
pub async fn get_restaking_config(&mut self) -> TestResult<Config> {
6878
let restaking_config = Config::find_program_address(&jito_restaking_program::id()).0;
6979
let restaking_config_data = self
@@ -81,6 +91,17 @@ impl TipRouterClient {
8191
Ok(*NcnConfig::try_from_slice_unchecked(config.data.as_slice()).unwrap())
8292
}
8393

94+
pub async fn get_tracked_mints(&mut self, ncn_pubkey: Pubkey) -> TestResult<TrackedMints> {
95+
let tracked_mints_pda =
96+
TrackedMints::find_program_address(&jito_tip_router_program::id(), &ncn_pubkey).0;
97+
let tracked_mints = self
98+
.banks_client
99+
.get_account(tracked_mints_pda)
100+
.await?
101+
.unwrap();
102+
Ok(*TrackedMints::try_from_slice_unchecked(tracked_mints.data.as_slice()).unwrap())
103+
}
104+
84105
pub async fn do_initialize_config(
85106
&mut self,
86107
ncn: Pubkey,
@@ -307,6 +328,91 @@ impl TipRouterClient {
307328
))
308329
.await
309330
}
331+
332+
pub async fn do_initialize_tracked_mints(&mut self, ncn: Pubkey) -> TestResult<()> {
333+
let ncn_config = NcnConfig::find_program_address(&jito_tip_router_program::id(), &ncn).0;
334+
let tracked_mints =
335+
TrackedMints::find_program_address(&jito_tip_router_program::id(), &ncn).0;
336+
337+
self.initialize_tracked_mints(&ncn_config, &tracked_mints, &ncn)
338+
.await
339+
}
340+
341+
pub async fn initialize_tracked_mints(
342+
&mut self,
343+
ncn_config: &Pubkey,
344+
tracked_mints: &Pubkey,
345+
ncn: &Pubkey,
346+
) -> TestResult<()> {
347+
let ix = InitializeTrackedMintsBuilder::new()
348+
.ncn_config(*ncn_config)
349+
.tracked_mints(*tracked_mints)
350+
.ncn(*ncn)
351+
.payer(self.payer.pubkey())
352+
.system_program(system_program::id())
353+
.instruction();
354+
355+
let blockhash = self.banks_client.get_latest_blockhash().await?;
356+
self.process_transaction(&Transaction::new_signed_with_payer(
357+
&[ix],
358+
Some(&self.payer.pubkey()),
359+
&[&self.payer],
360+
blockhash,
361+
))
362+
.await
363+
}
364+
365+
pub async fn do_register_mint(
366+
&mut self,
367+
ncn: Pubkey,
368+
vault: Pubkey,
369+
vault_ncn_ticket: Pubkey,
370+
ncn_vault_ticket: Pubkey,
371+
) -> TestResult<()> {
372+
let restaking_config = Config::find_program_address(&jito_restaking_program::id()).0;
373+
let tracked_mints =
374+
TrackedMints::find_program_address(&jito_tip_router_program::id(), &ncn).0;
375+
376+
self.register_mint(
377+
restaking_config,
378+
tracked_mints,
379+
ncn,
380+
vault,
381+
vault_ncn_ticket,
382+
ncn_vault_ticket,
383+
)
384+
.await
385+
}
386+
387+
pub async fn register_mint(
388+
&mut self,
389+
restaking_config: Pubkey,
390+
tracked_mints: Pubkey,
391+
ncn: Pubkey,
392+
vault: Pubkey,
393+
vault_ncn_ticket: Pubkey,
394+
ncn_vault_ticket: Pubkey,
395+
) -> TestResult<()> {
396+
let ix = RegisterMintBuilder::new()
397+
.restaking_config(restaking_config)
398+
.tracked_mints(tracked_mints)
399+
.ncn(ncn)
400+
.vault(vault)
401+
.vault_ncn_ticket(vault_ncn_ticket)
402+
.ncn_vault_ticket(ncn_vault_ticket)
403+
.restaking_program_id(jito_restaking_program::id())
404+
.vault_program_id(jito_vault_program::id())
405+
.instruction();
406+
407+
let blockhash = self.banks_client.get_latest_blockhash().await?;
408+
self.process_transaction(&Transaction::new_signed_with_payer(
409+
&[ix],
410+
Some(&self.payer.pubkey()),
411+
&[&self.payer],
412+
blockhash,
413+
))
414+
.await
415+
}
310416
}
311417

312418
#[inline(always)]
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#[cfg(test)]
2+
mod tests {
3+
use jito_tip_router_core::{ncn_config::NcnConfig, tracked_mints::TrackedMints};
4+
use solana_program::instruction::InstructionError;
5+
use solana_sdk::{signature::Keypair, signer::Signer};
6+
7+
use crate::fixtures::{assert_ix_error, test_builder::TestBuilder, TestResult};
8+
9+
#[tokio::test]
10+
async fn test_initialize_tracked_mints_ok() -> TestResult<()> {
11+
let mut fixture = TestBuilder::new().await;
12+
let mut tip_router_client = fixture.tip_router_client();
13+
let ncn_root = fixture.setup_ncn().await?;
14+
tip_router_client
15+
.do_initialize_config(ncn_root.ncn_pubkey, &ncn_root.ncn_admin)
16+
.await?;
17+
18+
tip_router_client
19+
.do_initialize_tracked_mints(ncn_root.ncn_pubkey)
20+
.await?;
21+
22+
let tracked_mints = tip_router_client
23+
.get_tracked_mints(ncn_root.ncn_pubkey)
24+
.await?;
25+
26+
assert_eq!(tracked_mints.ncn, ncn_root.ncn_pubkey);
27+
assert_eq!(tracked_mints.mint_count(), 0);
28+
Ok(())
29+
}
30+
31+
#[tokio::test]
32+
async fn test_initialize_tracked_mints_wrong_ncn_config_fails() -> TestResult<()> {
33+
let mut fixture = TestBuilder::new().await;
34+
let mut tip_router_client = fixture.tip_router_client();
35+
let ncn_root = fixture.setup_ncn().await?;
36+
tip_router_client
37+
.do_initialize_config(ncn_root.ncn_pubkey, &ncn_root.ncn_admin)
38+
.await?;
39+
40+
// Try to initialize with wrong NCN config
41+
let wrong_ncn_config = Keypair::new().pubkey();
42+
let (tracked_mints_key, _, _) = TrackedMints::find_program_address(
43+
&jito_tip_router_program::id(),
44+
&ncn_root.ncn_pubkey,
45+
);
46+
47+
let transaction_error = tip_router_client
48+
.initialize_tracked_mints(&wrong_ncn_config, &tracked_mints_key, &ncn_root.ncn_pubkey)
49+
.await;
50+
51+
assert_ix_error(transaction_error, InstructionError::InvalidAccountOwner);
52+
Ok(())
53+
}
54+
55+
#[tokio::test]
56+
async fn test_initialize_tracked_mints_wrong_ncn_fails() -> TestResult<()> {
57+
let mut fixture = TestBuilder::new().await;
58+
let mut tip_router_client = fixture.tip_router_client();
59+
let ncn_root = fixture.setup_ncn().await?;
60+
tip_router_client
61+
.do_initialize_config(ncn_root.ncn_pubkey, &ncn_root.ncn_admin)
62+
.await?;
63+
64+
// Try to initialize with wrong NCN
65+
let wrong_ncn = Keypair::new().pubkey();
66+
let (tracked_mints_key, _, _) =
67+
TrackedMints::find_program_address(&jito_tip_router_program::id(), &wrong_ncn);
68+
69+
let transaction_error = tip_router_client
70+
.initialize_tracked_mints(
71+
&NcnConfig::find_program_address(
72+
&jito_tip_router_program::id(),
73+
&ncn_root.ncn_pubkey,
74+
)
75+
.0,
76+
&tracked_mints_key,
77+
&wrong_ncn,
78+
)
79+
.await;
80+
81+
assert_ix_error(transaction_error, InstructionError::InvalidAccountData);
82+
Ok(())
83+
}
84+
85+
#[tokio::test]
86+
async fn test_initialize_tracked_mints_double_init_fails() -> TestResult<()> {
87+
let mut fixture = TestBuilder::new().await;
88+
let mut tip_router_client = fixture.tip_router_client();
89+
let ncn_root = fixture.setup_ncn().await?;
90+
tip_router_client
91+
.do_initialize_config(ncn_root.ncn_pubkey, &ncn_root.ncn_admin)
92+
.await?;
93+
94+
tip_router_client
95+
.do_initialize_tracked_mints(ncn_root.ncn_pubkey)
96+
.await?;
97+
98+
fixture.warp_slot_incremental(1).await?;
99+
100+
// Second initialization should fail
101+
let transaction_error = tip_router_client
102+
.do_initialize_tracked_mints(ncn_root.ncn_pubkey)
103+
.await;
104+
105+
assert_ix_error(transaction_error, InstructionError::InvalidAccountOwner);
106+
Ok(())
107+
}
108+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
mod admin_update_weight_table;
22
mod initialize_ncn_config;
3+
mod initialize_tracked_mints;
34
mod initialize_weight_table;
5+
mod register_mint;
46
mod set_config_fees;
57
mod set_new_admin;

0 commit comments

Comments
 (0)