Skip to content

Commit 285db06

Browse files
chore: move server.GenerateCoinKey and server.GenerateSaveCoinKey to … (#10957)
Cleaning it and moving the breaking "test" code to testutils Related to: #10956 --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
1 parent 43cf8eb commit 285db06

File tree

15 files changed

+55
-44
lines changed

15 files changed

+55
-44
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
116116
* [\#10748](https://github.com/cosmos/cosmos-sdk/pull/10748) Move legacy `x/gov` api to `v1beta1` directory.
117117
* [\#10816](https://github.com/cosmos/cosmos-sdk/pull/10816) Reuse blocked addresses from the bank module. No need to pass them to distribution.
118118
* [\#10852](https://github.com/cosmos/cosmos-sdk/pull/10852) Move `x/gov/types` to `x/gov/types/v1beta2`.
119+
* [\#10922](https://github.com/cosmos/cosmos-sdk/pull/10922), [/#10957](https://github.com/cosmos/cosmos-sdk/pull/10957) Move key `server.Generate*` functions to testutil and support custom mnemonics in in-process testing network. Moved `TestMnemonic` from `testutil` package to `testdata`.
119120

120121
### Client Breaking Changes
121122

client/keys/add_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/cosmos/cosmos-sdk/crypto/keyring"
1717
"github.com/cosmos/cosmos-sdk/simapp"
1818
"github.com/cosmos/cosmos-sdk/testutil"
19+
"github.com/cosmos/cosmos-sdk/testutil/testdata"
1920
sdk "github.com/cosmos/cosmos-sdk/types"
2021
"github.com/cosmos/go-bip39"
2122
)
@@ -202,7 +203,7 @@ func Test_runAddCmdDryRun(t *testing.T) {
202203
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)
203204

204205
path := sdk.GetConfig().GetFullBIP44Path()
205-
_, err = kb.NewAccount("subkey", testutil.TestMnemonic, "", path, hd.Secp256k1)
206+
_, err = kb.NewAccount("subkey", testdata.TestMnemonic, "", path, hd.Secp256k1)
206207
require.NoError(t, err)
207208

208209
t.Cleanup(func() {

client/keys/delete_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/cosmos/cosmos-sdk/crypto/keyring"
1414
"github.com/cosmos/cosmos-sdk/simapp"
1515
"github.com/cosmos/cosmos-sdk/testutil"
16+
"github.com/cosmos/cosmos-sdk/testutil/testdata"
1617
sdk "github.com/cosmos/cosmos-sdk/types"
1718
)
1819

@@ -39,7 +40,7 @@ func Test_runDeleteCmd(t *testing.T) {
3940
kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn, cdc)
4041
require.NoError(t, err)
4142

42-
_, err = kb.NewAccount(fakeKeyName1, testutil.TestMnemonic, "", path, hd.Secp256k1)
43+
_, err = kb.NewAccount(fakeKeyName1, testdata.TestMnemonic, "", path, hd.Secp256k1)
4344
require.NoError(t, err)
4445

4546
_, _, err = kb.NewMnemonic(fakeKeyName2, keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)

client/keys/export_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/cosmos/cosmos-sdk/client"
1212
"github.com/cosmos/cosmos-sdk/crypto/hd"
1313
"github.com/cosmos/cosmos-sdk/testutil"
14+
"github.com/cosmos/cosmos-sdk/testutil/testdata"
1415

1516
"github.com/cosmos/cosmos-sdk/client/flags"
1617
"github.com/cosmos/cosmos-sdk/crypto/keyring"
@@ -93,7 +94,7 @@ func Test_runExportCmd(t *testing.T) {
9394
})
9495

9596
path := sdk.GetConfig().GetFullBIP44Path()
96-
_, err = kb.NewAccount("keyname1", testutil.TestMnemonic, "", path, hd.Secp256k1)
97+
_, err = kb.NewAccount("keyname1", testdata.TestMnemonic, "", path, hd.Secp256k1)
9798
require.NoError(t, err)
9899

99100
clientCtx := client.Context{}.

client/keys/list_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/cosmos/cosmos-sdk/crypto/keyring"
1515
"github.com/cosmos/cosmos-sdk/simapp"
1616
"github.com/cosmos/cosmos-sdk/testutil"
17+
"github.com/cosmos/cosmos-sdk/testutil/testdata"
1718
sdk "github.com/cosmos/cosmos-sdk/types"
1819
)
1920

@@ -33,7 +34,7 @@ func Test_runListCmd(t *testing.T) {
3334
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)
3435

3536
path := "" //sdk.GetConfig().GetFullBIP44Path()
36-
_, err = kb.NewAccount("something", testutil.TestMnemonic, "", path, hd.Secp256k1)
37+
_, err = kb.NewAccount("something", testdata.TestMnemonic, "", path, hd.Secp256k1)
3738
require.NoError(t, err)
3839

3940
t.Cleanup(func() {

client/keys/rename_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/cosmos/cosmos-sdk/crypto/keyring"
1414
"github.com/cosmos/cosmos-sdk/simapp"
1515
"github.com/cosmos/cosmos-sdk/testutil"
16+
"github.com/cosmos/cosmos-sdk/testutil/testdata"
1617
sdk "github.com/cosmos/cosmos-sdk/types"
1718
)
1819

@@ -36,7 +37,7 @@ func Test_runRenameCmd(t *testing.T) {
3637
require.NoError(t, err)
3738

3839
// put fakeKeyName1 in keyring
39-
_, err = kb.NewAccount(fakeKeyName1, testutil.TestMnemonic, "", path, hd.Secp256k1)
40+
_, err = kb.NewAccount(fakeKeyName1, testdata.TestMnemonic, "", path, hd.Secp256k1)
4041
require.NoError(t, err)
4142

4243
clientCtx := client.Context{}.

client/keys/show_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
1717
"github.com/cosmos/cosmos-sdk/simapp"
1818
"github.com/cosmos/cosmos-sdk/testutil"
19+
"github.com/cosmos/cosmos-sdk/testutil/testdata"
1920
sdk "github.com/cosmos/cosmos-sdk/types"
2021
)
2122

@@ -76,11 +77,11 @@ func Test_runShowCmd(t *testing.T) {
7677
})
7778

7879
path := hd.NewFundraiserParams(1, sdk.CoinType, 0).String()
79-
_, err = kb.NewAccount(fakeKeyName1, testutil.TestMnemonic, "", path, hd.Secp256k1)
80+
_, err = kb.NewAccount(fakeKeyName1, testdata.TestMnemonic, "", path, hd.Secp256k1)
8081
require.NoError(t, err)
8182

8283
path2 := hd.NewFundraiserParams(1, sdk.CoinType, 1).String()
83-
_, err = kb.NewAccount(fakeKeyName2, testutil.TestMnemonic, "", path2, hd.Secp256k1)
84+
_, err = kb.NewAccount(fakeKeyName2, testdata.TestMnemonic, "", path2, hd.Secp256k1)
8485
require.NoError(t, err)
8586

8687
// Now try single key

crypto/ledger/ledger_mock.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build ledger && test_ledger_mock
12
// +build ledger,test_ledger_mock
23

34
package ledger
@@ -14,7 +15,7 @@ import (
1415

1516
"github.com/cosmos/cosmos-sdk/crypto/hd"
1617
csecp256k1 "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
17-
"github.com/cosmos/cosmos-sdk/testutil"
18+
"github.com/cosmos/cosmos-sdk/testutil/testdata"
1819
sdk "github.com/cosmos/cosmos-sdk/types"
1920
)
2021

@@ -45,7 +46,7 @@ func (mock LedgerSECP256K1Mock) GetPublicKeySECP256K1(derivationPath []uint32) (
4546
return nil, errors.New("Invalid derivation path")
4647
}
4748

48-
seed, err := bip39.NewSeedWithErrorChecking(testutil.TestMnemonic, "")
49+
seed, err := bip39.NewSeedWithErrorChecking(testdata.TestMnemonic, "")
4950
if err != nil {
5051
return nil, err
5152
}
@@ -87,7 +88,7 @@ func (mock LedgerSECP256K1Mock) GetAddressPubKeySECP256K1(derivationPath []uint3
8788

8889
func (mock LedgerSECP256K1Mock) SignSECP256K1(derivationPath []uint32, message []byte) ([]byte, error) {
8990
path := hd.NewParams(derivationPath[0], derivationPath[1], derivationPath[2], derivationPath[3] != 0, derivationPath[4])
90-
seed, err := bip39.NewSeedWithErrorChecking(testutil.TestMnemonic, "")
91+
seed, err := bip39.NewSeedWithErrorChecking(testdata.TestMnemonic, "")
9192
if err != nil {
9293
return nil, err
9394
}

crypto/ledger/ledger_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/cosmos/cosmos-sdk/codec/legacy"
1010
"github.com/cosmos/cosmos-sdk/crypto/hd"
1111
"github.com/cosmos/cosmos-sdk/crypto/types"
12-
"github.com/cosmos/cosmos-sdk/testutil"
12+
"github.com/cosmos/cosmos-sdk/testutil/testdata"
1313
sdk "github.com/cosmos/cosmos-sdk/types"
1414
)
1515

@@ -33,11 +33,11 @@ func checkDefaultPubKey(t *testing.T, priv types.LedgerPrivKey) {
3333
expectedPkStr := "PubKeySecp256k1{034FEF9CD7C4C63588D3B03FEB5281B9D232CBA34D6F3D71AEE59211FFBFE1FE87}"
3434
require.Equal(t, "eb5ae98721034fef9cd7c4c63588d3b03feb5281b9d232cba34d6f3d71aee59211ffbfe1fe87",
3535
fmt.Sprintf("%x", cdc.Amino.MustMarshalBinaryBare(priv.PubKey())),
36-
"Is your device using test mnemonic: %s ?", testutil.TestMnemonic)
36+
"Is your device using test mnemonic: %s ?", testdata.TestMnemonic)
3737
require.Equal(t, expectedPkStr, priv.PubKey().String())
3838
addr := sdk.AccAddress(priv.PubKey().Address()).String()
3939
require.Equal(t, "cosmos1w34k53py5v5xyluazqpq65agyajavep2rflq6h",
40-
addr, "Is your device using test mnemonic: %s ?", testutil.TestMnemonic)
40+
addr, "Is your device using test mnemonic: %s ?", testdata.TestMnemonic)
4141
}
4242

4343
func TestPublicKeyUnsafeHDPath(t *testing.T) {
@@ -74,7 +74,7 @@ func TestPublicKeyUnsafeHDPath(t *testing.T) {
7474

7575
// in this test we are chekcking if the generated keys are correct.
7676
require.Equal(t, expectedAnswers[i], priv.PubKey().String(),
77-
"Is your device using test mnemonic: %s ?", testutil.TestMnemonic)
77+
"Is your device using test mnemonic: %s ?", testdata.TestMnemonic)
7878

7979
// Store and restore
8080
serializedPk := priv.Bytes()
@@ -151,7 +151,7 @@ func TestPublicKeyHDPath(t *testing.T) {
151151
require.Equal(t, addr2, addr)
152152
require.Equal(t,
153153
expectedAddrs[i], addr,
154-
"Is your device using test mnemonic: %s ?", testutil.TestMnemonic)
154+
"Is your device using test mnemonic: %s ?", testdata.TestMnemonic)
155155

156156
// Check other methods
157157
tmp := priv.(PrivKeyLedgerSecp256k1)
@@ -161,7 +161,7 @@ func TestPublicKeyHDPath(t *testing.T) {
161161
// in this test we are chekcking if the generated keys are correct and stored in a right path.
162162
require.Equal(t,
163163
expectedPubKeys[i], priv.PubKey().String(),
164-
"Is your device using test mnemonic: %s ?", testutil.TestMnemonic)
164+
"Is your device using test mnemonic: %s ?", testdata.TestMnemonic)
165165

166166
// Store and restore
167167
serializedPk := priv.Bytes()
@@ -203,7 +203,7 @@ func TestSignaturesHD(t *testing.T) {
203203
require.NoError(t, err)
204204

205205
valid := pub.VerifySignature(msg, sig)
206-
require.True(t, valid, "Is your device using test mnemonic: %s ?", testutil.TestMnemonic)
206+
require.True(t, valid, "Is your device using test mnemonic: %s ?", testdata.TestMnemonic)
207207
}
208208
}
209209

simapp/simd/cmd/testnet.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
2727
"github.com/cosmos/cosmos-sdk/server"
2828
srvconfig "github.com/cosmos/cosmos-sdk/server/config"
29+
"github.com/cosmos/cosmos-sdk/testutil"
2930
"github.com/cosmos/cosmos-sdk/testutil/network"
3031
sdk "github.com/cosmos/cosmos-sdk/types"
3132
"github.com/cosmos/cosmos-sdk/types/module"
@@ -263,7 +264,7 @@ func initTestnetFiles(
263264
return err
264265
}
265266

266-
addr, secret, err := server.GenerateSaveCoinKey(kb, nodeDirName, "", true, algo)
267+
addr, secret, err := testutil.GenerateSaveCoinKey(kb, nodeDirName, "", true, algo)
267268
if err != nil {
268269
_ = os.RemoveAll(args.outputDir)
269270
return err

0 commit comments

Comments
 (0)