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
6b6c4d1c
Unverified
Commit
6b6c4d1c
authored
Nov 19, 2018
by
Anton Evangelatov
Committed by
GitHub
Nov 19, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/swarm: speed up tests - use global cluster (#18129)
parent
3333fe66
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
101 additions
and
92 deletions
+101
-92
access_test.go
cmd/swarm/access_test.go
+44
-35
export_test.go
cmd/swarm/export_test.go
+2
-2
feeds_test.go
cmd/swarm/feeds_test.go
+0
-2
fs_test.go
cmd/swarm/fs_test.go
+0
-6
run_test.go
cmd/swarm/run_test.go
+11
-0
upload_test.go
cmd/swarm/upload_test.go
+44
-47
No files found.
cmd/swarm/access_test.go
View file @
6b6c4d1c
...
...
@@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
// +build !windows
package
main
import
(
...
...
@@ -28,6 +26,7 @@ import (
gorand
"math/rand"
"net/http"
"os"
"runtime"
"strings"
"testing"
"time"
...
...
@@ -37,8 +36,7 @@ import (
"github.com/ethereum/go-ethereum/crypto/sha3"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/swarm/api"
swarm
"github.com/ethereum/go-ethereum/swarm/api/client"
swarmhttp
"github.com/ethereum/go-ethereum/swarm/api/http"
swarmapi
"github.com/ethereum/go-ethereum/swarm/api/client"
"github.com/ethereum/go-ethereum/swarm/testutil"
)
...
...
@@ -49,22 +47,41 @@ const (
var
DefaultCurve
=
crypto
.
S256
()
// TestAccessPassword tests for the correct creation of an ACT manifest protected by a password.
func
TestACT
(
t
*
testing
.
T
)
{
if
runtime
.
GOOS
==
"windows"
{
t
.
Skip
()
}
initCluster
(
t
)
cases
:=
[]
struct
{
name
string
f
func
(
t
*
testing
.
T
)
}{
{
"Password"
,
testPassword
},
{
"PK"
,
testPK
},
{
"ACTWithoutBogus"
,
testACTWithoutBogus
},
{
"ACTWithBogus"
,
testACTWithBogus
},
}
for
_
,
tc
:=
range
cases
{
t
.
Run
(
tc
.
name
,
tc
.
f
)
}
}
// testPassword tests for the correct creation of an ACT manifest protected by a password.
// The test creates bogus content, uploads it encrypted, then creates the wrapping manifest with the Access entry
// The parties participating - node (publisher), uploads to second node then disappears. Content which was uploaded
// is then fetched through 2nd node. since the tested code is not key-aware - we can just
// fetch from the 2nd node using HTTP BasicAuth
func
TestAccessPassword
(
t
*
testing
.
T
)
{
srv
:=
swarmhttp
.
NewTestSwarmServer
(
t
,
serverFunc
,
nil
)
defer
srv
.
Close
()
func
testPassword
(
t
*
testing
.
T
)
{
dataFilename
:=
testutil
.
TempFileWithContent
(
t
,
data
)
defer
os
.
RemoveAll
(
dataFilename
)
// upload the file with 'swarm up' and expect a hash
up
:=
runSwarm
(
t
,
"--bzzapi"
,
srv
.
URL
,
//it doesn't matter through which node we upload content
cluster
.
Nodes
[
0
]
.
URL
,
"up"
,
"--encrypt"
,
dataFilename
)
...
...
@@ -138,16 +155,17 @@ func TestAccessPassword(t *testing.T) {
if
a
.
Publisher
!=
""
{
t
.
Fatal
(
"should be empty"
)
}
client
:=
swarm
.
NewClient
(
srv
.
URL
)
client
:=
swarmapi
.
NewClient
(
cluster
.
Nodes
[
0
]
.
URL
)
hash
,
err
:=
client
.
UploadManifest
(
&
m
,
false
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
httpClient
:=
&
http
.
Client
{}
url
:=
cluster
.
Nodes
[
0
]
.
URL
+
"/"
+
"bzz:/"
+
hash
url
:=
srv
.
URL
+
"/"
+
"bzz:/"
+
hash
httpClient
:=
&
http
.
Client
{}
response
,
err
:=
httpClient
.
Get
(
url
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -189,7 +207,7 @@ func TestAccessPassword(t *testing.T) {
//download file with 'swarm down' with wrong password
up
=
runSwarm
(
t
,
"--bzzapi"
,
srv
.
URL
,
cluster
.
Nodes
[
0
]
.
URL
,
"down"
,
"bzz:/"
+
hash
,
tmp
,
...
...
@@ -203,16 +221,12 @@ func TestAccessPassword(t *testing.T) {
up
.
ExpectExit
()
}
//
TestAccess
PK tests for the correct creation of an ACT manifest between two parties (publisher and grantee).
//
test
PK tests for the correct creation of an ACT manifest between two parties (publisher and grantee).
// The test creates bogus content, uploads it encrypted, then creates the wrapping manifest with the Access entry
// The parties participating - node (publisher), uploads to second node (which is also the grantee) then disappears.
// Content which was uploaded is then fetched through the grantee's http proxy. Since the tested code is private-key aware,
// the test will fail if the proxy's given private key is not granted on the ACT.
func
TestAccessPK
(
t
*
testing
.
T
)
{
// Setup Swarm and upload a test file to it
cluster
:=
newTestCluster
(
t
,
2
)
defer
cluster
.
Shutdown
()
func
testPK
(
t
*
testing
.
T
)
{
dataFilename
:=
testutil
.
TempFileWithContent
(
t
,
data
)
defer
os
.
RemoveAll
(
dataFilename
)
...
...
@@ -318,7 +332,7 @@ func TestAccessPK(t *testing.T) {
if
a
.
Publisher
!=
pkComp
{
t
.
Fatal
(
"publisher key did not match"
)
}
client
:=
swarm
.
NewClient
(
cluster
.
Nodes
[
0
]
.
URL
)
client
:=
swarm
api
.
NewClient
(
cluster
.
Nodes
[
0
]
.
URL
)
hash
,
err
:=
client
.
UploadManifest
(
&
m
,
false
)
if
err
!=
nil
{
...
...
@@ -344,29 +358,24 @@ func TestAccessPK(t *testing.T) {
}
}
//
TestAccessACT
tests the creation of the ACT manifest end-to-end, without any bogus entries (i.e. default scenario = 3 nodes 1 unauthorized)
func
TestAccessACT
(
t
*
testing
.
T
)
{
testA
ccessA
CT
(
t
,
0
)
//
testACTWithoutBogus
tests the creation of the ACT manifest end-to-end, without any bogus entries (i.e. default scenario = 3 nodes 1 unauthorized)
func
testACTWithoutBogus
(
t
*
testing
.
T
)
{
testACT
(
t
,
0
)
}
//
TestAccessACTScale tests the creation of the ACT manifest end-to-end, with 1000 bogus entries (i.e. 1000 EC keys + default scenario = 3 nodes 1 unauthorized = 10
03 keys in the ACT manifest)
func
TestAccessACTScale
(
t
*
testing
.
T
)
{
testA
ccessACT
(
t
,
10
00
)
//
testACTWithBogus tests the creation of the ACT manifest end-to-end, with 100 bogus entries (i.e. 100 EC keys + default scenario = 3 nodes 1 unauthorized = 1
03 keys in the ACT manifest)
func
testACTWithBogus
(
t
*
testing
.
T
)
{
testA
CT
(
t
,
1
00
)
}
//
TestAccess
ACT tests the e2e creation, uploading and downloading of an ACT access control with both EC keys AND password protection
//
test
ACT tests the e2e creation, uploading and downloading of an ACT access control with both EC keys AND password protection
// the test fires up a 3 node cluster, then randomly picks 2 nodes which will be acting as grantees to the data
// set and also protects the ACT with a password. the third node should fail decoding the reference as it will not be granted access.
// the third node then then tries to download using a correct password (and succeeds) then uses a wrong password and fails.
// the publisher uploads through one of the nodes then disappears.
func
testAccessACT
(
t
*
testing
.
T
,
bogusEntries
int
)
{
// Setup Swarm and upload a test file to it
const
clusterSize
=
3
cluster
:=
newTestCluster
(
t
,
clusterSize
)
defer
cluster
.
Shutdown
()
func
testACT
(
t
*
testing
.
T
,
bogusEntries
int
)
{
var
uploadThroughNode
=
cluster
.
Nodes
[
0
]
client
:=
swarm
.
NewClient
(
uploadThroughNode
.
URL
)
client
:=
swarm
api
.
NewClient
(
uploadThroughNode
.
URL
)
r1
:=
gorand
.
New
(
gorand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
nodeToSkip
:=
r1
.
Intn
(
clusterSize
)
// a number between 0 and 2 (node indices in `cluster`)
...
...
cmd/swarm/export_test.go
View file @
6b6c4d1c
...
...
@@ -43,8 +43,8 @@ func TestCLISwarmExportImport(t *testing.T) {
}
cluster
:=
newTestCluster
(
t
,
1
)
// generate random 1
0
mb file
content
:=
testutil
.
RandomBytes
(
1
,
1000000
0
)
// generate random 1mb file
content
:=
testutil
.
RandomBytes
(
1
,
1000000
)
fileName
:=
testutil
.
TempFileWithContent
(
t
,
string
(
content
))
defer
os
.
Remove
(
fileName
)
...
...
cmd/swarm/feeds_test.go
View file @
6b6c4d1c
...
...
@@ -36,7 +36,6 @@ import (
)
func
TestCLIFeedUpdate
(
t
*
testing
.
T
)
{
srv
:=
swarmhttp
.
NewTestSwarmServer
(
t
,
func
(
api
*
api
.
API
)
swarmhttp
.
TestServer
{
return
swarmhttp
.
NewServer
(
api
,
""
)
},
nil
)
...
...
@@ -44,7 +43,6 @@ func TestCLIFeedUpdate(t *testing.T) {
defer
srv
.
Close
()
// create a private key file for signing
privkeyHex
:=
"0000000000000000000000000000000000000000000000000000000000001979"
privKey
,
_
:=
crypto
.
HexToECDSA
(
privkeyHex
)
address
:=
crypto
.
PubkeyToAddress
(
privKey
.
PublicKey
)
...
...
cmd/swarm/fs_test.go
View file @
6b6c4d1c
...
...
@@ -29,14 +29,8 @@ import (
"time"
"github.com/ethereum/go-ethereum/log"
colorable
"github.com/mattn/go-colorable"
)
func
init
()
{
log
.
PrintOrigins
(
true
)
log
.
Root
()
.
SetHandler
(
log
.
LvlFilterHandler
(
log
.
Lvl
(
*
loglevel
),
log
.
StreamHandler
(
colorable
.
NewColorableStderr
(),
log
.
TerminalFormat
(
true
))))
}
type
testFile
struct
{
filePath
string
content
string
...
...
cmd/swarm/run_test.go
View file @
6b6c4d1c
...
...
@@ -57,6 +57,17 @@ func init() {
})
}
const
clusterSize
=
3
var
clusteronce
sync
.
Once
var
cluster
*
testCluster
func
initCluster
(
t
*
testing
.
T
)
{
clusteronce
.
Do
(
func
()
{
cluster
=
newTestCluster
(
t
,
clusterSize
)
})
}
func
serverFunc
(
api
*
api
.
API
)
swarmhttp
.
TestServer
{
return
swarmhttp
.
NewServer
(
api
,
""
)
}
...
...
cmd/swarm/upload_test.go
View file @
6b6c4d1c
...
...
@@ -31,8 +31,7 @@ import (
"time"
"github.com/ethereum/go-ethereum/log"
swarm
"github.com/ethereum/go-ethereum/swarm/api/client"
swarmhttp
"github.com/ethereum/go-ethereum/swarm/api/http"
swarmapi
"github.com/ethereum/go-ethereum/swarm/api/client"
"github.com/ethereum/go-ethereum/swarm/testutil"
"github.com/mattn/go-colorable"
)
...
...
@@ -42,42 +41,50 @@ func init() {
log
.
Root
()
.
SetHandler
(
log
.
LvlFilterHandler
(
log
.
Lvl
(
*
loglevel
),
log
.
StreamHandler
(
colorable
.
NewColorableStderr
(),
log
.
TerminalFormat
(
true
))))
}
// TestCLISwarmUp tests that running 'swarm up' makes the resulting file
// available from all nodes via the HTTP API
func
TestCLISwarmUp
(
t
*
testing
.
T
)
{
func
TestSwarmUp
(
t
*
testing
.
T
)
{
if
runtime
.
GOOS
==
"windows"
{
t
.
Skip
()
}
testCLISwarmUp
(
false
,
t
)
}
func
TestCLISwarmUpRecursive
(
t
*
testing
.
T
)
{
if
runtime
.
GOOS
==
"windows"
{
t
.
Skip
()
initCluster
(
t
)
cases
:=
[]
struct
{
name
string
f
func
(
t
*
testing
.
T
)
}{
{
"NoEncryption"
,
testNoEncryption
},
{
"Encrypted"
,
testEncrypted
},
{
"RecursiveNoEncryption"
,
testRecursiveNoEncryption
},
{
"RecursiveEncrypted"
,
testRecursiveEncrypted
},
{
"DefaultPathAll"
,
testDefaultPathAll
},
}
for
_
,
tc
:=
range
cases
{
t
.
Run
(
tc
.
name
,
tc
.
f
)
}
testCLISwarmUpRecursive
(
false
,
t
)
}
//
TestCLISwarmUpEncrypted tests that running 'swarm encrypted-
up' makes the resulting file
//
testNoEncryption tests that running 'swarm
up' makes the resulting file
// available from all nodes via the HTTP API
func
TestCLISwarmUpEncrypted
(
t
*
testing
.
T
)
{
if
runtime
.
GOOS
==
"windows"
{
t
.
Skip
()
}
testCLISwarmUp
(
true
,
t
)
func
testNoEncryption
(
t
*
testing
.
T
)
{
testDefault
(
false
,
t
)
}
func
TestCLISwarmUpEncryptedRecursive
(
t
*
testing
.
T
)
{
if
runtime
.
GOOS
==
"windows"
{
t
.
Skip
()
}
test
CLISwarmUpRecursive
(
true
,
t
)
// testEncrypted tests that running 'swarm up --encrypted' makes the resulting file
// available from all nodes via the HTTP API
func
testEncrypted
(
t
*
testing
.
T
)
{
test
Default
(
true
,
t
)
}
func
testCLISwarmUp
(
toEncrypt
bool
,
t
*
testing
.
T
)
{
log
.
Info
(
"starting 3 node cluster"
)
cluster
:=
newTestCluster
(
t
,
3
)
defer
cluster
.
Shutdown
()
func
testRecursiveNoEncryption
(
t
*
testing
.
T
)
{
testRecursive
(
false
,
t
)
}
func
testRecursiveEncrypted
(
t
*
testing
.
T
)
{
testRecursive
(
true
,
t
)
}
func
testDefault
(
toEncrypt
bool
,
t
*
testing
.
T
)
{
tmpFileName
:=
testutil
.
TempFileWithContent
(
t
,
data
)
defer
os
.
Remove
(
tmpFileName
)
...
...
@@ -182,11 +189,7 @@ func testCLISwarmUp(toEncrypt bool, t *testing.T) {
}
}
func
testCLISwarmUpRecursive
(
toEncrypt
bool
,
t
*
testing
.
T
)
{
fmt
.
Println
(
"starting 3 node cluster"
)
cluster
:=
newTestCluster
(
t
,
3
)
defer
cluster
.
Shutdown
()
func
testRecursive
(
toEncrypt
bool
,
t
*
testing
.
T
)
{
tmpUploadDir
,
err
:=
ioutil
.
TempDir
(
""
,
"swarm-test"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -253,7 +256,7 @@ func testCLISwarmUpRecursive(toEncrypt bool, t *testing.T) {
switch
mode
:=
fi
.
Mode
();
{
case
mode
.
IsRegular
()
:
if
file
,
err
:=
swarm
.
Open
(
path
.
Join
(
tmpDownload
,
v
.
Name
()));
err
!=
nil
{
if
file
,
err
:=
swarm
api
.
Open
(
path
.
Join
(
tmpDownload
,
v
.
Name
()));
err
!=
nil
{
t
.
Fatalf
(
"encountered an error opening the file returned from the CLI: %v"
,
err
)
}
else
{
ff
:=
make
([]
byte
,
len
(
data
))
...
...
@@ -274,22 +277,16 @@ func testCLISwarmUpRecursive(toEncrypt bool, t *testing.T) {
}
}
//
TestCLISwarmUpDefaultPath
tests swarm recursive upload with relative and absolute
//
testDefaultPathAll
tests swarm recursive upload with relative and absolute
// default paths and with encryption.
func
TestCLISwarmUpDefaultPath
(
t
*
testing
.
T
)
{
if
runtime
.
GOOS
==
"windows"
{
t
.
Skip
()
}
testCLISwarmUpDefaultPath
(
false
,
false
,
t
)
testCLISwarmUpDefaultPath
(
false
,
true
,
t
)
testCLISwarmUpDefaultPath
(
true
,
false
,
t
)
testCLISwarmUpDefaultPath
(
true
,
true
,
t
)
func
testDefaultPathAll
(
t
*
testing
.
T
)
{
testDefaultPath
(
false
,
false
,
t
)
testDefaultPath
(
false
,
true
,
t
)
testDefaultPath
(
true
,
false
,
t
)
testDefaultPath
(
true
,
true
,
t
)
}
func
testCLISwarmUpDefaultPath
(
toEncrypt
bool
,
absDefaultPath
bool
,
t
*
testing
.
T
)
{
srv
:=
swarmhttp
.
NewTestSwarmServer
(
t
,
serverFunc
,
nil
)
defer
srv
.
Close
()
func
testDefaultPath
(
toEncrypt
bool
,
absDefaultPath
bool
,
t
*
testing
.
T
)
{
tmp
,
err
:=
ioutil
.
TempDir
(
""
,
"swarm-defaultpath-test"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -312,7 +309,7 @@ func testCLISwarmUpDefaultPath(toEncrypt bool, absDefaultPath bool, t *testing.T
args
:=
[]
string
{
"--bzzapi"
,
srv
.
URL
,
cluster
.
Nodes
[
0
]
.
URL
,
"--recursive"
,
"--defaultpath"
,
defaultPath
,
...
...
@@ -329,7 +326,7 @@ func testCLISwarmUpDefaultPath(toEncrypt bool, absDefaultPath bool, t *testing.T
up
.
ExpectExit
()
hash
:=
matches
[
0
]
client
:=
swarm
.
NewClient
(
srv
.
URL
)
client
:=
swarm
api
.
NewClient
(
cluster
.
Nodes
[
0
]
.
URL
)
m
,
isEncrypted
,
err
:=
client
.
DownloadManifest
(
hash
)
if
err
!=
nil
{
...
...
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