Skip to content

Commit

Permalink
test: fixes and update
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Aug 15, 2024
1 parent 5d4aebf commit 624c5fd
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 66 deletions.
2 changes: 1 addition & 1 deletion ape_solidity/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ def _flatten_source(
path = Path(path)
source_id = f"{get_relative_path(path, pm.path)}" if path.is_absolute() else f"{path}"
handled.add(source_id)
relevant_imports = list(import_tree[path])
relevant_imports = sorted(list(import_tree[path]), key=lambda x: x.raw_value)

final_source = ""
for import_metadata in relevant_imports:
Expand Down
131 changes: 66 additions & 65 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,67 @@
pragma solidity ^0.8.4;
// SPDX-License-Identifier: MIT
// File: ./././././././././././././././././././././././././././././././././././MissingPragma.sol
contract MissingPragma {
function foo() pure public returns(bool) {
return true;
}
}
// File: ./NumerousDefinitions.sol
struct Struct0 {
string name;
uint value;
}
struct Struct1 {
string name;
uint value;
}
struct Struct2 {
string name;
uint value;
}
struct Struct3 {
string name;
uint value;
}
struct Struct4 {
string name;
uint value;
}
struct Struct5 {
string name;
uint value;
}
contract NumerousDefinitions {
function foo() pure public returns(bool) {
return true;
}
}
// File: ./Source.extra.ext.sol
// Showing sources with extra extensions are by default excluded,
// unless used as an import somewhere in a non-excluded source.
contract SourceExtraExt {
function foo() pure public returns(bool) {
return true;
}
}
// File: ./subfolder/Relativecontract.sol
contract Relativecontract {
function foo() pure public returns(bool) {
return true;
}
}
// File: @browniedependency/contracts/BrownieContract.sol
contract CompilingContract {
Expand All @@ -23,7 +84,7 @@
}
}
// File: @dependency/contracts/Dependency.sol" as Depend2
// File: @dependency/contracts/Dependency.sol
struct DependencyStruct {
string name;
Expand Down Expand Up @@ -56,7 +117,7 @@
contract Enum {
enum Operation {Call, DelegateCall}
}
// File: { MyStruct } from "contracts/CompilesOnce.sol
// File: contracts/CompilesOnce.sol
struct MyStruct {
string name;
Expand All @@ -72,67 +133,6 @@
return true;
}
}
// File: ./././././././././././././././././././././././././././././././././././MissingPragma.sol
contract MissingPragma {
function foo() pure public returns(bool) {
return true;
}
}
// File: { Struct0, Struct1, Struct2, Struct3, Struct4, Struct5 } from "./NumerousDefinitions.sol
struct Struct0 {
string name;
uint value;
}
struct Struct1 {
string name;
uint value;
}
struct Struct2 {
string name;
uint value;
}
struct Struct3 {
string name;
uint value;
}
struct Struct4 {
string name;
uint value;
}
struct Struct5 {
string name;
uint value;
}
contract NumerousDefinitions {
function foo() pure public returns(bool) {
return true;
}
}
// File: ./Source.extra.ext.sol
// Showing sources with extra extensions are by default excluded,
// unless used as an import somewhere in a non-excluded source.
contract SourceExtraExt {
function foo() pure public returns(bool) {
return true;
}
}
// File: ./subfolder/Relativecontract.sol
contract Relativecontract {
function foo() pure public returns(bool) {
return true;
}
}
// File: Imports.sol
Expand All @@ -152,11 +152,12 @@


def test_cli_flatten(project, cli_runner):
path = project.contracts_folder / "Imports.sol"
filename = "Imports.sol"
path = project.contracts_folder / filename
arguments = ["flatten", str(path)]
end = ("--project", str(project.path))
with create_tempdir() as tmpdir:
file = tmpdir / "Imports.sol"
file = tmpdir / filename
arguments.extend([str(file), *end])
result = cli_runner.invoke(cli, arguments, catch_exceptions=False)
assert result.exit_code == 0, result.stderr_bytes
Expand Down
7 changes: 7 additions & 0 deletions tests/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,16 @@ def test_compile_performance(benchmark, compiler, project):
args=((path,),),
kwargs={"project": project},
rounds=1,
warmup_rounds=1,
)
assert len(result) > 0

# Currently seeing '~0.08; on macOS locally.
# Was seeing '~0.68' before https://github.com/ApeWorX/ape-solidity/pull/151
threshold = 0.2

assert benchmark.stats["median"] < threshold


def test_compile_multiple_definitions_in_source(project, compiler):
"""
Expand Down

0 comments on commit 624c5fd

Please sign in to comment.