@@ -27,7 +27,6 @@ import (
27
27
"testing"
28
28
"time"
29
29
30
- "github.com/ethereum/go-ethereum/console"
31
30
"github.com/ethereum/go-ethereum/rpc"
32
31
)
33
32
@@ -37,9 +36,10 @@ func TestConsoleWelcome(t *testing.T) {
37
36
coinbase := "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
38
37
39
38
// Start a geth console, make sure it's cleaned up and terminate the console
40
- geth := runGeth (t , "--nat" , "none" , "--nodiscover" , "--etherbase" , coinbase , "-shh" , "console" )
41
- defer geth .expectExit ()
42
- geth .stdin .Close ()
39
+ geth := runGeth (t ,
40
+ "--port" , "0" , "--maxpeers" , "0" , "--nodiscover" , "--nat" , "none" ,
41
+ "--etherbase" , coinbase , "--shh" ,
42
+ "console" )
43
43
44
44
// Gather all the infos the welcome message needs to contain
45
45
geth .setTemplateFunc ("goos" , func () string { return runtime .GOOS })
@@ -51,7 +51,6 @@ func TestConsoleWelcome(t *testing.T) {
51
51
sort .Strings (apis )
52
52
return apis
53
53
})
54
- geth .setTemplateFunc ("prompt" , func () string { return console .DefaultPrompt })
55
54
56
55
// Verify the actual welcome message to the required template
57
56
geth .expect (`
@@ -63,52 +62,63 @@ at block: 0 ({{niltime}})
63
62
datadir: {{.Datadir}}
64
63
modules:{{range apis}} {{.}}:1.0{{end}}
65
64
66
- {{prompt }}
65
+ > {{.InputLine "exit" }}
67
66
` )
67
+ geth .expectExit ()
68
68
}
69
69
70
70
// Tests that a console can be attached to a running node via various means.
71
71
func TestIPCAttachWelcome (t * testing.T ) {
72
72
// Configure the instance for IPC attachement
73
73
coinbase := "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
74
-
75
74
var ipc string
76
75
if runtime .GOOS == "windows" {
77
76
ipc = `\\.\pipe\geth` + strconv .Itoa (rand .Int ())
78
77
} else {
79
78
ws := tmpdir (t )
80
79
defer os .RemoveAll (ws )
81
-
82
80
ipc = filepath .Join (ws , "geth.ipc" )
83
81
}
84
- // Run the parent geth and attach with a child console
85
- geth := runGeth (t , "--nat" , "none" , "--nodiscover" , "--etherbase" , coinbase , "-shh" , "--ipcpath" , ipc )
86
- defer geth .interrupt ()
82
+ // Note: we need --shh because testAttachWelcome checks for default
83
+ // list of ipc modules and shh is included there.
84
+ geth := runGeth (t ,
85
+ "--port" , "0" , "--maxpeers" , "0" , "--nodiscover" , "--nat" , "none" ,
86
+ "--etherbase" , coinbase , "--shh" , "--ipcpath" , ipc )
87
87
88
88
time .Sleep (2 * time .Second ) // Simple way to wait for the RPC endpoint to open
89
89
testAttachWelcome (t , geth , "ipc:" + ipc )
90
+
91
+ geth .interrupt ()
92
+ geth .expectExit ()
90
93
}
91
94
92
95
func TestHTTPAttachWelcome (t * testing.T ) {
93
96
coinbase := "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
94
97
port := strconv .Itoa (rand .Intn (65535 - 1024 ) + 1024 ) // Yeah, sometimes this will fail, sorry :P
95
-
96
- geth := runGeth ( t , "--nat " , "none " , "--nodiscover " , "--etherbase " , coinbase , "--rpc " , "--rpcport " , port )
97
- defer geth . interrupt ( )
98
+ geth := runGeth ( t ,
99
+ "--port " , "0 " , "--maxpeers " , "0 " , "--nodiscover " , "--nat " , "none" ,
100
+ "--etherbase" , coinbase , "--rpc" , "--rpcport" , port )
98
101
99
102
time .Sleep (2 * time .Second ) // Simple way to wait for the RPC endpoint to open
100
103
testAttachWelcome (t , geth , "http://localhost:" + port )
104
+
105
+ geth .interrupt ()
106
+ geth .expectExit ()
101
107
}
102
108
103
109
func TestWSAttachWelcome (t * testing.T ) {
104
110
coinbase := "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
105
111
port := strconv .Itoa (rand .Intn (65535 - 1024 ) + 1024 ) // Yeah, sometimes this will fail, sorry :P
106
112
107
- geth := runGeth (t , "--nat" , "none" , "--nodiscover" , "--etherbase" , coinbase , "--ws" , "--wsport" , port )
108
- defer geth .interrupt ()
113
+ geth := runGeth (t ,
114
+ "--port" , "0" , "--maxpeers" , "0" , "--nodiscover" , "--nat" , "none" ,
115
+ "--etherbase" , coinbase , "--ws" , "--wsport" , port )
109
116
110
117
time .Sleep (2 * time .Second ) // Simple way to wait for the RPC endpoint to open
111
118
testAttachWelcome (t , geth , "ws://localhost:" + port )
119
+
120
+ geth .interrupt ()
121
+ geth .expectExit ()
112
122
}
113
123
114
124
func testAttachWelcome (t * testing.T , geth * testgeth , endpoint string ) {
@@ -135,7 +145,6 @@ func testAttachWelcome(t *testing.T, geth *testgeth, endpoint string) {
135
145
sort .Strings (apis )
136
146
return apis
137
147
})
138
- attach .setTemplateFunc ("prompt" , func () string { return console .DefaultPrompt })
139
148
140
149
// Verify the actual welcome message to the required template
141
150
attach .expect (`
@@ -147,6 +156,7 @@ at block: 0 ({{niltime}}){{if ipc}}
147
156
datadir: {{datadir}}{{end}}
148
157
modules:{{range apis}} {{.}}:1.0{{end}}
149
158
150
- {{prompt }}
159
+ > {{.InputLine "exit" }}
151
160
` )
161
+ attach .expectExit ()
152
162
}
0 commit comments