Skip to content

Commit

Permalink
Added negative tests (#55)
Browse files Browse the repository at this point in the history
* Added negative tests

* Addressing review comments
  • Loading branch information
traiansf authored Dec 20, 2024
1 parent 3b0a7fa commit 072367b
Show file tree
Hide file tree
Showing 3 changed files with 479 additions and 4 deletions.
6 changes: 4 additions & 2 deletions pykwasm/src/pykwasm/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from eth_account import Account
from requests.exceptions import ConnectionError
from web3 import Web3
from web3.exceptions import BadFunctionCallOutput, Web3RPCError
from web3.exceptions import BadFunctionCallOutput, ContractLogicError, Web3RPCError
from web3.middleware import SignAndSendRawMiddlewareBuilder

ABI_MAP = {
Expand Down Expand Up @@ -98,11 +98,13 @@ def run_method(w3, contract, sender, eth, method, params):
else:
tx_hash = func.transact({'from': sender.address, 'value': eth})
result_or_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
except (ConnectionError, BadFunctionCallOutput, Web3RPCError) as e:
except (ConnectionError, ContractLogicError, BadFunctionCallOutput, Web3RPCError) as e:
if isinstance(e, (ConnectionError, ConnectionRefusedError)):
msg = f'Failed to connect to node: {e.message}'
elif isinstance(e, BadFunctionCallOutput):
msg = f'Could not interpret function output: {",".join(e.args)}'
elif isinstance(e, ContractLogicError):
msg = f'Contract logic error: {e.message}'
else:
msg = f'Node RPC encountered an error: {e.message}'
print(msg, file=sys.stderr)
Expand Down
4 changes: 2 additions & 2 deletions pykwasm/src/pykwasm/kdist/wasm-semantics/ulm-wasm.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ These rules define various integration points between the ULM and our Wasm inter
</ulmWasm>
...
</generatedTop>
) => #if OutVal ==K NO_OUTPUT #then EVMC_INTERNAL_ERROR #else Status #fi
) => #if Status ==Int EVMC_SUCCESS andBool OutVal ==K NO_OUTPUT #then EVMC_INTERNAL_ERROR #else Status #fi
```

Hooks implementation
Expand Down Expand Up @@ -629,7 +629,7 @@ Handle the actual hook calls.
rule
<instrs>
#fail(ulmBytes(BYTES:Bytes)) => #throwException(EVMC_FAILURE, Bytes2String(BYTES))
#fail(ulmBytes(BYTES:Bytes)) => #throwException(EVMC_REVERT, Bytes2String(BYTES))
...
</instrs>
Expand Down
Loading

0 comments on commit 072367b

Please sign in to comment.