Skip to content

Commit

Permalink
add gas refund test to test_exception test case
Browse files Browse the repository at this point in the history
  • Loading branch information
macong-cdc committed Jul 19, 2022
1 parent 72a77f6 commit c24086e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 56 deletions.
20 changes: 0 additions & 20 deletions integration_tests/contracts/contracts/TheRevertContract.sol

This file was deleted.

54 changes: 19 additions & 35 deletions integration_tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,25 @@ def test_exception(cluster):
w3,
CONTRACTS["TestRevert"],
)
with pytest.raises(web3.exceptions.ContractLogicError):
send_transaction(
w3, contract.functions.transfer(5 * (10**18) - 1).buildTransaction()
)
more_than_enough_gas = 1000000

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

print(f"{receipt = }")
print(f"{w3.eth.max_priority_fee = }")
print(f"{w3.eth.gas_price = }")
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"]
)
assert 0 == contract.caller.query()

receipt = send_transaction(
Expand Down Expand Up @@ -690,34 +705,3 @@ def test_tx_inclusion(cronos, max_gas_wanted):
== receipts[2].blockNumber
== receipts[3].blockNumber
)


def test_refund_unused_gas_when_contract_state_reverted(cronos):
"""
Call a smart contract method that always revert with very high gas limit
Call tx should return status 0 (fail)
Fee is gasUsed * effectivePrice
"""

w3 = cronos.w3
the_revert_contract = deploy_contract(
w3, CONTRACTS["TheRevertContract"], key=KEYS["community"]
)

more_than_enough_gas = 1000000
dummy = 12
tx = the_revert_contract.functions.trigger_revert(dummy).buildTransaction(
{"gas": more_than_enough_gas}
)

balance_bef = w3.eth.get_balance(ADDRS["community"])
tx_receipt = send_transaction(w3, tx, KEYS["community"])
balance_aft = w3.eth.get_balance(ADDRS["community"])

assert tx_receipt["status"] == 0, "should be failed tx"
assert tx_receipt["gasUsed"] != more_than_enough_gas
assert (
balance_bef - balance_aft
== tx_receipt["gasUsed"] * tx_receipt["effectiveGasPrice"]
)
1 change: 0 additions & 1 deletion integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"TestMessageCall": "TestMessageCall.sol",
"CroBridge": "CroBridge.sol",
"CronosGravityCancellation": "CronosGravityCancellation.sol",
"TheRevertContract": "TheRevertContract.sol",
}


Expand Down

0 comments on commit c24086e

Please sign in to comment.