Skip to content

Commit

Permalink
Leap integration test workflow updates.
Browse files Browse the repository at this point in the history
Update Web3 functions now using snake case instead of camel case.

Update tx_wrapper index.js to use fetch import over require.

Workflow needs to install some dependencies as documented in test.
  • Loading branch information
oschwaldp-oci committed Jul 25, 2023
1 parent a16a4c2 commit 836fe14
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/contract.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,18 @@ jobs:
- name: Link Leap TestHarness Module (fix for v4 of leap)
run: sudo ln -s /usr/share/leap_testing/tests/TestHarness /usr/lib/python3/dist-packages/TestHarness

- name: Test Leap Integration
- name: Install Test Depedencies
run: |
pip install --upgrade web3
sudo apt install nodejs
sudo apt install npm
npm install eosjs
npm install ethereumjs-util
npm install node-fetch
npm install http-jsonrpc-server
npm install dotenv
npm install is-valid-hostname
- name: Test Leap Integration
run: |
./tests/leap/nodeos_eos_evm_test.py --eos-evm-contract-root ./contract/build --eos-evm-build-root ./build --use-tx-wrapper ./peripherals/tx_wrapper
4 changes: 2 additions & 2 deletions peripherals/tx_wrapper/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { Api, JsonRpc, RpcError } = require("eosjs");
const { JsSignatureProvider } = require("eosjs/dist/eosjs-jssig"); // development only
const fetch = require("node-fetch"); // node only; not needed in browsers
//const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
// const fetch = require("node-fetch"); // node only; not needed in browsers
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
const { TextEncoder, TextDecoder } = require("util"); // node only; native TextEncoder/Decoder

const RpcServer = require("http-jsonrpc-server");
Expand Down
38 changes: 21 additions & 17 deletions tests/leap/nodeos_eos_evm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ def interact_with_storage_contract(dest, nonce):
nonce=nonce,
gas=100000, #100k Gas
gasPrice=gasP,
to=Web3.toChecksumAddress(dest),
to=Web3.to_checksum_address(dest),
value=amount,
data=unhexlify("6057361d00000000000000000000000000000000000000000000000000000000000000%02x" % nonce),
chainId=evmChainId
), evmSendKey)

