Truffle-Test

成功編譯後嘗試執行松露測試我有這個錯誤:“未定義”的參數數量無效。得到 0 預期 1!

  • October 31, 2020

這是我的部署 hello js 文件

const hello = artifacts.require('./HelloWorld');

module.exports = function(deployer){
 deployer.deploy(hello);
};

這是契約程式碼

pragma solidity^0.5.16;

contract HelloWorld {

   string private name;
   mapping (address => uint256) public balance;

   constructor(string memory _name) public {
     name = _name;
     balance[msg.sender] = 1000;
   }

   function getName() public view returns (string memory) {
     return name;
   }

   function setName(string memory _name) public {
     name = _name;
   }
}

部署 HelloWorld 時必須傳遞一個字元串,因為它的建構子接收一個參數。

constructor(string memory _name) public {

例如它應該看起來像這樣

const hello = artifacts.require('./HelloWorld');

module.exports = function(deployer){
 deployer.deploy(hello, "zzzz");
};

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