From ff4322844484d8dd8826b11a9b85e9afbb99812f Mon Sep 17 00:00:00 2001 From: Harry <110472914+Cosmos-Harry@users.noreply.github.com> Date: Wed, 18 Oct 2023 18:50:17 -0400 Subject: [PATCH] added a separate test for restore-all --- cmd/keys_test.go | 88 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 11 deletions(-) diff --git a/cmd/keys_test.go b/cmd/keys_test.go index 79ea0aba6..b257a3626 100644 --- a/cmd/keys_test.go +++ b/cmd/keys_test.go @@ -56,17 +56,10 @@ func TestKeysRestore_Delete(t *testing.T) { }) // Restore a key with mnemonic to the chain. - res := sys.MustRun(t, "keys", "restore", "testChain", "default", relayertest.ZeroMnemonic) require.Equal(t, res.Stdout.String(), relayertest.ZeroCosmosAddr+"\n") require.Empty(t, res.Stderr.String()) - // Restore keys for all configured chains with a single mnemonic. - - res = sys.MustRun(t, "keys", "restore", "default", relayertest.ZeroMnemonic, "--restoreall") - require.Equal(t, res.Stdout.String(), relayertest.ZeroCosmosAddr+"\n") - require.Empty(t, res.Stderr.String()) - // Restored key must show up in list. res = sys.MustRun(t, "keys", "list", "testChain") require.Equal(t, res.Stdout.String(), "key(default) -> "+relayertest.ZeroCosmosAddr+"\n") @@ -108,10 +101,6 @@ func TestKeysExport(t *testing.T) { require.Equal(t, res.Stdout.String(), relayertest.ZeroCosmosAddr+"\n") require.Empty(t, res.Stderr.String()) - res = sys.MustRun(t, "keys", "restore", "default", relayertest.ZeroMnemonic, "--restoreall") - require.Equal(t, res.Stdout.String(), relayertest.ZeroCosmosAddr+"\n") - require.Empty(t, res.Stderr.String()) - // Export the key. res = sys.MustRun(t, "keys", "export", "testChain", "default") armorOut := res.Stdout.String() @@ -192,3 +181,80 @@ func TestKeysDefaultCoinType(t *testing.T) { require.Error(t, err, "same key was able to be imported twice") require.Contains(t, err.Error(), "cannot overwrite key") } + +func TestKeysRestoreAll_Delete(t *testing.T) { + t.Parallel() + + sys := relayertest.NewSystem(t) + + _ = sys.MustRun(t, "config", "init") + + slip44 := 118 + + sys.MustAddChain(t, "testChain", cmd.ProviderConfigWrapper{ + Type: "cosmos", + Value: cosmos.CosmosProviderConfig{ + AccountPrefix: "cosmos", + ChainID: "testcosmos", + KeyringBackend: "test", + Timeout: "10s", + Slip44: &slip44, + }, + }) + sys.MustAddChain(t, "testChain2", cmd.ProviderConfigWrapper{ + Type: "cosmos", + Value: cosmos.CosmosProviderConfig{ + AccountPrefix: "cosmos", + ChainID: "testcosmos-2", + KeyringBackend: "test", + Timeout: "10s", + Slip44: &slip44, + }, + }) + sys.MustAddChain(t, "testChain3", cmd.ProviderConfigWrapper{ + Type: "cosmos", + Value: cosmos.CosmosProviderConfig{ + AccountPrefix: "cosmos", + ChainID: "testcosmos-3", + KeyringBackend: "test", + Timeout: "10s", + Slip44: &slip44, + }, + }) + + // Restore keys for all configured chains with a single mnemonic. + res = sys.MustRun(t, "keys", "restore", "default", relayertest.ZeroMnemonic, "--restoreall") + require.Equal(t, res.Stdout.String(), relayertest.ZeroCosmosAddr+"\n") + require.Empty(t, res.Stderr.String()) + + // Restored key must show up in list. + res = sys.MustRun(t, "keys", "list", "testChain") + require.Equal(t, res.Stdout.String(), "key(default) -> "+relayertest.ZeroCosmosAddr+"\n") + require.Empty(t, res.Stderr.String()) + + res = sys.MustRun(t, "keys", "list", "testChain2") + require.Equal(t, res.Stdout.String(), "key(default) -> "+relayertest.ZeroCosmosAddr+"\n") + require.Empty(t, res.Stderr.String()) + + res = sys.MustRun(t, "keys", "list", "testChain3") + require.Equal(t, res.Stdout.String(), "key(default) -> "+relayertest.ZeroCosmosAddr+"\n") + require.Empty(t, res.Stderr.String()) + + // Deleting the key must succeed. + res = sys.MustRun(t, "keys", "delete", "testChain", "default", "-y") + require.Empty(t, res.Stdout.String()) + require.Equal(t, res.Stderr.String(), "key default deleted\n") + + res = sys.MustRun(t, "keys", "delete", "testChain2", "default", "-y") + require.Empty(t, res.Stdout.String()) + require.Equal(t, res.Stderr.String(), "key default deleted\n") + + res = sys.MustRun(t, "keys", "delete", "testChain3", "default", "-y") + require.Empty(t, res.Stdout.String()) + require.Equal(t, res.Stderr.String(), "key default deleted\n") + + // Listing the keys again gives the no keys warning. + res = sys.MustRun(t, "keys", "list", "testChain3") + require.Empty(t, res.Stdout.String()) + require.Contains(t, res.Stderr.String(), "no keys found for chain testChain3") +} \ No newline at end of file