diff --git a/integration_tests/cosmoscli.py b/integration_tests/cosmoscli.py index 809137c596..ecaab65c77 100644 --- a/integration_tests/cosmoscli.py +++ b/integration_tests/cosmoscli.py @@ -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: @@ -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 diff --git a/integration_tests/test_e2ee.py b/integration_tests/test_e2ee.py new file mode 100644 index 0000000000..9b20796d56 --- /dev/null +++ b/integration_tests/test_e2ee.py @@ -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 diff --git a/x/e2ee/autocli.go b/x/e2ee/autocli.go index 1d4ec40126..f83bedd8d0 100644 --- a/x/e2ee/autocli.go +++ b/x/e2ee/autocli.go @@ -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"}, + }, + }, + }, + }, } }