Skip to content

Commit

Permalink
Problem: python dependencies in integration tests are old (#1325)
Browse files Browse the repository at this point in the history
* Problem: python dependencies in integration tests are old

Solution:
- update python to 3.11
- update dependencies

fix lint

add eth-bloom

add eth-bloom

use eth_hash inplace of pysha3

gen pb2.py with protoc

fix format

fix format

fix test

Revert "gen pb2.py with protoc"

This reverts commit cbb83ca.

fix dup proto

fix sha

fix web3.py

fix test

cleanup amount_dict

* hexdigest

* remove any_pb2

* fix test

* cleanup

* rm b64encode

---------

Co-authored-by: mmsqe <[email protected]>
  • Loading branch information
yihuang and mmsqe authored Feb 21, 2024
1 parent ef3d26c commit e16b913
Show file tree
Hide file tree
Showing 11 changed files with 1,566 additions and 1,290 deletions.
20 changes: 9 additions & 11 deletions integration_tests/eip712_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import json
from pathlib import Path

import sha3
from eth_hash.auto import keccak
from google.protobuf import any_pb2

from .protobuf.cosmos.bank.v1beta1.tx_pb2 import MsgSend
from .protobuf.cosmos.base.v1beta1.coin_pb2 import Coin
Expand All @@ -18,7 +19,6 @@
)
from .protobuf.ethermint.crypto.v1.ethsecp256k1.keys_pb2 import PubKey as EPubKey
from .protobuf.ethermint.types.v1.web3_pb2 import ExtensionOptionsWeb3Tx
from .protobuf.google.protobuf.any_pb2 import Any

LEGACY_AMINO = 127
SIGN_DIRECT = 1
Expand Down Expand Up @@ -212,9 +212,8 @@ def create_transaction_with_multiple_messages(
account_number,
)

hash_amino = sha3.keccak_256()
hash_amino.update(sig_doc_amino.SerializeToString())
to_sign_amino = hash_amino.hexdigest()
hash_amino = keccak.new(sig_doc_amino.SerializeToString())
to_sign_amino = hash_amino.digest()

