I am running test for the default program which comes with anchor setup. However, I keep getting the above error.
the steps I followed were
- anchor init (project-name)
- start solana-test-validator
- anchor build -> anchor deploy
- update program ids on both anchor.toml and lib.rs
- anchor build -> anchor deploy then run the test
default lib.rs with hello world
use anchor_lang::prelude::*;
declare_id!("8455D3DCzghmDygw2STMttPo9sB6SBHUavNP7eHbqNiu");
#[program]
pub mod hello_world {
use super::*;
pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
msg!("Hello, world!");
Ok(())
}
}
#[derive(Accounts)]
pub struct Initialize {}
test file
it("Is initialized!", async () => {
// Add your test here.
const tx = await program.methods.initialize().rpc();
console.log("Your transaction signature", tx);
});
Error
Is initialized!:
TypeError: Cannot read properties of undefined (reading 'methods')
anchor build
first? It may be because your IDL (and thus, types) aren't built