From 9ca98d386339b40dc8afdcacd4d6c41bd7542e8c Mon Sep 17 00:00:00 2001 From: kayan Date: Mon, 26 Aug 2024 19:45:05 +0800 Subject: [PATCH 1/6] savanna transition test --- tests/nodeos_eos_evm_test.py | 72 +++++++++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 9 deletions(-) diff --git a/tests/nodeos_eos_evm_test.py b/tests/nodeos_eos_evm_test.py index f781d5b..71a3582 100755 --- a/tests/nodeos_eos_evm_test.py +++ b/tests/nodeos_eos_evm_test.py @@ -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") @@ -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" @@ -1120,6 +1120,60 @@ 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) + + 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") @@ -1127,7 +1181,7 @@ def get_block(num): 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") From d23d35ae7bf8f123ff1508d004bf524730d6430b Mon Sep 17 00:00:00 2001 From: kayan Date: Mon, 26 Aug 2024 21:56:39 +0800 Subject: [PATCH 2/6] fix test case --- tests/nodeos_eos_evm_gasparam_fork_test.py | 20 +++++++++++++------- tests/nodeos_eos_evm_test.py | 1 - 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/nodeos_eos_evm_gasparam_fork_test.py b/tests/nodeos_eos_evm_gasparam_fork_test.py index e6f55cc..f97c6e9 100755 --- a/tests/nodeos_eos_evm_gasparam_fork_test.py +++ b/tests/nodeos_eos_evm_gasparam_fork_test.py @@ -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 @@ -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"]) @@ -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) @@ -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) @@ -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) @@ -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}" @@ -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) @@ -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) diff --git a/tests/nodeos_eos_evm_test.py b/tests/nodeos_eos_evm_test.py index 71a3582..381fc23 100755 --- a/tests/nodeos_eos_evm_test.py +++ b/tests/nodeos_eos_evm_test.py @@ -1122,7 +1122,6 @@ def get_block(num): Utils.Print("Switching to Savanna") cluster.activateInstantFinality() - time.sleep(2.0) 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" From 08028af52ed2090cef27edc1c40235e3b9bd51a7 Mon Sep 17 00:00:00 2001 From: kayan Date: Mon, 26 Aug 2024 22:21:59 +0800 Subject: [PATCH 3/6] fix test case --- tests/nodeos_eos_evm_gasparam_fork_test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/nodeos_eos_evm_gasparam_fork_test.py b/tests/nodeos_eos_evm_gasparam_fork_test.py index f97c6e9..8b69d1f 100755 --- a/tests/nodeos_eos_evm_gasparam_fork_test.py +++ b/tests/nodeos_eos_evm_gasparam_fork_test.py @@ -758,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) @@ -942,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) @@ -1046,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) From 1ef4f08fd10101c4918234fd9b7172d1825907e4 Mon Sep 17 00:00:00 2001 From: Kayan <37097018+taokayan@users.noreply.github.com> Date: Tue, 27 Aug 2024 06:54:54 +0800 Subject: [PATCH 4/6] Update nodeos_eos_evm_test.py test with adding back time.sleep --- tests/nodeos_eos_evm_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/nodeos_eos_evm_test.py b/tests/nodeos_eos_evm_test.py index 381fc23..71a3582 100755 --- a/tests/nodeos_eos_evm_test.py +++ b/tests/nodeos_eos_evm_test.py @@ -1122,6 +1122,7 @@ def get_block(num): Utils.Print("Switching to Savanna") cluster.activateInstantFinality() + time.sleep(2.0) 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" From 41dc888d0e1624b55f62e3517c9d8d1d8a8bdc18 Mon Sep 17 00:00:00 2001 From: kayan Date: Tue, 27 Aug 2024 14:53:11 +0800 Subject: [PATCH 5/6] switch to instant finality at launch --- tests/nodeos_eos_evm_test.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tests/nodeos_eos_evm_test.py b/tests/nodeos_eos_evm_test.py index 381fc23..a8981d8 100755 --- a/tests/nodeos_eos_evm_test.py +++ b/tests/nodeos_eos_evm_test.py @@ -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,loadSystemContract=False,delay=5) is False: + if cluster.launch(pnodes=pnodes, totalNodes=total_nodes, extraNodeosArgs=extraNodeosArgs, specificExtraNodeosArgs=specificExtraNodeosArgs,loadSystemContract=False,activateIF=True,delay=5) is False: errorExit("Failed to stand up eos cluster.") Print ("Wait for Cluster stabilization") @@ -284,6 +284,10 @@ def toDict(dictToParse): errorExit("Cluster never stabilized") Print ("Cluster stabilized") + Utils.Print("make sure instant finality is switched") + 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" + prodNode = cluster.getNode(0) nonProdNode = cluster.getNode(1) @@ -1120,13 +1124,6 @@ def get_block(num): Utils.Print(" Found ERROR in EOS EVM RPC log: ", line) foundErr = True - Utils.Print("Switching to Savanna") - cluster.activateInstantFinality() - - 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 From c3c25aa4d2f930f06e1d26878219f140b2d03fcb Mon Sep 17 00:00:00 2001 From: kayan Date: Tue, 27 Aug 2024 14:58:30 +0800 Subject: [PATCH 6/6] remove duplicate tests --- tests/nodeos_eos_evm_test.py | 46 ------------------------------------ 1 file changed, 46 deletions(-) diff --git a/tests/nodeos_eos_evm_test.py b/tests/nodeos_eos_evm_test.py index a8981d8..0955d5b 100755 --- a/tests/nodeos_eos_evm_test.py +++ b/tests/nodeos_eos_evm_test.py @@ -1124,52 +1124,6 @@ def get_block(num): Utils.Print(" Found ERROR in EOS EVM RPC log: ", line) foundErr = True - # -------------------------------------------- - # 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")