Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
32258af8
Commit
32258af8
authored
8 years ago
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/geth: truly randomize console test RPC endpoints
parent
fdd61b83
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
4 deletions
+12
-4
consolecmd_test.go
cmd/geth/consolecmd_test.go
+12
-4
No files found.
cmd/geth/consolecmd_test.go
View file @
32258af8
...
...
@@ -17,7 +17,8 @@
package
main
import
(
"math/rand"
"crypto/rand"
"math/big"
"os"
"path/filepath"
"runtime"
...
...
@@ -73,7 +74,7 @@ func TestIPCAttachWelcome(t *testing.T) {
coinbase
:=
"0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
var
ipc
string
if
runtime
.
GOOS
==
"windows"
{
ipc
=
`\\.\pipe\geth`
+
strconv
.
Itoa
(
rand
.
Int
(
))
ipc
=
`\\.\pipe\geth`
+
strconv
.
Itoa
(
trulyRandInt
(
100000
,
999999
))
}
else
{
ws
:=
tmpdir
(
t
)
defer
os
.
RemoveAll
(
ws
)
...
...
@@ -94,7 +95,7 @@ func TestIPCAttachWelcome(t *testing.T) {
func
TestHTTPAttachWelcome
(
t
*
testing
.
T
)
{
coinbase
:=
"0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
port
:=
strconv
.
Itoa
(
rand
.
Intn
(
65535
-
1024
)
+
1024
)
// Yeah, sometimes this will fail, sorry :P
port
:=
strconv
.
Itoa
(
trulyRandInt
(
1024
,
65536
)
)
// Yeah, sometimes this will fail, sorry :P
geth
:=
runGeth
(
t
,
"--port"
,
"0"
,
"--maxpeers"
,
"0"
,
"--nodiscover"
,
"--nat"
,
"none"
,
"--etherbase"
,
coinbase
,
"--rpc"
,
"--rpcport"
,
port
)
...
...
@@ -108,7 +109,7 @@ func TestHTTPAttachWelcome(t *testing.T) {
func
TestWSAttachWelcome
(
t
*
testing
.
T
)
{
coinbase
:=
"0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
port
:=
strconv
.
Itoa
(
rand
.
Intn
(
65535
-
1024
)
+
1024
)
// Yeah, sometimes this will fail, sorry :P
port
:=
strconv
.
Itoa
(
trulyRandInt
(
1024
,
65536
)
)
// Yeah, sometimes this will fail, sorry :P
geth
:=
runGeth
(
t
,
"--port"
,
"0"
,
"--maxpeers"
,
"0"
,
"--nodiscover"
,
"--nat"
,
"none"
,
...
...
@@ -160,3 +161,10 @@ at block: 0 ({{niltime}}){{if ipc}}
`
)
attach
.
expectExit
()
}
// trulyRandInt generates a crypto random integer used by the console tests to
// not clash network ports with other tests running cocurrently.
func
trulyRandInt
(
lo
,
hi
int
)
int
{
num
,
_
:=
rand
.
Int
(
rand
.
Reader
,
big
.
NewInt
(
int64
(
hi
-
lo
)))
return
int
(
num
.
Int64
())
+
lo
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment