Questions tagged [anchor-test]
The anchor-test tag has no usage guidance.
58
questions
1
vote
1
answer
51
views
How do I fix error Syntax Error: Unexpected token '.' when running anchor test
I get the following error when I run anchor test to test my smart contract using typescript:
Error snippet
abortSignal: options?.abortSignal,
^
SyntaxError: ...
1
vote
1
answer
28
views
TypeScript production code to mint an NFT vs anchor testing code
How would I go about converting the following testing code (from an anchor project) to something that would interact with my frontend in production (or convert it into a function to be used in react ...
1
vote
1
answer
65
views
Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: Cross-program invocation with unauthorized signer
I am trying to run a test on anchor/metaplex code that should be minting a new NFT/creating a master edition account, however my test is failing and I'm not sure why. Here is the error message:
0 ...
2
votes
1
answer
51
views
Can't run Anchor test with the basic project
I just created an Anchor project with anchor init and tried to run anchor test but it didn't work. I always get the error:
Unable to get latest blockhash. Test validator does not look started. Check ....
2
votes
1
answer
25
views
Control time anchor test
I want to control time like moving forward to a specified block or time so that we can check if the function after the block/time lasts works well. Is there any way to do that in anchor solana?
3
votes
1
answer
157
views
Error trying to run anchor test
trying to learn anchor dev, following soldev.app.
I have a problem, when I run anchor test, this is the error I get:
Unable to get the latest blockhash. The test validator does not look started. Check ...
1
vote
2
answers
92
views
How can I test the anchor has_one check?
I want to test the anchor "has one" authority check so that only the signer that initialized the account can call a function in the smart contract.
This way only the wallet that called the ...
1
vote
1
answer
58
views
Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: Program failed to complete
I get this error when I am calling an instruction of a program from a client. I am using Seahorse library to write smart contract. The library transpiles python code to anchor rust program.
Here's the ...
3
votes
1
answer
31
views
How to pass instruction data in anchor tests?
I wrote an anchor program which initializes a counter account and sets its inital value to instruction_data.
pub fn initialize(ctx: Context<Initialize>, instruction_data: u64) -> Result<()&...
2
votes
1
answer
253
views
Insufficient lamports but my balance already is 7 SOL
I'm trying to transfer sol via smart contract but when I make a transfer tx, it return insufficent lamports, and it says I have 0 lamports.
pub fn buy_nft(
ctx: Context<BuyNft>,
...
1
vote
1
answer
126
views
The program expected this account to be already initialized
When I do anchor build, the compiler returns this error caused by mint, ownerTokenAccount, and buyerTokenAccount. Here is my code:
it("Is initialized!", async () => {
//
let ...
1
vote
0
answers
35
views
When using Event listener the rpc call to program function does nothing and eventualy time limit will exceed and test fails
This block of code is giving the trouble..
let listener = null;
//@ts-ignore
let [event, slot] = await new Promise((resolve, _reject) => {
listener = program.addEventListener(&...
1
vote
1
answer
51
views
Anchor unit tests wont work on localnet
Sorry for the noob question.
Im trying to test a program that I deployed locally, however when running anchor run test, I receive the following error.
Error: failed to get recent blockhash: FetchError:...
3
votes
2
answers
110
views
How to create a mint account on anchor test?
It would be extremely useful if I could create a mint account from a JSON file to test my anchor program.
I have this in my Anchor.toml to add the account when I run anchor test
[[test.validator....
3
votes
1
answer
40
views
Getting RPC Response error -32602, while trying to run anchor test
Output when running command anchor test
Running test suite: "/home/adilcpm/ratio/ratio-contracts/Anchor.toml"
Error: RPC response error -32602: Too many inputs provided; max 5
Caused by:
...
3
votes
1
answer
104
views
How to fix solana-test-validator Illegal instruction (core dumped) error even after building from source?
When running anchor test on a fresh project without any change, I got following error:
Unable to get recent blockhash. Test validator does not look started.
Check {} for errors. Consider increasing [...
3
votes
1
answer
173
views
AnchorError caused by account: program_data. Error Code: AccountNotInitialized
Running anchor test for the bpf-upgrade-state example program while on localnet results in the following error
Error: AnchorError caused by account: program_data. Error Code: AccountNotInitialized. ...
2
votes
0
answers
18
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 ...
4
votes
1
answer
62
views
Add a counter to track NFTs minted
I am trying to create a counter and increment it on every mint. On adding the counter code after deploying when I test it gives me an error on anchor run test:
lib.rs snippets:
#[account]
pub struct ...
4
votes
2
answers
59
views
Anchor test fails on Fedora
I'm using Fedora 36 for dev but I am having trouble running anchor test. I get the following output:
cargo-build-bpf child: /home/0xAckerman/.local/share/solana/install/active_release/bin/cargo-build-...
1
vote
1
answer
73
views
How to forward slot time when testing in solana - anchor
i'm trying to write a test for a program that requires n - number of slots to have passed before executing. Please is there a way to skip/forward slots using anchor? I'm using solana-test-validator to ...
1
vote
1
answer
34
views
Error processing Instruction 0: Cross-program invocation with unauthorized signer or writable account
i'm getting the error in the title mentioned above and none of the solutions online seem to fix my error. This is the error msg in its entirety:
Error: failed to send transaction: Transaction ...
2
votes
1
answer
59
views
Print in Solana Playground
I want to debug my program in Solana Playground. I am using the print function to get logs. The containing function is running but not producing any logs. Attaching a screenshot below.
0
votes
1
answer
28
views
How to implement Rust Struct in TS tests?
Hi guys I have a struct in my Rust code that is used in a struct that is a account, my code :
#[account]
pub struct TournamentTwoPlayers {
pub games: [Game; 1],
}
#[derive(AnchorSerialize, ...
1
vote
3
answers
342
views
error of "Cross-program invocation with unauthorized signer or writable account"
I am trying to create an ATA using this but i get this error
#[account(
init,
payer = signer,
seeds = [rent_manager.key().as_ref()],
bump,
token::mint = pay_mint,
token::authority = rent_manager,
)]
...
3
votes
2
answers
368
views
anchor test: Error: Your configured rpc port: 8899 is already in use
When I try to run 'anchor test' (on Ubuntu 20.04.1) following this tutorial
https://dev.to/edge-and-node/the-complete-guide-to-full-stack-solana-development-with-react-anchor-rust-and-phantom-3291
I ...
3
votes
1
answer
339
views
How to create an associated Token Account in anchor, I'm getting the following error: "insufficient account keys for instruction"
I need to create a SPL-Token before each test I'm running
So I created the 2 following functions : createMint and createUserAndAssociatedWallet
I'm able to create a mint but I can't create the ...
4
votes
2
answers
190
views
Error Code: ConstraintMut. Error Number: 2000. Error Message: A mut constraint was violated.'
failed: custom program error: 0x7d0'
pub fn bid(ctx: Context<Bid>, price: u64) -> Result<()> {
let auction = &ctx.accounts.auction;
let bidder = &mut ctx.accounts....
1
vote
2
answers
141
views
anchor test: error while loading shared libraries: libssl.so.1.1
I'm installing Solana on WSL following this guide:
https://github.com/LearnWithArjun/solana-env-setup/blob/main/mac_or_linux_setup.md
When I come to 'anchor test' I get this error:
anchor test
BPF SDK:...
3
votes
1
answer
277
views
How to use the Anchor's `features = ["cpi"]`?
In the anchor-lang docs it says,
The features = ["cpi"] is used so we can not only use puppet's types
but also its instruction builders and cpi functions. Without those, we
would have to ...
1
vote
2
answers
171
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 ...
0
votes
2
answers
145
views
How to convert string to as_bytes in typescript?
So, I have a PDA seed where I'm hashing a string (which is converted to bytes) and converting the hash result to_string and then as_bytes.
code:
anchor_lang::solana_program::hash::hash(name.as_bytes())...
0
votes
0
answers
20
views
I am generating two accounts and trying to use them in following manner
use anchor_lang::prelude::*;
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
#[program]
pub mod puppet {
use super::*;
pub fn initialize(ctx: Context<Initialize>)...
2
votes
2
answers
219
views
Error when creating PDA: Transaction simulation failed: Error processing Instruction 0: Program failed to complete
Following error occurs when I try to run anchor test:
Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: Program failed to complete
at Connection....
1
vote
1
answer
34
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 ...
0
votes
1
answer
82
views
How to measure test coverage for Anchor program?
How do I measure test coverage for an Anchor program?
If I write my tests in typescript, then there are no code coverage reports
If I write my tests in Rust (similar as specified here), and use the ...
1
vote
0
answers
17
views
How much slower are devnet transactions vs mainnet? [closed]
When I run my anchor tests, each RPC within the test script only takes around ~500ms. However, when using the same RPC on my program deployed to devnet, even RPC calls without a UI take around 20-30 ...
0
votes
0
answers
35
views
How can I get the user defined error message in anchor test? [duplicate]
This is My function
pub fn update_user(ctx: Context<Update>,
_x: String,
_y : String
) -> Result<()>{
...
1
vote
1
answer
114
views
How can I set a panic in anchor?
I am modifying this code
[https://github.com/coral-xyz/anchor/blob/master/examples/tutorial/basic-2/programs/basic-2/src/lib.rs][1]
in a way so when any non-authority wallet tries to update the count ...
0
votes
3
answers
136
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 :...
1
vote
2
answers
74
views
How can I use multiple account to check authority in anchor test?
For signing transactions, there is only one account (provider.wallet). I have written a program and it has some authority access functions, how can I use multiple accounts to check it?
If I generated ...
2
votes
0
answers
37
views
Generally I never get insufficient balance error when running anchor test, but sometimes every time I run test It takes all sol with error
There was a problem deploying: Output { status: ExitStatus(unix_wait_status(256)), stdout: "", stderr: "" }.
I am using devnet.
1
vote
1
answer
42
views
How to use the VSCode debugger when testing a Solana Anchor program
Is there a way to use the VSCode debugger on a Solana Anchor program. For instance how could I add a breakpoint and stop execution on line 6 of the Tic-Tac-Toe program whenever I run the JS tests.
I ...
1
vote
2
answers
213
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> {
#[...
2
votes
1
answer
69
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 ...
1
vote
1
answer
45
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 ...
0
votes
1
answer
21
views
Anchor build error: failed to download `serde_bytes v0.11.7`
I've been trying to follow the tutorials provided in https://www.anchor-lang.com/docs to build smart contracts. However when I try to use anchor build/anchor test, I am facing this error.
1
vote
1
answer
106
views
Globally installed anchor version is not correct
Getting an issue trying to run anchor test. How do I update my globally installed anchor?
Error: Globally installed anchor version is not correct. Expected "anchor-cli 0.24.2", found "...
3
votes
1
answer
55
views
How to read the contents of Anchor's test-ledger directory
I'm new to Anchor and Solana program development. I've done some reading on debugging Solana programs running in local by using solana-test-validator and solana logs.
However, I noticed when I'm ...
1
vote
1
answer
46
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 = ...