@@ -20,15 +20,13 @@ import (
20
20
)
21
21
22
22
func Test_runExportCmd (t * testing.T ) {
23
- cdc := moduletestutil .MakeTestEncodingConfig (codectestutil.CodecOptions {}).Codec
24
23
testCases := []struct {
25
- name string
26
- keyringBackend string
27
- extraArgs []string
28
- userInput string
29
- mustFail bool
30
- expectedOutput string
31
- expectedOutputContain string // only valid when expectedOutput is empty
24
+ name string
25
+ keyringBackend string
26
+ extraArgs []string
27
+ userInput string
28
+ mustFail bool
29
+ expectedOutput string
32
30
}{
33
31
{
34
32
name : "--unsafe only must fail" ,
@@ -51,33 +49,17 @@ func Test_runExportCmd(t *testing.T) {
51
49
expectedOutput : "" ,
52
50
},
53
51
{
54
- name : "--unsafe --unarmored-hex --yes success" ,
55
- keyringBackend : keyring .BackendTest ,
56
- extraArgs : []string {"--unsafe" , "--unarmored-hex" , "--yes" },
57
- userInput : "" ,
58
- mustFail : false ,
59
- expectedOutputContain : "2485e33678db4175dc0ecef2d6e1fc493d4a0d7f7ce83324b6ed70afe77f3485\n " ,
60
- },
61
- {
62
- name : "--unsafe --unarmored-hex success" ,
63
- keyringBackend : keyring .BackendTest ,
64
- extraArgs : []string {"--unsafe" , "--unarmored-hex" },
65
- userInput : "y\n " ,
66
- mustFail : false ,
67
- expectedOutputContain : "2485e33678db4175dc0ecef2d6e1fc493d4a0d7f7ce83324b6ed70afe77f3485\n " ,
68
- },
69
- {
70
- name : "--unsafe --unarmored-hex --indiscreet success" ,
52
+ name : "--unsafe --unarmored-hex succeed" ,
71
53
keyringBackend : keyring .BackendTest ,
72
- extraArgs : []string {"--unsafe" , "--unarmored-hex" , "--indiscreet" },
54
+ extraArgs : []string {"--unsafe" , "--unarmored-hex" },
73
55
userInput : "y\n " ,
74
56
mustFail : false ,
75
57
expectedOutput : "2485e33678db4175dc0ecef2d6e1fc493d4a0d7f7ce83324b6ed70afe77f3485\n " ,
76
58
},
77
59
{
78
60
name : "file keyring backend properly read password and user confirmation" ,
79
61
keyringBackend : keyring .BackendFile ,
80
- extraArgs : []string {"--unsafe" , "--unarmored-hex" , "--indiscreet" },
62
+ extraArgs : []string {"--unsafe" , "--unarmored-hex" },
81
63
// first 2 pass for creating the key, then unsafe export confirmation, then unlock keyring pass
82
64
userInput : "12345678\n 12345678\n y\n 12345678\n " ,
83
65
mustFail : false ,
@@ -90,12 +72,12 @@ func Test_runExportCmd(t *testing.T) {
90
72
kbHome := t .TempDir ()
91
73
defaultArgs := []string {
92
74
"keyname1" ,
93
- fmt .Sprintf ("--%s=%s" , flags .FlagKeyringDir , kbHome ),
75
+ fmt .Sprintf ("--%s=%s" , flags .FlagHome , kbHome ),
94
76
fmt .Sprintf ("--%s=%s" , flags .FlagKeyringBackend , tc .keyringBackend ),
95
77
}
96
78
97
79
cmd := ExportKeyCommand ()
98
- cmd .Flags ().AddFlagSet (Commands ().PersistentFlags ())
80
+ cmd .Flags ().AddFlagSet (Commands ("home" ).PersistentFlags ())
99
81
100
82
cmd .SetArgs (append (defaultArgs , tc .extraArgs ... ))
101
83
mockIn , mockOut := testutil .ApplyMockIO (cmd )
@@ -104,31 +86,28 @@ func Test_runExportCmd(t *testing.T) {
104
86
mockInBuf := bufio .NewReader (mockIn )
105
87
106
88
// create a key
107
- kb , err := keyring .New (sdk .KeyringServiceName (), tc .keyringBackend , kbHome , bufio .NewReader (mockInBuf ), cdc )
89
+ kb , err := keyring .New (sdk .KeyringServiceName (), tc .keyringBackend , kbHome , bufio .NewReader (mockInBuf ))
108
90
require .NoError (t , err )
109
- t .Cleanup (cleanupKeys (t , kb , "keyname1" ))
91
+ t .Cleanup (func () {
92
+ kb .Delete ("keyname1" ) // nolint:errcheck
93
+ })
110
94
111
- path := sdk .GetFullBIP44Path ()
112
- _ , err = kb .NewAccount ("keyname1" , testdata .TestMnemonic , "" , path , hd .Secp256k1 )
95
+ path := sdk .GetConfig (). GetFullBIP44Path ()
96
+ _ , err = kb .NewAccount ("keyname1" , testutil .TestMnemonic , "" , path , hd .Secp256k1 )
113
97
require .NoError (t , err )
114
98
115
99
clientCtx := client.Context {}.
116
100
WithKeyringDir (kbHome ).
117
101
WithKeyring (kb ).
118
- WithInput (mockInBuf ).
119
- WithCodec (cdc )
102
+ WithInput (mockInBuf )
120
103
ctx := context .WithValue (context .Background (), client .ClientContextKey , & clientCtx )
121
104
122
105
err = cmd .ExecuteContext (ctx )
123
106
if tc .mustFail {
124
107
require .Error (t , err )
125
108
} else {
126
109
require .NoError (t , err )
127
- if tc .expectedOutput != "" {
128
- require .Equal (t , tc .expectedOutput , mockOut .String ())
129
- } else if tc .expectedOutputContain != "" {
130
- require .Contains (t , mockOut .String (), tc .expectedOutputContain )
131
- }
110
+ require .Equal (t , tc .expectedOutput , mockOut .String ())
132
111
}
133
112
})
134
113
}
0 commit comments