Truffle

錯誤:找不到契約的工件

  • December 28, 2021

我是乙太坊開發的新手,並嘗試SimpleStorage使用松露測試合約:

我使用創建了文件結構turffle init,這是文件結構:

~/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 代替../contracts/SimpleStorage.solintartifacts.require 但沒有解決問題。所以感謝你的幫助。

您的程式碼中有錯字。替換contrcatcontract。該變數由 truffle 框架定義。

引用自:https://ethereum.stackexchange.com/questions/117487