Skip to content

Commit

Permalink
Merge pull request #342 from eosnetworkfoundation/kayan_gas_v3_test
Browse files Browse the repository at this point in the history
gas v3 test
  • Loading branch information
elmato authored Mar 5, 2025
2 parents f60012c + 235459e commit 84437ee
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions tests/nodeos_eos_evm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,7 @@ def get_block(num):
assert(b["consensusParameter"]["gasFeeParameters"]["gasSset"] == 39576)
assert(b["consensusParameter"]["gasFeeParameters"]["gasTxcreate"] == 64236)
assert(b["consensusParameter"]["gasFeeParameters"]["gasTxnewaccount"] == 36782)
gas_newAccount = b["consensusParameter"]["gasFeeParameters"]["gasNewaccount"]

# Verify header.baseFeePerGas still 10GWei (0x2540be400) it will change in 3mins
b = get_block("latest")
Expand Down Expand Up @@ -1224,6 +1225,8 @@ def get_block(num):
prodNode.waitForTransBlockIfNeeded(trans[1], True);
time.sleep(2)

validate_all_balances()

Print("Test eth_getLogs (call deposit)")
special_nonce += 1
signed_trx = w3.eth.account.sign_transaction(dict(
Expand All @@ -1250,8 +1253,105 @@ def get_block(num):
assert(len(logs) == 1)
assert(str(logs[0]['address']).lower() == str(eventor_contract).lower())

validate_all_balances()

####### END Test eth_getLogs

overhead_price = 900000000000
storage_price = 900000000000
Utils.Print("Set gas prices: overhead_price:{0}, storage_price:{1}".format(overhead_price, storage_price))
actData = {"prices":{"overhead_price":overhead_price,"storage_price":storage_price}}
trans = prodNode.pushMessage(evmAcc.name, "setgasprices", json.dumps(actData), '-p {0}'.format(evmAcc.name), silentErrors=True)
prodNode.waitForTransBlockIfNeeded(trans[1], True)
time.sleep(1)

# Switch to version 3, test overhead_price & storage_price
Utils.Print("Switch to evm_version 3, test overhead_price & storage_price")
actData = {"version":3}
trans = prodNode.pushMessage(evmAcc.name, "setversion", json.dumps(actData), '-p {0}'.format(evmAcc.name), silentErrors=True)
prodNode.waitForTransBlockIfNeeded(trans[1], True);
time.sleep(1)

evmSendKey = "ba8c9ff38e4179748925335a9891b969214b37dc3723a1754b8b849d3eea9ac0"
amount=1.0000
transferAmount="1.0000 {0}".format(CORE_SYMBOL)

for j in range(0,4):
overhead_price = 900000000000
storage_price = 450000000000 * (j + 1)
inclusion_price = 0
if j == 3:
inclusion_price = 300000000000
gas_price = overhead_price + inclusion_price
if storage_price > overhead_price:
gas_price = storage_price + inclusion_price
Utils.Print("Test gas v3 round %s: overhead_price=%s, storage_price=%s, inclusion_price=%s" % (j, overhead_price, storage_price,inclusion_price))
actData = {"prices":{"overhead_price":overhead_price,"storage_price":storage_price}}
trans = prodNode.pushMessage(evmAcc.name, "setgasprices", json.dumps(actData), '-p {0}'.format(evmAcc.name), silentErrors=True)
prodNode.waitForTransBlockIfNeeded(trans[1], True)

# Wait 3 mins
Utils.Print("Test gas v3 round %s: Wait 3 mins to ensure new gas prices become effective" % (j))
time.sleep(185)

# ensure EOS->EVM bridge still works
Utils.Print("Test gas v3 round %s: ensure EOS->EVM bridge still works" %(j))
nonProdNode.transferFunds(cluster.eosioAccount, evmAcc, "1.0000 EOS", "0xB106D2C286183FFC3D1F0C4A6f0753bB20B407c2", waitForTransBlock=True)

# ensure call action (special signature) still works
Utils.Print("Test gas v3 round %s: ensure call action (special signature) still works" % (j))
actData = {"from":minerAcc.name, "to":increment_contract[2:], "value":"0000000000000000000000000000000000000000000000000000000000000000", "data":"d09de08a", "gas_limit":"100000"}
trans = prodNode.pushMessage(evmAcc.name, "call", json.dumps(actData), '-p {0}'.format(minerAcc.name), silentErrors=False)
prodNode.waitForTransBlockIfNeeded(trans[1], True)

# ensure transaction fail if gas price is not enough
Utils.Print("Test gas v3 round %s: ensure transaction fail if gas price is not enough" % (j))
nonce = nonce + 1
signed_trx = w3.eth.account.sign_transaction(dict(
nonce=nonce,
gas=21000 + gas_newAccount,
maxFeePerGas = gas_price - inclusion_price - 1,
maxPriorityFeePerGas = 0,
to=Web3.to_checksum_address("0x9E126C57330FA71556628e0aabd6B6B6783d99fB"), #exising account
value=int(amount*10000*szabo*100), # .0001 EOS is 100 szabos
data=b'',
chainId=evmChainId
), evmSendKey)
actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(get_raw_transaction(signed_trx))[2:]}
trans = prodNode.pushMessage(evmAcc.name, "pushtx", json.dumps(actData), '-p {0}'.format(minerAcc.name), silentErrors=True)
assert not trans[0], f"push trx should have failed: {trans}"
nonce = nonce - 1

# test a success transfer under v3
Utils.Print("Test gas v3 round %s: test a success transfer, gas_price=%s, inclusion_price=%s" % (j, gas_price, inclusion_price))
bal1 = w3.eth.get_balance(Web3.to_checksum_address("0x9E126C57330FA71556628e0aabd6B6B6783d99fA"))
nonce = nonce + 1
signed_trx = w3.eth.account.sign_transaction(dict(
nonce=nonce,
gas=21000 + gas_newAccount,
maxFeePerGas = gas_price,
maxPriorityFeePerGas = inclusion_price,
to=Web3.to_checksum_address("0x9E126C57330FA71556628e0aabd6B6B6783d000" + chr(ord('0') + j)), # new addresses
value=int(amount*10000*szabo*100), # .0001 EOS is 100 szabos
data=b'',
chainId=evmChainId
), evmSendKey)
actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(get_raw_transaction(signed_trx))[2:]}
trans = prodNode.pushMessage(evmAcc.name, "pushtx", json.dumps(actData), '-p {0}'.format(minerAcc.name), silentErrors=False)
time.sleep(2.0)
bal2 = w3.eth.get_balance(Web3.to_checksum_address("0x9E126C57330FA71556628e0aabd6B6B6783d99fA"))
Utils.Print("Test gas v3 round %s: balance difference is %s" % (j, bal1 - bal2))
if j == 0: # overhead price 900 Gwei, storage price 450 Gwei, inclusion price 0 Gwei
assert bal1 - bal2 == int(amount*10000*szabo*100) + (21000 + int(gas_newAccount * 450 / 900)) * gas_price, "Test gas v3 0:balance is not as expected"
elif j == 1: # overhead price 900 Gwei, storage price 900 Gwei, inclusion price 0 Gwei
assert bal1 - bal2 == int(amount*10000*szabo*100) + (21000 + gas_newAccount) * gas_price, "Test gas v3 1:balance is not as expected"
elif j == 2: # overhead price 900 Gwei, storage price 1350 Gwei, inclusion price 0 Gwei
assert bal1 - bal2 == int(amount*10000*szabo*100) + (21000 - int(21000 * (1350 - 900) / 1350) + gas_newAccount) * gas_price, "Test gas v3 2:balance is not as expected"
elif j == 3: # overhead price 900 Gwei, storage price 1800 Gwei, inclusion price 300 Gwei
assert bal1 - bal2 == int(amount*10000*szabo*100) + (21000 - int(21000 * (1800 - 900) / (1800 + 300)) + int(gas_newAccount * 1800 / (1800 + 300))) * gas_price, "Test gas v3 3:balance is not as expected"

validate_all_balances()

Utils.Print("checking %s for errors" % (nodeStdErrDir))
foundErr = False
stdErrFile = open(nodeStdErrDir, "r")
Expand Down

0 comments on commit 84437ee

Please sign in to comment.