我刚接触ethereum开发,并尝试使用块菌测试SimpleStorage合同:
我使用turffle init创建了文件结构,下面是sturctur文件:
~/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是:
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时,我得到:
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,但是没有解决这个问题。所以感谢你的帮助。
发布于 2021-12-28 14:28:14
你的代码中有一个错误。将contrcat替换为contract。这个变量由块菌框架定义。
https://ethereum.stackexchange.com/questions/117487
复制相似问题