Skip to content

Commit

Permalink
Merge branch 'harry/wallet-init' of https://github.com/Cosmos-Harry/r…
Browse files Browse the repository at this point in the history
…elayer into harry/wallet-init

merging to solve the conflicting go.work.sum
  • Loading branch information
Cosmos-Harry committed Oct 19, 2023
2 parents 15ef967 + ff43228 commit 7ab6635
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")

Check failure on line 226 in cmd/keys_test.go

View workflow job for this annotation

GitHub Actions / build

undefined: res
require.Equal(t, res.Stdout.String(), relayertest.ZeroCosmosAddr+"\n")

Check failure on line 227 in cmd/keys_test.go

View workflow job for this annotation

GitHub Actions / build

undefined: res
require.Empty(t, res.Stderr.String())

Check failure on line 228 in cmd/keys_test.go

View workflow job for this annotation

GitHub Actions / build

undefined: res

// Restored key must show up in list.
res = sys.MustRun(t, "keys", "list", "testChain")

Check failure on line 231 in cmd/keys_test.go

View workflow job for this annotation

GitHub Actions / build

undefined: res
require.Equal(t, res.Stdout.String(), "key(default) -> "+relayertest.ZeroCosmosAddr+"\n")

Check failure on line 232 in cmd/keys_test.go

View workflow job for this annotation

GitHub Actions / build

undefined: res
require.Empty(t, res.Stderr.String())

Check failure on line 233 in cmd/keys_test.go

View workflow job for this annotation

GitHub Actions / build

undefined: res

res = sys.MustRun(t, "keys", "list", "testChain2")

Check failure on line 235 in cmd/keys_test.go

View workflow job for this annotation

GitHub Actions / build

undefined: res
require.Equal(t, res.Stdout.String(), "key(default) -> "+relayertest.ZeroCosmosAddr+"\n")

Check failure on line 236 in cmd/keys_test.go

View workflow job for this annotation

GitHub Actions / build

undefined: res
require.Empty(t, res.Stderr.String())

Check failure on line 237 in cmd/keys_test.go

View workflow job for this annotation

GitHub Actions / build

undefined: res

res = sys.MustRun(t, "keys", "list", "testChain3")

Check failure on line 239 in cmd/keys_test.go

View workflow job for this annotation

GitHub Actions / build

undefined: res
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 7ab6635

Please sign in to comment.