Skip to content

Commit

Permalink
feat: Ensure id is in the config
Browse files Browse the repository at this point in the history
Signed-off-by: Anirudh <[email protected]>
  • Loading branch information
anirudh2 committed Mar 9, 2023
1 parent c080329 commit 3240c2a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/configuration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Set default values for the config dictionary if the value was not specified in the config file.
# Config Specification
- `id::String`: The ID of the indexer for whom we're optimising. No default value.
- `network_subgraph_endpoint::String`: The network subgraph endpoint to query.
By default, `"https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-mainnet"`
- `writedir::String`: The directory to which to write the results of optimisation.
Expand Down Expand Up @@ -51,6 +52,7 @@ true
```
"""
function configuredefaults!(config::AbstractDict)
@assert haskey(config, "id")
setdefault!(
config,
"network_subgraph_endpoint",
Expand Down
7 changes: 5 additions & 2 deletions test/configuration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

@testset "configuration" begin
@testset "configuredefaults!" begin
config = Dict()
config = Dict{String,Any}()
@test_throws AssertionError AllocationOpt.configuredefaults!(config)

config = Dict{String,Any}("id" => "a")
config = AllocationOpt.configuredefaults!(config)
@test isnothing(config["readdir"])
@test config["writedir"] == "."
Expand All @@ -19,7 +22,7 @@
@test config["max_allocations"] == 10
@test !config["verbose"]

config = Dict{String,Any}("gas" => 0)
config = Dict{String,Any}("id" => "a", "gas" => 0)
config = AllocationOpt.configuredefaults!(config)
@test config["gas"] == 0
@test !config["verbose"]
Expand Down

0 comments on commit 3240c2a

Please sign in to comment.