From 7c541a0fba24d064dd100665e9831a3c76d4b16d Mon Sep 17 00:00:00 2001 From: macong-cdc Date: Mon, 18 Jul 2022 15:54:26 +0800 Subject: [PATCH] test gas refund when contract tx is reverted --- integration_tests/test_basic.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/integration_tests/test_basic.py b/integration_tests/test_basic.py index b50df7d6af..1f2e4de20e 100644 --- a/integration_tests/test_basic.py +++ b/integration_tests/test_basic.py @@ -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