fix: enforce optional manifest fields
This commit is contained in:
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user