fix: enforce optional manifest fields

This commit is contained in:
golem
2026-08-21 03:00:23 -06:00
parent c6bf8a683f
commit 54c893fdb7
4 changed files with 73 additions and 1 deletions
+14
View File
@@ -116,6 +116,7 @@ abstract contract DemoScript is Script {
actors = new Actor[](actorCount);
for (uint256 i; i < actorCount; ++i) {
string memory index = vm.toString(i);
_assertExactActorSchema(json, index);
actors[i].label = vm.parseJsonString(json, string.concat(".actors[", index, "].label"));
actors[i].address_ = vm.parseJsonAddress(json, string.concat(".actors[", index, "].address"));
}
@@ -124,6 +125,19 @@ abstract contract DemoScript is Script {
}
}
function _assertExactActorSchema(string memory json, string memory index) private view {
string[] memory keys = vm.parseJsonKeys(json, string.concat(".actors[", index, "]"));
bool hasLabel;
bool hasAddress;
if (keys.length != 2) revert InvalidManifestSchema(0);
for (uint256 i; i < keys.length; ++i) {
if (_equals(keys[i], "label")) hasLabel = true;
else if (_equals(keys[i], "address")) hasAddress = true;
else revert InvalidManifestSchema(0);
}
if (!hasLabel || !hasAddress) revert InvalidManifestSchema(0);
}
function _validateActorConfiguration(Manifest memory manifest) internal pure {
if (manifest.chainId == ANVIL_CHAIN_ID) {
if (