Skip to content

Commit

Permalink
some tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
coachchucksol committed Dec 7, 2024
1 parent 7168f9d commit c22377e
Show file tree
Hide file tree
Showing 4 changed files with 380 additions and 128 deletions.
23 changes: 13 additions & 10 deletions integration_tests/tests/fixtures/tip_router_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,10 @@ impl TipRouterClient {
pub async fn do_set_config_fees(
&mut self,
new_block_engine_fee_bps: Option<u16>,
base_fee_group: BaseFeeGroup,
base_fee_group: Option<BaseFeeGroup>,
new_base_fee_wallet: Option<Pubkey>,
new_base_fee_bps: Option<u16>,
ncn_fee_group: NcnFeeGroup,
ncn_fee_group: Option<NcnFeeGroup>,
new_ncn_fee_bps: Option<u16>,
ncn_root: &NcnRoot,
) -> TestResult<()> {
Expand All @@ -317,10 +317,10 @@ impl TipRouterClient {
&mut self,
config_pda: Pubkey,
new_block_engine_fee_bps: Option<u16>,
base_fee_group: BaseFeeGroup,
base_fee_group: Option<BaseFeeGroup>,
new_base_fee_wallet: Option<Pubkey>,
new_base_fee_bps: Option<u16>,
ncn_fee_group: NcnFeeGroup,
ncn_fee_group: Option<NcnFeeGroup>,
new_ncn_fee_bps: Option<u16>,
ncn_root: &NcnRoot,
) -> TestResult<()> {
Expand All @@ -333,14 +333,16 @@ impl TipRouterClient {
.config(config_pda)
.ncn(ncn_root.ncn_pubkey)
.ncn_admin(ncn_root.ncn_admin.pubkey())
.restaking_program(jito_restaking_program::id())
.base_fee_group(base_fee_group.group)
.ncn_fee_group(ncn_fee_group.group);
.restaking_program(jito_restaking_program::id());

if let Some(new_block_engine_fee_bps) = new_block_engine_fee_bps {
builder.new_block_engine_fee_bps(new_block_engine_fee_bps);
}

if let Some(base_fee_group) = base_fee_group {
builder.base_fee_group(base_fee_group.group);
}

if let Some(new_base_fee_wallet) = new_base_fee_wallet {
builder.new_base_fee_wallet(new_base_fee_wallet);
}
Expand All @@ -349,6 +351,10 @@ impl TipRouterClient {
builder.new_base_fee_bps(new_base_fee_bps);
}

if let Some(ncn_fee_group) = ncn_fee_group {
builder.ncn_fee_group(ncn_fee_group.group);
}

if let Some(new_ncn_fee_bps) = new_ncn_fee_bps {
builder.new_ncn_fee_bps(new_ncn_fee_bps);
}
Expand Down Expand Up @@ -619,9 +625,6 @@ impl TipRouterClient {
let (ncn_config, _, _) =
NcnConfig::find_program_address(&jito_tip_router_program::id(), &ncn);

let (base_reward_router, _, _) =
BaseRewardRouter::find_program_address(&jito_tip_router_program::id(), &ncn, ncn_epoch);

//TODO: Check admin is correct
let admin = self.payer.pubkey();

Expand Down
1 change: 1 addition & 0 deletions integration_tests/tests/tip_router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ mod register_mint;
mod set_config_fees;
mod set_new_admin;
mod set_tie_breaker;
mod set_tracked_mint_ncn_fee_group;
mod snapshot_vault_operator_delegation;
276 changes: 158 additions & 118 deletions integration_tests/tests/tip_router/set_config_fees.rs
Original file line number Diff line number Diff line change
@@ -1,121 +1,161 @@
#[cfg(test)]
mod tests {
// use jito_tip_router_core::{error::TipRouterError, ncn_fee_group::NcnFeeGroup};
// use solana_sdk::{
// clock::DEFAULT_SLOTS_PER_EPOCH,
// signature::{Keypair, Signer},
// };

// use crate::fixtures::{
// test_builder::TestBuilder, tip_router_client::assert_tip_router_error, TestResult,
// };

// #[tokio::test]
// async fn test_set_config_fees_ok() -> TestResult<()> {
// let mut fixture = TestBuilder::new().await;
// let mut tip_router_client = fixture.tip_router_client();
// let ncn_root = fixture.setup_ncn().await?;

// // Initialize config first - note that ncn_admin is now required as signer
// tip_router_client
// .do_initialize_config(ncn_root.ncn_pubkey, &ncn_root.ncn_admin)
// .await?;

// // Change fees and fee wallet
// let new_fee_wallet = Keypair::new();
// tip_router_client
// .do_set_config_fees(
// 100, // dao_fee_bps
// 200, // ncn_fee_bps
// 300, // block_engine_fee_bps
// new_fee_wallet.pubkey(),
// &ncn_root,
// )
// .await?;

// Ok(())
// }

// #[tokio::test]
// async fn test_set_config_fees_exceed_max_fails() -> TestResult<()> {
// let mut fixture = TestBuilder::new().await;
// let mut tip_router_client = fixture.tip_router_client();
// let ncn_root = fixture.setup_ncn().await?;

// // Initialize config first
// tip_router_client
// .do_initialize_config(ncn_root.ncn_pubkey, &ncn_root.ncn_admin)
// .await?;

// // Try to set fees above max
// let transaction_error = tip_router_client
// .do_set_config_fees(10_001, 0, 0, ncn_root.ncn_admin.pubkey(), &ncn_root)
// .await;

// assert_tip_router_error(transaction_error, TipRouterError::FeeCapExceeded);
// Ok(())
// }

// #[tokio::test]
// async fn test_set_config_fees_wrong_admin_fails() -> TestResult<()> {
// let mut fixture = TestBuilder::new().await;
// let mut tip_router_client = fixture.tip_router_client();
// let mut ncn_root = fixture.setup_ncn().await?;

// tip_router_client
// .do_initialize_config(ncn_root.ncn_pubkey, &ncn_root.ncn_admin)
// .await?;

// let wrong_admin = Keypair::new();
// ncn_root.ncn_admin = wrong_admin;
// let transaction_error = tip_router_client
// .do_set_config_fees(100, 200, 300, ncn_root.ncn_admin.pubkey(), &ncn_root)
// .await;

// assert_tip_router_error(transaction_error, TipRouterError::IncorrectFeeAdmin);
// Ok(())
// }

// #[tokio::test]
// async fn test_set_config_fees_across_epoch() -> TestResult<()> {
// let mut fixture = TestBuilder::new().await;
// let mut tip_router_client = fixture.tip_router_client();
// let ncn_root = fixture.setup_ncn().await?;

// // Initialize config first
// tip_router_client
// .do_initialize_config(ncn_root.ncn_pubkey, &ncn_root.ncn_admin)
// .await?;

// // Set new fees
// let new_fee_wallet = Keypair::new();
// tip_router_client
// .do_set_config_fees(100, 200, 0, new_fee_wallet.pubkey(), &ncn_root)
// .await?;

// // Advance epoch
// fixture
// .warp_slot_incremental(2 * DEFAULT_SLOTS_PER_EPOCH)
// .await?;

// let config = tip_router_client
// .get_ncn_config(ncn_root.ncn_pubkey)
// .await?;
// let clock = fixture.clock().await;
// assert_eq!(config.fee_config.dao_fee_bps(clock.epoch as u64), 100);
// assert_eq!(
// config
// .fee_config
// .ncn_fee_bps(NcnFeeGroup::default(), clock.epoch as u64)
// .unwrap(),
// 200
// );
// assert_eq!(
// config.fee_config.block_engine_fee_bps(clock.epoch as u64),
// 0
// );
// assert_eq!(config.fee_config.fee_wallet(), new_fee_wallet.pubkey());

// Ok(())
// }
use std::u64;

use jito_tip_router_core::{base_fee_group::BaseFeeGroup, ncn_fee_group::NcnFeeGroup};
use solana_sdk::pubkey::Pubkey;

use crate::fixtures::{test_builder::TestBuilder, TestResult};

#[tokio::test]
async fn test_set_config_fees_ok() -> TestResult<()> {
let mut fixture = TestBuilder::new().await;
let mut tip_router_client = fixture.tip_router_client();
let ncn_root = fixture.setup_ncn().await?;

const NEW_BLOCK_ENGINE_FEE: u16 = 500;
const NEW_BASE_FEE: u16 = 600;
const NEW_NCN_FEE: u16 = 700;

let new_base_fee_wallet = Pubkey::new_unique();

// Initialize config first - note that ncn_admin is now required as signer
tip_router_client
.do_initialize_config(ncn_root.ncn_pubkey, &ncn_root.ncn_admin)
.await?;

let base_fee_group = BaseFeeGroup::default();
let ncn_fee_group = NcnFeeGroup::default();

// Change fees and fee wallet
tip_router_client
.do_set_config_fees(
Some(NEW_BLOCK_ENGINE_FEE),
Some(base_fee_group),
Some(new_base_fee_wallet),
Some(NEW_BASE_FEE),
Some(ncn_fee_group),
Some(NEW_NCN_FEE),
&ncn_root,
)
.await?;

let ncn_config = tip_router_client
.get_ncn_config(ncn_root.ncn_pubkey)
.await?;

assert_eq!(
ncn_config.fee_config.block_engine_fee_bps(),
NEW_BLOCK_ENGINE_FEE
);

assert_eq!(
ncn_config
.fee_config
.base_fee_wallet(base_fee_group)
.unwrap(),
new_base_fee_wallet
);

let current_fees = ncn_config.fee_config.current_fees(u64::MAX);

assert_eq!(
current_fees.base_fee_bps(base_fee_group).unwrap(),
NEW_BASE_FEE
);

assert_eq!(
current_fees.ncn_fee_bps(ncn_fee_group).unwrap(),
NEW_NCN_FEE
);

Ok(())
}

#[tokio::test]
async fn test_set_config_all_fees_ok() -> TestResult<()> {
let mut fixture = TestBuilder::new().await;
let mut tip_router_client = fixture.tip_router_client();
let ncn_root = fixture.setup_ncn().await?;

const NEW_BLOCK_ENGINE_FEE: u16 = 500;
const NEW_BASE_FEE: u16 = 600;
const NEW_NCN_FEE: u16 = 700;

let new_base_fee_wallet = Pubkey::new_unique();

// Initialize config first - note that ncn_admin is now required as signer
tip_router_client
.do_initialize_config(ncn_root.ncn_pubkey, &ncn_root.ncn_admin)
.await?;

// Change fees and fee wallet
tip_router_client
.do_set_config_fees(
Some(NEW_BLOCK_ENGINE_FEE),
None,
None,
None,
None,
None,
&ncn_root,
)
.await?;

for group in BaseFeeGroup::all_groups().iter() {
// Change fees and fee wallet
tip_router_client
.do_set_config_fees(
None,
Some(*group),
Some(new_base_fee_wallet),
Some(NEW_BASE_FEE),
None,
None,
&ncn_root,
)
.await?;
}

for group in NcnFeeGroup::all_groups().iter() {
// Change fees and fee wallet
tip_router_client
.do_set_config_fees(
None,
None,
None,
None,
Some(*group),
Some(NEW_NCN_FEE),
&ncn_root,
)
.await?;
}

let ncn_config = tip_router_client
.get_ncn_config(ncn_root.ncn_pubkey)
.await?;

assert_eq!(
ncn_config.fee_config.block_engine_fee_bps(),
NEW_BLOCK_ENGINE_FEE
);

let current_fees = ncn_config.fee_config.current_fees(u64::MAX);

for group in BaseFeeGroup::all_groups().iter() {
assert_eq!(
ncn_config.fee_config.base_fee_wallet(*group).unwrap(),
new_base_fee_wallet
);

assert_eq!(current_fees.base_fee_bps(*group).unwrap(), NEW_BASE_FEE);
}

for group in NcnFeeGroup::all_groups().iter() {
assert_eq!(current_fees.ncn_fee_bps(*group).unwrap(), NEW_NCN_FEE);
}

Ok(())
}
}
Loading

0 comments on commit c22377e

Please sign in to comment.