【发布时间】:2023-01-09 05:07:45
【问题描述】:
您好,我正在尝试在锚点中测试我的第一个文件,但它一直出现此错误, 我得到的错误:
TypeError: Cannot read properties of undefined (reading 'local')
at Suite.<anonymous> (/home/benny/mycalcdapp/tests/mycalcdapp.ts:6:36)
at Object.create (/home/benny/mycalcdapp/node_modules/mocha/lib/interfaces/common.js:148:19)
at context.describe.context.context (/home/benny/mycalcdapp/node_modules/mocha/lib/interfaces/bdd.js:42:27)
at Object.<anonymous> (/home/benny/mycalcdapp/tests/mycalcdapp.ts:5:1)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Module.m._compile (/home/benny/mycalcdapp/node_modules/ts-node/src/index.ts:439:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
.ts 文件进行测试:
const assert = require('assert');
const anchor = require('@project-serum/anchor');
const { SystemProgram } = anchor.web3;
describe('mycalcdapp', () => {
const provider = anchor.Provider.local();
anchor.setProvider(provider);
const calculator = anchor.web3.Keypair.generate();
const program = anchor.workspace.mycalcdapp;
it('creates a calculator', async () => {
await program.rpc.create('Welocme to solana', {
accounts: {
calculator: calculator.publicKey,
user: provider.wallet.publicKey,
system_program: SystemProgram.programId,
},
signers: [calculator],
});
const account = await program.account.calculator.fetch(
calculator.publicKey
);
assert.ok(account.greeting === 'Welcome to solana');
});
});
我已经看到另一个类似的关于无法读取 rpc 的 stackoverflow postv,但也没有得到回答:(
【问题讨论】:
标签: typescript solana anchor-solana