# SignDirect
sig_info_direct = create_signer_info(
Expand All @@ -230,19 +229,18 @@ def create_transaction_with_multiple_messages(
chain_id,
account_number,
)
hash_direct = sha3.keccak_256()
hash_direct.update(sign_doc_direct.SerializeToString())
to_sign_direct = hash_direct.hexdigest()
hash_direct = keccak.new(sign_doc_direct.SerializeToString())
to_sign_direct = hash_direct.digest()
return {
"legacyAmino": {
"body": body,
"authInfo": auth_info_amino,
"signBytes": base64.b64decode(to_sign_amino),
"signBytes": to_sign_amino,
},
"signDirect": {
"body": body,
"authInfo": auth_info_direct,
"signBytes": base64.b64decode(to_sign_direct),
"signBytes": to_sign_direct,
},
}

Expand All @@ -256,7 +254,7 @@ def create_body_with_multiple_messages(messages, memo):


def create_any_message(msg):
any = Any()
any = any_pb2.Any()
any.Pack(msg["message"], "/")
return any

Expand Down
7 changes: 3 additions & 4 deletions integration_tests/gravity_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sha3
import toml
from eth_account.account import Account
from eth_hash.auto import keccak
from eth_utils import to_checksum_address
from hexbytes import HexBytes
from pystarport import ports
Expand Down Expand Up @@ -131,11 +131,10 @@ def prepare_gravity(custom_cronos, custom_geth):
print("gravity contract deployed", contract.address)

# make all the orchestrator "Relayer" roles
k_relayer = sha3.keccak_256()
k_relayer.update(b"RELAYER")
k_relayer = keccak.new(b"RELAYER")
for _, address in enumerate(eth_addresses):
set_role_tx = contract.functions.grantRole(
k_relayer.hexdigest(), address
k_relayer.digest().hex(), address
).build_transaction({"from": admin.address})
set_role_receipt = send_transaction(w3, set_role_tx, admin.key)
print("set_role_tx", set_role_receipt)
Expand Down
2,639 changes: 1,476 additions & 1,163 deletions integration_tests/poetry.lock

Large diffs are not rendered by default.

38 changes: 0 additions & 38 deletions integration_tests/protobuf/google/protobuf/any_pb2.py

This file was deleted.

43 changes: 20 additions & 23 deletions integration_tests/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,27 @@ description = ""
authors = ["chain-dev <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.8"
pytest = "^7.0.1"
pytest-github-actions-annotate-failures = "^0.1.1"
flake8 = "^4.0.1"
black = "^22.3.0"
flake8-black = "^0.3.2"
flake8-isort = "^6.1.1"
pep8-naming = "^0.11.1"
protobuf = "^3.13.0"
grpcio = "^1.53.2"
pyyaml = "^6.0.1"
python-dateutil = "^2.8.1"
web3 = "^6.0.0b6"
eth-bloom = "^1.0.4"
python-dotenv = "^0.19.2"
pystarport = { git = "https://github.com/crypto-com/pystarport.git", branch = "main", rev = "403b845" }
websockets = "^10.3"
toml = "^0.10.2"
pysha3 = "^1.0.2"
jsonnet = "^0.18.0"
eth-account = "^0.7.0"
python = "^3.9"
pytest = "^8.0"
pytest-github-actions-annotate-failures = "^0.2"
flake8 = "^7.0"
black = "^24.2"
flake8-black = "^0.3"
flake8-isort = "^6.1"
pep8-naming = "^0.13"
protobuf = "^4.25"
python-dateutil = "^2.8"
web3 = "^6.15"
python-dotenv = "^1.0"
pystarport = { git = "https://github.com/crypto-com/pystarport.git", branch = "main" }
websockets = "^12.0"
toml = "^0"
jsonnet = "^0"
eth-account = "^0.11"
cprotobuf = "^0.1.11"
pathspec = "^0.10.1"
flaky = "^3.7.0"
flaky = "^3.7"
eth-bloom = "^3.0"
eth-hash = "^0"

[tool.poetry.dev-dependencies]

Expand Down
4 changes: 2 additions & 2 deletions integration_tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ def test_event_log_filter(cronos):
mycontract = deploy_contract(w3, CONTRACTS["Greeter"])
assert "Hello" == mycontract.caller.greet()
current_height = hex(w3.eth.get_block_number())
event_filter = mycontract.events.ChangeGreeting.createFilter(
event_filter = mycontract.events.ChangeGreeting.create_filter(
fromBlock=current_height
)

tx = mycontract.functions.setGreeting("world").build_transaction()
tx_receipt = send_transaction(w3, tx)
log = mycontract.events.ChangeGreeting().processReceipt(tx_receipt)[0]
log = mycontract.events.ChangeGreeting().process_receipt(tx_receipt)[0]
assert log["event"] == "ChangeGreeting"
assert tx_receipt.status == 1
new_entries = event_filter.get_new_entries()
Expand Down
4 changes: 1 addition & 3 deletions integration_tests/test_gravity.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ def test_multiple_attestation_processing(gravity):
print("fund all accounts")
for name in ACCOUNTS:
address = ACCOUNTS[name].address
send_transaction(
geth, {"to": address, "value": 10**17}, KEYS["validator"]
)
send_transaction(geth, {"to": address, "value": 10**17}, KEYS["validator"])
tx = erc20.functions.transfer(address, amount).build_transaction(
{"from": ADDRS["validator"]}
)
Expand Down
37 changes: 30 additions & 7 deletions integration_tests/test_ibc_rly.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,35 @@ def ibc(request, tmp_path_factory):
)


def amount_dict(amt, denom):
return [
AttributeDict(
{
"amount": amt,
"denom": denom,
}
)
]


def coin_received(receiver, amt, denom):
return {
"receiver": receiver,
"amount": [(amt, denom)],
"amount": amount_dict(amt, denom),
}


def coin_base(minter, amt, denom):
return {
"minter": minter,
"amount": [(amt, denom)],
"amount": amount_dict(amt, denom),
}


def coin_spent(spender, amt, denom):
return {
"spender": spender,
"amount": [(amt, denom)],
"amount": amount_dict(amt, denom),
}


Expand All @@ -98,14 +109,14 @@ def transfer(src, dst, amt, denom):
return {
"recipient": dst,
"sender": src,
"amount": [(amt, denom)],
"amount": amount_dict(amt, denom),
}


def burn(burner, amt, denom):
return {
"burner": burner,
"amount": [(amt, denom)],
"amount": amount_dict(amt, denom),
}


Expand All @@ -117,7 +128,13 @@ def recv_packet(seq, src, dst, amt, denom):
"packetDstPort": "transfer",
"packetDstChannel": channel,
"connectionId": "connection-0",
"packetDataHex": (dst, src, [(amt, denom)]),
"packetDataHex": AttributeDict(
{
"receiver": dst,
"sender": src,
"amount": amount_dict(amt, denom),
}
),
}


Expand Down Expand Up @@ -146,7 +163,13 @@ def write_ack(seq, src, dst, amt, denom):
"packetDstPort": "transfer",
"packetDstChannel": channel,
"connectionId": "connection-0",
"packetDataHex": (dst, src, [(amt, denom)]),
"packetDataHex": AttributeDict(
{
"receiver": dst,
"sender": src,
"amount": amount_dict(amt, denom),
}
),
}


