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

[1.0] savanna transition integration test for EVM #284

Merged
merged 7 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
26 changes: 16 additions & 10 deletions tests/nodeos_eos_evm_gasparam_fork_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
Print=Utils.Print
errorExit=Utils.errorExit

def get_raw_transaction(signed_trx):
if hasattr(signed_trx, 'raw_transaction'):
return signed_trx.raw_transaction
else:
return signed_trx.rawTransaction

def analyzeBPs(bps0, bps1, expectDivergence):
start=0
index=None
Expand Down Expand Up @@ -198,7 +204,7 @@ def interact_with_storage_contract(dest, nonce):
chainId=evmChainId
), evmSendKey)

actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:]}
actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(get_raw_transaction(signed_trx))[2:]}
retValue = prodNode.pushMessage(evmAcc.name, "pushtx", json.dumps(actData), '-p {0}'.format(minerAcc.name))
assert retValue[0], "pushtx to ETH contract failed."
Utils.Print("\tBlock#", retValue[1]["processed"]["block_num"])
Expand Down Expand Up @@ -486,7 +492,7 @@ def makeReservedEvmAddress(account):
chainId=evmChainId
), evmSendKey)

actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:]}
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))
prodNode.waitForTransBlockIfNeeded(trans[1], True)

Expand All @@ -512,7 +518,7 @@ def makeReservedEvmAddress(account):
chainId=evmChainId
), evmSendKey)

actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:]}
actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(get_raw_transaction(signed_trx))[2:]}
Utils.Print("Send balance again, with correct nonce")
retValue = prodNode.pushMessage(evmAcc.name, "pushtx", json.dumps(actData), '-p {0}'.format(minerAcc.name), silentErrors=True)
time.sleep(1.0)
Expand All @@ -532,7 +538,7 @@ def makeReservedEvmAddress(account):
chainId=evmChainId
), evmSendKey)

actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:]}
actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(get_raw_transaction(signed_trx))[2:]}
Utils.Print("Send balance again, with invalid chainid")
retValue = prodNode.pushMessage(evmAcc.name, "pushtx", json.dumps(actData), '-p {0}'.format(minerAcc.name), silentErrors=True)
time.sleep(1.0)
Expand Down Expand Up @@ -565,7 +571,7 @@ def makeReservedEvmAddress(account):
data=Web3.to_bytes(hexstr='608060405234801561001057600080fd5b506101b6806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80632e64cec11461003b5780636057361d14610059575b600080fd5b610043610075565b604051610050919061013f565b60405180910390f35b610073600480360381019061006e9190610103565b61007e565b005b60008054905090565b806000819055503373ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040516100e3919061013f565b60405180910390a350565b6000813590506100fd81610169565b92915050565b60006020828403121561011957610118610164565b5b6000610127848285016100ee565b91505092915050565b6101398161015a565b82525050565b60006020820190506101546000830184610130565b92915050565b6000819050919050565b600080fd5b6101728161015a565b811461017d57600080fd5b5056fea264697066735822122061ba78daf70a6edb2db7cbb1dbac434da1ba14ec0e009d4df8907b8c6ee4d63264736f6c63430008070033'),
chainId=evmChainId
), evmSendKey)
actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:]}
actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(get_raw_transaction(signed_trx))[2:]}
retValue = prodNode.pushMessage(evmAcc.name, "pushtx", json.dumps(actData), '-p {0}'.format(minerAcc.name), silentErrors=True)
time.sleep(1.0)
assert retValue[0], f"push trx should have succeeded: {retValue}"
Expand Down Expand Up @@ -705,7 +711,7 @@ def makeReservedEvmAddress(account):
data=b'',
chainId=evmChainId
), evmSendKey)
actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:]}
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(1.0)
prodNode.waitForTransBlockIfNeeded(trans[1], True)
Expand Down Expand Up @@ -752,7 +758,7 @@ def makeReservedEvmAddress(account):
# Verify header.nonce == 1 (evmversion=1)
evm_block = w3.eth.get_block('latest')
Utils.Print("before fork, the latest evm block is:" + str(evm_block))
assert(evm_block["nonce"].hex() == "0x0000000000000001")
assert(evm_block["nonce"].hex() == "0000000000000001")
assert("consensusParameter" in evm_block)
assert(evm_block["consensusParameter"]["gasFeeParameters"]["gasCodedeposit"] == 477)
assert(evm_block["consensusParameter"]["gasFeeParameters"]["gasNewaccount"] == 165519)
Expand Down Expand Up @@ -911,7 +917,7 @@ def makeReservedEvmAddress(account):
data=b'',
chainId=evmChainId
), evmSendKey)
actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:]}
actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(get_raw_transaction(signed_trx))[2:]}

