Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tip Router: Fix stack frame initialize_weight_table #13

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/src/weight_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ impl WeightTable {
}
}

pub fn initialize(&mut self, ncn: Pubkey, ncn_epoch: u64, slot_created: u64, bump: u8) {
*self = WeightTable::new(ncn, ncn_epoch, slot_created, bump);
}

pub fn seeds(ncn: &Pubkey, ncn_epoch: u64) -> Vec<Vec<u8>> {
Vec::from_iter(
[
Expand Down
23 changes: 17 additions & 6 deletions integration_tests/tests/tip_router/initialize_weight_table.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
#[cfg(test)]
mod tests {

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

#[tokio::test]
async fn test_initialize_weight_table_ok() -> TestResult<()> {
async fn test_initialize_weight_table_ok() {
let mut fixture = TestBuilder::new().await;
let mut tip_router_client = fixture.tip_router_client();
let mut restaking_client = fixture.restaking_program_client();

let test_ncn = fixture.create_initial_test_ncn(1, 1).await?;
let test_ncn = fixture.create_initial_test_ncn(1, 1).await.unwrap();

fixture.warp_slot_incremental(1000).await?;
fixture.warp_slot_incremental(1000).await.unwrap();

let slot = fixture.clock().await.slot;

tip_router_client
.do_initialize_weight_table(test_ncn.ncn_root.ncn_pubkey, slot)
.await?;
.await
.unwrap();

Ok(())
let ncn_epoch = restaking_client.get_ncn_epoch(slot).await.unwrap();
let weight_table = tip_router_client
.get_weight_table(test_ncn.ncn_root.ncn_pubkey, ncn_epoch)
.await
.unwrap();

assert!(weight_table.initialized());
assert_eq!(weight_table.ncn(), test_ncn.ncn_root.ncn_pubkey);
assert_eq!(weight_table.ncn_epoch(), ncn_epoch);
assert_eq!(weight_table.slot_created(), slot);
}
}
2 changes: 1 addition & 1 deletion program/src/initialize_weight_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn process_initialize_weight_table(
weight_table_data[0] = WeightTable::DISCRIMINATOR;
let weight_table_account = WeightTable::try_from_slice_unchecked_mut(&mut weight_table_data)?;

*weight_table_account = WeightTable::new(*ncn.key, ncn_epoch, current_slot, weight_table_bump);
weight_table_account.initialize(*ncn.key, ncn_epoch, current_slot, weight_table_bump);

weight_table_account.initalize_weight_table(&unique_mints)?;

Expand Down