Skip to content

Commit

Permalink
swarm, cmd/swarm: address ineffectual assignments (ethereum#18048)
Browse files Browse the repository at this point in the history
* swarm, cmd/swarm: address ineffectual assignments

* swarm/network: remove unused vars from testHandshake

* swarm/storage/feed: revert cursor changes
  • Loading branch information
nonsense authored and zelig committed Nov 7, 2018
1 parent 81533de commit cf3b187
Show file tree
Hide file tree
Showing 20 changed files with 61 additions and 24 deletions.
6 changes: 6 additions & 0 deletions cmd/swarm/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions cmd/swarm/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
3 changes: 1 addition & 2 deletions cmd/swarm/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions swarm/api/act.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 3 additions & 0 deletions swarm/api/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions swarm/api/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion swarm/api/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion swarm/api/http/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion swarm/api/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions swarm/network/hive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down
12 changes: 1 addition & 11 deletions swarm/network/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions swarm/network/simulation/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand Down
3 changes: 3 additions & 0 deletions swarm/network/stream/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions swarm/pss/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions swarm/pss/notify/notify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions swarm/pss/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion swarm/state/dbstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions swarm/state/dbstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion swarm/state/inmemorystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions swarm/storage/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cf3b187

Please sign in to comment.