Skip to content
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
6 changes: 6 additions & 0 deletions src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ pub fn run() -> Result<(), Box<dyn Error>> {
// contract contains that source method's tests/specification.
let mut protocol_spec = ProtocolSpecification::new();
for src_contract in src_contracts {
// Skip contracts with no functions - they have nothing to specify
if src_contract.functions.is_empty() {
continue;
}

let mut contract_specification = ContractSpecification::new(src_contract.clone());
let src_contract_name = src_contract.contract.unwrap().name.unwrap().name;

Expand Down Expand Up @@ -114,6 +119,7 @@ impl ContractSpecification {
// which is the order we want to print in.
let src_fns = &self.src_contract.functions;
let num_src_fns = src_fns.len();

for (i, src_fn) in src_fns.iter().enumerate() {
let src_fn_name_prefix = if i == num_src_fns - 1 { "└── " } else { "├── " };

Expand Down
8 changes: 8 additions & 0 deletions tests/spec-proj2-EmptyContract/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
solc_version = "0.8.19"
optimizer = true
optimizer_runs = 200
via_ir = false
7 changes: 7 additions & 0 deletions tests/spec-proj2-EmptyContract/src/EmptyContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract EmptyContract {
// This contract has no functions
uint256 public someVariable;
}
9 changes: 9 additions & 0 deletions tests/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,12 @@ Contract Specification: ERC20
"#;
assert_eq!(stdout, expected_spec);
}

#[test]
fn test_spec_proj2_empty_contract() {
let output = run_scopelint("spec-proj2-EmptyContract");
let stdout = String::from_utf8(output.stdout).unwrap();
// Empty contracts should be ignored and produce no output
let expected_spec = "";
assert_eq!(stdout, expected_spec);
}
Loading