contract WrapperCreator {
function WrapperCreator() {
}
function createTopic(string name, bytes32[] resultNames, uint256 endBlock)
returns (Topic tokenAddress)
{
return new Topic(name, resultNames, bettingEndBlock);
}
}测试用例
pragma solidity ^0.4.0;
import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/WrapperCreator.sol";
contract TestWrapperCreator {
bytes32[3] resultNames;
function beforeEach() {
resultNames = new bytes32[](3);
resultNames[0] = "first";
resultNames[1] = "second";
resultNames[2] = "third";
}
function testConstructor() {
WrapperCreator wrapperCreator = WrapperCreator(DeployedAddresses.WrapperCreator());
Topic testTopic = wrapperCreator.createTopic("test", resultNames, 1000000);
Assert.equal(testTopic.getResultName(0), "first", "Expected result name matches");
}
},../test/TestWrapperCreator.sol:11:23: TypeError: Type bytes32[] memory is not implicitly convertible to expected type bytes32[3] storage ref.
resultNames = new bytes32[](3);
^--------------^
,../test/TestWrapperCreator.sol:19:60: TypeError: Invalid type for argument in function call. Invalid implicit conversion from bytes32[3] storage ref to bytes32[] memory requested.
Topic testTopic = eventCreator.createTopic("test", resultNames, 1000000);发布于 2017-08-25 10:36:28
createTopic方法期望使用bytes32[]类型,这是一个动态的bytes32数组,但是您要向它传递一个bytes32[3],一个固定大小的bytes32数组。
变化
bytes32[3] resultNames;至
bytes32[] resultNames;还请注意,您正在传递一个存储引用,因此如果方法修改数组,下一个测试将读取更新的值。
发布于 2017-08-25 10:58:30
或者,您可以使用:
bytes32[3] resultNames;
function beforeEach() {
bytes32[3] storage a ;
resultNames =a;
resultNames[0] = "first";
resultNames[1] = "second";
resultNames[2] = "third";
}https://ethereum.stackexchange.com/questions/25127
复制相似问题