1

The test here uses "solana-program-test" and async/await. https://github.com/solana-labs/example-helloworld/blob/master/src/program-rust/tests/lib.rs

Can I run these test scripts on devnet by modifying some parameters?

I am wondering if I can use this async/await type test code to interact with actual deployed programs on devnet.

1
  • you've edited this question to mean something totally different than what it did orignally
    – trent.sol
    Commented Jul 23, 2022 at 3:59

2 Answers 2

1

You'll have far better control over your test environment if you instead use the solana-program-test crate or solana-test-valdidator binary from the CLI tools

2
  • The test uses solana-programa-test. the line let (mut banks_client, payer, recent_blockhash) = program_test.start().await; connects to the local network, I suppose. Can I make the devnet client?
    – gbb
    Commented Jul 21, 2022 at 22:03
  • no. ProgramTest uses a very stripped down version of the runtime, not a full local-cluster. if you want to use devnet, you'd need to adapt your tests. however, as I alluded to in my answer, you don't really want to use devnet to back your test framework. use something that you have full control over, like the things my answer suggests
    – trent.sol
    Commented Jul 23, 2022 at 4:02
1

No, you can't run this test without modifications. As mentioned in comments to previous answer, solana-program-test is not a full validator. It runs only bpf/sbf interpreter with access to accounts, created in the test.

If you want to adapt the test to devnet, you have to rewrite it with solana-client crate and manually send all the needed instructions including program deployment, account creation, filling the accounts with necessary data, if needed. However, you can't write to accounts not owned by you and before changing the ownership runtime zeroize any data, stored in the account, so it is only possible to "prepare" account owned by "user", not the program itself.

To sum up, you'd better stick with solana-program-test.

If you really want to run tests on devnet, you can take a look on the utility we used to prepare the environment for out program (it has quite nontrivial bootstrap process exactly because of a number of program-owned accounts, that have to be present on-chain). Sorry in advance for the absence of comments in this crate, right now we are working on a different part of the project.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.