I am currently working on "CreateAccount" test on solana, i am using provider and it automatically signs transactions so it is working but i want to test a new user so i want to create account by passing keypair to signers instead of provider.
My Anchor Version: 0.25.0
Rust Code:
#[derive(Accounts)]
pub struct CreateUserAccount<'info> {
// User's account
#[account(mut)]
pub signer: Signer<'info>,
// Creating a new account for every user with seed of their wallet address.
// This constraint one-account per wallet address
#[account(
init,
payer = signer,
space = UserAccount::LEN,
seeds = ["user-account".as_bytes(), signer.key().as_ref()],
bump,
)]
pub user_account: Account<'info, UserAccount>,
pub system_program: Program<'info, System>,
}
Working frontend test:
describe('teamdao-tournament', () => {
const provider = anchor.AnchorProvider.env()
anchor.setProvider(provider)
const program = anchor.workspace.TeamdaoTournament as Program<TeamdaoTournament>
it('Creating a new account for user', async () => {
const ix = await program.methods.createUserAccount().accounts().signers();
const userAccountAddress = (await ix.pubkeys()).userAccount;
console.log('User account address :: ', userAccountAddress.toString())
const tx = await ix.rpc()
console.log('Your transaction signature', tx)
}
}
What i want to do (not working):
describe('teamdao-tournament', () => {
const program = anchor.workspace.TeamdaoTournament as Program<TeamdaoTournament>
const newUser = anchor.web3.Keypair.generate();
it('Creating a new account for user', async () => {
const ix = await program.methods.createUserAccount().accounts({
signer: newUser.publicKey
}).signers([newUser]);
const userAccountAddress = (await ix.pubkeys()).userAccount;
console.log('User account address :: ', userAccountAddress.toString())
// Create user's facebook address
const tx = await ix.rpc()
console.log('Your transaction signature', tx)
}
}
second one getting error: "Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x1"
How to fix that?