Skip to content

Commit

Permalink
added error checking to linting
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph committed Oct 8, 2020
1 parent c9955a3 commit 0b082ef
Show file tree
Hide file tree
Showing 62 changed files with 1,737 additions and 768 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ linters:
enable:
- bodyclose
- deadcode
- errcheck
- goconst
- gocritic
- gofmt
Expand All @@ -19,7 +20,6 @@ linters:
- nakedret
- unconvert
- varcheck
# - errcheck
# - golint
# - lll
# - gocyclo
Expand Down
15 changes: 12 additions & 3 deletions cache/lru_cache_benchmark_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package cache

import (
Expand All @@ -13,7 +16,9 @@ func BenchmarkLRUCachePutSmall(b *testing.B) {
for n := 0; n < b.N; n++ {
for i := 0; i < smallLen; i++ {
var idBytes [32]byte
rand.Read(idBytes[:])
if _, err := rand.Read(idBytes[:]); err != nil {
b.Fatal(err)
}
cache.Put(ids.NewID(idBytes), n)
}
b.StopTimer()
Expand All @@ -28,7 +33,9 @@ func BenchmarkLRUCachePutMedium(b *testing.B) {
for n := 0; n < b.N; n++ {
for i := 0; i < mediumLen; i++ {
var idBytes [32]byte
rand.Read(idBytes[:])
if _, err := rand.Read(idBytes[:]); err != nil {
b.Fatal(err)
}
cache.Put(ids.NewID(idBytes), n)
}
b.StopTimer()
Expand All @@ -43,7 +50,9 @@ func BenchmarkLRUCachePutLarge(b *testing.B) {
for n := 0; n < b.N; n++ {
for i := 0; i < largeLen; i++ {
var idBytes [32]byte
rand.Read(idBytes[:])
if _, err := rand.Read(idBytes[:]); err != nil {
b.Fatal(err)
}
cache.Put(ids.NewID(idBytes), n)
}
b.StopTimer()
Expand Down
8 changes: 5 additions & 3 deletions chains/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,14 @@ func (m *manager) buildChain(chainParams ChainParameters) (*chain, error) {
return nil, fmt.Errorf("the vm should have type avalanche.DAGVM or snowman.ChainVM. Chain not created")
}

// Register the chain with the timeout manager
if err := m.TimeoutManager.RegisterChain(ctx, consensusParams.Namespace); err != nil {
return nil, err
}

// Allows messages to be routed to the new chain
m.ManagerConfig.Router.AddChain(chain.Handler)

// Register the chain with the timeout manager
m.TimeoutManager.RegisterChain(ctx, consensusParams.Namespace)

// If the X or P Chain panics, do not attempt to recover
if m.CriticalChains.Contains(chainParams.ID) {
go ctx.Log.RecoverAndPanic(chain.Handler.Dispatch)
Expand Down
34 changes: 25 additions & 9 deletions ids/aliases_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (c) 2020, Alex Willmer. All rights reserved.
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package ids
Expand Down Expand Up @@ -37,7 +37,9 @@ func TestAliaserLookup(t *testing.T) {
id := NewID([32]byte{'K', 'a', 't', 'e', ' ', 'K', 'a', 'n', 'e'})
aliaser := Aliaser{}
aliaser.Initialize()
aliaser.Alias(id, "Batwoman")
if err := aliaser.Alias(id, "Batwoman"); err != nil {
t.Fatal(err)
}

res, err := aliaser.Lookup("Batwoman")
if err != nil {
Expand All @@ -63,8 +65,12 @@ func TestAliaserAliases(t *testing.T) {
id := NewID([32]byte{'B', 'r', 'u', 'c', 'e', ' ', 'W', 'a', 'y', 'n', 'e'})
aliaser := Aliaser{}
aliaser.Initialize()
aliaser.Alias(id, "Batman")
aliaser.Alias(id, "Dark Knight")
if err := aliaser.Alias(id, "Batman"); err != nil {
t.Fatal(err)
}
if err := aliaser.Alias(id, "Dark Knight"); err != nil {
t.Fatal(err)
}

aliases := aliaser.Aliases(id)
expected := []string{"Batman", "Dark Knight"}
Expand All @@ -78,8 +84,12 @@ func TestAliaserPrimaryAlias(t *testing.T) {
id2 := NewID([32]byte{'B', 'r', 'u', 'c', 'e', ' ', 'W', 'a', 'y', 'n', 'e'})
aliaser := Aliaser{}
aliaser.Initialize()
aliaser.Alias(id2, "Batman")
aliaser.Alias(id2, "Dark Knight")
if err := aliaser.Alias(id2, "Batman"); err != nil {
t.Fatal(err)
}
if err := aliaser.Alias(id2, "Dark Knight"); err != nil {
t.Fatal(err)
}

res, err := aliaser.PrimaryAlias(id1)
if res != "" {
Expand All @@ -104,7 +114,9 @@ func TestAliaserAliasClash(t *testing.T) {
id2 := NewID([32]byte{'D', 'i', 'c', 'k', ' ', 'G', 'r', 'a', 'y', 's', 'o', 'n'})
aliaser := Aliaser{}
aliaser.Initialize()
aliaser.Alias(id1, "Batman")
if err := aliaser.Alias(id1, "Batman"); err != nil {
t.Fatal(err)
}

err := aliaser.Alias(id2, "Batman")
if err == nil {
Expand All @@ -117,8 +129,12 @@ func TestAliaserRemoveAlias(t *testing.T) {
id2 := NewID([32]byte{'J', 'a', 'm', 'e', 's', ' ', 'G', 'o', 'r', 'd', 'o', 'n'})
aliaser := Aliaser{}
aliaser.Initialize()
aliaser.Alias(id1, "Batman")
aliaser.Alias(id1, "Dark Knight")
if err := aliaser.Alias(id1, "Batman"); err != nil {
t.Fatal(err)
}
if err := aliaser.Alias(id1, "Dark Knight"); err != nil {
t.Fatal(err)
}

aliaser.RemoveAliases(id1)

Expand Down
16 changes: 12 additions & 4 deletions ids/bag_benchmark_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package ids

import (
"crypto/rand"
"testing"
)

//
func BenchmarkBagListSmall(b *testing.B) {
smallLen := 5
bag := Bag{}
for i := 0; i < smallLen; i++ {
var idBytes [32]byte
rand.Read(idBytes[:])
if _, err := rand.Read(idBytes[:]); err != nil {
b.Fatal(err)
}
NewID(idBytes)
bag.Add(NewID(idBytes))
}
Expand All @@ -26,7 +30,9 @@ func BenchmarkBagListMedium(b *testing.B) {
bag := Bag{}
for i := 0; i < mediumLen; i++ {
var idBytes [32]byte
rand.Read(idBytes[:])
if _, err := rand.Read(idBytes[:]); err != nil {
b.Fatal(err)
}
NewID(idBytes)
bag.Add(NewID(idBytes))
}
Expand All @@ -42,7 +48,9 @@ func BenchmarkBagListLarge(b *testing.B) {
bag := Bag{}
for i := 0; i < largeLen; i++ {
var idBytes [32]byte
rand.Read(idBytes[:])
if _, err := rand.Read(idBytes[:]); err != nil {
b.Fatal(err)
}
NewID(idBytes)
bag.Add(NewID(idBytes))
}
Expand Down
3 changes: 3 additions & 0 deletions ids/queue_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package ids

import (
Expand Down
16 changes: 12 additions & 4 deletions ids/set_benchmark_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package ids

import (
"crypto/rand"
"testing"
)

//
func BenchmarkSetListSmall(b *testing.B) {
smallLen := 5
set := Set{}
for i := 0; i < smallLen; i++ {
var idBytes [32]byte
rand.Read(idBytes[:])
if _, err := rand.Read(idBytes[:]); err != nil {
b.Fatal(err)
}
NewID(idBytes)
set.Add(NewID(idBytes))
}
Expand All @@ -26,7 +30,9 @@ func BenchmarkSetListMedium(b *testing.B) {
set := Set{}
for i := 0; i < mediumLen; i++ {
var idBytes [32]byte
rand.Read(idBytes[:])
if _, err := rand.Read(idBytes[:]); err != nil {
b.Fatal(err)
}
NewID(idBytes)
set.Add(NewID(idBytes))
}
Expand All @@ -42,7 +48,9 @@ func BenchmarkSetListLarge(b *testing.B) {
set := Set{}
for i := 0; i < largeLen; i++ {
var idBytes [32]byte
rand.Read(idBytes[:])
if _, err := rand.Read(idBytes[:]); err != nil {
b.Fatal(err)
}
NewID(idBytes)
set.Add(NewID(idBytes))
}
Expand Down
Loading

0 comments on commit 0b082ef

Please sign in to comment.