Skip to content

Commit

Permalink
Problem: tx inclusion logic when block gas limit exceeded is not tested
Browse files Browse the repository at this point in the history
Solution:
- add integration test to test tx inclusion logic when block gas limit exceeded.
  • Loading branch information
yihuang committed Mar 7, 2022
1 parent 522abc9 commit 83e0374
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ replace github.com/ethereum/go-ethereum => github.com/crypto-org-chain/go-ethere
// TODO: remove when ibc-go and ethermint upgrades cosmos-sdk
replace github.com/cosmos/cosmos-sdk => github.com/cosmos/cosmos-sdk v0.44.7-0.20220214161517-8a26cd10b4be

replace github.com/tharsis/ethermint => github.com/crypto-org-chain/ethermint v0.7.3-0.20220307062109-cf15e288ccda
replace github.com/tharsis/ethermint => github.com/crypto-org-chain/ethermint v0.7.3-0.20220307013541-e3c38bb961a0

// Note: gorocksdb bindings for OptimisticTransactionDB are not merged upstream, so we use a fork
// See https://github.com/tecbot/gorocksdb/pull/216
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:ma
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/crypto-org-chain/ethermint v0.7.3-0.20220307062109-cf15e288ccda h1:wqI9k6j5YsCGOmaB99fmnWwhQBZnJ3G0JdYLjqja0so=
github.com/crypto-org-chain/ethermint v0.7.3-0.20220307062109-cf15e288ccda/go.mod h1:J96LX4KvLyl+5jV6+mt/4l6srtGX/mdDTuqQQuYrdDk=
github.com/crypto-org-chain/ethermint v0.7.3-0.20220307013541-e3c38bb961a0 h1:/mygBmxynU1ytA1lQoPNZ4z8VoOYSo4r0TQJQ7yaWD4=
github.com/crypto-org-chain/ethermint v0.7.3-0.20220307013541-e3c38bb961a0/go.mod h1:J96LX4KvLyl+5jV6+mt/4l6srtGX/mdDTuqQQuYrdDk=
github.com/crypto-org-chain/go-ethereum v1.10.3-patched h1:kr6oQIYOi2VC8SZwkhlUDZE1Omit/YHVysKMgCB2nes=
github.com/crypto-org-chain/go-ethereum v1.10.3-patched/go.mod h1:99onQmSd1GRGOziyGldI41YQb7EESX3Q4H41IfJgIQQ=
github.com/crypto-org-chain/ibc-go v1.2.1-hooks h1:wuWaQqm/TFKJQwuFgjCPiPumQio+Yik5Z1DObDExrrU=
Expand Down
6 changes: 3 additions & 3 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3712,13 +3712,13 @@
sha256 = "1sgjf2vaq554ybc0cwkzn17cz2ibzph2rq0dgaw21c2hym09437x"

["github.com/tharsis/ethermint"]
sumVersion = "v0.7.3-0.20220307062109-cf15e288ccda"
sumVersion = "v0.7.3-0.20220307013541-e3c38bb961a0"
vendorPath = "github.com/crypto-org-chain/ethermint"
["github.com/tharsis/ethermint".fetch]
type = "git"
url = "https://github.com/crypto-org-chain/ethermint"
rev = "cf15e288ccdabacb1bd9a6ed919865713a874cfc"
sha256 = "1xczlbsmq48drq8wq1l700vmixnr0y83ljsfi2v5va05nfs0ig40"
rev = "e3c38bb961a0461af6281a5e24616f436cb93fcd"
sha256 = "0bqss02021rmkgfmbnkfd2q5aplk5caibpxyb440dahswp0v6r80"

["github.com/tidwall/gjson"]
sumVersion = "v1.6.7"
Expand Down
37 changes: 37 additions & 0 deletions integration_tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Greeter,
deploy_contract,
send_transaction,
sign_transaction,
wait_for_block,
wait_for_port,
)
Expand Down Expand Up @@ -237,3 +238,39 @@ def test_log0(cluster):
assert (
log.data == "0x68656c6c6f20776f726c64000000000000000000000000000000000000000000"
)


def test_tx_inclusion(cronos):
"""
- send multiple heavy transactions at the same time.
- check they are included in consecutively blocks without failure.
"""
w3 = cronos.w3
# bigger than block_gas_limit/2, so at most one tx in a block
tx_gas_limit = 80000000
amount = 1000
# use different sender accounts to be able be send concurrently
signed_txs = []
for account in ["validator", "community", "signer1", "signer2"]:
signed_txs.append(
sign_transaction(
w3,
{
"to": ADDRS["validator"],
"value": amount,
"gas": tx_gas_limit,
},
KEYS[account],
)
)

for signed in signed_txs:
w3.eth.send_raw_transaction(signed.rawTransaction)

receipts = [
w3.eth.wait_for_transaction_receipt(signed.hash) for signed in signed_txs
]

# the transactions should be included in differnt but consecutive blocks
for receipt, next_receipt in zip(receipts, receipts[1:]):
assert next_receipt.blockNumber == receipt.blockNumber + 1
9 changes: 7 additions & 2 deletions integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,17 @@ def deploy_contract(w3, jsonfile, args=(), key=KEYS["validator"]):
return w3.eth.contract(address=address, abi=info["abi"])


def send_transaction(w3, tx, key):
def sign_transaction(w3, tx, key=KEYS["validator"]):
"fill default fields and sign"
acct = Account.from_key(key)
tx["from"] = acct.address
tx = fill_transaction_defaults(w3, tx)
tx = fill_nonce(w3, tx)
signed = acct.sign_transaction(tx)
return acct.sign_transaction(tx)


def send_transaction(w3, tx, key):
signed = sign_transaction(w3, tx, key)
txhash = w3.eth.send_raw_transaction(signed.rawTransaction)
return w3.eth.wait_for_transaction_receipt(txhash)

Expand Down

0 comments on commit 83e0374

Please sign in to comment.