Skip to content

Commit

Permalink
Merge pull request #254 from eosnetworkfoundation/elmato/kayan_dynami…
Browse files Browse the repository at this point in the history
…c_chainid

[1.0] dynamic chainid
  • Loading branch information
elmato authored Jul 10, 2024
2 parents d462226 + b22440c commit 49ff777
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion external/silkworm
2 changes: 1 addition & 1 deletion src/rpc_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void rpc_plugin::set_program_options( appbase::options_description& cli, appbase
"maximum number of rpc readers")
("api-spec", boost::program_options::value<std::string>()->default_value("eth"),
"comma separated api spec, possible values: debug,engine,eth,net,parity,erigon,txpool,trace,web3")
("chain-id", boost::program_options::value<uint32_t>()->default_value(silkworm::kEOSEVMLocalTestnetConfig.chain_id),
("chain-id", boost::program_options::value<uint32_t>()->default_value(25555),
"override chain-id")
("rpc-quirk-flag", boost::program_options::value<uint64_t>()->default_value(0),
"rpc quirk flag")
Expand Down
42 changes: 24 additions & 18 deletions tests/nodeos_eos_evm_different_token_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@
evmRPCPOpen = None
eosEvmMinerPOpen = None

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

def interact_with_storage_contract(dest, nonce):
for i in range(1, 5): # execute a few
Utils.Print("Execute ETH contract")
Expand All @@ -111,7 +117,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 @@ -383,7 +389,7 @@ def getAccountGasBalance(node, account):
cmd="set account permission " + defertest2Acc.name + " active --add-code -p " + defertest2Acc.name + "@active"
prodNode.processCleosCmd(cmd, cmd, silentErrors=False, returnType=ReturnType.raw)

trans = prodNode.pushMessage(evmAcc.name, "init", "{\"chainid\":15555, \"token_contract\":\"gasgasgasgas\", \"fee_params\": {\"gas_price\": \"10000000000\", \"miner_cut\": 10000, \"ingress_bridge_fee\": \"0.00000000 GAS\"}}", '-p eosio.evm')
trans = prodNode.pushMessage(evmAcc.name, "init", "{\"chainid\":18888, \"token_contract\":\"gasgasgasgas\", \"fee_params\": {\"gas_price\": \"10000000000\", \"miner_cut\": 10000, \"ingress_bridge_fee\": \"0.00000000 GAS\"}}", '-p eosio.evm')

prodNode.waitForTransBlockIfNeeded(trans[1], True)
transId=prodNode.getTransId(trans[1])
Expand All @@ -398,7 +404,7 @@ def getAccountGasBalance(node, account):
},
"coinbase": "0x0000000000000000000000000000000000000000",
"config": {
"chainId": 15555,
"chainId": 18888,
"homesteadBlock": 0,
"eip150Block": 0,
"eip155Block": 0,
Expand Down Expand Up @@ -455,7 +461,7 @@ def getAccountGasBalance(node, account):
if not (i+1) % 20: time.sleep(1)

Utils.Print("Send balance")
evmChainId = 15555
evmChainId = 18888
fromAdd = "f39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
toAdd = '0x9edf022004846bc987799d552d1b8485b317b7ed'
amount = 100
Expand All @@ -473,7 +479,7 @@ def getAccountGasBalance(node, 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 @@ -499,7 +505,7 @@ def getAccountGasBalance(node, 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)
assert retValue[0], f"push trx should have succeeded: {retValue}"
Expand All @@ -518,14 +524,14 @@ def getAccountGasBalance(node, 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)
assert not retValue[0], f"push trx should have failed: {retValue}"

# correct values for continuing
nonce -= 1
evmChainId = 15555
evmChainId = 18888

Utils.Print("Simple Solidity contract")
# // SPDX-License-Identifier: GPL-3.0
Expand All @@ -540,7 +546,7 @@ def getAccountGasBalance(node, account):
# }
# }
nonce += 1
evmChainId = 15555
evmChainId = 18888
gasP = getGasPrice()
signed_trx = w3.eth.account.sign_transaction(dict(
nonce=nonce,
Expand All @@ -550,7 +556,7 @@ def getAccountGasBalance(node, 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:]}
retValue = prodNode.pushMessage(evmAcc.name, "pushtx", json.dumps(actData), '-p {0}'.format(minerAcc.name))
assert retValue[0], f"push trx should have succeeded: {retValue}"
nonce = interact_with_storage_contract(makeContractAddress(fromAdd, nonce), nonce)
Expand Down Expand Up @@ -675,7 +681,7 @@ def getAccountGasBalance(node, 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=True)
prodNode.waitForTransBlockIfNeeded(trans[1], True)
row4=prodNode.getTableRow(evmAcc.name, evmAcc.name, "account", 4) # 4th balance of this integration test
Expand Down Expand Up @@ -708,7 +714,7 @@ def getAccountGasBalance(node, 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=True)
prodNode.waitForTransBlockIfNeeded(trans[1], True)
row4=prodNode.getTableRow(evmAcc.name, evmAcc.name, "account", 4) # 4th balance of this integration test
Expand Down Expand Up @@ -757,12 +763,12 @@ def getAccountGasBalance(node, account):
gas=1000000,
gasPrice=getGasPrice(),
data=Web3.to_bytes(hexstr='608060405234801561001057600080fd5b50610284806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80630a79309b1461003b578063d09de08a1461006b575b600080fd5b61005560048036038101906100509190610176565b610075565b60405161006291906101bc565b60405180910390f35b6100736100bd565b005b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600081548092919061010c90610206565b9190505550565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061014382610118565b9050919050565b61015381610138565b811461015e57600080fd5b50565b6000813590506101708161014a565b92915050565b60006020828403121561018c5761018b610113565b5b600061019a84828501610161565b91505092915050565b6000819050919050565b6101b6816101a3565b82525050565b60006020820190506101d160008301846101ad565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610211826101a3565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610243576102426101d7565b5b60018201905091905056fea264697066735822122026d27f46966ee75c7a8b2a43923c8796438013de730eb9eec6c24ff581913d6864736f6c63430008120033'),
chainId=15555
chainId=18888
), accSpecialKey)

# Deploy "Increment" contract
increment_contract = makeContractAddress(accSpecialAdd, special_nonce)
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=True)
prodNode.waitForTransBlockIfNeeded(trans[1], True);