actData = {"miner":minerAcc.name, "rlptx":Web3.toHex(signed_trx.rawTransaction)[2:]}
actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[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 All @@ -139,6 +139,7 @@ def writeTxWrapperEnv():
PORT="18888"
EOS_EVM_ACCOUNT="evmevmevmevm"
EOS_SENDER="{txWrapAcc.name}"
EOS_PERMISSION="active"
'''
envFile.write(env)

Expand Down Expand Up @@ -187,6 +188,9 @@ def processUrllibRequest(endpoint, payload={}, silentErrors=False, exitOnError=F
unhandledEnumType(returnType)
else:
return None
except:
Utils.Print("Unknown exception occurred during processUrllibRequest")
raise

if exitMsg is not None:
exitMsg=": " + exitMsg
Expand Down Expand Up @@ -221,7 +225,7 @@ def normalize_address(x, allow_blank=False):
return x

def makeContractAddress(sender, nonce):
return Web3.toHex(Web3.keccak(rlp.encode([normalize_address(sender), nonce]))[12:])
return Web3.to_hex(Web3.keccak(rlp.encode([normalize_address(sender), nonce]))[12:])

def makeReservedEvmAddress(account):
bytearr = [0xbb, 0xbb, 0xbb, 0xbb,
Expand Down Expand Up @@ -374,7 +378,7 @@ def makeReservedEvmAddress(account):

# init with 1 Million EOS
for i,k in enumerate(addys):
print("addys: [{0}] [{1}] [{2}]".format(i,k[2:].lower(), len(k[2:])))
Utils.Print("addys: [{0}] [{1}] [{2}]".format(i,k[2:].lower(), len(k[2:])))
transferAmount="1000000.0000 {0}".format(CORE_SYMBOL)
Print("Transfer funds %s from account %s to %s" % (transferAmount, cluster.eosioAccount.name, evmAcc.name))
prodNode.transferFunds(cluster.eosioAccount, evmAcc, transferAmount, "0x" + k[2:].lower(), waitForTransBlock=True)
Expand All @@ -393,13 +397,13 @@ def makeReservedEvmAddress(account):
nonce=nonce,
gas=100000, #100k Gas
gasPrice=gasP,
to=Web3.toChecksumAddress(toAdd),
to=Web3.to_checksum_address(toAdd),
value=amount,
data=b'',
chainId=evmChainId
), evmSendKey)

actData = {"miner":minerAcc.name, "rlptx":Web3.toHex(signed_trx.rawTransaction)[2:]}
actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:]}
trans = prodNode.pushMessage(evmAcc.name, "pushtx", json.dumps(actData), '-p {0}'.format(minerAcc.name))
prodNode.waitForTransBlockIfNeeded(trans[1], True)

Expand All @@ -419,13 +423,13 @@ def makeReservedEvmAddress(account):
nonce=nonce,
gas=100000, #100k Gas
gasPrice=gasP,
to=Web3.toChecksumAddress(toAdd),
to=Web3.to_checksum_address(toAdd),
value=amount,
data=b'',
chainId=evmChainId
), evmSendKey)

actData = {"miner":minerAcc.name, "rlptx":Web3.toHex(signed_trx.rawTransaction)[2:]}
actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[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 @@ -438,13 +442,13 @@ def makeReservedEvmAddress(account):
nonce=nonce,
gas=100000, #100k Gas
gasPrice=gasP,
to=Web3.toChecksumAddress(toAdd),
to=Web3.to_checksum_address(toAdd),
value=amount,
data=b'',
chainId=evmChainId
), evmSendKey)

actData = {"miner":minerAcc.name, "rlptx":Web3.toHex(signed_trx.rawTransaction)[2:]}
actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[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}"
Expand Down Expand Up @@ -472,11 +476,11 @@ def makeReservedEvmAddress(account):
nonce=nonce,
gas=1000000, #5M Gas
gasPrice=gasP,
data=Web3.toBytes(hexstr='608060405234801561001057600080fd5b50610150806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80632e64cec11461003b5780636057361d14610059575b600080fd5b610043610075565b60405161005091906100a1565b60405180910390f35b610073600480360381019061006e91906100ed565b61007e565b005b60008054905090565b8060008190555050565b6000819050919050565b61009b81610088565b82525050565b60006020820190506100b66000830184610092565b92915050565b600080fd5b6100ca81610088565b81146100d557600080fd5b50565b6000813590506100e7816100c1565b92915050565b600060208284031215610103576101026100bc565b5b6000610111848285016100d8565b9150509291505056fea2646970667358fe12209ffe32fe5779018f7ee58886c856a4cfdf550f2df32cec944f57716a3abf4a5964736f6c63430008110033'),
data=Web3.to_bytes(hexstr='608060405234801561001057600080fd5b50610150806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80632e64cec11461003b5780636057361d14610059575b600080fd5b610043610075565b60405161005091906100a1565b60405180910390f35b610073600480360381019061006e91906100ed565b61007e565b005b60008054905090565b8060008190555050565b6000819050919050565b61009b81610088565b82525050565b60006020820190506100b66000830184610092565b92915050565b600080fd5b6100ca81610088565b81146100d557600080fd5b50565b6000813590506100e7816100c1565b92915050565b600060208284031215610103576101026100bc565b5b6000610111848285016100d8565b9150509291505056fea2646970667358fe12209ffe32fe5779018f7ee58886c856a4cfdf550f2df32cec944f57716a3abf4a5964736f6c63430008110033'),
chainId=evmChainId
), evmSendKey)

actData = {"miner":minerAcc.name, "rlptx":Web3.toHex(signed_trx.rawTransaction)[2:]}
actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:]}
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}"
nonce = interact_with_storage_contract(makeContractAddress(fromAdd, nonce), nonce)
Expand Down Expand Up @@ -592,12 +596,12 @@ def makeReservedEvmAddress(account):
nonce=nonce,
gas=100000, #100k Gas
gasPrice=gasP,
to=Web3.toChecksumAddress(toAdd),
to=Web3.to_checksum_address(toAdd),
value=int(amount*10000*szabo*100), # .0001 EOS is 100 szabos
data=b'',
chainId=evmChainId
), evmSendKey)
actData = {"miner":minerAcc.name, "rlptx":Web3.toHex(signed_trx.rawTransaction)[2:]}
actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[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 @@ -625,12 +629,12 @@ def makeReservedEvmAddress(account):
nonce=nonce,
gas=100000, #100k Gas
gasPrice=gasP,
to=Web3.toChecksumAddress(toAdd),
to=Web3.to_checksum_address(toAdd),
value=int(amount*10000*szabo*100),
data=b'',
chainId=evmChainId
), evmSendKey)
actData = {"miner":minerAcc.name, "rlptx":Web3.toHex(signed_trx.rawTransaction)[2:]}
actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[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 @@ -667,7 +671,7 @@ def makeReservedEvmAddress(account):
rows=prodNode.getTable(evmAcc.name, evmAcc.name, "account")
for row in rows['rows']:
Utils.Print("Checking 0x{0} balance".format(row['eth_address']))
r = w3.eth.get_balance(Web3.toChecksumAddress('0x'+row['eth_address']))
r = w3.eth.get_balance(Web3.to_checksum_address('0x'+row['eth_address']))
assert r == int(row['balance'],16), f"{row['eth_address']} {r} != {int(row['balance'],16)}"

foundErr = False
Expand Down

0 comments on commit 836fe14

Please sign in to comment.