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

banks client CU meter not working for solana-program-test #34494

Closed
cavemanloverboy opened this issue Dec 16, 2023 · 2 comments
Closed

banks client CU meter not working for solana-program-test #34494

cavemanloverboy opened this issue Dec 16, 2023 · 2 comments
Labels
community Community contribution

Comments

@cavemanloverboy
Copy link
Contributor

For no good reason, I have a suspicion this is a MacOS problem. I don't have a linux machine to test on, but the folks I've been in contact with say this works on their linux machine.

If I take the example-helloworld program and insert this diff

% git diff tests
diff --git a/src/program-rust/tests/lib.rs b/src/program-rust/tests/lib.rs
index cc9cc02..890b43e 100644
--- a/src/program-rust/tests/lib.rs
+++ b/src/program-rust/tests/lib.rs
@@ -54,7 +54,8 @@ async fn test_helloworld() {
         Some(&payer.pubkey()),
     );
     transaction.sign(&[&payer], recent_blockhash);
-    banks_client.process_transaction(transaction).await.unwrap();
+    let meta = banks_client.process_transaction_with_metadata(transaction).await.unwrap();
+    println!("CUs: {}", meta.metadata.unwrap().compute_units_consumed);

     // Verify account has one greeting
     let greeted_account = banks_client

to print CUs, I always get:

running 1 test
[2023-12-16T19:02:55.406071000Z INFO  solana_program_test] "helloworld" builtin program
[2023-12-16T19:02:55.429180000Z DEBUG solana_runtime::message_processor::stable_log] Program 1111111QLbz7JHiBTspS962RLKV8GndWFwiEaqKM invoke [1]
[2023-12-16T19:02:55.429236000Z DEBUG solana_runtime::message_processor::stable_log] Program 1111111QLbz7JHiBTspS962RLKV8GndWFwiEaqKM invoke [1]
[2023-12-16T19:02:55.429320000Z DEBUG solana_runtime::message_processor::stable_log] Program log: Hello World Rust program entrypoint
[2023-12-16T19:02:55.429328000Z DEBUG solana_runtime::message_processor::stable_log] Program log: Greeted 1 time(s)!
[2023-12-16T19:02:55.429335000Z DEBUG solana_runtime::message_processor::stable_log] Program 1111111QLbz7JHiBTspS962RLKV8GndWFwiEaqKM success
[2023-12-16T19:02:55.429369000Z DEBUG solana_runtime::message_processor::stable_log] Program 1111111QLbz7JHiBTspS962RLKV8GndWFwiEaqKM success
CUs: 0
[2023-12-16T19:02:55.430223000Z DEBUG solana_runtime::message_processor::stable_log] Program 1111111QLbz7JHiBTspS962RLKV8GndWFwiEaqKM invoke [1]
[2023-12-16T19:02:55.430247000Z DEBUG solana_runtime::message_processor::stable_log] Program 1111111QLbz7JHiBTspS962RLKV8GndWFwiEaqKM invoke [1]
[2023-12-16T19:02:55.430315000Z DEBUG solana_runtime::message_processor::stable_log] Program log: Hello World Rust program entrypoint
[2023-12-16T19:02:55.430324000Z DEBUG solana_runtime::message_processor::stable_log] Program log: Greeted 2 time(s)!
[2023-12-16T19:02:55.430328000Z DEBUG solana_runtime::message_processor::stable_log] Program 1111111QLbz7JHiBTspS962RLKV8GndWFwiEaqKM success
[2023-12-16T19:02:55.430349000Z DEBUG solana_runtime::message_processor::stable_log] Program 1111111QLbz7JHiBTspS962RLKV8GndWFwiEaqKM success
test test_helloworld ... ok

Not only is the reported CUs zero, it appears I can essentially do infinite compute within the instruction. As such, the test environment is not ideal.

@cavemanloverboy cavemanloverboy added the community Community contribution label Dec 16, 2023
@ifiokjr
Copy link

ifiokjr commented Jul 20, 2024

@cavemanloverboy was this ever resolved? Is that why you closed it?

I'm seeing very low CU values in my BanksClient tests. I'm wondering how to check the actual CU without running a local validator.

@cavemanloverboy
Copy link
Contributor Author

no i just learned that it's not actually metered (on this version at least) when not running the bpf program

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Community contribution
Projects
None yet
Development

No branches or pull requests

2 participants