Skip to content

Commit

Permalink
Execution of contract initialization code (#54)
Browse files Browse the repository at this point in the history
* port contract initialization code to kontrol

* Set Version: 0.1.10

* Point to branch

* Fix formatting

* Update expected files

* Turn on verbose flag for integration tests

* Revert test-pr.yml

* edit workflow file

* Set Version: 0.1.11

* Set Version: 0.1.11

* edit workflow file

* Fix contracts.k.expected

* Revert test-pr.yml

* Set Version: 0.1.12

* Set Version: 0.1.13

* Set Version: 0.1.14

* Merge master into branch

* Add warning if constructor doesn't exist

* Use master branch of kevm

* Set Version: 0.1.21

* Fix formatting, update kevm

* Update test_foundry_kompile expected

* Update expected output

* Remove commented lines

* Set Version: 0.1.23

* Set Version: 0.1.24

---------

Co-authored-by: devops <devops@runtimeverification.com>
  • Loading branch information
nwatson22 and devops authored Oct 11, 2023
1 parent 75ad658 commit 27d42f3
Show file tree
Hide file tree
Showing 22 changed files with 9,725 additions and 893 deletions.
2 changes: 1 addition & 1 deletion package/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.23
0.1.24
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.23"
version = "0.1.24"
description = "Foundry integration for KEVM"
authors = [
"Runtime Verification, Inc. <contact@runtimeverification.com>",
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.23'
VERSION: Final = '0.1.24'
9 changes: 9 additions & 0 deletions src/kontrol/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def exec_prove(
counterexample_info: bool = False,
trace_rewrites: bool = False,
auto_abstract_gas: bool = False,
run_constructor: bool = False,
**kwargs: Any,
) -> None:
_ignore_arg(kwargs, 'main_module', f'--main-module: {kwargs["main_module"]}')
Expand Down Expand Up @@ -195,6 +196,7 @@ def exec_prove(
smt_retry_limit=smt_retry_limit,
trace_rewrites=trace_rewrites,
auto_abstract_gas=auto_abstract_gas,
run_constructor=run_constructor,
)
failed = 0
for pid, r in results.items():
Expand Down Expand Up @@ -519,6 +521,13 @@ def _parse_test_version_tuple(value: str) -> tuple[str, int | None]:
action='store_true',
help='Use the booster RPC server instead of kore-rpc.',
)
prove_args.add_argument(
'--run-constructor',
dest='run_constructor',
default=False,
action='store_true',
help='Include the contract constructor in the test execution.',
)

show_args = command_parser.add_parser(
'show',
Expand Down
17 changes: 13 additions & 4 deletions src/kontrol/foundry.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def all_non_tests(self) -> list[str]:
for contract in self.contracts.values()
for method in contract.methods
if f'{contract.name}.{method.signature}' not in self.all_tests
]
] + [f'{contract.name}.init' for contract in self.contracts.values()]

@staticmethod
def _escape_brackets(regs: list[str]) -> list[str]:
Expand Down Expand Up @@ -385,13 +385,20 @@ def get_optional_proof(self, test_id: str) -> Proof | None:
return Proof.read_proof_data(self.proofs_dir, test_id)
return None

def get_contract_and_method(self, test: str) -> tuple[Contract, Contract.Method]:
def get_contract_and_method(self, test: str) -> tuple[Contract, Contract.Method | Contract.Constructor]:
contract_name, method_name = test.split('.')
contract = self.contracts[contract_name]

if method_name == 'init':
constructor = self.contracts[contract_name].constructor
if constructor is None:
raise ValueError(f'Contract {contract_name} does not have a constructor.')
return contract, constructor

method = contract.method_by_sig[method_name]
return contract, method

def get_method(self, test: str) -> Contract.Method:
def get_method(self, test: str) -> Contract.Method | Contract.Constructor:
_, method = self.get_contract_and_method(test)
return method

Expand Down Expand Up @@ -429,7 +436,7 @@ def resolve_proof_version(
_LOGGER.info(
f'Using the the latest version {latest_version} of test {test} because it is up to date and no version was specified.'
)
if not method.contract_up_to_date(self.digest_file):
if type(method) is Contract.Method and not method.contract_up_to_date(self.digest_file):
_LOGGER.warning(
f'Test {test} was not reinitialized because it is up to date, but the contract it is a part of has changed.'
)
Expand All @@ -448,7 +455,9 @@ def latest_proof_version(
find the highest used proof ID, to be used as a default. Returns None if no version of this proof exists.
"""
proof_ids = listdir(self.proofs_dir)
print(proof_ids)
versions = {int(pid.split(':')[1]) for pid in proof_ids if pid.split(':')[0] == test}
print(versions)
return max(versions, default=None)

def free_proof_version(
Expand Down
Loading

0 comments on commit 27d42f3

Please sign in to comment.