Skip to content

Commit

Permalink
Added comment to kontrol summary auto-generated file (#263)
Browse files Browse the repository at this point in the history
* Added comment to kontrol summary auto-generated file

* Set Version: 0.1.105

* added comment to auto-generated files

* fixed issue with append

* Added comment to auto generated as an option to kontrol summary command

* updated deployment summary outputs in test data

* Fixed \n issue in test outuput fiees

* Set Version: 0.1.106

* updated .k.expected files

* Set Version: 0.1.108

* Set Version: 0.1.112

* Added --license parameter to kontrol summary command

* Set Version: 0.1.113

* Modified UNLICENSED output

* Set Version: 0.1.113

* Updated .expected files

* Set Version: 0.1.114

* Updated .expected

* Addressed PR comments

* update expected output

* Fixed issue

* fix errors

* sort args

* Set Version: 0.1.115

---------

Co-authored-by: devops <[email protected]>
Co-authored-by: Andrei <[email protected]>
  • Loading branch information
3 people authored Jan 15, 2024
1 parent 90d913d commit 0e238a7
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.114
0.1.115
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "kontrol"
version = "0.1.114"
version = "0.1.115"
description = "Foundry integration for KEVM"
authors = [
"Runtime Verification, Inc. <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion src/kontrol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
if TYPE_CHECKING:
from typing import Final

VERSION: Final = '0.1.114'
VERSION: Final = '0.1.115'
18 changes: 18 additions & 0 deletions src/kontrol/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ def exec_summary(
contract_names: Path | None,
output_dir_name: str | None,
foundry_root: Path,
license: str,
comment_generated_file: str,
condense_summary: bool = False,
**kwargs: Any,
) -> None:
Expand All @@ -132,6 +134,8 @@ def exec_summary(
contract_names=contract_names,
output_dir_name=output_dir_name,
foundry=_load_foundry(foundry_root),
license=license,
comment_generated_file=comment_generated_file,
condense_summary=condense_summary,
)

Expand Down Expand Up @@ -688,6 +692,20 @@ def _parse_test_version_tuple(value: str) -> tuple[str, int | None]:
type=str,
help='Path to write summary .sol files, relative to foundry root',
)
summary_args.add_argument(
'--comment-generated-files',
dest='comment_generated_file',
default='// This file was autogenerated by running `kontrol summary`. Do not edit this file manually.\n',
type=str,
help='Comment to write at the top of the auto generated summary files',
)
summary_args.add_argument(
'--license',
dest='license',
default='UNLICENSED',
type=str,
help='License for the auto generated contracts',
)

prove_args = command_parser.add_parser(
'prove',
Expand Down
16 changes: 10 additions & 6 deletions src/kontrol/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ def __init__(self, name: str, accounts: dict | None = None) -> None:
for acc_key in list(self.accounts):
self.accounts[acc_key] = self.accounts[acc_key]

def generate_header(self) -> list[str]:
def generate_header(self, comment_generated_file: str, license: str) -> list[str]:
lines = []
lines.append(f'// SPDX-License-Identifier: {license}')
lines.append(comment_generated_file)
lines.append(f'pragma solidity {self.SOLIDITY_VERSION};\n')
lines.append('import { Vm } from "forge-std/Vm.sol";\n')
return lines
Expand Down Expand Up @@ -58,20 +60,22 @@ def generate_main_contract(self) -> list[str]:
lines.append('}')
return lines

def generate_condensed_file(self) -> list[str]:
lines = self.generate_header()
def generate_condensed_file(self, comment_generated_file: str, license: str) -> list[str]:
lines = self.generate_header(comment_generated_file, license)
lines += self.generate_code_contract()
lines += self.generate_main_contract()
return lines

def generate_main_contract_file(self) -> list[str]:
lines = self.generate_header()
def generate_main_contract_file(self, comment_generated_file: str, license: str) -> list[str]:
lines = self.generate_header(comment_generated_file, license)
lines.append('import { ' + self.name + 'Code } from "./' + self.name + 'Code.sol";')
lines += self.generate_main_contract()
return lines

def generate_code_contract_file(self) -> list[str]:
def generate_code_contract_file(self, comment_generated_file: str, license: str) -> list[str]:
lines = []
lines.append(f'// SPDX-License-Identifier: {license}')
lines.append(comment_generated_file)
lines.append(f'pragma solidity {self.SOLIDITY_VERSION};\n')
lines += self.generate_code_contract()
return lines
Expand Down
11 changes: 8 additions & 3 deletions src/kontrol/foundry.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,8 @@ def foundry_summary(
contract_names: Path | None,
output_dir_name: str | None,
foundry: Foundry,
license: str,
comment_generated_file: str,
condense_summary: bool = False,
) -> None:
if not accesses_file.exists():
Expand All @@ -808,12 +810,15 @@ def foundry_summary(

main_file = output_dir / Path(name + '.sol')

if not license.strip():
raise ValueError('License cannot be empty or blank')

if condense_summary:
main_file.write_text('\n'.join(summary_contract.generate_condensed_file()))
main_file.write_text('\n'.join(summary_contract.generate_condensed_file(comment_generated_file, license)))
else:
code_file = output_dir / Path(name + 'Code.sol')
main_file.write_text('\n'.join(summary_contract.generate_main_contract_file()))
code_file.write_text('\n'.join(summary_contract.generate_code_contract_file()))
main_file.write_text('\n'.join(summary_contract.generate_main_contract_file(comment_generated_file, license)))
code_file.write_text('\n'.join(summary_contract.generate_code_contract_file(comment_generated_file, license)))


def foundry_section_edge(
Expand Down
4 changes: 2 additions & 2 deletions src/tests/integration/test-data/contracts.k.expected
Original file line number Diff line number Diff line change
Expand Up @@ -3138,7 +3138,7 @@ module S2KsrcZModDeploymentSummary-CONTRACT



rule ( #initBytecode ( S2KsrcZModDeploymentSummary ) => #parseByteStack ( "0x608060405234801561001057600080fd5b50610323806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063b5b8c44814610030575b600080fd5b61003861003a565b005b6000807f885cb69240a935d632d79c317109709ecfa91a80626ff3989d68f67f5b1dd12d60001c6001600160a01b031663b4d6c782735615deb798bb3e4dfa0139dfa1b3d433cc23b72f60405180610140016040528061010681526020016101e861010691396040518363ffffffff1660e01b81526004016100bd929190610182565b600060405180830381600087803b1580156100d757600080fd5b505af11580156100eb573d6000803e3d6000fd5b50506040516370ca10bb60e01b8152735615deb798bb3e4dfa0139dfa1b3d433cc23b72f60048201526000602482018190526003604483018190529095509350737109709ecfa91a80626ff3989d68f67f5b1dd12d92506370ca10bb9150606401600060405180830381600087803b15801561016657600080fd5b505af115801561017a573d6000803e3d6000fd5b505050505050565b60018060a01b038316815260006020604081840152835180604085015260005b818110156101be578581018301518582016060015282016101a2565b818111156101d0576000606083870101525b50601f01601f19169290920160600194935050505056fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c80633fb5c1cb1460415780638381f58a146053578063d09de08a14606d575b600080fd5b6051604c3660046083565b600055565b005b605b60005481565b60405190815260200160405180910390f35b6051600080549080607c83609b565b9190505550565b600060208284031215609457600080fd5b5035919050565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff820360f2577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b506001019056fea164736f6c634300080f000aa264697066735822122068ab91daa9ffb5a7d2f0c5e4d0883eb7dcddc4df53678c0ea17294ae87d8c7e564736f6c634300080d0033" ) )
rule ( #initBytecode ( S2KsrcZModDeploymentSummary ) => #parseByteStack ( "0x608060405234801561001057600080fd5b50610323806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063b5b8c44814610030575b600080fd5b61003861003a565b005b6000807f885cb69240a935d632d79c317109709ecfa91a80626ff3989d68f67f5b1dd12d60001c6001600160a01b031663b4d6c782735615deb798bb3e4dfa0139dfa1b3d433cc23b72f60405180610140016040528061010681526020016101e861010691396040518363ffffffff1660e01b81526004016100bd929190610182565b600060405180830381600087803b1580156100d757600080fd5b505af11580156100eb573d6000803e3d6000fd5b50506040516370ca10bb60e01b8152735615deb798bb3e4dfa0139dfa1b3d433cc23b72f60048201526000602482018190526003604483018190529095509350737109709ecfa91a80626ff3989d68f67f5b1dd12d92506370ca10bb9150606401600060405180830381600087803b15801561016657600080fd5b505af115801561017a573d6000803e3d6000fd5b505050505050565b60018060a01b038316815260006020604081840152835180604085015260005b818110156101be578581018301518582016060015282016101a2565b818111156101d0576000606083870101525b50601f01601f19169290920160600194935050505056fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c80633fb5c1cb1460415780638381f58a146053578063d09de08a14606d575b600080fd5b6051604c3660046083565b600055565b005b605b60005481565b60405190815260200160405180910390f35b6051600080549080607c83609b565b9190505550565b600060208284031215609457600080fd5b5035919050565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff820360f2577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b506001019056fea164736f6c634300080f000aa264697066735822122065ddb5d6f20688945c5fd013278ae89252bfdb6a75b5b19859708c4163839b6b64736f6c634300080d0033" ) )


syntax Bytes ::= S2KsrcZModDeploymentSummaryContract "." S2KsrcZModDeploymentSummaryMethod [function(), symbol(), klabel(method_src%DeploymentSummary)]
Expand All @@ -3162,7 +3162,7 @@ module S2KsrcZModDeploymentSummaryCode-CONTRACT



rule ( #initBytecode ( S2KsrcZModDeploymentSummaryCode ) => #parseByteStack ( "0x6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea2646970667358221220bf3c83c706325d6596b0b6aaa825b20074dd820772ee9da90f5c6788b8f244c564736f6c634300080d0033" ) )
rule ( #initBytecode ( S2KsrcZModDeploymentSummaryCode ) => #parseByteStack ( "0x6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea26469706673582212200b7867accb23ecb775c2ab8bb72766ea046d5a6121003d74cfee2c1276ed0e4d64736f6c634300080d0033" ) )


endmodule
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-License-Identifier: UNLICENSED
// This file was autogenerated by running `kontrol summary`. Do not edit this file manually.

pragma solidity ^0.8.13;

import { Vm } from "forge-std/Vm.sol";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-License-Identifier: UNLICENSED
// This file was autogenerated by running `kontrol summary`. Do not edit this file manually.

pragma solidity ^0.8.13;

contract DeploymentSummaryCode {
Expand Down
2 changes: 2 additions & 0 deletions src/tests/integration/test_foundry_prove.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@ def test_deployment_summary(
TEST_DATA_DIR / 'accesses.json',
contract_names=None,
output_dir_name='src',
license='UNLICENSED',
comment_generated_file='// This file was autogenerated by running `kontrol summary`. Do not edit this file manually.\n',
foundry=foundry,
)

Expand Down

0 comments on commit 0e238a7

Please sign in to comment.