Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: no trace detail on insufficient balance #554

Merged
merged 3 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (cli) [#537](https://github.com/crypto-org-chain/ethermint/pull/537) Fix unsuppored sign mode SIGN_MODE_TEXTUAL for bank transfer.
* (cli) [#543](https://github.com/crypto-org-chain/ethermint/pull/543) Fix graceful shutdown.
* (rpc) [#545](https://github.com/crypto-org-chain/ethermint/pull/545) Fix state overwrite in debug trace APIs.
* (rpc) [#554](https://github.com/crypto-org-chain/ethermint/pull/554) No trace detail on insufficient balance.

### Improvements

Expand Down
38 changes: 38 additions & 0 deletions tests/integration_tests/hardhat/contracts/FeeCollector.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract FeeCollector {
address public owner;
uint256 public balance;

event TransferReceived(address _from, uint _amount);
event TransferSent(address _from, address _destAddr, uint _amount);

constructor() {
owner = msg.sender;
}

receive() external payable {
balance += msg.value;
emit TransferReceived(msg.sender, msg.value);
}

function withdraw(uint amount, address payable destAddr) public {
require(msg.sender == owner, "Only owner can withdraw funds");
require(amount <= balance, "Insufficient funds");

destAddr.transfer(amount);
balance -= amount;
emit TransferSent(msg.sender, destAddr, amount);
}

function transferERC20(IERC20 token, address to, uint256 amount) public {
require(msg.sender == owner, "Only owner can withdraw funds");
uint256 erc20balance = token.balanceOf(address(this));
require(amount <= erc20balance, "balance is low");
token.transfer(to, amount);
emit TransferSent(msg.sender, to, amount);
}
}
60 changes: 59 additions & 1 deletion tests/integration_tests/test_tracers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
deploy_contract,
derive_new_account,
derive_random_account,
send_raw_transactions,
send_transaction,
send_txs,
sign_transaction,
w3_wait_for_new_blocks,
)

Expand Down Expand Up @@ -156,6 +158,62 @@ def process(w3):
assert res[0] == res[-1], res


def test_trace_tx_reverse_transfer(ethermint):
method = "debug_traceTransaction"

Check warning

Code scanning / CodeQL

Unreachable code Warning test

This statement is unreachable.
tracer = {"tracer": "callTracer"}
acc = derive_new_account(11)
gas = 44582

def process(w3):
fund_acc(w3, acc, fund=70000000000000000)
contract, _ = deploy_contract(w3, CONTRACTS["FeeCollector"], key=acc.key)
w3_wait_for_new_blocks(w3, 1)
print("mm-balance-bf", w3.eth.block_number, w3.eth.get_balance(acc.address))
raw_transactions = []
nonce = w3.eth.get_transaction_count(acc.address)
amt = 30000000000000000
tx = {
"from": acc.address,
"to": contract.address,
"value": hex(amt),
"nonce": nonce,
"gas": hex(gas),
}
print("mm-tx", tx)
signed = sign_transaction(w3, tx, acc.key)
raw_transactions.append(signed.rawTransaction)
tx = contract.functions.withdraw(amt, ADDRS["community"]).build_transaction(
{
"from": acc.address,
"nonce": nonce + 1,
"gas": hex(gas),
}
)
print("mm-tx", tx)
signed = sign_transaction(w3, tx, acc.key)
raw_transactions.append(signed.rawTransaction)

w3_wait_for_new_blocks(w3, 1)
sended_hash_set = send_raw_transactions(w3, raw_transactions)
w3_wait_for_new_blocks(w3, 1)
for h in sended_hash_set:
tx_hash = h.hex()
tx_res = w3.provider.make_request(
method,
[tx_hash, tracer],
)
print("mm-tx_res", tx_res)
print("mm-balance-af", w3.eth.block_number, w3.eth.get_balance(acc.address))
assert "result" in tx_res
return tx_res["result"]

providers = [ethermint.w3]
with ThreadPoolExecutor(len(providers)) as exec:
tasks = [exec.submit(process, w3) for w3 in providers]
res = [future.result() for future in as_completed(tasks)]
assert len(res) == len(providers)


def test_tracecall_insufficient_funds(ethermint, geth):
method = "debug_traceCall"
acc = derive_random_account()
Expand Down Expand Up @@ -540,7 +598,7 @@ def test_refund_unused_gas_when_contract_tx_reverted_state_overrides(ethermint):
"balance": hex(balance),
"nonce": hex(nonce),
}
}
},
},
],
)
Expand Down
1 change: 1 addition & 0 deletions tests/integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"Caller": "Caller.sol",
"Random": "Random.sol",
"TestBlockTxProperties": "TestBlockTxProperties.sol",
"FeeCollector": "FeeCollector.sol",
}


Expand Down
6 changes: 0 additions & 6 deletions x/evm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,12 +728,6 @@ func (k *Keeper) prepareTrace(
return nil, 0, status.Error(codes.Internal, err.Error())
}

if res.VmError != "" {
if res.VmError == vm.ErrInsufficientBalance.Error() {
return nil, 0, status.Error(codes.Internal, res.VmError)
}
}

var result interface{}
result, err = tracer.GetResult()
if err != nil {
Expand Down
Loading