Skip to content

Commit

Permalink
Fix forgecmd read empty config from forge.toml (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranbt authored Mar 27, 2024
1 parent e301a72 commit 858b058
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
5 changes: 4 additions & 1 deletion cmd/geth/forgecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ func readContext(ctx *cli.Context) (*vm.SuaveContext, error) {
if err := tomlConfig.NewDecoder(bytes.NewReader(data)).Decode(&config); err != nil {
return nil, err
}
cfg = config.Profile.Suave
if config.Profile.Suave != nil {
// Only apply the suave config if it exists
cfg = config.Profile.Suave
}
}

// override the config if the flags are set
Expand Down
18 changes: 17 additions & 1 deletion cmd/geth/forgecmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,26 @@ func TestForgeReadConfig(t *testing.T) {

ctx := cli.NewContext(nil, flagSet(t, forgeCommand.Flags), nil)

// read context from non-existent config file
ctx.Set("config", "./testdata/forge_not_exists.toml")

_, err := readContext(ctx)
require.Error(t, err)

// read context from valid config toml file WITHOUT suave section
// it should fallback to the default values
ctx.Set("config", "./testdata/forge_noconfig.toml")

sCtx, err := readContext(ctx)
require.NoError(t, err)

require.Len(t, sCtx.Backend.ExternalWhitelist, 0)
require.Len(t, sCtx.Backend.DnsRegistry, 0)

// read context from config toml file
ctx.Set("config", "./testdata/forge.toml")

sCtx, err := readContext(ctx)
sCtx, err = readContext(ctx)
require.NoError(t, err)
require.Equal(t, sCtx.Backend.ExternalWhitelist, []string{"a", "b"})
require.Equal(t, sCtx.Backend.DnsRegistry, map[string]string{"a": "b", "c": "d"})
Expand Down
3 changes: 3 additions & 0 deletions cmd/geth/testdata/forge_noconfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[profile.ci.fuzz]
runs = 10_000
solc_version = "0.8.23"

0 comments on commit 858b058

Please sign in to comment.