Skip to content

Commit

Permalink
Fixes to eos-evm-miner setup/usage/integration.
Browse files Browse the repository at this point in the history
eos-evm-miner currently relies on the eosio.evm account, so switch to using eosio.evm over evmevmevmevm.

Update miner configuration via setting private key, account name, rpc endpoint, and port for the test configuration.

Fix eos-evm-node and eos-evm-rpc and eos-evm-miner being spun up in process daemon so that their respective processes can be cleaned up correctly. Fixes orphaned test processes.

Add missing eos-evm-node argument ship-core-account now that account name has changed.
  • Loading branch information
oschwaldp-oci committed Aug 9, 2023
1 parent a636c9e commit 4808a06
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
1 change: 1 addition & 0 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ jobs:
pushd eos-evm-miner
echo "EVM_MINER_ROOT=$(pwd)" >> "$GITHUB_OUTPUT"
npm install
npm build
popd
- name: Test Leap Integration
Expand Down
47 changes: 29 additions & 18 deletions tests/nodeos_eos_evm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import json
import shutil
import shlex
import signal
import subprocess
import sys
Expand Down Expand Up @@ -123,14 +124,23 @@ def interact_with_storage_contract(dest, nonce):
return nonce

def setEosEvmMinerEnv():
os.environ["PRIVATE_KEY"]="5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
os.environ["MINER_ACCOUNT"]="evmtester"
os.environ["RPC_ENDPOINTS"]="http://127.0.0.1:8888|http://192.168.1.1:8888"
os.environ["PORT"]="50305"
os.environ["PRIVATE_KEY"]=f"{minerAcc.activePrivateKey}"
os.environ["MINER_ACCOUNT"]=f"{minerAcc.name}"
os.environ["RPC_ENDPOINTS"]="http://127.0.0.1:8888"
os.environ["PORT"]="18888"
os.environ["LOCK_GAS_PRICE"]="true"
os.environ["MINER_PERMISSION"]="active"
os.environ["EXPIRE_SEC"]="60"

Utils.Print(f"Set up configuration of eos-evm-miner via environment variables.")
Utils.Print(f"PRIVATE_KEY: {os.environ.get('PRIVATE_KEY')}")
Utils.Print(f"MINER_ACCOUNT: {os.environ.get('MINER_ACCOUNT')}")
Utils.Print(f"RPC_ENDPOINTS: {os.environ.get('RPC_ENDPOINTS')}")
Utils.Print(f"PORT: {os.environ.get('PORT')}")
Utils.Print(f"LOCK_GAS_PRICE: {os.environ.get('LOCK_GAS_PRICE')}")
Utils.Print(f"MINER_PERMISSION: {os.environ.get('MINER_PERMISSION')}")
Utils.Print(f"EXPIRE_SEC: {os.environ.get('EXPIRE_SEC')}")

def processUrllibRequest(endpoint, payload={}, silentErrors=False, exitOnError=False, exitMsg=None, returnType=ReturnType.json):
cmd = f"{endpoint}"
req = urllib.request.Request(cmd, method="POST")
Expand Down Expand Up @@ -265,10 +275,9 @@ def makeReservedEvmAddress(account):
Utils.errorExit("FAILURE - create keys")

evmAcc = accounts[0]
evmAcc.name = "evmevmevmevm"
evmAcc.name = "eosio.evm"
testAcc = accounts[1]
txWrapAcc = accounts[2]
minerAcc = txWrapAcc
minerAcc = accounts[2]

testWalletName="test"

Expand Down Expand Up @@ -302,10 +311,10 @@ def makeReservedEvmAddress(account):
prodNode.publishContract(evmAcc, contractDir, wasmFile, abiFile, waitForTransBlock=True)

# add eosio.code permission
cmd="set account permission evmevmevmevm active --add-code -p evmevmevmevm@active"
cmd="set account permission eosio.evm active --add-code -p eosio.evm@active"
prodNode.processCleosCmd(cmd, cmd, silentErrors=True, returnType=ReturnType.raw)

trans = prodNode.pushMessage(evmAcc.name, "init", '{{"chainid":15555, "fee_params": {{"gas_price": "10000000000", "miner_cut": 100000, "ingress_bridge_fee": "0.0000 {0}"}}}}'.format(CORE_SYMBOL), '-p evmevmevmevm')
trans = prodNode.pushMessage(evmAcc.name, "init", '{{"chainid":15555, "fee_params": {{"gas_price": "10000000000", "miner_cut": 100000, "ingress_bridge_fee": "0.0000 {0}"}}}}'.format(CORE_SYMBOL), '-p eosio.evm')
prodNode.waitForTransBlockIfNeeded(trans[1], True)
transId=prodNode.getTransId(trans[1])
blockNum = prodNode.getBlockNumByTransId(transId)
Expand Down Expand Up @@ -346,7 +355,7 @@ def makeReservedEvmAddress(account):
trans=prodNode.pushMessage(evmAcc.name, "open", '[{0}]'.format(minerAcc.name), '-p {0}'.format(minerAcc.name))

