aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Evangelatov <anton.evangelatov@gmail.com>2018-11-08 03:39:08 +0800
committerViktor TrĂ³n <viktor.tron@gmail.com>2018-11-08 03:39:08 +0800
commitcf3b187bdef59078ba6570a2f5ee046ab87bcefd (patch)
treefbc16d9216df0d32e745f88cb3ac22e6dab256bf
parent81533deae5ee4a7ec08842e2b6647f3affde5a71 (diff)
downloadgo-tangerine-cf3b187bdef59078ba6570a2f5ee046ab87bcefd.tar
go-tangerine-cf3b187bdef59078ba6570a2f5ee046ab87bcefd.tar.gz
go-tangerine-cf3b187bdef59078ba6570a2f5ee046ab87bcefd.tar.bz2
go-tangerine-cf3b187bdef59078ba6570a2f5ee046ab87bcefd.tar.lz
go-tangerine-cf3b187bdef59078ba6570a2f5ee046ab87bcefd.tar.xz
go-tangerine-cf3b187bdef59078ba6570a2f5ee046ab87bcefd.tar.zst
go-tangerine-cf3b187bdef59078ba6570a2f5ee046ab87bcefd.zip
swarm, cmd/swarm: address ineffectual assignments (#18048)
* swarm, cmd/swarm: address ineffectual assignments * swarm/network: remove unused vars from testHandshake * swarm/storage/feed: revert cursor changes
-rw-r--r--cmd/swarm/access.go6
-rw-r--r--cmd/swarm/fs_test.go3
-rw-r--r--cmd/swarm/upload_test.go3
-rw-r--r--swarm/api/act.go3
-rw-r--r--swarm/api/client/client_test.go3
-rw-r--r--swarm/api/filesystem.go4
-rw-r--r--swarm/api/http/server.go2
-rw-r--r--swarm/api/http/server_test.go5
-rw-r--r--swarm/api/manifest.go1
-rw-r--r--swarm/network/hive_test.go6
-rw-r--r--swarm/network/protocol_test.go12
-rw-r--r--swarm/network/simulation/bucket_test.go4
-rw-r--r--swarm/network/stream/syncer_test.go3
-rw-r--r--swarm/pss/client/client_test.go6
-rw-r--r--swarm/pss/notify/notify_test.go6
-rw-r--r--swarm/pss/protocol_test.go6
-rw-r--r--swarm/state/dbstore.go2
-rw-r--r--swarm/state/dbstore_test.go3
-rw-r--r--swarm/state/inmemorystore.go2
-rw-r--r--swarm/storage/types.go5
20 files changed, 61 insertions, 24 deletions
diff --git a/cmd/swarm/access.go b/cmd/swarm/access.go
index 629781edd..072541b65 100644
--- a/cmd/swarm/access.go
+++ b/cmd/swarm/access.go
@@ -114,6 +114,9 @@ func accessNewPass(ctx *cli.Context) {
utils.Fatalf("error getting session key: %v", err)
}
m, err := api.GenerateAccessControlManifest(ctx, ref, accessKey, ae)
+ if err != nil {
+ utils.Fatalf("had an error generating the manifest: %v", err)
+ }
if dryRun {
err = printManifests(m, nil)
if err != nil {
@@ -147,6 +150,9 @@ func accessNewPK(ctx *cli.Context) {
utils.Fatalf("error getting session key: %v", err)
}
m, err := api.GenerateAccessControlManifest(ctx, ref, sessionKey, ae)
+ if err != nil {
+ utils.Fatalf("had an error generating the manifest: %v", err)
+ }
if dryRun {
err = printManifests(m, nil)
if err != nil {
diff --git a/cmd/swarm/fs_test.go b/cmd/swarm/fs_test.go
index 4f38b094b..3b722515e 100644
--- a/cmd/swarm/fs_test.go
+++ b/cmd/swarm/fs_test.go
@@ -80,6 +80,9 @@ func TestCLISwarmFs(t *testing.T) {
t.Fatal(err)
}
dirPath2, err := createDirInDir(dirPath, "AnotherTestSubDir")
+ if err != nil {
+ t.Fatal(err)
+ }
dummyContent := "somerandomtestcontentthatshouldbeasserted"
dirs := []string{
diff --git a/cmd/swarm/upload_test.go b/cmd/swarm/upload_test.go
index 0ac2456a5..ba4463e8b 100644
--- a/cmd/swarm/upload_test.go
+++ b/cmd/swarm/upload_test.go
@@ -243,8 +243,7 @@ func testCLISwarmUpRecursive(toEncrypt bool, t *testing.T) {
}
defer os.RemoveAll(tmpDownload)
bzzLocator := "bzz:/" + hash
- flagss := []string{}
- flagss = []string{
+ flagss := []string{
"--bzzapi", cluster.Nodes[0].URL,
"down",
"--recursive",
diff --git a/swarm/api/act.go b/swarm/api/act.go
index 52d909827..e54369f9a 100644
--- a/swarm/api/act.go
+++ b/swarm/api/act.go
@@ -458,6 +458,9 @@ func DoACT(ctx *cli.Context, privateKey *ecdsa.PrivateKey, salt []byte, grantees
return nil, nil, nil, err
}
sessionKey, err := NewSessionKeyPK(privateKey, granteePub, salt)
+ if err != nil {
+ return nil, nil, nil, err
+ }
hasher := sha3.NewKeccak256()
hasher.Write(append(sessionKey, 0))
diff --git a/swarm/api/client/client_test.go b/swarm/api/client/client_test.go
index 03c6cbb28..c30d69911 100644
--- a/swarm/api/client/client_test.go
+++ b/swarm/api/client/client_test.go
@@ -457,6 +457,9 @@ func TestClientCreateUpdateFeed(t *testing.T) {
}
feedManifestHash, err := client.CreateFeedWithManifest(createRequest)
+ if err != nil {
+ t.Fatal(err)
+ }
correctManifestAddrHex := "0e9b645ebc3da167b1d56399adc3276f7a08229301b72a03336be0e7d4b71882"
if feedManifestHash != correctManifestAddrHex {
diff --git a/swarm/api/filesystem.go b/swarm/api/filesystem.go
index 43695efc1..266ef71be 100644
--- a/swarm/api/filesystem.go
+++ b/swarm/api/filesystem.go
@@ -122,6 +122,10 @@ func (fs *FileSystem) Upload(lpath, index string, toEncrypt bool) (string, error
var wait func(context.Context) error
ctx := context.TODO()
hash, wait, err = fs.api.fileStore.Store(ctx, f, stat.Size(), toEncrypt)
+ if err != nil {
+ errors[i] = err
+ return
+ }
if hash != nil {
list[i].Hash = hash.Hex()
}
diff --git a/swarm/api/http/server.go b/swarm/api/http/server.go
index 803b78987..3c6735a73 100644
--- a/swarm/api/http/server.go
+++ b/swarm/api/http/server.go
@@ -366,7 +366,7 @@ func (s *Server) handleMultipartUpload(r *http.Request, boundary string, mw *api
}
var size int64
- var reader io.Reader = part
+ var reader io.Reader
if contentLength := part.Header.Get("Content-Length"); contentLength != "" {
size, err = strconv.ParseInt(contentLength, 10, 64)
if err != nil {
diff --git a/swarm/api/http/server_test.go b/swarm/api/http/server_test.go
index 159c8a159..04d0e045a 100644
--- a/swarm/api/http/server_test.go
+++ b/swarm/api/http/server_test.go
@@ -263,7 +263,7 @@ func TestBzzFeed(t *testing.T) {
if resp.StatusCode == http.StatusOK {
t.Fatal("Expected error status since feed update does not contain multihash. Received 200 OK")
}
- b, err = ioutil.ReadAll(resp.Body)
+ _, err = ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
@@ -491,6 +491,9 @@ func testBzzGetPath(encrypted bool, t *testing.T) {
}
defer resp.Body.Close()
respbody, err = ioutil.ReadAll(resp.Body)
+ if err != nil {
+ t.Fatalf("Error while reading response body: %v", err)
+ }
if string(respbody) != testmanifest[v] {
isexpectedfailrequest := false
diff --git a/swarm/api/manifest.go b/swarm/api/manifest.go
index 7c4cc88e4..890ed88bd 100644
--- a/swarm/api/manifest.go
+++ b/swarm/api/manifest.go
@@ -557,7 +557,6 @@ func (mt *manifestTrie) findPrefixOf(path string, quitC chan bool) (entry *manif
if path != entry.Path {
return nil, 0
}
- pos = epl
}
}
return nil, 0
diff --git a/swarm/network/hive_test.go b/swarm/network/hive_test.go
index 059c3dc96..56adc5a8e 100644
--- a/swarm/network/hive_test.go
+++ b/swarm/network/hive_test.go
@@ -70,6 +70,9 @@ func TestHiveStatePersistance(t *testing.T) {
defer os.RemoveAll(dir)
store, err := state.NewDBStore(dir) //start the hive with an empty dbstore
+ if err != nil {
+ t.Fatal(err)
+ }
params := NewHiveParams()
s, pp := newHiveTester(t, params, 5, store)
@@ -90,6 +93,9 @@ func TestHiveStatePersistance(t *testing.T) {
store.Close()
persistedStore, err := state.NewDBStore(dir) //start the hive with an empty dbstore
+ if err != nil {
+ t.Fatal(err)
+ }
s1, pp := newHiveTester(t, params, 1, persistedStore)
diff --git a/swarm/network/protocol_test.go b/swarm/network/protocol_test.go
index cdf370f35..f0d266628 100644
--- a/swarm/network/protocol_test.go
+++ b/swarm/network/protocol_test.go
@@ -153,17 +153,7 @@ func newBzzHandshakeTester(t *testing.T, n int, addr *BzzAddr, lightNode bool) *
// should test handshakes in one exchange? parallelisation
func (s *bzzTester) testHandshake(lhs, rhs *HandshakeMsg, disconnects ...*p2ptest.Disconnect) error {
- var peers []enode.ID
- id := rhs.Addr.ID()
- if len(disconnects) > 0 {
- for _, d := range disconnects {
- peers = append(peers, d.Peer)
- }
- } else {
- peers = []enode.ID{id}
- }
-
- if err := s.TestExchanges(HandshakeMsgExchange(lhs, rhs, id)...); err != nil {
+ if err := s.TestExchanges(HandshakeMsgExchange(lhs, rhs, rhs.Addr.ID())...); err != nil {
return err
}
diff --git a/swarm/network/simulation/bucket_test.go b/swarm/network/simulation/bucket_test.go
index 461d99825..69df19bfe 100644
--- a/swarm/network/simulation/bucket_test.go
+++ b/swarm/network/simulation/bucket_test.go
@@ -94,7 +94,7 @@ func TestServiceBucket(t *testing.T) {
t.Fatalf("expected %q, got %q", customValue, s)
}
- v, ok = sim.NodeItem(id2, customKey)
+ _, ok = sim.NodeItem(id2, customKey)
if ok {
t.Fatal("bucket item should not be found")
}
@@ -119,7 +119,7 @@ func TestServiceBucket(t *testing.T) {
t.Fatalf("expected %q, got %q", testValue+id1.String(), s)
}
- v, ok = items[id2]
+ _, ok = items[id2]
if ok {
t.Errorf("node 2 item should not be found")
}
diff --git a/swarm/network/stream/syncer_test.go b/swarm/network/stream/syncer_test.go
index 113807b98..b0e35b0db 100644
--- a/swarm/network/stream/syncer_test.go
+++ b/swarm/network/stream/syncer_test.go
@@ -62,6 +62,9 @@ func createMockStore(globalStore *mockdb.GlobalStore, id enode.ID, addr *network
params.Init(datadir)
params.BaseKey = addr.Over()
lstore, err = storage.NewLocalStore(params, mockStore)
+ if err != nil {
+ return nil, "", err
+ }
return lstore, datadir, nil
}
diff --git a/swarm/pss/client/client_test.go b/swarm/pss/client/client_test.go
index cfef3c794..8f2f0e805 100644
--- a/swarm/pss/client/client_test.go
+++ b/swarm/pss/client/client_test.go
@@ -252,7 +252,13 @@ func newServices() adapters.Services {
ctxlocal, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
keys, err := wapi.NewKeyPair(ctxlocal)
+ if err != nil {
+ return nil, err
+ }
privkey, err := w.GetPrivateKey(keys)
+ if err != nil {
+ return nil, err
+ }
psparams := pss.NewPssParams().WithPrivateKey(privkey)
pskad := kademlia(ctx.Config.ID)
ps, err := pss.NewPss(pskad, psparams)
diff --git a/swarm/pss/notify/notify_test.go b/swarm/pss/notify/notify_test.go
index 675b41ada..d4d383a6b 100644
--- a/swarm/pss/notify/notify_test.go
+++ b/swarm/pss/notify/notify_test.go
@@ -223,7 +223,13 @@ func newServices(allowRaw bool) adapters.Services {
ctxlocal, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
keys, err := wapi.NewKeyPair(ctxlocal)
+ if err != nil {
+ return nil, err
+ }
privkey, err := w.GetPrivateKey(keys)
+ if err != nil {
+ return nil, err
+ }
pssp := pss.NewPssParams().WithPrivateKey(privkey)
pssp.MsgTTL = time.Second * 30
pssp.AllowRaw = allowRaw
diff --git a/swarm/pss/protocol_test.go b/swarm/pss/protocol_test.go
index f4209fea5..4ef3e90a0 100644
--- a/swarm/pss/protocol_test.go
+++ b/swarm/pss/protocol_test.go
@@ -93,11 +93,17 @@ func testProtocol(t *testing.T) {
lctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
lsub, err := clients[0].Subscribe(lctx, "pss", lmsgC, "receive", topic)
+ if err != nil {
+ t.Fatal(err)
+ }
defer lsub.Unsubscribe()
rmsgC := make(chan APIMsg)
rctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
rsub, err := clients[1].Subscribe(rctx, "pss", rmsgC, "receive", topic)
+ if err != nil {
+ t.Fatal(err)
+ }
defer rsub.Unsubscribe()
// set reciprocal public keys
diff --git a/swarm/state/dbstore.go b/swarm/state/dbstore.go
index 5e5c172b2..b0aa92e27 100644
--- a/swarm/state/dbstore.go
+++ b/swarm/state/dbstore.go
@@ -69,7 +69,7 @@ func (s *DBStore) Get(key string, i interface{}) (err error) {
// Put stores an object that implements Binary for a specific key.
func (s *DBStore) Put(key string, i interface{}) (err error) {
- bytes := []byte{}
+ var bytes []byte
marshaler, ok := i.(encoding.BinaryMarshaler)
if !ok {
diff --git a/swarm/state/dbstore_test.go b/swarm/state/dbstore_test.go
index 6683e788f..f7098956d 100644
--- a/swarm/state/dbstore_test.go
+++ b/swarm/state/dbstore_test.go
@@ -112,6 +112,9 @@ func testPersistedStore(t *testing.T, store Store) {
as := []string{}
err = store.Get("key2", &as)
+ if err != nil {
+ t.Fatal(err)
+ }
if len(as) != 3 {
t.Fatalf("serialized array did not match expectation")
diff --git a/swarm/state/inmemorystore.go b/swarm/state/inmemorystore.go
index 1ca25404a..3ba48592b 100644
--- a/swarm/state/inmemorystore.go
+++ b/swarm/state/inmemorystore.go
@@ -59,7 +59,7 @@ func (s *InmemoryStore) Get(key string, i interface{}) (err error) {
func (s *InmemoryStore) Put(key string, i interface{}) (err error) {
s.mu.Lock()
defer s.mu.Unlock()
- bytes := []byte{}
+ var bytes []byte
marshaler, ok := i.(encoding.BinaryMarshaler)
if !ok {
diff --git a/swarm/storage/types.go b/swarm/storage/types.go
index ada86831f..092843db0 100644
--- a/swarm/storage/types.go
+++ b/swarm/storage/types.go
@@ -244,11 +244,8 @@ func GenerateRandomChunk(dataSize int64) Chunk {
}
func GenerateRandomChunks(dataSize int64, count int) (chunks []Chunk) {
- if dataSize > ch.DefaultSize {
- dataSize = ch.DefaultSize
- }
for i := 0; i < count; i++ {
- ch := GenerateRandomChunk(ch.DefaultSize)
+ ch := GenerateRandomChunk(dataSize)
chunks = append(chunks, ch)
}
return chunks