Expand All @@ -774,10 +780,10 @@ def getAccountGasBalance(node, account):
gasPrice=getGasPrice(),
to=Web3.to_checksum_address(increment_contract),
data=Web3.to_bytes(hexstr='D09DE08A'), # sha3(increment())=0xD09DE08A
chainId=15555
chainId=18888
), accSpecialKey)

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)
prodNode.waitForTransBlockIfNeeded(trans[1], True);

Expand Down Expand Up @@ -835,7 +841,7 @@ def getAccountGasBalance(node, account):
data=b'',
chainId=evmChainId
), evmSendKey)
actData = {"recipient":defertestAcc.name, "account":evmAcc.name, "miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:], "rlptx2":Web3.to_hex(signed_trx2.rawTransaction)[2:]}
actData = {"recipient":defertestAcc.name, "account":evmAcc.name, "miner":minerAcc.name, "rlptx":Web3.to_hex(get_raw_transaction(signed_trx))[2:], "rlptx2":Web3.to_hex(get_raw_transaction(signed_trx2))[2:]}
trans = prodNode.pushMessage(defertest2Acc.name, "notifytest", json.dumps(actData), '-p {0}'.format(defertest2Acc.name), silentErrors=False)
prodNode.waitForTransBlockIfNeeded(trans[1], True)
row4=prodNode.getTableRow(evmAcc.name, evmAcc.name, "account", 4) # 4th balance of this integration test
Expand Down Expand Up @@ -971,7 +977,7 @@ def get_block(num):
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)
prodNode.waitForTransBlockIfNeeded(trans[1], True)
row4=prodNode.getTableRow(evmAcc.name, evmAcc.name, "account", 4) # 4th balance of this integration test
Expand Down

0 comments on commit 49ff777

Please sign in to comment.