Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/StdConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ contract StdConfig {
// Cache the entire configuration to storage
for (uint256 i = 0; i < chain_keys.length; i++) {
string memory chain_key = chain_keys[i];
// Ignore top-level keys that are not tables
if (vm.parseTomlKeys(content, string.concat("$.", chain_key)).length == 0) {
// Ignore top-level keys that are not tables, or are empty tables.
// `parseTomlKeys` reverts for a value that is not a table.
try vm.parseTomlKeys(content, string.concat("$.", chain_key)) returns (string[] memory subKeys) {
if (subKeys.length == 0) continue;
} catch {
continue;
}
uint256 chainId = resolveChainId(chain_key);
Expand Down
25 changes: 25 additions & 0 deletions test/Config.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -456,4 +456,29 @@ contract ConfigTest is Test, Config {

vm.removeFile(configOnly);
}

function test_loadConfigIgnoresTopLevelValues() public {
// Only tables are chain sections, so top-level values like these are skipped.
string memory withValues = "./test/fixtures/config_top_level_values.toml";
vm.writeFile(
withValues,
string.concat(
"version = 1\n",
"owners = [\"0x000000000000000000000000000000000000dEaD\"]\n",
"\n",
"[mainnet]\n",
"endpoint_url = \"https://ethereum.reth.rs/rpc\"\n",
"\n",
"[mainnet.uint]\n",
"number = 1234\n"
)
);

_loadConfig(withValues, false);

assertEq(config.getChainIds().length, 1);
assertEq(config.get(1, "number").toUint256(), 1234);

vm.removeFile(withValues);
}
}