Questions tagged [testing]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
3 votes
0 answers
44 views

Changes to runtime's LoadedPrograms between 1.17.6 and versions after in the ProgramTest context

Can someone summarize the changes to how LoadedPrograms work between version 1.17.6 and versions after? The changes have broken my ProgramTest setup and I would like to know if I can recreate it after ...
billy's user avatar
  • 353
1 vote
1 answer
23 views

solana local chain

i try to running solana in local my environment with help of solana-test-validator and its running in local environment absolute fine. but i have some doubt it create its own genesis config with ...
Dick grayson's user avatar
0 votes
0 answers
23 views

Solana 1.17+, what processor should be used when instantiating ProgramTest::new()?

I recently upgraded from Solana 1.14 to 1.17.22 and I'm not able to write rust tests that way I've previously been able to. Specifically, previously, when instantiating ProgramTest::new I've typically ...
Ted's user avatar
  • 1
3 votes
1 answer
146 views

`ProgramFailedToComplete` when I make a transaction

I receive ProgramFailedToComplete when I make a CPI: 1) vault Is initialized!: Error: Raw transaction 3pa2qbGAFNMUbdCXr8nqN43qw9tTzt2ZyFYV3jBAAKN5VpKnOMMMWY4q¿duaUPsUsdtDKsEsgRBLNUGCyk7rFXzb failed ({&...
jakerumbles's user avatar
0 votes
2 answers
361 views

Issue with .env file

I'm just beginning to learn and I'm using the SolDev bootcamp however, I've found an issue where I get this error message, PS C:\Users\Student\Documents\Solana_Web3\generate-keypair> npx esrun ...
johnny's user avatar
  • 69
1 vote
1 answer
154 views

How to deploy Solana private chain with at least 4 nodes for testing on single or multiple machines

I want to send transactions to the blockchain and obtain the execution results of the transactions.I followed the instructions in the official documentation below for the setup, but I'm not sure if ...
sdjasj's user avatar
  • 35
1 vote
1 answer
65 views

Custom Program Error 0x0 When Running Test

I've looked around and I see this is a common error that devs run into based on the fact that an account was already initialized. I'm just wondering how to fix it so that I can run tests without ...
Brian M.'s user avatar
  • 111
2 votes
1 answer
141 views

HashMaps in Anchor

Does anyone have experience using HashMaps in an Anchor project? I have the following implementation for a struct: #[account] #[derive(Debug)] pub struct Company { pub id: u64, // 8 bytes pub ...
brknarsy's user avatar
0 votes
1 answer
33 views

How to test balance change of my staking program

I am following a tutorial to make a staking app and I want to test the functionality of my instruction. I have tried "getTokenAccountBalance", but it remain unchanged before and after the ...
Tropical Dog's user avatar
1 vote
1 answer
31 views

what tx_count means in bench-tps.sh?

I've a questions, for NDEBUG=1 ./multinode-demo/bench-tps.sh --tx_count 50000 what is tx_count ? what happens if I increment or decrement this value? Because by default is 50000 but in the webpage ...
David C's user avatar
  • 13
1 vote
0 answers
40 views

How do I test a single function on the Solana VM?

Say I have a test function like this: #[test] fn my_test() { assert_eq!(2 + 2, 4) } I could test this with regular cargo test but that will run the function on my OS, not as it would run in a ...
KevinH's user avatar
  • 402
1 vote
1 answer
54 views

BanksClient: should I prefer `process_transaction_with_metadata` over `process_transaction?`

I've noticed that process_transaction (and process_transaction_with_preflight_and_commitment) hangs when a program is missing from BanksServer or when it encounters an AccountInUse error. It probably ...
KevinH's user avatar
  • 402
2 votes
1 answer
39 views

How to implement a front-end unit/integration test

I am looking to create a test script for an application implemented with frontend only code. How do you guys implement unit tests and integration tests for the front end? Also, if you know of any ...
ysaito's user avatar
  • 21
2 votes
2 answers
177 views

Instruction index: 0 Reason: A seeds constraint was violated. Getting this while testing in playground for the UpdateFund ctx

#[program] pub mod fund { use super::*; pub fn initialize_user( ctx:Context<InitializeUser>, ) -> Result<()> { msg!("User Initialized"); ...
0xmadhan's user avatar
2 votes
2 answers
296 views

TryingToInitPayerAsProgramAccount. Error Number: 4101. You cannot/should not initialize the payer account as a program account

I have a simple program: #[program] pub mod my_cool_project { use super::*; pub fn initialize(ctx: Context<Initialize>) -> Result<()> { let counter = &mut ctx....
Daniel Cukier's user avatar
1 vote
1 answer
118 views

Program file data not available when running test

When I try to run my tests with cargo test-bpf, I get this error: thread 'processor::tests::it_works' panicked at 'Program file data not available for program_name (...)' This is my test code: #[cfg(...
Daniel Cukier's user avatar
2 votes
1 answer
35 views

Does testing through ProgramTestContext have any disadvantage over `solana-test-validator`?

solana-test-validator is basically a full validator run locally. ProgramTestContext looks more light-weight. Does testing through ProgramTestContext skip any checks compared to solana-test-validator?
itsfarseen's user avatar
0 votes
1 answer
64 views

Is it possible to do getProgramAccounts using ProgramTestContext?

I am trying to speed up my tests by switching from using a local test validator to using ProgramTestContext. This will let me execute multiple tests in parallel where each one has its own instance of ...
itsfarseen's user avatar
1 vote
1 answer
84 views

'failed to select a version' error when running 'cargo test-bpf'

I am writing unit tests for a native rust program using solana-sdk, solana-program-test and assert_matches crates. After writing the tests, when I try to execute them using cargo test-bpf command, I ...
Shubham Singh's user avatar
2 votes
1 answer
383 views

How to test token transfer?

I have a program lib.rs that at some point make a USDC transfer from one account to another. It works on mainnet because I put the token_program_id that corresponds to USDC but this token_program_id ...
rudy rhatal's user avatar
1 vote
1 answer
235 views

Looking for complete/good example of how to test Solana Smart contracts with Javascript (Jest)

I'm looking for a good example or open-source project where I can see and learn how to test Solana smart contracts properly. I would also like to see how to test smart contracts using other programs ...
Ladi's user avatar
  • 23
2 votes
0 answers
38 views

How to target a specific Test.toml instead of all of them with anchor test?

Running anchor test in a project with multiple Test.toml files executes every command labeled "test" in every Test.toml [script] block, (and from that of the Anchor.toml too). I've looked ...
HelmetFace's user avatar
  • 1,697
2 votes
2 answers
128 views

Testing transactions that should fail with anchor

I am currently writing unit test for my Solana contract written using the Anchor framework. I have created unit tests for the positive flow of how things should work, and all the tests are passing, ...
michaelb's user avatar
0 votes
1 answer
114 views

BPF test crashes if duration >~10s

I am doing a heavy set of tests, and one of these have to create several thousands of accounts and change one specific account 1k times. Sometimes the test runs, other times it blows up after the 950~ ...
Tiago 's user avatar
  • 96
0 votes
2 answers
69 views

What are recommendations of things to do before publishing to mainnet?

There is a lot of risk in publishing to mainnet. Some of the things that I'm having difficulty with, as someone without resources to assist, is that I don't have people with a better understanding of ...
DevelopingJoku's user avatar
1 vote
2 answers
750 views

How to run anchor tests partially?

Having a project that has grown a bit larger I have modularized the tests into separate files. Calling the test script works fine with running over all files. But I couldn't figure out or find ...
tenxsoydev's user avatar
2 votes
3 answers
183 views

How to fix the "Program processor not available" error in integration test?

Based on the code here I am trying to run an integration test using the solana_program_test crate. The integration test code I am executing is as follows: #![feature(backtrace)] #![cfg(feature = "...
dade's user avatar
  • 292
1 vote
1 answer
141 views

How to locally test interaction with external contracts (chainlink and pyth oracles )?

I have a Solana smart contract (written with Anchor) that interacts with Pyth and Chainlink Solana oracles. In EVM world, we would either redeploy the necessary contracts locally in the test start-up ...
Roberts Ivanovs's user avatar
0 votes
3 answers
396 views

How to convert number to buffer in Anchor TS test

I have this seeds seeds = [b"game".as_ref(),authority.key().as_ref(),player_one_account.games_count.to_be_bytes().as_ref()] The games_count is a u16. I want to create a PDA with these seeds :...
Reza Aslejeddian's user avatar
1 vote
2 answers
728 views

How to sign a transaction with keypair?

I'm working on pda's and I have this code: #[derive(Accounts)] #[instruction(user_name: String , phone_number: String , email: String)] pub struct CreateUserAccount<'info> { #[...
Reza Aslejeddian's user avatar
3 votes
1 answer
326 views

what is the relation between Signers & Wallets in testing

What is the difference between provider.wallet.Pubkey , provider.Pubkey and anchor.web3.Keypair.generate().publicKey at testing? I am confused where to use each one of them because they look the ...
Reza Aslejeddian's user avatar
1 vote
3 answers
641 views

Failing to create associated token account in rust tests. It says insufficient account keys for instruction

https://github.com/SushantChandla/test-mint-bug/blob/main/programs/mint-bug/tests/mint.rs I am trying to create an associated token account please have a look at the github file. The error I get is ...
Sushant Chandla's user avatar
1 vote
1 answer
81 views

Error: Your configured rpc port: 8899 is already in use

I am getting this error when i am running the command anchor test : Error: Your configured rpc port: 8899 is already in use And i know i have to kill the local validator from this question but i don't ...
Reza Aslejeddian's user avatar
1 vote
1 answer
170 views

How to generate new wallets in anchor typescript tests

I'm writing some unit tests and want to test that a user cannot update data on a PDA created by another user. How can I get "another user?" I'm creating the first user: const provider = ...
Will's user avatar
  • 113
2 votes
2 answers
165 views

How to sign with PDAs

I have a this function pub fn sign_up(ctx: Context<SignUp> , user_name: String , phone_number: String , email: String) -> Result<()> {// logic is here} And in SignUp i have : #[derive(...
Reza Aslejeddian's user avatar
1 vote
1 answer
468 views

Anchor: How can I check specific Anchor Error Codes are caught in my test script if they are expected? [closed]

I have the following setName function and Name error code setup in my script as: pub fn set_name( ctx: Context<Name>, name: String, ) -> Result<()> { if ...
Omega's user avatar
  • 55
3 votes
1 answer
60 views

Can't process_transaction twice within a test

I'm trying to write test functions in Rust for an Anchor program, and I want to check that a particular instruction can't be called twice. Hence, I'm trying to do process_transaction twice. But the ...
sayantank's user avatar
  • 425
1 vote
0 answers
47 views

dApp automated UI testing [closed]

I would like to set up integration automated UI tests for my dApp using Cypress, Puppeteer, or Selenium. At this point, the testing framework does not matter to me. Can anyone suggest ways to test the ...
cloudberry's user avatar
0 votes
1 answer
47 views

Anchor Testing Workflow? [closed]

How do you guys go about testing? Seems like program unit tests should be standard rust tests with cargo test. There are some program tests that are run with cargo test-bpf. Then test deployment, ...
Robbing Blocks's user avatar
1 vote
1 answer
369 views

Send Instruction with multiple parameters to non-anchor program help (instruciton_data)

I am working with a solana program which was written a couple years ago and it is non-anchor. I am specifically having trouble with calling the program functions from the test-side, the data field ...
Lola1222's user avatar
2 votes
0 answers
90 views

Error: failed to get info about account, TypeError

I'm working on a Localhost connection for unit testing. Just tried to request an airdrop and then get the account info but i'm getting the following error: Error: failed to get info about account ...
naynim's user avatar
  • 41
3 votes
2 answers
243 views

How to test a function that is expected to return error?

I got two questions : First : I have some custom error type declared in the smart contract and I want to check the appropriate error to be returned from the function call , I wonder how can I get the ...
Reza Aslejeddian's user avatar
3 votes
1 answer
530 views

IdlError: Type not found

I am trying to test an initialize function that takes in as parameter an object rather than just one value: pub fn initialize(ctx: Context<InitializeAuction>, args: CreateAuctionArgs) -> ...
Daniel Pavel's user avatar
0 votes
1 answer
109 views

Anchor test fails [closed]

I have this function : pub fn sign_up(ctx: Context<SignUp> , user_name: String , phone: String , email: String) -> Result<()> {// Code is here} And inside it i have : // Email ...
Reza Aslejeddian's user avatar
5 votes
2 answers
142 views

PDA Anchor Test: Transaction simulation failed: Error processing Instruction 0: Cross-program invocation with unauthorized signer or writable account

I was playing around with PDA's in anchor, but I'm having problems writing tests for it. When I try to use anchor's worspace to create a transaction I get the error: Error: failed to send transaction: ...
JoshChang's user avatar
1 vote
1 answer
126 views

Your configured rpc port: 8899 is already in use

When I run anchor test command get this error . Error: Your configured rpc port: 8899 is already in use I checked that port but look like there is no such process is using that port on my device .
Reza Aslejeddian's user avatar
3 votes
1 answer
135 views

How to airdrop arbitrary token on devnet

For testing purpose, is there a way to obtain/airdrop some amount of an arbitrary token on devnet? The only thing I know about the token I would like to request an airdrop for, is the token mint ...
Yifan Jiang's user avatar
2 votes
1 answer
246 views

Is there a way to get large amounts of SOL on Devnet/Testnet

For proper testing of our app, we need large amounts of SOL (upwards of 50,000 SOL) in Devnet and/or Testnet accounts. The solana airdrop command is becoming more and more limited, both in terms of ...
AllBlooming's user avatar
  • 2,249
0 votes
1 answer
54 views

Does Anchor localnet come with the spl_token loaded?

I have been fiddling around with tests using Anchor. I spent a fair deal of time ensuring that spl token was included in my localnet before running tests. However, after getting my initial call to the ...
TovarishFin's user avatar
3 votes
1 answer
280 views

How to include other programs and test CPIs on localnet using Anchor?

Say for instance I am building something that interacts with the spl_token program. How do I include this and test this interaction? Do I need to copy and paste the code into the programs directory ...
TovarishFin's user avatar