-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
cli: init rust test #2805
cli: init rust test #2805
Conversation
@aoikurokawa is attempting to deploy a commit to the coral-xyz Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for starting on this!
I am submitting this pull request for review. As I am not entirely confident about my implementation, I would greatly appreciate any advice or suggestions. I am open to feedback and happy to make any necessary adjustments.
Can we add this as a template instead of a separate flag? It would also be much easier to add it that way since you can just specify all the necessary files in one place similar to
anchor/cli/src/rust_template.rs
Line 69 in 94fde24
fn create_program_template_multiple(name: &str, program_path: &Path) -> Files { |
Thank you for the review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work, thanks! A few more things and it should be good to merge.
@acheroncrypto |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
For anyone wishing to try this, use
Look inside You'll see a file with the contents: use std::str::FromStr;
use anchor_client::{
solana_sdk::{
commitment_config::CommitmentConfig, pubkey::Pubkey, signature::read_keypair_file,
},
Client, Cluster,
};
#[test]
fn test_initialize() {
let program_id = "ALBsctEzCR2MuZ65KczywWQYEyhjdbq7B5LnkuYg1sie";
let anchor_wallet = std::env::var("ANCHOR_WALLET").unwrap();
let payer = read_keypair_file(&anchor_wallet).unwrap();
let client = Client::new_with_options(Cluster::Localnet, &payer, CommitmentConfig::confirmed());
let program_id = Pubkey::from_str(program_id).unwrap();
let program = client.program(program_id).unwrap();
let tx = program
.request()
.accounts(aaa::accounts::Initialize {})
.args(aaa::instruction::Initialize {})
.send()
.expect("");
println!("Your transaction signature {}", tx);
} Then run |
Hi, this feature is so good, we want use only rust when developing smart contracts. But this feature isn't well documented. For this reason I want to ask my question in here. #[derive(Accounts)]
pub struct Initialize<'info> {
#[account(
init,
payer = signer,
space = Counter::SPACE
)]
pub counter: Account<'info, Counter>,
#[account(mut)]
pub signer: Signer<'info>,
pub system_program: Program<'info, System>,
}
// ....
// test code:
let tx = program
.request()
.accounts(anchor_tutor_1::accounts::Initialize {
counter: payer.pubkey(),
signer: payer.pubkey(),
system_program: system_program::ID,
})
.args(anchor_tutor_1::instruction::Initialize {})
.send()
.expect("Transaction failed"); This code isn't working. The error message: thread 'test_initialize::test_initialize' panicked at tests/src/test_initialize.rs:31:10: So how can I sovle this? Thanks. |
I think the account of counter should not be
|
@aoikurokawa thanks for your response. I searched in google but I didn't find information about writing tests inside of rust. Do you have any suggestion about documentation, example code etc? Thanks. |
@kevinrodriguez-io Most test codes are written in Rust. So I think you can take some hints from it. |
OwO ? |
Problem
close #2680
Summary of Changes
rust-template
inanchor init -t
command.I am submitting this pull request for review. As I am not entirely confident about my implementation, I would greatly appreciate any advice or suggestions. I am open to feedback and happy to make any necessary adjustments.