truffle
truffle copied to clipboard
Does truffle support testing functions with string array parameters?
- [ ] I've opened a support ticket before filing this issue.
Issue
I'm going to test function with string array parameters. But it seems like being passing an empty array in the truffle test.
Steps to Reproduce
*.sol
function createParent(
string[] calldata _childrenName
) external{
}
*.test.js
Try to call createParent function like this.
await this.contract.createParent(["D", "E", "F"]);
Expected Behavior
Should pass string array parameter.
Actual Results
Seems like passing parameter is an empty array
Environment
- Operating System: Windows 10
- Ethereum client:
- Truffle version (
truffle version): v5.521 - node version (
node --version): v16.17.0 - npm version (
npm --version): v8.15.0
Yes, passing in arrays of strings is supported. Do you have more detailed reproduction steps so we can try to determine what's going wrong here? (Say a repo we could check out?) Thanks!
I'm trying to push Child struct array to Parent struct.
struct Parent {
Child[] children;
}
struct Child {
string name;
}
function createParent(
string[] calldata _childrenName
) external{
Parent storage parent = _allParents[parentCounter];
for(uint256 i = 0; i < _childrenName.length; i ++) {
parent.children.push(Child(_childrenName[i]));
}
parentCounter++;
}
After creating a parent there are no children in Parent struct.
children is undefined
The field children cannot be undefined, because Solidity doesn't have any notion of undefined. How are you determining this? Do you have more complete code we could check out?
I should probably be more explicit -- I expect the problem is probably in whatever Javascript code you've written to interact with the contract, so I'd want to see that to determine what's going on. That's part of what I meant when I said I was looking for more complete code.
Closing for issue maintenance. @mastercodingbear Feel free to open a new issue if you're still running into this, along with repro steps that we can follow. Thanks!