Skip to content

Commit

Permalink
Read warning when contract out of date, write digest file with format…
Browse files Browse the repository at this point in the history
…ting
  • Loading branch information
nwatson22 committed Sep 7, 2023
1 parent 912ded5 commit e96b841
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
17 changes: 10 additions & 7 deletions kevm-pyk/src/kontrol/foundry.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ def up_to_date(self) -> bool:
digest_dict = json.loads(self.digest_file.read_text())
if 'foundry' not in digest_dict:
digest_dict['foundry'] = ''
self.digest_file.write_text(json.dumps(digest_dict))
self.digest_file.write_text(json.dumps(digest_dict, indent=4))
return digest_dict['foundry'] == self.digest

def update_digest(self) -> None:
digest_dict = {}
if self.digest_file.exists():
digest_dict = json.loads(self.digest_file.read_text())
digest_dict['foundry'] = self.digest
self.digest_file.write_text(json.dumps(digest_dict))
self.digest_file.write_text(json.dumps(digest_dict, indent=4))

_LOGGER.info(f'Updated Foundry digest file: {self.digest_file}')

Expand Down Expand Up @@ -402,12 +402,11 @@ def get_optional_proof(self, test_id: str) -> Proof | None:
return Proof.read_proof_data(self.proofs_dir, test_id)
return None

def get_method(self, test: str) -> Method:
def get_method(self, test: str) -> Contract.Method:
contract_name, method_name = test.split('.')
contract = self.contracts[contract_name]
return contract.method_by_sig[method_name]


def resolve_proof_version(
self,
test: str,
Expand Down Expand Up @@ -442,6 +441,10 @@ 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):
_LOGGER.warning(
f'Test {test} was not reinitialized because it is up to date, but the contract it is a part of has changed.'
)
return latest_version

_LOGGER.info(
Expand Down Expand Up @@ -567,15 +570,15 @@ def kompilation_up_to_date() -> bool:
digest_dict = json.loads(foundry.digest_file.read_text())
if 'kompilation' not in digest_dict:
digest_dict['kompilation'] = ''
foundry.digest_file.write_text(json.dumps(digest_dict))
foundry.digest_file.write_text(json.dumps(digest_dict, indent=4))
return digest_dict['kompilation'] == kompilation_digest()

def update_kompilation_digest() -> None:
digest_dict = {}
if foundry.digest_file.exists():
digest_dict = json.loads(foundry.digest_file.read_text())
digest_dict['kompilation'] = kompilation_digest()
foundry.digest_file.write_text(json.dumps(digest_dict))
foundry.digest_file.write_text(json.dumps(digest_dict, indent=4))

_LOGGER.info('Updated Kompilation digest')

Expand Down Expand Up @@ -736,7 +739,7 @@ def _split_test(test: tuple[str, int]) -> tuple[str, str, int]:
]

_LOGGER.info(f'Updating digests: {[test_name for test_name, _ in tests]}')
for (test_name, _) in tests:
for test_name, _ in tests:
foundry.get_method(test_name).update_digest(foundry.digest_file)
_LOGGER.info(f'Updating digests: {setup_methods}')
for test_name in setup_methods:
Expand Down
17 changes: 14 additions & 3 deletions kevm-pyk/src/kontrol/solc_to_k.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,30 @@ def up_to_date(self, digest_file: Path) -> bool:
digest_dict = json.loads(digest_file.read_text())
if 'methods' not in digest_dict:
digest_dict['methods'] = {}
digest_file.write_text(json.dumps(digest_dict))
digest_file.write_text(json.dumps(digest_dict, indent=4))
if self.qualified_name not in digest_dict['methods']:
return False
return digest_dict['methods'][self.qualified_name]['method'] == self.digest

def contract_up_to_date(self, digest_file: Path) -> bool:
if not digest_file.exists():
return False
digest_dict = json.loads(digest_file.read_text())
if 'methods' not in digest_dict:
digest_dict['methods'] = {}
digest_file.write_text(json.dumps(digest_dict, indent=4))
if self.qualified_name not in digest_dict['methods']:
return False
return digest_dict['methods'][self.qualified_name]['contract'] == self.contract_digest

def update_digest(self, digest_file: Path) -> None:
digest_dict = {}
if digest_file.exists():
digest_dict = json.loads(digest_file.read_text())
if 'methods' not in digest_dict:
digest_dict['methods'] = {}
digest_dict['methods'][self.qualified_name] = {'method': self.digest}
digest_file.write_text(json.dumps(digest_dict))
digest_dict['methods'][self.qualified_name] = {'method': self.digest, 'contract': self.contract_digest}
digest_file.write_text(json.dumps(digest_dict, indent=4))

_LOGGER.info(f'Updated method {self.qualified_name} in digest file: {digest_file}')

Expand Down

0 comments on commit e96b841

Please sign in to comment.