Here everything seems fine but still got this error please guide me here :-
Place bid program. :-
pub fn place_bid(ctx: Context<PlaceBid>, bid_amount: u64) -> Result<()> {
msg!("Bidding started");
let auction = &mut ctx.accounts.auction;
let current_time = Clock::get()?.unix_timestamp;
require!(current_time >= auction.start_time, AuctionError::AuctionNotStarted);
require!(current_time < auction.end_time, AuctionError::AuctionEnded);
require!(bid_amount > auction.highest_bid, AuctionError::BidTooLow);
auction.highest_bid = bid_amount;
auction.highest_bidder = ctx.accounts.bidder.key();
system_program::transfer(
CpiContext::new(
ctx.accounts.system_program.to_account_info(),
system_program::Transfer {
from: ctx.accounts.bidder.to_account_info(),
to: ctx.accounts.escrow_account.to_account_info(),
},
),
bid_amount,
)?;
msg!("Bid has been placed");
Ok(())
}
#[derive(Accounts)]
pub struct PlaceBid<'info> {
#[account(mut)]
pub auction: Account<'info, Auction>,
#[account(mut)]
pub bidder: Signer<'info>,
#[account(
mut,
associated_token::mint = mint,
associated_token::authority = bidder,
)]
pub bidder_token_account: Account<'info, TokenAccount>,
#[account (
mut,
seeds = [b"escrow", auction.key().as_ref()],
bump,
)]
pub escrow_account: Account<'info, TokenAccount>,
pub mint: Account<'info, Mint>,
pub token_program: Program<'info, Token>,
pub system_program: Program<'info, System>,
pub associated_token_program: Program<'info, AssociatedToken>,
pub rent: Sysvar<'info, Rent>,
}
This is the test case :-
it('Place bid', async () => {
const bidderTokenAccount = getAssociatedTokenAddressSync(
mintKeyPair.publicKey,
bidderKeypair.publicKey
);
const escrowAccount = getAssociatedTokenAddressSync(
auctionKeyPair.publicKey,
auctionKeyPair.publicKey,
true
);
const createEscrowAccountIx = createAssociatedTokenAccountInstruction(
payer.publicKey,
escrowAccount,
auctionKeyPair.publicKey,
mintKeyPair.publicKey,
TOKEN_PROGRAM_ID,
SystemProgram.programId
);
const bidAmount = new anchor.BN(1500000000);
const transactionSignature = await program.methods
.placeBid(bidAmount)
.accounts({
auction: auctionKeyPair.publicKey,
bidder: bidderKeypair.publicKey,
bidderTokenAccount: bidderTokenAccount,
escrowAccount: escrowAccount,
mint: mintKeyPair.publicKey,
tokenProgram: TOKEN_PROGRAM_ID,
systemProgram: SystemProgram.programId,
})
.preInstructions([createEscrowAccountIx])
.signers([bidderKeypair])
.rpc({ skipPreflight: true });
console.log('Bid placed');
console.log('Transaction signature', transactionSignature);
});