# push transaction to node0's minor fork (proda, prodb)
trans = prodNode.pushMessage(evmAcc.name, "pushtx", json.dumps(actData), '-p {0}'.format(minerAcc.name), silentErrors=False)
Expand All @@ -936,7 +942,7 @@ def makeReservedEvmAddress(account):
# verify eos-evm-node get the new gas parameter from the minor fork
evm_block = w3.eth.get_block('latest')
Utils.Print("in minor fork, the latest evm block is:" + str(evm_block))
assert(evm_block["nonce"].hex() == "0x0000000000000001")
assert(evm_block["nonce"].hex() == "0000000000000001")
assert("consensusParameter" in evm_block)

assert(evm_block["consensusParameter"]["gasFeeParameters"]["gasCodedeposit"] == 573)
Expand Down Expand Up @@ -1040,7 +1046,7 @@ def makeReservedEvmAddress(account):

evm_block = w3.eth.get_block('latest')
Utils.Print("after fork resolved, the latest evm block is:" + str(evm_block))
assert(evm_block["nonce"].hex() == "0x0000000000000001")
assert(evm_block["nonce"].hex() == "0000000000000001")
assert("consensusParameter" in evm_block)

assert(evm_block["consensusParameter"]["gasFeeParameters"]["gasCodedeposit"] == 477)
Expand Down
72 changes: 63 additions & 9 deletions tests/nodeos_eos_evm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def toDict(dictToParse):
extraNodeosArgs="--contracts-console --resource-monitor-not-shutdown-on-threshold-exceeded"

Print("Stand up cluster")
if cluster.launch(pnodes=pnodes, totalNodes=total_nodes, extraNodeosArgs=extraNodeosArgs, specificExtraNodeosArgs=specificExtraNodeosArgs,delay=5) is False:
if cluster.launch(pnodes=pnodes, totalNodes=total_nodes, extraNodeosArgs=extraNodeosArgs, specificExtraNodeosArgs=specificExtraNodeosArgs,loadSystemContract=False,delay=5) is False:
errorExit("Failed to stand up eos cluster.")

Print ("Wait for Cluster stabilization")
Expand Down Expand Up @@ -313,16 +313,16 @@ def toDict(dictToParse):
# create accounts via eosio as otherwise a bid is needed
for account in accounts:
Print("Create new account %s via %s" % (account.name, cluster.eosioAccount.name))
trans=nonProdNode.createInitializeAccount(account, cluster.eosioAccount, stakedDeposit=0, waitForTransBlock=True, stakeNet=10000, stakeCPU=10000, buyRAM=10000000, exitOnError=True)

trans=nonProdNode.createAccount(account, cluster.eosioAccount,0,waitForTransBlock=True)

# max supply 1000000000.0000 (1 Billion)
transferAmount="100000000.0000 {0}".format(CORE_SYMBOL) # 100 Million
transferAmount="60000000.0000 {0}".format(CORE_SYMBOL)
if account.name == evmAcc.name:
transferAmount="58999999.0000 {0}".format(CORE_SYMBOL)

Print("Transfer funds %s from account %s to %s" % (transferAmount, cluster.eosioAccount.name, account.name))
nonProdNode.transferFunds(cluster.eosioAccount, account, transferAmount, "test transfer", waitForTransBlock=True)
if account.name == evmAcc.name:
# stake more for evmAcc so it has a smaller balance, during setup of addys below the difference will be transferred in
trans=nonProdNode.delegatebw(account, 20000000.0000 + numAddys*1000000.0000, 20000001.0000, waitForTransBlock=True, exitOnError=True)
else:
trans=nonProdNode.delegatebw(account, 20000000.0000, 20000000.0000, waitForTransBlock=True, exitOnError=True)

