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 101490d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 41 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: 21 additions & 9 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 @@ -96,18 +95,31 @@ def test_gov_update_params(cronos, tmp_path):
print("params", rsp)
assert rsp == params

# gen two keys for two accounts
# gen identity key for one account
name = "e2ee-identity"
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")
pubkey0 = cli.keygen(keyring_name=name)
sender = "validator"
cli.register_e2ee_key(pubkey0, _from=sender)
assert cli.query_e2ee_key(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")
cli1 = cronos.cosmos_cli(1)
rsp = cli1.transfer(cli1.address("validator"), cli1.address("validator"), "1basetcro")

Check failure on line 124 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:124:25: BLK100 Black would make changes.

Check failure on line 124 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:124:89: E501 line too long (90 > 88 characters)
assert rsp["code"] == 0, rsp["raw_log"]

Check failure on line 125 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:125:44: W292 no newline at end of file

Check failure on line 125 in integration_tests/test_gov_update_params.py

View workflow job for this annotation

GitHub Actions / integration_tests (gov)

test_gov_update_params[True] AssertionError: cosmossdk.io/errors.(*Error).Wrapf cosmossdk.io/errors/errors.go:155 github.com/cosmos/cosmos-sdk/x/bank/keeper.BaseSendKeeper.IsSendEnabledCoins github.com/cosmos/cosmos-sdk/x/bank/keeper/send.go:381 github.com/cosmos/cosmos-sdk/x/bank/keeper.msgServer.Send github.com/cosmos/cosmos-sdk/x/bank/keeper/msg_server.go:30 github.com/cosmos/cosmos-sdk/x/bank/types._Msg_Send_Handler.func1 github.com/cosmos/cosmos-sdk/x/bank/types/tx.pb.go:604 github.com/cosmos/cosmos-sdk/baseapp.(*MsgServiceRouter).RegisterService.func2.1 github.com/cosmos/cosmos-sdk/baseapp/msg_service_router.go:118 github.com/cosmos/cosmos-sdk/x/bank/types._Msg_Send_Handler github.com/cosmos/cosmos-sdk/x/bank/types/tx.pb.go:606 github.com/cosmos/cosmos-sdk/baseapp.(*MsgServiceRouter).RegisterService.func2 github.com/cosmos/cosmos-sdk/baseapp/msg_service_router.go:139 github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runMsgs github.com/cosmos/cosmos-sdk/baseapp/baseapp.go:807 github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runTx github.com/cosmos/cosmos-sdk/baseapp/baseapp.go:750 github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).DeliverTx github.com/cosmos/cosmos-sdk/baseapp/abci.go:430 github.com/cometbft/cometbft/abci/client.(*localClient).DeliverTxAsync github.com/cometbft/cometbft/abci/client/local_client.go:82 github.com/cometbft/cometbft/proxy.(*appConnConsensus).DeliverTxAsync github.com/cometbft/cometbft/proxy/app_conn.go:106 github.com/cometbft/cometbft/state.execBlockOnProxyApp github.com/cometbft/cometbft/state/execution.go:376 github.com/cometbft/cometbft/state.(*BlockExecutor).ApplyBlock github.com/cometbft/cometbft/state/execution.go:197 github.com/cometbft/cometbft/consensus.(*State).finalizeCommit github.com/cometbft/cometbft/consensus/state.go:1710 github.com/cometbft/cometbft/consensus.(*State).tryFinalizeCommit github.com/cometbft/cometbft/consensus/state.go:1619 github.com/cometbft/cometbft/consensus.(*State).enterCommit.func1 github.com/cometbft/cometbft/consensus/state.go:1554 github.com/cometbft/cometbft/consensus.(*State).enterCommit github.com/cometbft/cometbft/consensus/state.go:1592 github.com/cometbft/cometbft/consensus.(*State).addVote github.com/cometbft/cometbft/consensus/state.go:2223 github.com/cometbft/cometbft/consensus.(*State).tryAddVote github.com/cometbft/cometbft/consensus/state.go:2012 github.com/cometbft/cometbft/consensus.(*State).handleMsg github.com/cometbft/cometbft/consensus/state.go:865 github.com/cometbft/cometbft/consensus.(*State).receiveRoutine github.com/cometbft/cometbft/consensus/state.go:772 failed to execute message; message index: 0: basetcro transfers are currently disabled: send transactions are disabled assert 5 == 0
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 101490d

Please sign in to comment.