I am writing a simple smart contract for storing an array of bytes32, pushing to it, and retrieving it:
contract SimpleStorage {
bytes32[] public items;
event ItemAdded(bytes32 contents);
function addItem(bytes32 contents) public returns(bool) {
items.push(contents);
emit ItemAdded(contents);
return true;
}
function getAllItems() public constant returns(bytes32[]) {
return items;
}
}
This compiles fine, but when I try to write a Solidity test for this contract I am unable to store the result of getAllItems
.
Line in question:
bytes32[] result = simpleStorage.getAllItems();
The error I get is: Type inaccessible dynamic type is not implicitly convertible to expected type bytes32[] storage pointer.
From this Github issue I see that it is known (and planned to be fixed in Ethereum 2.0) that we simply cannot at this time call functions that return dynamic arrays from another contract. We can, however, use these functions from the ABI.
Does this mean that it is essentially impossible to write Solidity tests for these types of functions at this time (since the unit tests are themselves contracts)? Has anyone else run into this issue and found a way around it?
I know I can just stick to writing JS tests but I am curious if there is a way to test these types of contracts using Solidity.