Argument type BN is assignable to parameter of type u64
I tried to create a test for the vote app I am following in the Solana Bootcamp but in the test file I got an error when initializing the poll. Here are my files
#![allow(clippy::result_large_err)]
use anchor_lang::prelude::*;
declare_id!("coUnmi3oBUtwtd9fjeAvSsJssXh5A5xyPbhpewyzRVF");
#[program]
pub mod voting {
use super::*;
pub fn initialize_poll(ctx: Context<InitializePoll>,
poll_id: u64,
description: String,
poll_start: u64,
poll_end: u64) -> Result<()> {
let poll = &mut ctx.accounts.poll;
poll.poll_id = poll_id;
poll.description = description;
poll.poll_start = poll_start,
poll.poll_end = poll_end;
poll.candidate_votes = 0;
Ok(())
}
#[derive(Accounts)]
#[instruction(poll_id: u64)]
pub struct InitializePoll<'info> {
#[account(mut)]
pub signer: Signer<'info>,
#[account(
init,
payer = signer,
space = 8 + Poll::INIT_SPACE,
seeds = [poll_id.to_le_bytes().as_ref()],
bump,
)]
pub poll: Account<'info, Poll>,
pub system_program: Program<'info, System>,
}
#[account]
#[derive(InitSpace)]
pub struct Poll {
pub poll_id: u64,
#[max_len(280)]
pub description: String,
pub poll_start: u64,
pub poll_end: u64,
pub candidate_votes: u64,
}
}
test file
import * as anchor from '@coral-xyz/anchor';
import { BankrunProvider, startAnchor } from 'anchor-bankrun';
import {Program} from '@coral-xyz/anchor';
import {Keypair, PublicKey} from '@solana/web3.js';
import {Voting} from '../target/types/voting';
const IDL = require('../target/idl/voting.json');
const votingAddress = new PublicKey('coUnmi3oBUtwtd9fjeAvSsJssXh5A5xyPbhpewyzRVF');
describe('voting', () => {
// Configure the client to use the local cluster.
it('Initialize Voting', async () => {
const context = await startAnchor("", [{name: "voting", programId: votingAddress}], []);
const provider = new BankrunProvider(context);
const votingProgram = new Program<Voting>(
IDL,
provider
);
const votingKeypair = Keypair.generate();
await votingProgram.methods.initializePoll(
new anchor.BN(1),
"What is your favorite sandwish?",
new anchor.BN(0),
new anchor.BN(1835048538),
).rpc();
})
})
The error is from this line of code
await votingProgram.methods.initializePoll(
new anchor.BN(1),
"What is your favorite sandwish?",
new anchor.BN(0),
new anchor.BN(1835048538),
).rpc();
Error code
Argument of type '[BN, string, BN, BN]' is not assignable to parameter of type 'ArgsTuple<[{ name: "pollId"; type: "u64"; }], RecursiveDepth4<[{ name: "poll"; type: { kind: "struct"; fields: [{ name: "pollId"; type: "u64"; }, { name: "description"; type: "string"; }, { name: "pollStart"; type: "u64"; }, { ...; }, { ...; }]; }; }], DecodedHelper<...>>>'.
Type '[BN, string, BN, BN]' is not assignable to type '[BN]'.
Source has 4 element(s) but target allows only 1.ts(2345)
Responses