我有一份简单的合同,我正在努力为Truffle的合同编写Solidity测试。以下是代码示例 -
File: dummycontract.sol
pragma solidity ^0.4.17;
contract DummyContract {
uint[] public elements;
function addElement(uint element) public {
elements.push(element);
}
function getNumberOfElements() public view returns(uint) {
uint numElements = uint(elements.length);
return numElements;
}
}
测试文件 -
pragma solidity ^0.4.17;
import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/dummycontract.sol";
contract TestZombieFactory {
function testInitialState() public {
DummyContract dummyContract = DummyContract(DeployedAddresses.DummyContract());
uint numberOfElements = dummyContract.getNumberOfElements();
Assert.equal(numberOfElements == 0);
}
}
在运行truffle test
时,我收到以下错误 -
TypeError: Member "equal" is not available in type(library Assert) outside of storage.
Assert.equal(numberOfElements == 0);
有人可以向我解释一下吗?
答案 0 :(得分:2)
您对<h1>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti doloribus beatae laboriosam aspernatur magni, molestias possimus, rerum voluptates dolorum aliquam est soluta animi inventore ut at eius voluptatum quod omnis.</h1>
的使用不正确。它需要两个值并在函数内进行比较。函数签名是
Assert.equal()
将您的测试合同更改为以下内容,它将起作用。
function equal(uint A, uint B, string message) constant returns (bool result)
答案 1 :(得分:2)
你应该替换
Assert.equal(numberOfElements,0);
与
function myFunction() {
var a = document.getElementById("QuantityList").value;
return a;
}
function myFunction2(a) {
var b = a * 4.99;
document.getElementById("demo").innerHTML = b;
return b;
}