From 4fce8696604d392d4f6ce8c893704f62578712f3 Mon Sep 17 00:00:00 2001 From: Joe Caulfield Date: Wed, 2 Oct 2024 17:17:34 +0700 Subject: [PATCH] tests: profile compute units in success cases --- program/tests/close.rs | 10 +++++----- program/tests/deploy.rs | 3 ++- program/tests/extend_program.rs | 3 ++- program/tests/initialize_buffer.rs | 1 + program/tests/set_authority.rs | 7 +++++-- program/tests/set_authority_checked.rs | 6 ++++-- program/tests/upgrade.rs | 3 ++- program/tests/write.rs | 2 ++ 8 files changed, 23 insertions(+), 12 deletions(-) diff --git a/program/tests/close.rs b/program/tests/close.rs index 7b68dcb..483b8ae 100644 --- a/program/tests/close.rs +++ b/program/tests/close.rs @@ -186,7 +186,7 @@ fn buffer_fail_authority_not_signer() { fn buffer_success() { let mollusk = setup(); - let buffer = Pubkey::new_unique(); + let buffer = Pubkey::new_from_array([1; 32]); // Consistent CUs when logging. let destination = Pubkey::new_unique(); let authority = Pubkey::new_unique(); @@ -213,6 +213,7 @@ fn buffer_success() { ], &[ Check::success(), + Check::compute_units(12_809), // Closed, but still owned by the loader. Check::account(&buffer) .data(&[0, 0, 0, 0]) // Size of Uninitialized. @@ -433,9 +434,7 @@ fn programdata_fail_incorrect_authority() { ), ), ], - &[ - Check::err(ProgramError::IncorrectAuthority), - ], + &[Check::err(ProgramError::IncorrectAuthority)], ); } @@ -491,7 +490,7 @@ fn programdata_success() { let destination = Pubkey::new_unique(); let authority = Pubkey::new_unique(); - let program = Pubkey::new_unique(); + let program = Pubkey::new_from_array([1; 32]); // Consistent CUs when logging. let programdata = get_program_data_address(&program); @@ -529,6 +528,7 @@ fn programdata_success() { ], &[ Check::success(), + Check::compute_units(14_450), // Closed, but still owned by the loader. Check::account(&programdata) .data(&[0, 0, 0, 0]) // Size of Uninitialized. diff --git a/program/tests/deploy.rs b/program/tests/deploy.rs index d7930a1..ed7578e 100644 --- a/program/tests/deploy.rs +++ b/program/tests/deploy.rs @@ -619,7 +619,7 @@ fn success() { let mollusk = setup(); let payer = Pubkey::new_unique(); - let program = Pubkey::new_unique(); + let program = Pubkey::new_from_array([1; 32]); // Consistent CUs when logging. let buffer = Pubkey::new_unique(); let authority = Pubkey::new_unique(); @@ -670,6 +670,7 @@ fn success() { ], &[ Check::success(), + Check::compute_units(21_870), Check::account(&program) .data( &bincode::serialize(&UpgradeableLoaderState::Program { diff --git a/program/tests/extend_program.rs b/program/tests/extend_program.rs index ec5e583..ea592f9 100644 --- a/program/tests/extend_program.rs +++ b/program/tests/extend_program.rs @@ -559,7 +559,7 @@ fn success() { let mut mollusk = setup(); mollusk.warp_to_slot(2); // To move past deployment slot. - let program = Pubkey::new_unique(); + let program = Pubkey::new_from_array([1; 32]); // Consistent CUs when logging. let payer = Pubkey::new_unique(); let programdata = get_program_data_address(&program); @@ -613,6 +613,7 @@ fn success() { ], &[ Check::success(), + Check::compute_units(7_018), Check::account(&programdata) .lamports(new_rent_exemption) .space(new_size) diff --git a/program/tests/initialize_buffer.rs b/program/tests/initialize_buffer.rs index e283acc..724d173 100644 --- a/program/tests/initialize_buffer.rs +++ b/program/tests/initialize_buffer.rs @@ -110,6 +110,7 @@ fn success() { ], &[ Check::success(), + Check::compute_units(2_171), Check::account(&source) .lamports(100_000_000) .owner(&solana_loader_v3_program::id()) diff --git a/program/tests/set_authority.rs b/program/tests/set_authority.rs index 8380167..267919f 100644 --- a/program/tests/set_authority.rs +++ b/program/tests/set_authority.rs @@ -171,7 +171,7 @@ fn buffer_success() { let buffer = Pubkey::new_unique(); let current_authority = Pubkey::new_unique(); - let new_authority = Pubkey::new_unique(); + let new_authority = Pubkey::new_from_array([1; 32]); // Consistent CUs when logging. let elf = &[3; 5_000]; @@ -204,6 +204,7 @@ fn buffer_success() { ], &[ Check::success(), + Check::compute_units(14_654), Check::account(&buffer) .data( &check_data(Some(new_authority)), // Updated. @@ -317,7 +318,7 @@ fn programdata_success() { let programdata = Pubkey::new_unique(); let current_authority = Pubkey::new_unique(); - let new_authority = Pubkey::new_unique(); + let new_authority = Pubkey::new_from_array([1; 32]); // Consistent CUs when logging. let elf = &[3; 5_000]; @@ -354,6 +355,7 @@ fn programdata_success() { ], &[ Check::success(), + Check::compute_units(14_657), Check::account(&programdata) .data( &check_data(Some(new_authority)), // Updated. @@ -382,6 +384,7 @@ fn programdata_success() { ], &[ Check::success(), + Check::compute_units(1_936), Check::account(&programdata) .data( &check_data(None), // Updated. diff --git a/program/tests/set_authority_checked.rs b/program/tests/set_authority_checked.rs index 80a40df..c532f39 100644 --- a/program/tests/set_authority_checked.rs +++ b/program/tests/set_authority_checked.rs @@ -172,7 +172,7 @@ fn buffer_success() { let buffer = Pubkey::new_unique(); let current_authority = Pubkey::new_unique(); - let new_authority = Pubkey::new_unique(); + let new_authority = Pubkey::new_from_array([1; 32]); // Consistent CUs when logging. let elf = &[3; 5_000]; @@ -205,6 +205,7 @@ fn buffer_success() { ], &[ Check::success(), + Check::compute_units(14_136), Check::account(&buffer) .data( &check_data(Some(new_authority)), // Updated. @@ -350,7 +351,7 @@ fn programdata_success() { let programdata = Pubkey::new_unique(); let current_authority = Pubkey::new_unique(); - let new_authority = Pubkey::new_unique(); + let new_authority = Pubkey::new_from_array([1; 32]); // Consistent CUs when logging. let elf = &[3; 5_000]; @@ -387,6 +388,7 @@ fn programdata_success() { ], &[ Check::success(), + Check::compute_units(14_117), Check::account(&programdata) .data( &check_data(Some(new_authority)), // Updated. diff --git a/program/tests/upgrade.rs b/program/tests/upgrade.rs index 3a6ba01..dd73c2d 100644 --- a/program/tests/upgrade.rs +++ b/program/tests/upgrade.rs @@ -848,7 +848,7 @@ fn success() { let mut mollusk = setup(); mollusk.warp_to_slot(2); // To move past deployment slot. - let program = Pubkey::new_unique(); + let program = Pubkey::new_from_array([1; 32]); // Consistent CUs when logging. let buffer = Pubkey::new_unique(); let spill = Pubkey::new_unique(); let authority = Pubkey::new_unique(); @@ -899,6 +899,7 @@ fn success() { ], &[ Check::success(), + Check::compute_units(16_683), Check::account(&program) .data( &bincode::serialize(&UpgradeableLoaderState::Program { diff --git a/program/tests/write.rs b/program/tests/write.rs index c59588c..e5c82c9 100644 --- a/program/tests/write.rs +++ b/program/tests/write.rs @@ -209,6 +209,7 @@ fn success() { ], &[ Check::success(), + Check::compute_units(1_425), Check::account(&buffer).data(&check_data).build(), ], ); @@ -227,6 +228,7 @@ fn success() { ], &[ Check::success(), + Check::compute_units(1_397), Check::account(&buffer).data(&check_data).build(), ], );