I'm new to Solidity development and I'm trying to figure out the best way to test a function which sets the values of a struct in my Truffle environment.
Firstly, is it expected that the result of the promise returns in the format below:
[ BigNumber { s: 1, e: 0, c: [ 5 ] }, 'John' ]
And if so is this the correct pattern to test the correct property has been set by the setter method (in this case name: John): assert.equal(res[1], "John");
See below for the example contract I'm attempting to test:
./contracts/Adoption.sol:
contract Adoption {
struct Dog {
uint age;
string name;
}
Dog[] public dogs;
function createDog(uint _age, string _name) public {
dogs.push(Dog(_age, _name)) - 1;
}
}
./test/Adoption.js
return Adoption.deployed()
.then(function(instance) {
instance.createDog(5, "John");
return instance.dogs(0);
})
.then(function(res) {
// dog age should equal 5
assert.equal(res[0], 5);
// dog name should equal John
assert.equal(res[1], "John");
});