2

wrapper class to instantiate other classes

contract WrapperCreator {

    function WrapperCreator() {
    }

    function createTopic(string name, bytes32[] resultNames, uint256 endBlock)
        returns (Topic tokenAddress)
    {
        return new Topic(name, resultNames, bettingEndBlock);
    }
}

test cases for WrapperCreator

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");
    }
}

I get the following errors:

,../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);
3

The createTopic method expect bytes32[] type, a dynamic array of bytes32, but you are passing to it a bytes32[3], a fixed size array of bytes32.

Change

bytes32[3] resultNames;

to

bytes32[] resultNames;

Please also note that you are passing a storage ref, so if the method modify the array the next test will read updated values.

1

Alternatively you can use :

bytes32[3] resultNames;
function beforeEach() {

    bytes32[3] storage a ;
    resultNames =a;
    resultNames[0] = "first";
    resultNames[1] = "second";
    resultNames[2] = "third";
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.