I am current trying to build a solana calculator project on my mac(M3 version), mostly duplicate the code what I learned on Udemy. So basically I am trying run the same of the teacher on my pc successfully.
What i use:
Anchor
Mocha
node_modules/@project-serum
solana
What I did:
- use anchor init to create a project
- anchor build(i can build without errors)
- Add some code to lib.rs file:
use anchor_lang::prelude::*;
declare_id!("CfaDqW3stWavnEn8KZLnqSLbmTzUjhn3aNawSCtsVbGu");
#[program]
pub mod mycalculatordapp {
use super::*;
pub fn create(ctx: Context<Create>, init_message: String) -> Result<()> {
let calculator = &mut ctx.accounts.calculator;
calculator.greeting = init_message;
Ok(())
}
}
#[derive(Accounts)]
pub struct Create<'info>{
#[account(init, payer=user, space=264)]
pub calculator: Account<'info, Calculator>,
#[account(mut)]
pub user: Signer<'info>,
pub system_program: Program<'info, System>
}
#[account]
pub struct Calculator {
pub greeting: String,
pub result: i64,
pub remainder: i64
}
- Add a simple test code to mycalculatordapp.ts file:
const assert = require('assert');
const anchor = require('@project-serum/anchor');
const { SystemProgram } = anchor.web3;
describe('mycalculatordapp', () => {
const provider = anchor.Provider.local();
});
And then I got this Error when I run ‘anchor test’ on my terminal:
TypeError: Cannot read properties of undefined (reading ‘local’)
at Suite. (/Users/chester/Desktop/dev/mycalculatordapp/tests/mycalculatordapp.ts:6:36)
at Object.create (/Users/chester/Desktop/dev/mycalculatordapp/node_modules/mocha/lib/interfaces/common.js:148:19)
at context.describe.context.context (/Users/chester/Desktop/dev/mycalculatordapp/node_modules/mocha/lib/interfaces/bdd.js:42:27)
at Object. (/Users/chester/Desktop/dev/mycalculatordapp/tests/mycalculatordapp.ts:5:1)
at Module._compile (node:internal/modules/cjs/loader:1369:14)
at Module.m._compile (/Users/chester/Desktop/dev/mycalculatordapp/node_modules/ts-node/src/index.ts:439:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
at Object.require.extensions. [as .ts] (/Users/chester/Desktop/dev/mycalculatordapp/node_modules/ts-node/src/index.ts:442:12)
at Module.load (node:internal/modules/cjs/loader:1206:32)
at Function.Module._load (node:internal/modules/cjs/loader:1022:12)
at Module.require (node:internal/modules/cjs/loader:1231:19)
at require (node:internal/modules/helpers:179:18)
at Object.exports.requireOrImport (/Users/chester/Desktop/dev/mycalculatordapp/node_modules/mocha/lib/nodejs/esm-utils.js:60:20)
at Object.exports.loadFilesAsync (/Users/chester/Desktop/dev/mycalculatordapp/node_modules/mocha/lib/nodejs/esm-utils.js:103:20)
at singleRun (/Users/chester/Desktop/dev/mycalculatordapp/node_modules/mocha/lib/cli/run-helpers.js:125:3)
at Object.exports.handler (/Users/chester/Desktop/dev/mycalculatordapp/node_modules/mocha/lib/cli/run.js:374:5)
error Command failed with exit code 1.
I have tried my ways but just can’t not solve this issue, hope some professionals can take a look and give me a insight.
I have check all the dependencies, which should be installed correctly. The problem will be very likely to caused by this line:
const provider = anchor.Provider.local();
I am not sure is there a environmental set up error of any other issue, just can’t pass this.
Chester H is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.