From 396996e5f9b3a6f240f99f6f38cbddaf444b1503 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Thu, 7 Nov 2024 18:17:00 +0800 Subject: [PATCH] simple reproduce --- .../hardhat/contracts/FeeCollector.sol | 38 ++--------- tests/integration_tests/test_tracers.py | 67 ++++++------------- 2 files changed, 27 insertions(+), 78 deletions(-) diff --git a/tests/integration_tests/hardhat/contracts/FeeCollector.sol b/tests/integration_tests/hardhat/contracts/FeeCollector.sol index 7700b50882..71027eed74 100644 --- a/tests/integration_tests/hardhat/contracts/FeeCollector.sol +++ b/tests/integration_tests/hardhat/contracts/FeeCollector.sol @@ -1,38 +1,10 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; +contract FeeCollector { + event TokensMinted(address indexed to, uint256 amount); -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; + function mint(uint256 amount) public payable { + emit TokensMinted(msg.sender, amount); } - - 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); - } -} \ No newline at end of file +} diff --git a/tests/integration_tests/test_tracers.py b/tests/integration_tests/test_tracers.py index 20878165e6..968bb7c196 100644 --- a/tests/integration_tests/test_tracers.py +++ b/tests/integration_tests/test_tracers.py @@ -159,59 +159,36 @@ def process(w3): def test_trace_tx_reverse_transfer(ethermint): + print("reproduce only") + return method = "debug_traceTransaction" 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 = { + w3 = ethermint.w3 + fund_acc(w3, acc, fund=40000000000000000) + contract, _ = deploy_contract(w3, CONTRACTS["FeeCollector"]) + amt = 18633908679862681 + raw_transactions = [] + nonce = w3.eth.get_transaction_count(acc.address) + tx = contract.functions.mint(amt).build_transaction( + { "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), - } + ) + raw_transactions.append(sign_transaction(w3, tx, acc.key).rawTransaction) + tx = tx | {"nonce": nonce + 1} + raw_transactions.append(sign_transaction(w3, tx, acc.key).rawTransaction) + w3_wait_for_new_blocks(w3, 1) + sended_hash_set = send_raw_transactions(w3, raw_transactions) + for h in sended_hash_set: + tx_hash = h.hex() + tx_res = w3.provider.make_request( + method, + [tx_hash, tracer], ) - 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) + print(tx_res) def test_tracecall_insufficient_funds(ethermint, geth):