diff --git a/ape_solidity/compiler.py b/ape_solidity/compiler.py index a778892..97fee09 100644 --- a/ape_solidity/compiler.py +++ b/ape_solidity/compiler.py @@ -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: diff --git a/tests/test_cli.py b/tests/test_cli.py index 1e719ad..495cbe9 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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 { @@ -23,7 +84,7 @@ } } -// File: @dependency/contracts/Dependency.sol" as Depend2 +// File: @dependency/contracts/Dependency.sol struct DependencyStruct { string name; @@ -56,7 +117,7 @@ contract Enum { enum Operation {Call, DelegateCall} } -// File: { MyStruct } from "contracts/CompilesOnce.sol +// File: contracts/CompilesOnce.sol struct MyStruct { string name; @@ -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 @@ -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 diff --git a/tests/test_compiler.py b/tests/test_compiler.py index 6f3b5e2..7ae4713 100644 --- a/tests/test_compiler.py +++ b/tests/test_compiler.py @@ -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): """