首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误:找不到合同的工件

错误:找不到合同的工件
EN

Ethereum用户
提问于 2021-12-28 14:00:02
回答 1查看 660关注 0票数 1

我刚接触ethereum开发,并尝试使用块菌测试SimpleStorage合同:

我使用turffle init创建了文件结构,下面是sturctur文件:

代码语言:javascript
复制
~/Desktop/truffle-test$ tree .
.
├── build
│   └── contracts
│       └── SimpleStorage.json
├── contracts
│   └── SimpleStorage.sol
├── migrations
│   └── 3_deploy_simpleStorage.js
├── test
│   └── simpleStorage-test.js
└── truffle-config.js

我的simpleStorage-test.js是:

代码语言:javascript
复制
const simpleStorage = artifacts.require('../contracts/SimpleStorage.sol');

contrcat('SimpleStorage', ()=> {
    it('should update data', async ()=> {
        const storage = await simpleStorage.new();
        await storage.set(10);
        const data = await storage.get();
        assert(data.toString()==='10');
    });
}); 

我可以迁移契约,并看到事务出现在Ganache-GUI上,但是当我运行truffle test时,我得到:

代码语言:javascript
复制
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.

ReferenceError: contrcat is not defined
    at Object.<anonymous> (/home/pc/Desktop/truffle-test/test/simpleStorage-test.js:3:1)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at /usr/local/lib/node_modules/truffle/node_modules/mocha/lib/mocha.js:390:36
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/usr/local/lib/node_modules/truffle/node_modules/mocha/lib/mocha.js:387:14)
    at Mocha.run (/usr/local/lib/node_modules/truffle/node_modules/mocha/lib/mocha.js:961:10)
    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/testing/Test.js:157:1
    at new Promise (<anonymous>)
    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/testing/Test.js:156:1)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at Object.module.exports [as run] (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/test/run.js:56:1)
    at Command.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:189:1)
Truffle v5.4.26 (core: 5.4.26)
Node v16.13.0

我尝试了不同的东西,比如SimpleStorage,而不是tartifacts.require中的../contracts/SimpleStorage.sol,但是没有解决这个问题。所以感谢你的帮助。

EN

回答 1

Ethereum用户

回答已采纳

发布于 2021-12-28 14:28:14

你的代码中有一个错误。将contrcat替换为contract。这个变量由块菌框架定义。

票数 2
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/117487

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档