Skip to content

Commit

Permalink
test gas refund when contract tx is reverted (#590)
Browse files Browse the repository at this point in the history
  • Loading branch information
macong-cdc authored Jul 25, 2022
1 parent 851b021 commit e574f14
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions integration_tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,34 @@ def test_exception(cluster):
assert 5 * (10**18) == contract.caller.query()


def test_refund_unused_gas_when_contract_tx_reverted(cluster):
"""
Call a smart contract method that reverts with very high gas limit
Call tx receipt should be status 0 (fail)
Fee is gasUsed * effectiveGasPrice
"""
w3 = cluster.w3
contract = deploy_contract(w3, CONTRACTS["TestRevert"])
more_than_enough_gas = 1000000

balance_bef = w3.eth.get_balance(ADDRS["community"])
receipt = send_transaction(
w3,
contract.functions.transfer(5 * (10**18) - 1).buildTransaction(
{"gas": more_than_enough_gas}
),
key=KEYS["community"],
)
balance_aft = w3.eth.get_balance(ADDRS["community"])

assert receipt["status"] == 0, "should be a failed tx"
assert receipt["gasUsed"] != more_than_enough_gas
assert (
balance_bef - balance_aft == receipt["gasUsed"] * receipt["effectiveGasPrice"]
)


def test_message_call(cronos):
"stress test the evm by doing message calls as much as possible"
w3 = cronos.w3
Expand Down

0 comments on commit e574f14

Please sign in to comment.