Skip to content

Commit

Permalink
added a separate test for restore-all
Browse files Browse the repository at this point in the history
  • Loading branch information
Cosmos-Harry authored Oct 18, 2023
1 parent c23f207 commit ff43228
Showing 1 changed file with 77 additions and 11 deletions.
88 changes: 77 additions & 11 deletions cmd/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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")
}

0 comments on commit ff43228

Please sign in to comment.