Skip to content

Instantly share code, notes, and snippets.

Created January 1, 2018 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/65260d973a5640741a7d6174bf8fe7e6 to your computer and use it in GitHub Desktop.
Save anonymous/65260d973a5640741a7d6174bf8fe7e6 to your computer and use it in GitHub Desktop.
Failing to create an array of structs containing an array of structs
pragma solidity ^0.4.18;
contract Foo {
struct Baz {
uint bazNum;
}
struct Bar {
Baz[] bazzes;
uint barNum;
}
Bar[] bars;
function createBar(uint barNum)
public
returns (uint)
{
uint barId = 0;//bars.length;
bars[barId].barNum = barNum;
return barId;
}
function getBarNum(uint barId)
public
view
returns (uint)
{
return bars[barId].barNum;
}
}
pragma solidity ^0.4.18;
import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/Foo.sol";
contract TestFoo {
Foo foo = Foo(DeployedAddresses.Foo());
function testFoo() public {
uint barId = foo.createBar(10);
Assert.equal(barId, 0, "First Bar Id");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment