Skip to content

Commit

Permalink
test e2ee pubkey
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Jul 10, 2024
1 parent ec65c88 commit 12db3a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
11 changes: 7 additions & 4 deletions integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1922,10 +1922,13 @@ def register_e2ee_key(self, key, **kwargs):
rsp = self.event_query_tx_for(rsp["txhash"])
return rsp

def keygen(self, **kwargs):
def e2ee_keygen(self, **kwargs):
return self.raw("e2ee", "keygen", home=self.data_dir, **kwargs).strip().decode()

def encrypt(self, input, *recipients, **kwargs):
def e2ee_pubkey(self, **kwargs):
return self.raw("e2ee", "pubkey", home=self.data_dir, **kwargs).strip().decode()

def e2ee_encrypt(self, input, *recipients, **kwargs):
return (
self.raw(
"e2ee",
Expand All @@ -1939,7 +1942,7 @@ def encrypt(self, input, *recipients, **kwargs):
.decode()
)

def decrypt(self, input, identity="e2ee-identity", **kwargs):
def e2ee_decrypt(self, input, identity="e2ee-identity", **kwargs):
return (
self.raw(
"e2ee",
Expand All @@ -1953,7 +1956,7 @@ def decrypt(self, input, identity="e2ee-identity", **kwargs):
.decode()
)

def encrypt_to_validators(self, input, **kwargs):
def e2ee_encrypt_to_validators(self, input, **kwargs):
return (
self.raw(
"e2ee",
Expand Down
13 changes: 7 additions & 6 deletions integration_tests/test_e2ee.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

def test_register(cronos: Cronos):
cli = cronos.cosmos_cli()
pubkey0 = cli.keygen(keyring_name="key0")
pubkey0 = cli.e2ee_keygen(keyring_name="key0")
with pytest.raises(AssertionError) as exc:
cli.register_e2ee_key(pubkey0 + "malformed", _from="validator")
assert "malformed recipient" in str(exc.value)
Expand All @@ -23,7 +23,8 @@ def gen_validator_identity(cronos: Cronos):
cli = cronos.cosmos_cli(i)
if cli.query_e2ee_key(cli.address("validator")):
return
pubkey = cli.keygen()
pubkey = cli.e2ee_keygen()
assert cli.e2ee_pubkey() == pubkey
cli.register_e2ee_key(pubkey, _from="validator")
assert cli.query_e2ee_key(cli.address("validator")) == pubkey

Expand Down Expand Up @@ -54,23 +55,23 @@ def test_encrypt_decrypt(cronos):
plainfile = cli0.data_dir / "plaintext"
plainfile.write_text(content)
cipherfile = cli0.data_dir / "ciphertext"
cli0.encrypt(
cli0.e2ee_encrypt(
plainfile,
cli0.address("validator"),
cli1.address("validator"),
output=cipherfile,
)

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


def encrypt_to_validators(cli, content):
blocklist = json.dumps(content)
plainfile = cli.data_dir / "plaintext"
plainfile.write_text(blocklist)
cipherfile = cli.data_dir / "ciphertext"
cli.encrypt_to_validators(plainfile, output=cipherfile)
cli.e2ee_encrypt_to_validators(plainfile, output=cipherfile)
rsp = cli.store_blocklist(cipherfile, _from="validator")
assert rsp["code"] == 0, rsp["raw_log"]

Expand Down

0 comments on commit 12db3a6

Please sign in to comment.