Skip to content

Instantly share code, notes, and snippets.

Created Jan 1, 2018
Embed
What would you like to do?
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