Skip to content

Commit

Permalink
Problem: encryption-key cmd is not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Apr 26, 2024
1 parent f69878b commit b73fea9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
35 changes: 34 additions & 1 deletion integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ def __init__(self, cmd):
def __call__(self, cmd, *args, stdin=None, stderr=subprocess.STDOUT, **kwargs):
"execute chain-maind"
args = " ".join(build_cli_args_safe(cmd, *args, **kwargs))
return interact(f"{self.cmd} {args}", input=stdin, stderr=stderr)
cli = f"{self.cmd} {args}"
print("mm-cli", cli)
return interact(cli, input=stdin, stderr=stderr)


class CosmosCLI:
Expand Down Expand Up @@ -1840,3 +1842,34 @@ def query_bank_send(self, *denoms):
output="json",
)
).get("send_enabled", [])

def query_e2ee_key(self, address):
return json.loads(
self.raw(
"q",
"e2ee",
"key",
address,
home=self.data_dir,
output="json",
)
)

def set_e2ee_key(self, key, **kwargs):
kwargs.setdefault("gas_prices", DEFAULT_GAS_PRICE)
kwargs.setdefault("gas", DEFAULT_GAS)
rsp = json.loads(
self.raw(
"tx",
"e2ee",
"set-encryption-key",
key,
"-y",
home=self.data_dir,
stderr=subprocess.DEVNULL,
**kwargs,
)
)
if rsp["code"] == 0:
rsp = self.event_query_tx_for(rsp["txhash"])
return rsp
10 changes: 10 additions & 0 deletions integration_tests/test_e2ee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import base64


def test_set_key(cronos):
cli = cronos.cosmos_cli()
key = base64.b64encode(b"new_key").decode("utf-8")
cli.set_e2ee_key(key, _from="community")
adr = cli.address("community")
p = cli.query_e2ee_key(adr)
assert p["key"] == key
13 changes: 13 additions & 0 deletions x/e2ee/autocli.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,18 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
},
},
},
Tx: &autocliv1.ServiceCommandDescriptor{
Service: "e2ee.Msg",
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "RegisterEncryptionKey",
Use: "set-encryption-key [key]",
Short: "Set encryption key is stored associated with the user address.",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{ProtoField: "key"},
},
},
},
},
}
}

0 comments on commit b73fea9

Please sign in to comment.