rust Solana测试程序锚测试失败tsconfig.json”>需要类型为“json”的导入Assert

r8xiu3jd  于 2023-02-04  发布在  其他
关注(0)|答案(2)|浏览(107)

I ran anchor test --skip-deploy and all it should do is initialize my program, but all I get is this error, that I cannot resolve. I checked the tsconfig.json settings they should be fine. This is just the default anchor setup and I'm not importing any unusual JSON files anywhere.
anchor test --skip-deploy BPF SDK: /Users/julia/.local/share/solana/install/releases/1.9.5/solana-release/bin/sdk/bpf cargo-build-bpf child: rustup toolchain list -v cargo-build-bpf child: cargo +bpf build --target bpfel-unknown-unknown --release warning: unused variable: ctx --> programs/feeRedeemCounter/src/lib.rs:8:23 | 8 | pub fn initialize(ctx: Context) -> ProgramResult { | ^^^ help: if this is intentional, prefix it with an underscore: _ctx | = note: #[warn(unused_variables)] on by default
warning: feeRedeemCounter (lib) generated 1 warning Finished release [optimized] target(s) in 1.28s cargo-build-bpf child: /Users/julia/.local/share/solana/install/releases/1.9.5/solana-release/bin/sdk/bpf/dependencies/bpf-tools/llvm/bin/llvm-readelf --dyn-symbols /Users/julia/Downloads/anchorTutorial/feeRedeemCounter/target/deploy/fee_redeem_counter.so
To deploy this program: $ solana program deploy /Users/julia/Downloads/anchorTutorial/feeRedeemCounter/target/deploy/fee_redeem_counter.so The program address will default to this keypair (override with --program-id): /Users/julia/Downloads/anchorTutorial/feeRedeemCounter/target/deploy/fee_redeem_counter-keypair.json yarn run v1.22.17 warning package.json: No license field $ /Users/julia/Downloads/anchorTutorial/feeRedeemCounter/node_modules/.bin/ts-mocha -p ./tsconfig.json -t 1000000 'tests/**/*.ts'
TypeError: Module "file:///Users/julia/Downloads/anchorTutorial/feeRedeemCounter/tsconfig.json" needs an import assertion of type "json" at new NodeError (node:internal/errors:371:5) at validateAssertions (node:internal/modules/esm/assert:82:15) at defaultLoad (node:internal/modules/esm/load:24:3) at ESMLoader.load (node:internal/modules/esm/loader:359:26) at ESMLoader.moduleProvider (node:internal/modules/esm/loader:280:58) at new ModuleJob (node:internal/modules/esm/module_job:66:26) at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:297:17) at ESMLoader.getModuleJob (node:internal/modules/esm/loader:261:34) at async Promise.all (index 0) at ESMLoader.import (node:internal/modules/esm/loader:337:24) at importModuleDynamicallyWrapper (node:internal/vm/module:437:15) at formattedImport (/Users/julia/Downloads/anchorTutorial/feeRedeemCounter/node_modules/mocha/lib/nodejs/esm-utils.js:7:14) at Object.exports.requireOrImport (/Users/julia/Downloads/anchorTutorial/feeRedeemCounter/node_modules/mocha/lib/nodejs/esm-utils.js:48:32) at Object.exports.loadFilesAsync (/Users/julia/Downloads/anchorTutorial/feeRedeemCounter/node_modules/mocha/lib/nodejs/esm-utils.js:103:20) at singleRun (/Users/julia/Downloads/anchorTutorial/feeRedeemCounter/node_modules/mocha/lib/cli/run-helpers.js:125:3) at Object.exports.handler (/Users/julia/Downloads/anchorTutorial/feeRedeemCounter/node_modules/mocha/lib/cli/run.js:374:5) error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. Error: Program address not found.

7jmck4yq

7jmck4yq1#

我解决了自己的问题
Yarn添加度ts-摩卡

sr4lhrrt

sr4lhrrt2#

yarn add ts-mocha

这对我不起作用,我删除了package-lock.json,然后将npm包更新为最新版本

"devDependencies": {
    "@types/chai": "^4.3.4",
    "@types/mocha": "^10.0.1",
    "@types/node": "^18.11.18",
    "chai": "^4.3.7",
    "mocha": "^10.2.0",
    "ts-mocha": "^10.0.0",
    "typescript": "^4.9.5"

然后更新提供者代码:

import * as anchor from "@project-serum/anchor";

const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);

相关问题