Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed May 3, 2024
1 parent 3258b5b commit a006f83
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 39 deletions.
33 changes: 26 additions & 7 deletions integration_tests/test_e2ee.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
from .utils import prepare_cipherfile


def test_encrypt_decrypt(cronos):
cli = cronos.cosmos_cli()
cli0 = cronos.cosmos_cli()
cli1 = cronos.cosmos_cli(1)

# gen two keys for two accounts
name0 = "key0"
name1 = "key1"
pubkey0 = cli0.keygen(keyring_name=name0)
pubkey1 = cli1.keygen(keyring_name=name1)
sender = "validator"
cli0.register_e2ee_key(pubkey0, _from=sender)
cli1.register_e2ee_key(pubkey1, _from=sender)
# query in batch
assert cli0.query_e2ee_keys(cli0.address(sender), cli1.address(sender)) == [
pubkey0,
pubkey1,
]
# prepare data file to encrypt
content = "Hello World!"
cipherfile = prepare_cipherfile(cli, cli1, name0, name1, content)
assert cli.decrypt(cipherfile, identity=name0) == content
assert cli1.decrypt(cipherfile, identity=name1) == content
plainfile = cli0.data_dir / "plaintext"
plainfile.write_text(content)
cipherfile = cli0.data_dir / "ciphertext"
cli0.encrypt(
plainfile,
cli0.address(sender),
cli1.address(sender),
output=cipherfile,
)

assert cli0.decrypt(cipherfile, identity="key0") == content
assert cli1.decrypt(cipherfile, identity="key1") == content
30 changes: 23 additions & 7 deletions integration_tests/test_gov_update_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
approve_proposal,
deploy_contract,
eth_to_bech32,
prepare_cipherfile,
wait_for_new_blocks,
wait_for_port,
)
Expand Down Expand Up @@ -101,13 +100,30 @@ def test_gov_update_params(cronos, tmp_path):
cli1 = cronos.cosmos_cli(1)
addr = cli.address("user")
content = json.dumps({"addresses": [addr]})
cipherfile = prepare_cipherfile(cli, cli1, name, name, content)
cronos.supervisorctl("stop", "all")
cronos.supervisorctl("start", "cronos_777-1-node0", "cronos_777-1-node1")
# gen two keys for two accounts
pubkey0 = cli.keygen(keyring_name=name)
sender = "validator"
cli.register_e2ee_key(pubkey0, _from=sender)
# query in batch
assert cli.query_e2ee_keys(cli.address(sender)) == [
pubkey0,
]
# prepare data file to encrypt
plainfile = cli.data_dir / "plaintext"
plainfile.write_text(content)
cipherfile = cli.data_dir / "ciphertext"
cli.encrypt(
plainfile,
cli.address(sender),
output=cipherfile,
)
cronos.supervisorctl("stop", "cronos_777-1-node0")
cronos.supervisorctl("start", "cronos_777-1-node0")
wait_for_port(ports.evmrpc_port(cronos.base_port(0)))
rsp = cli.store_blocklist(cipherfile, from_="validator")
assert rsp["code"] == 0, rsp["raw_log"]
wait_for_new_blocks(cli, 2)
rsp = cli.transfer(addr, cli.address("validator"), "1basetcro")
assert rsp["code"] != 0
assert "signer is blocked" in rsp["raw_log"]
with pytest.raises(AssertionError):
rsp = cli.transfer(addr, cli.address("validator"), "1basetcro")
rsp = cli1.transfer(cli1.address("validator"), cli1.address("validator"), "1basetcro")

Check failure on line 128 in integration_tests/test_gov_update_params.py

View workflow job for this annotation

GitHub Actions / Lint python

./integration_tests/test_gov_update_params.py:128:25: BLK100 Black would make changes.

Check failure on line 128 in integration_tests/test_gov_update_params.py

View workflow job for this annotation

GitHub Actions / Lint python

./integration_tests/test_gov_update_params.py:128:89: E501 line too long (90 > 88 characters)
assert rsp["code"] == 0, rsp["raw_log"]

Check failure on line 129 in integration_tests/test_gov_update_params.py

View workflow job for this annotation

GitHub Actions / Lint python

./integration_tests/test_gov_update_params.py:129:44: W292 no newline at end of file
25 changes: 0 additions & 25 deletions integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,28 +732,3 @@ def get_send_enable(port):
url = f"http://127.0.0.1:{port}/cosmos/bank/v1beta1/params"
raw = requests.get(url).json()
return raw["params"]["send_enabled"]


def prepare_cipherfile(cli0, cli1, name0, name1, content):
# gen two keys for two accounts
pubkey0 = cli0.keygen(keyring_name=name0)
pubkey1 = cli1.keygen(keyring_name=name1)
sender = "validator"
cli0.register_e2ee_key(pubkey0, _from=sender)
cli1.register_e2ee_key(pubkey1, _from=sender)
# query in batch
assert cli0.query_e2ee_keys(cli0.address(sender), cli1.address(sender)) == [
pubkey0,
pubkey1,
]
# prepare data file to encrypt
plainfile = cli0.data_dir / "plaintext"
plainfile.write_text(content)
cipherfile = cli0.data_dir / "ciphertext"
cli0.encrypt(
plainfile,
cli0.address(sender),
cli1.address(sender),
output=cipherfile,
)
return cipherfile

0 comments on commit a006f83

Please sign in to comment.