Created
January 1, 2018 20:37
-
-
Save anonymous/65260d973a5640741a7d6174bf8fe7e6 to your computer and use it in GitHub Desktop.
Failing to create an array of structs containing an array of structs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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