Skip to content

Commit a1f3878

Browse files
lmarsfjl
authored andcommitted
swarm/test: add integration test for 'swarm up' (ethereum#14353)
1 parent a20a02c commit a1f3878

17 files changed

+1048
-293
lines changed

cmd/geth/accountcmd_test.go

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,21 @@ func tmpDatadirWithKeystore(t *testing.T) string {
4444

4545
func TestAccountListEmpty(t *testing.T) {
4646
geth := runGeth(t, "account", "list")
47-
geth.expectExit()
47+
geth.ExpectExit()
4848
}
4949

5050
func TestAccountList(t *testing.T) {
5151
datadir := tmpDatadirWithKeystore(t)
5252
geth := runGeth(t, "account", "list", "--datadir", datadir)
53-
defer geth.expectExit()
53+
defer geth.ExpectExit()
5454
if runtime.GOOS == "windows" {
55-
geth.expect(`
55+
geth.Expect(`
5656
Account #0: {7ef5a6135f1fd6a02593eedc869c6d41d934aef8} keystore://{{.Datadir}}\keystore\UTC--2016-03-22T12-57-55.920751759Z--7ef5a6135f1fd6a02593eedc869c6d41d934aef8
5757
Account #1: {f466859ead1932d743d622cb74fc058882e8648a} keystore://{{.Datadir}}\keystore\aaa
5858
Account #2: {289d485d9771714cce91d3393d764e1311907acc} keystore://{{.Datadir}}\keystore\zzz
5959
`)
6060
} else {
61-
geth.expect(`
61+
geth.Expect(`
6262
Account #0: {7ef5a6135f1fd6a02593eedc869c6d41d934aef8} keystore://{{.Datadir}}/keystore/UTC--2016-03-22T12-57-55.920751759Z--7ef5a6135f1fd6a02593eedc869c6d41d934aef8
6363
Account #1: {f466859ead1932d743d622cb74fc058882e8648a} keystore://{{.Datadir}}/keystore/aaa
6464
Account #2: {289d485d9771714cce91d3393d764e1311907acc} keystore://{{.Datadir}}/keystore/zzz
@@ -68,20 +68,20 @@ Account #2: {289d485d9771714cce91d3393d764e1311907acc} keystore://{{.Datadir}}/k
6868

6969
func TestAccountNew(t *testing.T) {
7070
geth := runGeth(t, "account", "new", "--lightkdf")
71-
defer geth.expectExit()
72-
geth.expect(`
71+
defer geth.ExpectExit()
72+
geth.Expect(`
7373
Your new account is locked with a password. Please give a password. Do not forget this password.
7474
!! Unsupported terminal, password will be echoed.
7575
Passphrase: {{.InputLine "foobar"}}
7676
Repeat passphrase: {{.InputLine "foobar"}}
7777
`)
78-
geth.expectRegexp(`Address: \{[0-9a-f]{40}\}\n`)
78+
geth.ExpectRegexp(`Address: \{[0-9a-f]{40}\}\n`)
7979
}
8080

8181
func TestAccountNewBadRepeat(t *testing.T) {
8282
geth := runGeth(t, "account", "new", "--lightkdf")
83-
defer geth.expectExit()
84-
geth.expect(`
83+
defer geth.ExpectExit()
84+
geth.Expect(`
8585
Your new account is locked with a password. Please give a password. Do not forget this password.
8686
!! Unsupported terminal, password will be echoed.
8787
Passphrase: {{.InputLine "something"}}
@@ -95,8 +95,8 @@ func TestAccountUpdate(t *testing.T) {
9595
geth := runGeth(t, "account", "update",
9696
"--datadir", datadir, "--lightkdf",
9797
"f466859ead1932d743d622cb74fc058882e8648a")
98-
defer geth.expectExit()
99-
geth.expect(`
98+
defer geth.ExpectExit()
99+
geth.Expect(`
100100
Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
101101
!! Unsupported terminal, password will be echoed.
102102
Passphrase: {{.InputLine "foobar"}}
@@ -108,8 +108,8 @@ Repeat passphrase: {{.InputLine "foobar2"}}
108108

109109
func TestWalletImport(t *testing.T) {
110110
geth := runGeth(t, "wallet", "import", "--lightkdf", "testdata/guswallet.json")
111-
defer geth.expectExit()
112-
geth.expect(`
111+
defer geth.ExpectExit()
112+
geth.Expect(`
113113
!! Unsupported terminal, password will be echoed.
114114
Passphrase: {{.InputLine "foo"}}
115115
Address: {d4584b5f6229b7be90727b0fc8c6b91bb427821f}
@@ -123,8 +123,8 @@ Address: {d4584b5f6229b7be90727b0fc8c6b91bb427821f}
123123

124124
func TestWalletImportBadPassword(t *testing.T) {
125125
geth := runGeth(t, "wallet", "import", "--lightkdf", "testdata/guswallet.json")
126-
defer geth.expectExit()
127-
geth.expect(`
126+
defer geth.ExpectExit()
127+
geth.Expect(`
128128
!! Unsupported terminal, password will be echoed.
129129
Passphrase: {{.InputLine "wrong"}}
130130
Fatal: could not decrypt key with given passphrase
@@ -137,19 +137,19 @@ func TestUnlockFlag(t *testing.T) {
137137
"--datadir", datadir, "--nat", "none", "--nodiscover", "--dev",
138138
"--unlock", "f466859ead1932d743d622cb74fc058882e8648a",
139139
"js", "testdata/empty.js")
140-
geth.expect(`
140+
geth.Expect(`
141141
Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
142142
!! Unsupported terminal, password will be echoed.
143143
Passphrase: {{.InputLine "foobar"}}
144144
`)
145-
geth.expectExit()
145+
geth.ExpectExit()
146146

147147
wantMessages := []string{
148148
"Unlocked account",
149149
"=0xf466859ead1932d743d622cb74fc058882e8648a",
150150
}
151151
for _, m := range wantMessages {
152-
if !strings.Contains(geth.stderrText(), m) {
152+
if !strings.Contains(geth.StderrText(), m) {
153153
t.Errorf("stderr text does not contain %q", m)
154154
}
155155
}
@@ -160,8 +160,8 @@ func TestUnlockFlagWrongPassword(t *testing.T) {
160160
geth := runGeth(t,
161161
"--datadir", datadir, "--nat", "none", "--nodiscover", "--dev",
162162
"--unlock", "f466859ead1932d743d622cb74fc058882e8648a")
163-
defer geth.expectExit()
164-
geth.expect(`
163+
defer geth.ExpectExit()
164+
geth.Expect(`
165165
Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
166166
!! Unsupported terminal, password will be echoed.
167167
Passphrase: {{.InputLine "wrong1"}}
@@ -180,22 +180,22 @@ func TestUnlockFlagMultiIndex(t *testing.T) {
180180
"--datadir", datadir, "--nat", "none", "--nodiscover", "--dev",
181181
"--unlock", "0,2",
182182
"js", "testdata/empty.js")
183-
geth.expect(`
183+
geth.Expect(`
184184
Unlocking account 0 | Attempt 1/3
185185
!! Unsupported terminal, password will be echoed.
186186
Passphrase: {{.InputLine "foobar"}}
187187
Unlocking account 2 | Attempt 1/3
188188
Passphrase: {{.InputLine "foobar"}}
189189
`)
190-
geth.expectExit()
190+
geth.ExpectExit()
191191

192192
wantMessages := []string{
193193
"Unlocked account",
194194
"=0x7ef5a6135f1fd6a02593eedc869c6d41d934aef8",
195195
"=0x289d485d9771714cce91d3393d764e1311907acc",
196196
}
197197
for _, m := range wantMessages {
198-
if !strings.Contains(geth.stderrText(), m) {
198+
if !strings.Contains(geth.StderrText(), m) {
199199
t.Errorf("stderr text does not contain %q", m)
200200
}
201201
}
@@ -207,15 +207,15 @@ func TestUnlockFlagPasswordFile(t *testing.T) {
207207
"--datadir", datadir, "--nat", "none", "--nodiscover", "--dev",
208208
"--password", "testdata/passwords.txt", "--unlock", "0,2",
209209
"js", "testdata/empty.js")
210-
geth.expectExit()
210+
geth.ExpectExit()
211211

212212
wantMessages := []string{
213213
"Unlocked account",
214214
"=0x7ef5a6135f1fd6a02593eedc869c6d41d934aef8",
215215
"=0x289d485d9771714cce91d3393d764e1311907acc",
216216
}
217217
for _, m := range wantMessages {
218-
if !strings.Contains(geth.stderrText(), m) {
218+
if !strings.Contains(geth.StderrText(), m) {
219219
t.Errorf("stderr text does not contain %q", m)
220220
}
221221
}
@@ -226,8 +226,8 @@ func TestUnlockFlagPasswordFileWrongPassword(t *testing.T) {
226226
geth := runGeth(t,
227227
"--datadir", datadir, "--nat", "none", "--nodiscover", "--dev",
228228
"--password", "testdata/wrong-passwords.txt", "--unlock", "0,2")
229-
defer geth.expectExit()
230-
geth.expect(`
229+
defer geth.ExpectExit()
230+
geth.Expect(`
231231
Fatal: Failed to unlock account 0 (could not decrypt key with given passphrase)
232232
`)
233233
}
@@ -238,14 +238,14 @@ func TestUnlockFlagAmbiguous(t *testing.T) {
238238
"--keystore", store, "--nat", "none", "--nodiscover", "--dev",
239239
"--unlock", "f466859ead1932d743d622cb74fc058882e8648a",
240240
"js", "testdata/empty.js")
241-
defer geth.expectExit()
241+
defer geth.ExpectExit()
242242

243243
// Helper for the expect template, returns absolute keystore path.
244-
geth.setTemplateFunc("keypath", func(file string) string {
244+
geth.SetTemplateFunc("keypath", func(file string) string {
245245
abs, _ := filepath.Abs(filepath.Join(store, file))
246246
return abs
247247
})
248-
geth.expect(`
248+
geth.Expect(`
249249
Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
250250
!! Unsupported terminal, password will be echoed.
251251
Passphrase: {{.InputLine "foobar"}}
@@ -257,14 +257,14 @@ Your passphrase unlocked keystore://{{keypath "1"}}
257257
In order to avoid this warning, you need to remove the following duplicate key files:
258258
keystore://{{keypath "2"}}
259259
`)
260-
geth.expectExit()
260+
geth.ExpectExit()
261261

262262
wantMessages := []string{
263263
"Unlocked account",
264264
"=0xf466859ead1932d743d622cb74fc058882e8648a",
265265
}
266266
for _, m := range wantMessages {
267-
if !strings.Contains(geth.stderrText(), m) {
267+
if !strings.Contains(geth.StderrText(), m) {
268268
t.Errorf("stderr text does not contain %q", m)
269269
}
270270
}
@@ -275,14 +275,14 @@ func TestUnlockFlagAmbiguousWrongPassword(t *testing.T) {
275275
geth := runGeth(t,
276276
"--keystore", store, "--nat", "none", "--nodiscover", "--dev",
277277
"--unlock", "f466859ead1932d743d622cb74fc058882e8648a")
278-
defer geth.expectExit()
278+
defer geth.ExpectExit()
279279

280280
// Helper for the expect template, returns absolute keystore path.
281-
geth.setTemplateFunc("keypath", func(file string) string {
281+
geth.SetTemplateFunc("keypath", func(file string) string {
282282
abs, _ := filepath.Abs(filepath.Join(store, file))
283283
return abs
284284
})
285-
geth.expect(`
285+
geth.Expect(`
286286
Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
287287
!! Unsupported terminal, password will be echoed.
288288
Passphrase: {{.InputLine "wrong"}}
@@ -292,5 +292,5 @@ Multiple key files exist for address f466859ead1932d743d622cb74fc058882e8648a:
292292
Testing your passphrase against all of them...
293293
Fatal: None of the listed files could be unlocked.
294294
`)
295-
geth.expectExit()
295+
geth.ExpectExit()
296296
}

cmd/geth/consolecmd_test.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ func TestConsoleWelcome(t *testing.T) {
4747
"console")
4848

4949
// Gather all the infos the welcome message needs to contain
50-
geth.setTemplateFunc("goos", func() string { return runtime.GOOS })
51-
geth.setTemplateFunc("goarch", func() string { return runtime.GOARCH })
52-
geth.setTemplateFunc("gover", runtime.Version)
53-
geth.setTemplateFunc("gethver", func() string { return params.Version })
54-
geth.setTemplateFunc("niltime", func() string { return time.Unix(0, 0).Format(time.RFC1123) })
55-
geth.setTemplateFunc("apis", func() string { return ipcAPIs })
50+
geth.SetTemplateFunc("goos", func() string { return runtime.GOOS })
51+
geth.SetTemplateFunc("goarch", func() string { return runtime.GOARCH })
52+
geth.SetTemplateFunc("gover", runtime.Version)
53+
geth.SetTemplateFunc("gethver", func() string { return params.Version })
54+
geth.SetTemplateFunc("niltime", func() string { return time.Unix(0, 0).Format(time.RFC1123) })
55+
geth.SetTemplateFunc("apis", func() string { return ipcAPIs })
5656

5757
// Verify the actual welcome message to the required template
58-
geth.expect(`
58+
geth.Expect(`
5959
Welcome to the Geth JavaScript console!
6060
6161
instance: Geth/v{{gethver}}/{{goos}}-{{goarch}}/{{gover}}
@@ -66,7 +66,7 @@ at block: 0 ({{niltime}})
6666
6767
> {{.InputLine "exit"}}
6868
`)
69-
geth.expectExit()
69+
geth.ExpectExit()
7070
}
7171

7272
// Tests that a console can be attached to a running node via various means.
@@ -90,8 +90,8 @@ func TestIPCAttachWelcome(t *testing.T) {
9090
time.Sleep(2 * time.Second) // Simple way to wait for the RPC endpoint to open
9191
testAttachWelcome(t, geth, "ipc:"+ipc, ipcAPIs)
9292

93-
geth.interrupt()
94-
geth.expectExit()
93+
geth.Interrupt()
94+
geth.ExpectExit()
9595
}
9696

9797
func TestHTTPAttachWelcome(t *testing.T) {
@@ -104,8 +104,8 @@ func TestHTTPAttachWelcome(t *testing.T) {
104104
time.Sleep(2 * time.Second) // Simple way to wait for the RPC endpoint to open
105105
testAttachWelcome(t, geth, "http://localhost:"+port, httpAPIs)
106106

107-
geth.interrupt()
108-
geth.expectExit()
107+
geth.Interrupt()
108+
geth.ExpectExit()
109109
}
110110

111111
func TestWSAttachWelcome(t *testing.T) {
@@ -119,29 +119,29 @@ func TestWSAttachWelcome(t *testing.T) {
119119
time.Sleep(2 * time.Second) // Simple way to wait for the RPC endpoint to open
120120
testAttachWelcome(t, geth, "ws://localhost:"+port, httpAPIs)
121121

122-
geth.interrupt()
123-
geth.expectExit()
122+
geth.Interrupt()
123+
geth.ExpectExit()
124124
}
125125

126126
func testAttachWelcome(t *testing.T, geth *testgeth, endpoint, apis string) {
127127
// Attach to a running geth note and terminate immediately
128128
attach := runGeth(t, "attach", endpoint)
129-
defer attach.expectExit()
130-
attach.stdin.Close()
129+
defer attach.ExpectExit()
130+
attach.CloseStdin()
131131

132132
// Gather all the infos the welcome message needs to contain
133-
attach.setTemplateFunc("goos", func() string { return runtime.GOOS })
134-
attach.setTemplateFunc("goarch", func() string { return runtime.GOARCH })
135-
attach.setTemplateFunc("gover", runtime.Version)
136-
attach.setTemplateFunc("gethver", func() string { return params.Version })
137-
attach.setTemplateFunc("etherbase", func() string { return geth.Etherbase })
138-
attach.setTemplateFunc("niltime", func() string { return time.Unix(0, 0).Format(time.RFC1123) })
139-
attach.setTemplateFunc("ipc", func() bool { return strings.HasPrefix(endpoint, "ipc") })
140-
attach.setTemplateFunc("datadir", func() string { return geth.Datadir })
141-
attach.setTemplateFunc("apis", func() string { return apis })
133+
attach.SetTemplateFunc("goos", func() string { return runtime.GOOS })
134+
attach.SetTemplateFunc("goarch", func() string { return runtime.GOARCH })
135+
attach.SetTemplateFunc("gover", runtime.Version)
136+
attach.SetTemplateFunc("gethver", func() string { return params.Version })
137+
attach.SetTemplateFunc("etherbase", func() string { return geth.Etherbase })
138+
attach.SetTemplateFunc("niltime", func() string { return time.Unix(0, 0).Format(time.RFC1123) })
139+
attach.SetTemplateFunc("ipc", func() bool { return strings.HasPrefix(endpoint, "ipc") })
140+
attach.SetTemplateFunc("datadir", func() string { return geth.Datadir })
141+
attach.SetTemplateFunc("apis", func() string { return apis })
142142

143143
// Verify the actual welcome message to the required template
144-
attach.expect(`
144+
attach.Expect(`
145145
Welcome to the Geth JavaScript console!
146146
147147
instance: Geth/v{{gethver}}/{{goos}}-{{goarch}}/{{gover}}
@@ -152,7 +152,7 @@ at block: 0 ({{niltime}}){{if ipc}}
152152
153153
> {{.InputLine "exit" }}
154154
`)
155-
attach.expectExit()
155+
attach.ExpectExit()
156156
}
157157

158158
// trulyRandInt generates a crypto random integer used by the console tests to

cmd/geth/dao_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ func testDAOForkBlockNewChain(t *testing.T, test int, genesis string, expectBloc
112112
if err := ioutil.WriteFile(json, []byte(genesis), 0600); err != nil {
113113
t.Fatalf("test %d: failed to write genesis file: %v", test, err)
114114
}
115-
runGeth(t, "--datadir", datadir, "init", json).cmd.Wait()
115+
runGeth(t, "--datadir", datadir, "init", json).WaitExit()
116116
} else {
117117
// Force chain initialization
118118
args := []string{"--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none", "--ipcdisable", "--datadir", datadir}
119119
geth := runGeth(t, append(args, []string{"--exec", "2+2", "console"}...)...)
120-
geth.cmd.Wait()
120+
geth.WaitExit()
121121
}
122122
// Retrieve the DAO config flag from the database
123123
path := filepath.Join(datadir, "geth", "chaindata")

cmd/geth/genesis_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ func TestCustomGenesis(t *testing.T) {
9797
if err := ioutil.WriteFile(json, []byte(tt.genesis), 0600); err != nil {
9898
t.Fatalf("test %d: failed to write genesis file: %v", i, err)
9999
}
100-
runGeth(t, "--datadir", datadir, "init", json).cmd.Wait()
100+
runGeth(t, "--datadir", datadir, "init", json).WaitExit()
101101

102102
// Query the custom genesis block
103103
geth := runGeth(t,
104104
"--datadir", datadir, "--maxpeers", "0", "--port", "0",
105105
"--nodiscover", "--nat", "none", "--ipcdisable",
106106
"--exec", tt.query, "console")
107-
geth.expectRegexp(tt.result)
108-
geth.expectExit()
107+
geth.ExpectRegexp(tt.result)
108+
geth.ExpectExit()
109109
}
110110
}

0 commit comments

Comments
 (0)