Skip to main content

Questions tagged [testing]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
8 views

make anchor tests run one after the other

So i'm writing tests for my anchor program, using the mocha testing framework (as per default) Inside of my describe, I want to do different tests, so different it() instructions, but I need them to ...
FluffyMuffin47's user avatar
0 votes
1 answer
30 views

Increase timeStamp during Anchor Test cases of TS(typescipt)

How to increase timeStamp during Anchor Test cases of TS(typescipt), I have use sinon pkg but It's not happening const clockStub = sinon.stub(Date, 'now').returns(Date.now() + (15 * 24 * 3600 * 1000))...
hammad ali's user avatar
1 vote
1 answer
33 views

How to use spl_token account with solana-program-test crate?

I am trying to write a test with the solana-program-test crate for a solana program. This program makes a CPI to a token program: let ix = Instruction { program_id: *token_program.key, ...
S.Rivas's user avatar
  • 11
0 votes
0 answers
15 views

In my code :- Failed to send transaction: Transaction simulation failed: Error processing Instruction 0: Program failed to complete

In this code this line is giving error while testing the code :- MyInstruction::PreSale() => { let tree = unsafe { WHITELIST_TREE.unwrap() }; pre_sale(accounts, tree ) ...
Aditya's user avatar
  • 157
3 votes
1 answer
84 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
  • 352
1 vote
1 answer
48 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
1 vote
0 answers
37 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
  • 11
3 votes
1 answer
455 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
3 answers
724 views

Secret Key format issue in .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
258 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
75 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
  • 121
2 votes
1 answer
240 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
44 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
39 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
44 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
  • 422
1 vote
1 answer
63 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
  • 422
2 votes
1 answer
56 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
255 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
470 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
144 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
39 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
73 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
94 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
438 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
293 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
40 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,757
2 votes
3 answers
175 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
1 vote
1 answer
140 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
  • 116
0 votes
2 answers
76 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
1k 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
216 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
196 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
523 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
891 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
438 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
769 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
86 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
271 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
194 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
648 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
66 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
  • 435
1 vote
0 answers
59 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
53 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
429 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
103 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
305 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
713 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
116 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
147 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
171 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