Expand Down
4 changes: 2 additions & 2 deletions integration_tests/test_ica_precompile.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def submit_msgs(
print(f"wait for {timeout_in_s}s")
wait_for_check_tx(cli_host, ica_address, num_txs, timeout_in_s)
else:
logs = event.getLogs()
logs = event.get_logs()
assert len(logs) > 0
assert logs[0].args == AttributeDict(
{
Expand Down Expand Up @@ -195,7 +195,7 @@ def wait_for_packet_log(start, event, channel_id, seq, status):
)

def check_log():
logs = event.getLogs(fromBlock=start)
logs = event.get_logs(fromBlock=start)
return len(logs) > 0 and logs[-1].args == expected

wait_for_fn("packet log", check_log)
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/test_pruned_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_pruned_node(cronos):
{
"from": "0x57f96e6B86CdeFdB3d412547816a82E3E0EbF9D2",
"gas": exp_gas_used,
"input": (
"input": HexBytes(
"0xa9059cbb000000000000000000000000378c50d9264c63f3f92b806d4ee56e"
"9d86ffb3ec000000000000000000000000000000000000000000000000000000"
"000000000a"
Expand Down
58 changes: 22 additions & 36 deletions nix/testenv.nix
Original file line number Diff line number Diff line change
@@ -1,40 +1,26 @@
{ poetry2nix, lib, python310 }:
{ poetry2nix, lib, python311 }:
poetry2nix.mkPoetryEnv {
projectDir = ../integration_tests;
python = python310;
overrides = poetry2nix.overrides.withDefaults (lib.composeManyExtensions [
(self: super:
let
buildSystems = {
eth-bloom = [ "setuptools" ];
pystarport = [ "poetry-core" ];
cprotobuf = [ "setuptools" ];
durations = [ "setuptools" ];
multitail2 = [ "setuptools" ];
pytest-github-actions-annotate-failures = [ "setuptools" ];
flake8-black = [ "setuptools" ];
flake8-isort = [ "hatchling" ];
multiaddr = [ "setuptools" ];
};
in
lib.mapAttrs
(attr: systems: super.${attr}.overridePythonAttrs
(old: {
nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ map (a: self.${a}) systems;
}))
buildSystems
)
(self: super: {
eth-bloom = super.eth-bloom.overridePythonAttrs {
preConfigure = ''
substituteInPlace setup.py --replace \'setuptools-markdown\' ""
'';
python = python311;
overrides = poetry2nix.overrides.withDefaults (self: super:
let
buildSystems = {
pystarport = [ "poetry-core" ];
cprotobuf = [ "setuptools" ];
durations = [ "setuptools" ];
multitail2 = [ "setuptools" ];
pytest-github-actions-annotate-failures = [ "setuptools" ];
flake8-black = [ "setuptools" ];
flake8-isort = [ "hatchling" ];
pyunormalize = [ "setuptools" ];
eth-bloom = [ "setuptools" ];
};
pyyaml-include = super.pyyaml-include.overridePythonAttrs {
preConfigure = ''
substituteInPlace setup.py --replace "setup()" "setup(version=\"1.3\")"
'';
};
})
]);
in
lib.mapAttrs
(attr: systems: super.${attr}.overridePythonAttrs
(old: {
nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ map (a: self.${a}) systems;
}))
buildSystems
);
}

0 comments on commit e16b913

Please sign in to comment.