I'm a big fan of TDD/BDD so I figured hardhat and chai/waffle are a good start to learning smart contract development.
I've run into an issue though where I'm wondering what best practice would be to expect
the state of a mapped, nested struct?
Minimal example:
contract MyContract {
struct Inner{uint foo;}
struct Outer{Inner bar;}
uint idx;
mapping (uint => Outer) mapped;
function doSomething(uint _val) public {
mapped[idx] = Outer(Inner(_val));
}
}
How would I go about testing that Inner.foo
has the correct value after the call to doSomething(123)
?
The only solution I've found so far is creating a function getOuter(uint _idx) public view returns (Outer memory)
and use that to retrieve the value to expect
in the test.
This however would mean adding a function to the contract that is only needed for testing as well as using pragma experimental ABIEncoderV2;
which - well, sounds kinda experimental.
What's the correct way to solve this?