Skip to content

Commit

Permalink
getting closer
Browse files Browse the repository at this point in the history
  • Loading branch information
coachchucksol committed Nov 13, 2024
1 parent 5a671a6 commit 38f98b5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 74 deletions.
18 changes: 18 additions & 0 deletions integration_tests/tests/fixtures/restaking_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,30 @@ pub struct NcnRoot {
pub ncn_admin: Keypair,
}

impl Clone for NcnRoot {
fn clone(&self) -> Self {
Self {
ncn_pubkey: self.ncn_pubkey,
ncn_admin: self.ncn_admin.insecure_clone(),
}
}
}

#[derive(Debug)]
pub struct OperatorRoot {
pub operator_pubkey: Pubkey,
pub operator_admin: Keypair,
}

impl Clone for OperatorRoot {
fn clone(&self) -> Self {
Self {
operator_pubkey: self.operator_pubkey,
operator_admin: self.operator_admin.insecure_clone(),
}
}
}

pub struct RestakingProgramClient {
banks_client: BanksClient,
payer: Keypair,
Expand Down
95 changes: 21 additions & 74 deletions integration_tests/tests/fixtures/test_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@ use crate::fixtures::{
};

pub struct ConfiguredVault {

Check failure on line 24 in integration_tests/tests/fixtures/test_builder.rs

View workflow job for this annotation

GitHub Actions / cargo test

struct `ConfiguredVault` is never constructed
pub vault_program_client: VaultProgramClient,
#[allow(dead_code)]
pub restaking_program_client: RestakingProgramClient,
pub vault_config_admin: Keypair,
pub ncn_root: NcnRoot,
pub vault_root: VaultRoot,
#[allow(dead_code)]
pub restaking_config_admin: Keypair,
pub operator_roots: Vec<OperatorRoot>,
}

Expand Down Expand Up @@ -131,35 +126,36 @@ impl TestBuilder {

pub async fn setup_ncn(&mut self) -> TestResult<NcnRoot> {
let mut restaking_program_client = self.restaking_program_client();
let mut vault_program_client = self.vault_program_client();

vault_program_client.do_initialize_config().await?;
restaking_program_client.do_initialize_config().await?;
let ncn_root = restaking_program_client.do_initialize_ncn().await?;

Ok(ncn_root)
}

pub async fn add_vault_to_ncn(&mut self, ncn_root: &NcnRoot) {
//TODO start here
}

/// Configures a vault with an NCN and operators fully configured
pub async fn setup_vault_with_ncn_and_operators(
pub async fn setup_vault(
&mut self,
deposit_fee_bps: u16,
withdrawal_fee_bps: u16,
reward_fee_bps: u16,
num_operators: u16,
slasher_amounts: &[u64],
ncn_root: &NcnRoot,
operator_roots: &[OperatorRoot],
) -> TestResult<ConfiguredVault> {
let mut vault_program_client = self.vault_program_client();
let mut restaking_program_client = self.restaking_program_client();

let (vault_config_admin, vault_root) = vault_program_client
.setup_config_and_vault(deposit_fee_bps, withdrawal_fee_bps, reward_fee_bps)
const DEPOSIT_FEE_BPS: u16 = 10;
const WITHDRAWAL_FEE_BPS: u16 = 10;
const REWARD_FEE_BPS: u16 = 10;

let vault_root = vault_program_client
.do_initialize_vault(
DEPOSIT_FEE_BPS,
WITHDRAWAL_FEE_BPS,
REWARD_FEE_BPS,
9,
&self.context.payer.pubkey(),
)
.await?;
let restaking_config_admin = restaking_program_client.do_initialize_config().await?;

let ncn_root = restaking_program_client.do_initialize_ncn().await?;

// vault <> ncn
restaking_program_client
Expand All @@ -177,10 +173,7 @@ impl TestBuilder {
.do_warmup_vault_ncn_ticket(&vault_root, &ncn_root.ncn_pubkey)
.await?;

let mut operator_roots = Vec::with_capacity(num_operators as usize);
for _ in 0..num_operators {
let operator_root = restaking_program_client.do_initialize_operator().await?;

for operator_root in operator_roots {
// ncn <> operator
restaking_program_client
.do_initialize_ncn_operator_state(&ncn_root, &operator_root.operator_pubkey)
Expand All @@ -207,58 +200,12 @@ impl TestBuilder {
&operator_root.operator_pubkey,
)
.await?;

operator_roots.push(operator_root);
}

let mut slashers_amounts: Vec<(Keypair, u64)> = Vec::with_capacity(slasher_amounts.len());
for amount in slasher_amounts {
let slasher = Keypair::new();
self.transfer(&slasher.pubkey(), 10.0).await?;

restaking_program_client
.do_initialize_ncn_vault_slasher_ticket(
&ncn_root,
&vault_root.vault_pubkey,
&slasher.pubkey(),
*amount,
)
.await?;
self.warp_slot_incremental(1).await.unwrap();
restaking_program_client
.do_warmup_ncn_vault_slasher_ticket(
&ncn_root,
&vault_root.vault_pubkey,
&slasher.pubkey(),
)
.await?;

vault_program_client
.do_initialize_vault_ncn_slasher_ticket(
&vault_root,
&ncn_root.ncn_pubkey,
&slasher.pubkey(),
)
.await?;
self.warp_slot_incremental(1).await.unwrap();
vault_program_client
.do_warmup_vault_ncn_slasher_ticket(
&vault_root,
&ncn_root.ncn_pubkey,
&slasher.pubkey(),
)
.await?;

slashers_amounts.push((slasher, *amount));
}

Ok(ConfiguredVault {
vault_program_client,
restaking_program_client,
ncn_root: ncn_root.clone(),
vault_root,
vault_config_admin,
restaking_config_admin,
operator_roots,
operator_roots: operator_roots.to_vec(),
})
}
}
9 changes: 9 additions & 0 deletions integration_tests/tests/fixtures/vault_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ pub struct VaultRoot {
pub vault_admin: Keypair,
}

impl Clone for VaultRoot {
fn clone(&self) -> Self {
Self {
vault_pubkey: self.vault_pubkey,
vault_admin: self.vault_admin.insecure_clone(),
}
}
}

impl Debug for VaultRoot {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
Expand Down

0 comments on commit 38f98b5

Please sign in to comment.