#
# Setup eos-evm-minder
# Setup eos-evm-miner
#
if useMiner is not None:
setEosEvmMinerEnv()
Expand All @@ -357,12 +366,12 @@ def makeReservedEvmAddress(account):
os.makedirs(dataDir)
outFile = open(outDir, "w")
errFile = open(errDir, "w")
cmd = "npm run mine"
cmd = "node dist/index.js"
Utils.Print("Launching: %s" % cmd)
eosEvmMinerPOpen=subprocess.Popen(cmd, stdout=outFile, stderr=errFile, shell=True, cwd=useMiner)
cmdArr=shlex.split(cmd)
eosEvmMinerPOpen=subprocess.Popen(cmdArr, stdout=outFile, stderr=errFile, cwd=useMiner)
time.sleep(10) # let miner start up


Utils.Print("Transfer initial balances")

# init with 1 Million EOS
Expand Down Expand Up @@ -483,7 +492,7 @@ def makeReservedEvmAddress(account):
Utils.Print("Generated EVM json genesis file in: %s" % genesisJson)
Utils.Print("")
Utils.Print("You can now run:")
Utils.Print(" eos-evm-node --plugin=blockchain_plugin --ship-endpoint=127.0.0.1:8999 --genesis-json=%s --chain-data=/tmp/data --verbosity=5" % genesisJson)
Utils.Print(" eos-evm-node --plugin=blockchain_plugin --ship-core-account=eosio.evm --ship-endpoint=127.0.0.1:8999 --genesis-json=%s --chain-data=/tmp/data --verbosity=5" % genesisJson)
Utils.Print(" eos-evm-rpc --eos-evm-node=127.0.0.1:8080 --http-port=0.0.0.0:8881 --chaindata=/tmp/data --api-spec=eth,debug,net,trace")
Utils.Print("")

Expand Down Expand Up @@ -650,9 +659,10 @@ def makeReservedEvmAddress(account):
os.makedirs(dataDir)
outFile = open(nodeStdOutDir, "w")
errFile = open(nodeStdErrDir, "w")
cmd = f"{eosEvmBuildRoot}/bin/eos-evm-node --plugin=blockchain_plugin --ship-endpoint=127.0.0.1:8999 --genesis-json={genesisJson} --verbosity=5 --nocolor=1 --chain-data={dataDir}"
cmd = f"{eosEvmBuildRoot}/bin/eos-evm-node --plugin=blockchain_plugin --ship-core-account=eosio.evm --ship-endpoint=127.0.0.1:8999 --genesis-json={genesisJson} --verbosity=5 --nocolor=1 --chain-data={dataDir}"
Utils.Print(f"Launching: {cmd}")
evmNodePOpen=Utils.delayedCheckOutput(cmd, stdout=outFile, stderr=errFile)
cmdArr=shlex.split(cmd)
evmNodePOpen=Utils.delayedCheckOutput(cmdArr, stdout=outFile, stderr=errFile)

time.sleep(10) # allow time to sync trxs

Expand All @@ -663,13 +673,14 @@ def makeReservedEvmAddress(account):
errFile = open(rpcStdErrDir, "w")
cmd = f"{eosEvmBuildRoot}/bin/eos-evm-rpc --eos-evm-node=127.0.0.1:8080 --http-port=0.0.0.0:8881 --chaindata={dataDir} --api-spec=eth,debug,net,trace"
Utils.Print(f"Launching: {cmd}")
evmRPCPOpen=Utils.delayedCheckOutput(cmd, stdout=outFile, stderr=errFile)
cmdArr=shlex.split(cmd)
evmRPCPOpen=Utils.delayedCheckOutput(cmdArr, stdout=outFile, stderr=errFile)

# Validate all balances are the same on both sides
rows=prodNode.getTable(evmAcc.name, evmAcc.name, "account")
for row in rows['rows']:
Utils.Print("Checking 0x{0} balance".format(row['eth_address']))
r = 0
r = -1
try:
r = w3.eth.get_balance(Web3.to_checksum_address('0x'+row['eth_address']))
except:
Expand Down

0 comments on commit 4808a06

Please sign in to comment.