Skip to content

hevm: skip unit test contracts with no code #785

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

Merged
merged 2 commits into from
Sep 15, 2021
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
17 changes: 17 additions & 0 deletions src/dapp-tests/pass/abstract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pragma solidity ^0.6.7;

import {DSTest} from "ds-test/test.sol";

// should not be run (no code)
abstract contract MyTest is DSTest {
function testAbstract() public {
assertTrue(true);
}
}

// should run and pass
contract TestMy is MyTest {
function testTrue() public {
assertTrue(true);
}
}
1 change: 1 addition & 0 deletions src/hevm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
### Fixed

- The block gas limit and basefee are now correctly fetched when running tests via rpc
- Test contracts with no code (e.g. `abstract` contracts) are now skipped

## 0.48.0 - 2021-08-03

Expand Down
2 changes: 1 addition & 1 deletion src/hevm/src/EVM/Dapp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ findUnitTests match =
Nothing -> []
Just _ ->
let testNames = unitTestMethodsFiltered (regexMatches match) c
in [(view contractName c, testNames) | not (null testNames)]
in [(view contractName c, testNames) | not (BS.null (view runtimeCode c)) && not (null testNames)]

unitTestMethodsFiltered :: (Text -> Bool) -> (SolcContract -> [(Test, [AbiType])])
unitTestMethodsFiltered matcher c =
Expand Down