When I am running an anchor test, I am getting the following error, of invalid arguments. Funnily enough, the crowdFundingPlatform argument it says is missing, is never in any of the code I wrote, as you can see below this error in my anchor files.
CrowdFunding
1) Is initialized!
0 passing (22ms)
1 failing
1) CrowdFunding
Is initialized!:
Error: Invalid arguments: crowdFundingPlatform not provided.
Here is the JS test:
describe("CrowdFunding", () => {
// Configure the client to use the local cluster.
const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);
const program = anchor.workspace.CrowdFunding;
const platform = anchor.web3.Keypair.generate();
it('Is initialized!', async () => {
const crowd_funding_platform = anchor.web3.Keypair.generate();
await program.rpc.initialize(
"limk",
"description",
"title",
new anchor.BN(1),
{
accounts: {
crowd_funding_platform: crowd_funding_platform.publicKey,
authority: program.provider.wallet.publicKey,
system_program: anchor.web3.SystemProgram.programId,
},
signers: [crowd_funding_platform],
})
const PlatformAccount = await program.account.crowd_funding_platform.fetch(crowd_funding_platform.publicKey);
console.log(PlatformAccount);
});
})
Here is the smart contract framework for the initialize function, as you can see, there is no 'crowdFundingPlatform'
pub fn initialize(
ctx: Context<Initialize>,
Image: String,
Description: String,
Title: String,
Donation_Goal: u64,
) -> ProgramResult {
let campaign = &mut ctx.accounts.crowd_funding_platform;
campaign.Image = Image;
campaign.Description = Description;
campaign.Title = Title;
campaign.Amount_Donated = 0;
campaign.Donation_Goal = Donation_Goal;
Ok(())
}
#[derive(Accounts)]
pub struct Initialize<'info> {
#[account(
init,
payer = authority,
space = size_of::<CrowdFundingPlatform>() + 8,
seeds = [b"crowd_funding_platform".as_ref()],
bump
)]
pub crowd_funding_platform: Account<'info, CrowdFundingPlatform>,
#[account(mut)]
pub authority: Signer<'info>,
pub system_program: Program<'info, System>,
}
Replace crowd_funding_platform and system_program with crowdFundingPlatform and systemProgram in js file. Here is full js code:
describe("CrowdFunding", () => {
// Configure the client to use the local cluster.
const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);
const program = anchor.workspace.CrowdFunding;
const platform = anchor.web3.Keypair.generate();
it('Is initialized!', async () => {
const [crowdFundingPlatform] = await anchor.web3.PublicKey.findProgramAddress([Buffer.from("crowd_funding_platform")], program.programId);
await program.methods.initialize(
"limk",
"description",
"title",
new anchor.BN(1)
)
.accounts({
crowdFundingPlatform,
authority: program.provider.wallet.publicKey,
systemProgram: anchor.web3.SystemProgram.programId,
})
.rpc();
const PlatformAccount = await program.account.crowdFundingPlatform.fetch(crowdFundingPlatform.publicKey);
console.log(PlatformAccount);
});
})