contractDir=eosEvmContractRoot + "/evm_runtime"
wasmFile="evm_runtime.wasm"
Expand Down Expand Up @@ -1120,14 +1120,68 @@ def get_block(num):
Utils.Print(" Found ERROR in EOS EVM RPC log: ", line)
foundErr = True

Utils.Print("Switching to Savanna")
cluster.activateInstantFinality()
time.sleep(2.0)
heifner marked this conversation as resolved.
Show resolved Hide resolved

info = cluster.biosNode.getInfo(exitOnError=True)
assert (info["head_block_num"] - info["last_irreversible_block_num"]) < 9, "Instant finality enabled LIB diff should be small"


# --------------------------------------------
# EVM -> EOS
# 0x9E126C57330FA71556628e0aabd6B6B6783d99fA private key: 0xba8c9ff38e4179748925335a9891b969214b37dc3723a1754b8b849d3eea9ac0
toAdd = makeReservedEvmAddress(convert_name_to_value(aliceAcc.name))
evmSendKey = "ba8c9ff38e4179748925335a9891b969214b37dc3723a1754b8b849d3eea9ac0"
amount=1.0000
transferAmount="1.0000 {0}".format(CORE_SYMBOL)
bal1 = w3.eth.get_balance(Web3.to_checksum_address("0x9E126C57330FA71556628e0aabd6B6B6783d99fA"))
Print("Using new gas param, transfer funds %s from account %s to reserved account (EVM->EOS)" % (transferAmount, evmAcc.name))
nonce = nonce + 1
signed_trx = w3.eth.account.sign_transaction(dict(
nonce=nonce,
gas=100000, #100k Gas
maxFeePerGas = 900000000000,
maxPriorityFeePerGas = 900000000000,
#gasPrice=900000000000,
to=Web3.to_checksum_address(toAdd),
value=int(amount*10000*szabo*100), # .0001 EOS is 100 szabos
data=b'',
chainId=evmChainId
), evmSendKey)
Print("EVM transaction hash is: %s" % (Web3.to_hex(signed_trx.hash)))
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)
prodNode.waitForTransBlockIfNeeded(trans[1], True)
row4=prodNode.getTableRow(evmAcc.name, evmAcc.name, "account", 4) # 4th balance of this integration test
Utils.Print("\tverify balance from evm-rpc, account row4: ", row4)
bal2 = w3.eth.get_balance(Web3.to_checksum_address("0x9E126C57330FA71556628e0aabd6B6B6783d99fA"))

# balance different = 1.0 EOS (val) + 900(Gwei) (21000(base gas))
assert(bal1 == bal2 + 1000000000000000000 + 900000000000 * 21000)

Utils.Print("try to get transaction %s from evm-rpc" % (Web3.to_hex(signed_trx.hash)))
evm_tx = w3.eth.get_transaction(signed_trx.hash)
tx_dict = toDict(evm_tx)
Utils.Print("evm transaction is %s" % (json.dumps(tx_dict)))
assert(prefix_0x(str(tx_dict["hash"])) == str(Web3.to_hex(signed_trx.hash)))

Utils.Print("try to get transaction receipt %s from evm-rpc" % (Web3.to_hex(signed_trx.hash)))
evm_tx = w3.eth.get_transaction_receipt(signed_trx.hash)
tx_dict = toDict(evm_tx)
Utils.Print("evm transaction receipt is %s" % (json.dumps(tx_dict)))
assert(prefix_0x(str(tx_dict["transactionHash"])) == str(Web3.to_hex(signed_trx.hash)))

validate_all_balances() # validate balances between native & EVM

testSuccessful= not foundErr
if testSuccessful:
Utils.Print("test success, ready to shut down cluster")
else:
Utils.Print("test failed, ready to shut down cluster")

finally:
Utils.Print("test success, shutting down cluster")
Utils.Print("shutting down cluster")
TestHelper.shutdown(cluster, walletMgr, testSuccessful=testSuccessful, dumpErrorDetails=dumpErrorDetails)
if killEosInstances:
Utils.Print("killing EOS instances")
Expand Down
Loading