Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed May 3, 2024
1 parent ab18183 commit 8ad4b75
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 29 deletions.
1 change: 0 additions & 1 deletion app/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func NewProposalHandler(txDecoder sdk.TxDecoder, identity age.Identity) *Proposa
}

func (h *ProposalHandler) SetBlockList(blob []byte) error {
fmt.Println("SetBlockList")
if h.Identity == nil {
return nil

Check warning on line 37 in app/proposal.go

View check run for this annotation

Codecov / codecov/patch

app/proposal.go#L35-L37

Added lines #L35 - L37 were not covered by tests
}
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,7 @@ def query_e2ee_key(self, address):
home=self.data_dir,
output="json",
)
)["key"]
).get("key")

def query_e2ee_keys(self, *addresses):
return json.loads(
Expand All @@ -1869,7 +1869,7 @@ def query_e2ee_keys(self, *addresses):
home=self.data_dir,
output="json",
)
)["keys"]
).get("keys")

def register_e2ee_key(self, key, **kwargs):
kwargs.setdefault("gas_prices", DEFAULT_GAS_PRICE)
Expand Down
89 changes: 63 additions & 26 deletions integration_tests/test_e2ee.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,77 @@
import json

import pytest

from .network import Cronos
from .utils import wait_for_new_blocks


def gen_validator_identity(cronos: Cronos):
for i in range(len(cronos.config["validators"])):
cli = cronos.cosmos_cli(i)
if cli.query_e2ee_key(cli.address("validator")):
return
pubkey = cli.keygen()
cli.register_e2ee_key(pubkey, _from="validator")
assert cli.query_e2ee_key(cli.address("validator")) == pubkey

cronos.supervisorctl("restart", f"cronos_777-1-node{i}")

wait_for_new_blocks(cronos.cosmos_cli(), 1)


def test_encrypt_decrypt(cronos):
gen_validator_identity(cronos)

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,
]
assert (
len(
cli0.query_e2ee_keys(
cli0.address("validator"),
cli1.address("validator"),
)
)
== 2
)

# prepare data file to encrypt
content = "Hello World!"
def test_block_list(cronos):
cli0 = cronos.cosmos_cli()
cli1 = cronos.cosmos_cli(1)
plainfile = cli0.data_dir / "plaintext"
plainfile.write_text(content)
cipherfile = cli0.data_dir / "ciphertext"
cli0.encrypt(
plainfile,
cli0.address("validator"),
cli1.address("validator"),
output=cipherfile,
)

assert cli0.decrypt(cipherfile) == content
assert cli1.decrypt(cipherfile) == content

# prepare encryption keys for validators
cli0.register_e2ee_key(cli0.keygen(), _from="validator")
cli1.register_e2ee_key(cli1.keygen(), _from="validator")

user = cli0.address("user")
def test_block_list(cronos):
gen_validator_identity(cronos)
cli = cronos.cosmos_cli()

user = cli.address("user")

blocklist = json.dumps({"addresses": [user]})
plainfile = cli0.data_dir / "plaintext"
plainfile = cli.data_dir / "plaintext"
plainfile.write_text(blocklist)
cipherfile = cli0.data_dir / "ciphertext"
cli0.encrypt_to_validators(plainfile, output=cipherfile)
rsp = cli0.store_blocklist(cipherfile, _from="validator")
cipherfile = cli.data_dir / "ciphertext"
cli.encrypt_to_validators(plainfile, output=cipherfile)
rsp = cli.store_blocklist(cipherfile, _from="validator")
assert rsp["code"] == 0, rsp["raw_log"]

wait_for_new_blocks(cli0, 2)
rsp = cli0.transfer(user, cli0.address("validator"), "1basetcro")
assert rsp["code"] != 0
# normal tx works
cli.transfer(cli.address("validator"), user, "1basetcro")

# blocked tx don't work
with pytest.raises(AssertionError) as exc:
cli.transfer(user, cli.address("validator"), "1basetcro")

assert "timed out waiting for event" in str(exc.value)

0 comments on commit 8ad4b75

Please sign in to comment.