truffle中test测试

在truffle中test测试需要注意变量名的书写规范,合约以Test开头,后面的单词首字母必须大写,对于合约的函数首字母小写开头。如果在truffle中test文件命名不对,会出现合约无法执行的错误。示例如下所示:

pragma solidity ^0.4.24;

import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/SimpleStorage.sol";

contract TestSimpleStorage {

  function testItStoresAValue() public {
    SimpleStorage simpleStorage = SimpleStorage(DeployedAddresses.SimpleStorage());

    simpleStorage.set(89);

    uint expected = 89;

    Assert.equal(simpleStorage.get(), expected, "It should store the value 89.");
  }

}

比较好的博客:https://www.cnblogs.com/Evsward/p/contract.html

你可能感兴趣的:(区块链,truffle)