diff --git a/p2p/simulations/adapters/inproc_test.go b/p2p/simulations/adapters/inproc_test.go index 76be7228d1..4fe7f10461 100644 --- a/p2p/simulations/adapters/inproc_test.go +++ b/p2p/simulations/adapters/inproc_test.go @@ -25,7 +25,10 @@ import ( ) func TestSocketPipe(t *testing.T) { - c1, c2, _ := socketPipe() + c1, c2, err := socketPipe() + if err != nil { + t.Fatal(err) + } done := make(chan struct{}) @@ -52,7 +55,7 @@ func TestSocketPipe(t *testing.T) { t.Fatal(err) } - if bytes.Compare(msg, out) != 0 { + if !bytes.Equal(msg, out) { t.Fatalf("expected %#v, got %#v", msg, out) } } @@ -67,7 +70,10 @@ func TestSocketPipe(t *testing.T) { } func TestSocketPipeBidirections(t *testing.T) { - c1, c2, _ := socketPipe() + c1, c2, err := socketPipe() + if err != nil { + t.Fatal(err) + } done := make(chan struct{}) @@ -90,7 +96,7 @@ func TestSocketPipeBidirections(t *testing.T) { t.Fatal(err) } - if bytes.Compare(out, []byte(`ping`)) == 0 { + if !bytes.Equal(out, []byte(`ping`)) { msg := []byte(`pong`) _, err := c2.Write(msg) if err != nil { @@ -108,7 +114,7 @@ func TestSocketPipeBidirections(t *testing.T) { t.Fatal(err) } - if bytes.Compare(out, expected) != 0 { + if !bytes.Equal(out, expected) { t.Fatalf("expected %#v, got %#v", expected, out) } } @@ -124,7 +130,10 @@ func TestSocketPipeBidirections(t *testing.T) { } func TestTcpPipe(t *testing.T) { - c1, c2, _ := tcpPipe() + c1, c2, err := tcpPipe() + if err != nil { + t.Fatal(err) + } done := make(chan struct{}) @@ -151,7 +160,7 @@ func TestTcpPipe(t *testing.T) { t.Fatal(err) } - if bytes.Compare(msg, out) != 0 { + if !bytes.Equal(msg, out) { t.Fatalf("expected %#v, got %#v", msg, out) } } @@ -166,7 +175,10 @@ func TestTcpPipe(t *testing.T) { } func TestTcpPipeBidirections(t *testing.T) { - c1, c2, _ := tcpPipe() + c1, c2, err := tcpPipe() + if err != nil { + t.Fatal(err) + } done := make(chan struct{}) @@ -191,7 +203,7 @@ func TestTcpPipeBidirections(t *testing.T) { t.Fatal(err) } - if bytes.Compare(expected, out) != 0 { + if !bytes.Equal(expected, out) { t.Fatalf("expected %#v, got %#v", out, expected) } else { msg := []byte(fmt.Sprintf("pong %02d", i)) @@ -211,7 +223,7 @@ func TestTcpPipeBidirections(t *testing.T) { t.Fatal(err) } - if bytes.Compare(expected, out) != 0 { + if !bytes.Equal(expected, out) { t.Fatalf("expected %#v, got %#v", out, expected) } } @@ -226,7 +238,10 @@ func TestTcpPipeBidirections(t *testing.T) { } func TestNetPipe(t *testing.T) { - c1, c2, _ := netPipe() + c1, c2, err := netPipe() + if err != nil { + t.Fatal(err) + } done := make(chan struct{}) @@ -256,7 +271,7 @@ func TestNetPipe(t *testing.T) { t.Fatal(err) } - if bytes.Compare(msg, out) != 0 { + if !bytes.Equal(msg, out) { t.Fatalf("expected %#v, got %#v", msg, out) } } @@ -272,7 +287,10 @@ func TestNetPipe(t *testing.T) { } func TestNetPipeBidirections(t *testing.T) { - c1, c2, _ := netPipe() + c1, c2, err := netPipe() + if err != nil { + t.Fatal(err) + } done := make(chan struct{}) @@ -305,7 +323,7 @@ func TestNetPipeBidirections(t *testing.T) { t.Fatal(err) } - if bytes.Compare(expected, out) != 0 { + if !bytes.Equal(expected, out) { t.Fatalf("expected %#v, got %#v", expected, out) } } @@ -323,7 +341,7 @@ func TestNetPipeBidirections(t *testing.T) { t.Fatal(err) } - if bytes.Compare(expected, out) != 0 { + if !bytes.Equal(expected, out) { t.Fatalf("expected %#v, got %#v", expected, out) } else { msg := []byte(fmt.Sprintf(pongTemplate, i)) diff --git a/pot/pot_test.go b/pot/pot_test.go index 7befdf71ba..1175abd80c 100644 --- a/pot/pot_test.go +++ b/pot/pot_test.go @@ -271,10 +271,7 @@ func testPotEachNeighbour(n *Pot, pof Pof, val Val, expCount int, fs ...func(Val } } count++ - if count == expCount { - return false - } - return true + return count != expCount }) if err == nil && count < expCount { return fmt.Errorf("not enough neighbours returned, expected %v, got %v", expCount, count) @@ -558,10 +555,7 @@ func benchmarkEachNeighbourSync(t *testing.B, max, count int, d time.Duration) { n.EachNeighbour(val, pof, func(v Val, po int) bool { time.Sleep(d) m++ - if m == count { - return false - } - return true + return m != count }) } t.StopTimer() diff --git a/swarm/network/bitvector/bitvector_test.go b/swarm/network/bitvector/bitvector_test.go index ae759404d1..6192f704a7 100644 --- a/swarm/network/bitvector/bitvector_test.go +++ b/swarm/network/bitvector/bitvector_test.go @@ -58,11 +58,11 @@ func TestBitvectorGetSet(t *testing.T) { bv.Set(i, true) for j := 0; j < length; j++ { if j == i { - if bv.Get(j) != true { + if !bv.Get(j) { t.Errorf("element on index %v is not set to true", i) } } else { - if bv.Get(j) != false { + if bv.Get(j) { t.Errorf("element on index %v is not false", i) } } @@ -70,7 +70,7 @@ func TestBitvectorGetSet(t *testing.T) { bv.Set(i, false) - if bv.Get(i) != false { + if bv.Get(i) { t.Errorf("element on index %v is not set to false", i) } } @@ -82,7 +82,7 @@ func TestBitvectorNewFromBytesGet(t *testing.T) { if err != nil { t.Error(err) } - if bv.Get(3) != true { + if !bv.Get(3) { t.Fatalf("element 3 is not set to true: state %08b", bv.b[0]) } } diff --git a/swarm/network/stream/messages.go b/swarm/network/stream/messages.go index 22592d288c..63c8783fdf 100644 --- a/swarm/network/stream/messages.go +++ b/swarm/network/stream/messages.go @@ -269,9 +269,6 @@ func (m TakeoverProofMsg) String() string { func (p *Peer) handleTakeoverProofMsg(req *TakeoverProofMsg) error { _, err := p.getServer(req.Stream) - if err != nil { - return err - } // store the strongest takeoverproof for the stream in streamer - return nil + return err } diff --git a/swarm/pss/pss.go b/swarm/pss/pss.go index bb3540844d..4a434431c4 100644 --- a/swarm/pss/pss.go +++ b/swarm/pss/pss.go @@ -216,9 +216,7 @@ func (self *Pss) APIs() []rpc.API { Public: true, }, } - for _, auxapi := range self.auxAPIs { - apis = append(apis, auxapi) - } + apis = append(apis, self.auxAPIs...) return apis } @@ -389,7 +387,7 @@ func (self *Pss) SetPeerPublicKey(pubkey *ecdsa.PublicKey, topic Topic, address address: address, } self.pubKeyPoolMu.Lock() - if _, ok := self.pubKeyPool[pubkeyid]; ok == false { + if _, ok := self.pubKeyPool[pubkeyid]; !ok { self.pubKeyPool[pubkeyid] = make(map[Topic]*pssPeer) } self.pubKeyPool[pubkeyid][topic] = psp @@ -538,7 +536,7 @@ func (self *Pss) cleanKeys() (count int) { match = true } } - if match == false { + if !match { expiredtopics = append(expiredtopics, topic) } } diff --git a/swarm/pss/pss_test.go b/swarm/pss/pss_test.go index c674bbec40..c705fb8b50 100644 --- a/swarm/pss/pss_test.go +++ b/swarm/pss/pss_test.go @@ -719,7 +719,7 @@ func testNetwork(t *testing.T) { select { case recvmsg := <-msgC: idx, _ := binary.Uvarint(recvmsg.Msg) - if recvmsgs[idx] == false { + if !recvmsgs[idx] { log.Debug("msg recv", "idx", idx, "id", id) recvmsgs[idx] = true trigger <- id diff --git a/swarm/storage/dbstore.go b/swarm/storage/dbstore.go index 634f79ef92..ea1ef46a02 100644 --- a/swarm/storage/dbstore.go +++ b/swarm/storage/dbstore.go @@ -733,8 +733,7 @@ func (s *DbStore) setCapacity(c uint64) { s.capacity = c if s.entryCnt > c { - var ratio float32 - ratio = float32(1.01) - float32(c)/float32(s.entryCnt) + ratio := float32(1.01) - float32(c)/float32(s.entryCnt) if ratio < gcArrayFreeRatio { ratio = gcArrayFreeRatio } diff --git a/swarm/storage/dbstore_test.go b/swarm/storage/dbstore_test.go index 6b86ed518e..65a1bc9669 100644 --- a/swarm/storage/dbstore_test.go +++ b/swarm/storage/dbstore_test.go @@ -206,7 +206,7 @@ func testIterator(t *testing.T, mock bool) { } for i = 0; i < chunkcount; i++ { - if bytes.Compare(chunkkeys[i], chunkkeys_results[i]) != 0 { + if !bytes.Equal(chunkkeys[i], chunkkeys_results[i]) { t.Fatalf("Chunk put #%d key '%v' does not match iterator's key '%v'", i, chunkkeys[i], chunkkeys_results[i]) } } diff --git a/swarm/storage/resource.go b/swarm/storage/resource.go index 3f27de5e3e..448c359741 100644 --- a/swarm/storage/resource.go +++ b/swarm/storage/resource.go @@ -625,10 +625,7 @@ func (self *ResourceHandler) verifyContent(chunkdata []byte) error { } func (self *ResourceHandler) hasUpdate(name string, period uint32) bool { - if self.resources[name].lastPeriod == period { - return true - } - return false + return self.resources[name].lastPeriod == period } type resourceChunkStore struct { diff --git a/swarm/storage/types.go b/swarm/storage/types.go index 8de7472627..2e6f6d7d47 100644 --- a/swarm/storage/types.go +++ b/swarm/storage/types.go @@ -156,10 +156,7 @@ func (c KeyCollection) Len() int { } func (c KeyCollection) Less(i, j int) bool { - if bytes.Compare(c[i], c[j]) == -1 { - return true - } - return false + return bytes.Compare(c[i], c[j]) == -1 } func (c KeyCollection) Swap(i, j int) { diff --git a/swarm/swarm.go b/swarm/swarm.go index d566918fe7..31d8146a98 100644 --- a/swarm/swarm.go +++ b/swarm/swarm.go @@ -262,20 +262,13 @@ func (self *Swarm) Stop() error { // implements the node.Service interface func (self *Swarm) Protocols() (protos []p2p.Protocol) { - - for _, p := range self.bzz.Protocols() { - protos = append(protos, p) - } + protos = append(protos, self.bzz.Protocols()...) if self.ps != nil { - for _, p := range self.ps.Protocols() { - protos = append(protos, p) - } + protos = append(protos, self.ps.Protocols()...) } if self.streamer != nil { - for _, p := range self.streamer.Protocols() { - protos = append(protos, p) - } + protos = append(protos, self.streamer.Protocols()...) } return } @@ -336,14 +329,10 @@ func (self *Swarm) APIs() []rpc.API { // {Namespace, Version, api.NewAdmin(self), false}, } - for _, api := range self.bzz.APIs() { - apis = append(apis, api) - } + apis = append(apis, self.bzz.APIs()...) if self.ps != nil { - for _, api := range self.ps.APIs() { - apis = append(apis, api) - } + apis = append(apis, self.ps.APIs()...) } return apis