Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fine tune coverage #569

Merged
merged 6 commits into from
Feb 7, 2025
Merged
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
13 changes: 7 additions & 6 deletions docs/src/project_configuration/testing_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ contract MyContract {
the [`timeout`](./fuzzing_config.md#timeout) is hit, or the user manually stops execution.
- **Default**: `true`

### `testViewMethods`

- **Type**: Boolean
- **Description**: Whether `pure` / `view` functions should be called and tested.
- **Default**: `true`
-

### `testAllContracts`

- **Type**: Boolean
Expand Down Expand Up @@ -85,12 +92,6 @@ contract MyContract {
- **Description**: Enable or disable assertion testing
- **Default**: `true`

### `testViewMethods`

- **Type**: Boolean
- **Description**: Whether `pure` / `view` functions should be tested for assertion failures.
- **Default**: `false`

### `panicCodeConfig`

- **Type**: Struct
Expand Down
6 changes: 3 additions & 3 deletions fuzzing/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ type TestingConfig struct {
// than just the contracts specified in the project configuration's deployment order.
TestAllContracts bool `json:"testAllContracts"`

// TestViewMethods dictates whether constant/pure/view methods should be called and tested.
TestViewMethods bool `json:"testViewMethods"`

// TraceAll describes whether a trace should be attached to each element of a finalized shrunken call sequence,
// e.g. when a call sequence triggers a test failure. Test providers may attach execution traces by default,
// even if this option is not enabled.
Expand Down Expand Up @@ -198,9 +201,6 @@ type AssertionTestingConfig struct {
// Enabled describes whether testing is enabled.
Enabled bool `json:"enabled"`

// TestViewMethods dictates whether constant/pure/view methods should be tested.
TestViewMethods bool `json:"testViewMethods"`

// PanicCodeConfig describes the various panic codes that can be enabled and be treated as a "failing case"
PanicCodeConfig PanicCodeConfig `json:"panicCodeConfig"`
}
Expand Down
4 changes: 2 additions & 2 deletions fuzzing/config/config_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ func GetDefaultProjectConfig(platform string) (*ProjectConfig, error) {
StopOnFailedTest: true,
StopOnFailedContractMatching: false,
StopOnNoTests: true,
TestViewMethods: true,
TestAllContracts: false,
TraceAll: false,
TargetFunctionSignatures: []string{},
ExcludeFunctionSignatures: []string{},
AssertionTesting: AssertionTestingConfig{
Enabled: true,
TestViewMethods: false,
Enabled: true,
PanicCodeConfig: PanicCodeConfig{
FailOnAssertion: true,
},
Expand Down
4 changes: 2 additions & 2 deletions fuzzing/fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func (f *Fuzzer) AddCompilationTargets(compilations []compilationTypes.Compilati
assertionTestMethods, propertyTestMethods, optimizationTestMethods := fuzzingutils.BinTestByType(&contract,
f.config.Fuzzing.Testing.PropertyTesting.TestPrefixes,
f.config.Fuzzing.Testing.OptimizationTesting.TestPrefixes,
f.config.Fuzzing.Testing.AssertionTesting.TestViewMethods)
f.config.Fuzzing.Testing.TestViewMethods)
contractDefinition.AssertionTestMethods = assertionTestMethods
contractDefinition.PropertyTestMethods = propertyTestMethods
contractDefinition.OptimizationTestMethods = optimizationTestMethods
Expand Down Expand Up @@ -842,7 +842,7 @@ func (f *Fuzzer) Start() error {
// If StopOnNoTests is true and there are no test cases, then throw an error
if f.config.Fuzzing.Testing.StopOnNoTests && len(f.testCases) == 0 {
err = fmt.Errorf("no assertion, property, optimization, or custom tests were found to fuzz")
if !f.config.Fuzzing.Testing.AssertionTesting.TestViewMethods {
if !f.config.Fuzzing.Testing.TestViewMethods {
err = fmt.Errorf("no assertion, property, optimization, or custom tests were found to fuzz and testing view methods is disabled")
}
f.logger.Error("Failed to start fuzzer", err)
Expand Down
1 change: 0 additions & 1 deletion fuzzing/fuzzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ func TestAssertionMode(t *testing.T) {
config.Fuzzing.Testing.AssertionTesting.PanicCodeConfig.FailOnIncorrectStorageAccess = true
config.Fuzzing.Testing.AssertionTesting.PanicCodeConfig.FailOnOutOfBoundsArrayAccess = true
config.Fuzzing.Testing.AssertionTesting.PanicCodeConfig.FailOnPopEmptyArray = true
config.Fuzzing.Testing.AssertionTesting.TestViewMethods = true
config.Fuzzing.Testing.PropertyTesting.Enabled = false
config.Fuzzing.Testing.OptimizationTesting.Enabled = false
config.Slither.UseSlither = false
Expand Down
2 changes: 1 addition & 1 deletion fuzzing/fuzzer_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (fw *FuzzerWorker) updateMethods() {
// Any non-constant method should be tracked as a state changing method.
if method.IsConstant() {
// Only track the pure/view method if testing view methods is enabled
if fw.fuzzer.config.Fuzzing.Testing.AssertionTesting.TestViewMethods {
if fw.fuzzer.config.Fuzzing.Testing.TestViewMethods {
fw.pureMethods = append(fw.pureMethods, fuzzerTypes.DeployedContractMethod{Address: contractAddress, Contract: contractDefinition, Method: method})
}
} else {
Expand Down