-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for RecoverKey
in the chain interface.
#176
Conversation
…helper method which generates a user using a provided mnemonic.
func (c *PenumbraChain) RecoverKey(ctx context.Context, name, mnemonic string) error { | ||
return fmt.Errorf("RecoverKey not implemented for PenumbraChain") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure exactly what would need to be done here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this error is fine for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, Penumbra is highly experimental right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few things to clean up, but I think we'll be able to get this merged soon.
func (c *PenumbraChain) RecoverKey(ctx context.Context, name, mnemonic string) error { | ||
return fmt.Errorf("RecoverKey not implemented for PenumbraChain") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this error is fine for now.
test_user.go
Outdated
Denom: chainCfg.Denom, | ||
}) | ||
require.NoError(t, err, "failed to get funds from faucet") | ||
require.NoError(t, test.WaitForBlocks(ctx, 5, chain), "failed to wait for blocks") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did 5 come from anywhere special? Would 4 or 3 work?
Some of these tests can take a long time to complete, so if there is a way to minimize time spent waiting, we should take it.
Maybe it would make more sense to not wait inside this function, and indicate in Godoc that the caller should wait for some blocks to complete before the funds will be accessible. There is one wait at the end of GetAndFundTestUsers
that would be redundant with this call, if it stays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wait was just taken from the existing GetAndFundTestUsers
function, however I think it's no harm removing it and letting the caller know as you suggested. I can remove from both.
interchain_test.go
Outdated
require.NotEmpty(t, users[0].KeyName) | ||
}) | ||
|
||
_ = ic.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preferable to defer ic.Close()
immediately after the initial assignment.
If the linter complains about a discarded error value, defer func() { _ = ic.Close() }
is fine.
ibc/types.go
Outdated
// GetShell returns the shell that should be used when executing scripts. | ||
func (c ChainConfig) GetShell() string { | ||
if c.Shell == "" { | ||
return "sh" | ||
} | ||
return c.Shell | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, I think we should assume all containers have sh
available. It will likely be a long time before we run into something we can't do with plain sh
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. The benefit is keeping ChainConfig
simple.
interchain_test.go
Outdated
ic := ibctest.NewInterchain(). | ||
AddChain(gaia0). | ||
AddChain(gaia1). | ||
AddRelayer(r, "r"). | ||
AddLink(ibctest.InterchainLink{ | ||
Chain1: gaia0, | ||
Chain2: gaia1, | ||
Relayer: r, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this test is only exercising funding a user, I think this can be reduced to ic := ibctest.NewInterchain().AddChain(gaia0)
.
This should be testable even without an Interchain
, but since that does the heavy lifting to start a chain, it's probably more convenient than calling several methods directly on a chain.
interchain_test.go
Outdated
NetworkID: network, | ||
})) | ||
|
||
t.Run("Test User creation with mnemonic", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Names of subtests should be shorter because they are displayed after the outer test's name. This line can be t.Run("with mnemonic", ...)
.
interchain_test.go
Outdated
require.NotEmpty(t, user.KeyName) | ||
}) | ||
|
||
t.Run("Test user creation without mnemonic", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t.Run("without mnemonic", ...)
chain/cosmos/chain_node.go
Outdated
// RecoverKey restores a key from a given mnemonic. | ||
func (tn *ChainNode) RecoverKey(ctx context.Context, keyName, mnemonic string) error { | ||
command := []string{ | ||
tn.Chain.Config().GetShell(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be hardcoded to "sh"
after removing the GetShell
method.
chain/cosmos/chain_node.go
Outdated
command := []string{ | ||
tn.Chain.Config().GetShell(), | ||
"-c", | ||
fmt.Sprintf(`echo "%s" | %s keys add %s --recover --keyring-backend %s --home %s --output json`, mnemonic, tn.Chain.Config().Bin, keyName, keyring.BackendTest, tn.NodeHome()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo %q | ...
should be safer, as that will surround the string with quotes and add some escaping of special characters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this, I wasn't familiar with %q here!
ibc/types.go
Outdated
// GetShell returns the shell that should be used when executing scripts. | ||
func (c ChainConfig) GetShell() string { | ||
if c.Shell == "" { | ||
return "sh" | ||
} | ||
return c.Shell | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. The benefit is keeping ChainConfig
simple.
func (c *PenumbraChain) RecoverKey(ctx context.Context, name, mnemonic string) error { | ||
return fmt.Errorf("RecoverKey not implemented for PenumbraChain") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, Penumbra is highly experimental right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies, I did not mean to approve previously, just comment.
@mark-rushakoff ready for another look, I've addressed your feedback, thanks for taking a look so quickly! Tests seem to be failing but it looks like an environmental issue on the test host? |
@agouin thanks for letting me know! I had missed that PR being merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @chatton!
Description
This PR adds the functionality to recover a test user from a given mnemonic.
Checklist
Changes
RecoverKey
toChainNode
andCosmosChain
types.RecoverKey
toChain
interface.AddedShell
field toChainConfig
. This is to allow you to specify which shell commands which run using-c <script>
will use, as not all images will have the same shells.GetAndFundTestUserWithMnemonic
which generates a user using a given mnemonic.GetAndFundTestUsers
to delegate toGetAndFundTestUserWithMnemonic
generateUserWallet
to eitherCreate
orRecover
based on the presence of a mnemonic.Testing
Tests have been added which verify that users can be created using
CreateKey
andRecoverKey
closes #169