Skip to content

Commit

Permalink
Fix lint issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
arijitAD committed Apr 13, 2021
1 parent 5be799b commit 737945e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 58 deletions.
30 changes: 2 additions & 28 deletions dot/core/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package core

import (
"io"
"math/big"
"os"
"sort"
Expand All @@ -33,36 +32,11 @@ import (
"github.com/ChainSafe/gossamer/lib/runtime/extrinsic"
"github.com/ChainSafe/gossamer/lib/runtime/wasmer"
"github.com/ChainSafe/gossamer/lib/transaction"
"github.com/ChainSafe/gossamer/lib/utils"
log "github.com/ChainSafe/log15"
"github.com/stretchr/testify/require"
)

type mockDigestItem struct {
i int
}

func newMockDigestItem(i int) *mockDigestItem {
return &mockDigestItem{
i: i,
}
}

func (d *mockDigestItem) String() string {
return ""
}

func (d *mockDigestItem) Type() byte {
return byte(d.i)
}

func (d *mockDigestItem) Encode() ([]byte, error) {
return []byte{byte(d.i)}, nil
}

func (d *mockDigestItem) Decode(_ io.Reader) error {
return nil
}

func addTestBlocksToState(t *testing.T, depth int, blockState BlockState) []*types.Header {
return addTestBlocksToStateWithParent(t, blockState.BestBlockHash(), depth, blockState)
}
Expand Down Expand Up @@ -247,7 +221,7 @@ func TestHandleChainReorg_WithReorg_Transactions(t *testing.T) {
ParentHash: ancestor.Header.Hash(),
Number: big.NewInt(0).Add(ancestor.Header.Number, big.NewInt(1)),
Digest: types.Digest{
newMockDigestItem(1),
utils.NewMockDigestItem(1),
},
},
Body: body,
Expand Down
32 changes: 3 additions & 29 deletions lib/blocktree/blocktree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ package blocktree

import (
"bytes"
"io"
"math/big"
"reflect"
"testing"

database "github.com/ChainSafe/chaindb"
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/utils"

"github.com/stretchr/testify/require"
)
Expand All @@ -36,32 +36,6 @@ var testHeader = &types.Header{
Number: big.NewInt(0),
}

type mockDigestItem struct {
i int
}

func newMockDigestItem(i int) *mockDigestItem {
return &mockDigestItem{
i: i,
}
}

func (d *mockDigestItem) String() string {
return ""
}

func (d *mockDigestItem) Type() byte {
return byte(d.i)
}

func (d *mockDigestItem) Encode() ([]byte, error) {
return []byte{byte(d.i)}, nil
}

func (d *mockDigestItem) Decode(_ io.Reader) error {
return nil
}

func newBlockTreeFromNode(head *node, db database.Database) *BlockTree {
return &BlockTree{
head: head,
Expand Down Expand Up @@ -279,7 +253,7 @@ func TestBlockTree_GetAllBlocksAtDepth(t *testing.T) {
header := &types.Header{
ParentHash: previousHash,
Number: big.NewInt(int64(i)),
Digest: types.Digest{newMockDigestItem(9)},
Digest: types.Digest{utils.NewMockDigestItem(9)},
}

hash := header.Hash()
Expand All @@ -298,7 +272,7 @@ func TestBlockTree_GetAllBlocksAtDepth(t *testing.T) {
header := &types.Header{
ParentHash: previousHash,
Number: big.NewInt(int64(i)),
Digest: types.Digest{newMockDigestItem(7)},
Digest: types.Digest{utils.NewMockDigestItem(7)},
}

hash := header.Hash()
Expand Down
3 changes: 2 additions & 1 deletion lib/blocktree/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/ChainSafe/chaindb"
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/utils"

"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -54,7 +55,7 @@ func createTestBlockTree(header *types.Header, depth int, db chaindb.Database) (
header := &types.Header{
ParentHash: previousHash,
Number: big.NewInt(int64(i)),
Digest: types.Digest{newMockDigestItem(rand.Intn(256))},
Digest: types.Digest{utils.NewMockDigestItem(rand.Intn(256))},
}

hash := header.Hash()
Expand Down
33 changes: 33 additions & 0 deletions lib/utils/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package utils

import (
"fmt"
"io"
"os"
"path"
"testing"
Expand Down Expand Up @@ -74,3 +75,35 @@ func RemoveTestDir(t *testing.T) {
fmt.Println(fmt.Errorf("failed to remove test directory: %s", err))
}
}

// MockDigestItem ...
type MockDigestItem struct {
i int
}

// NewMockDigestItem creates a mock digest item for testing purposes.
func NewMockDigestItem(i int) *MockDigestItem {
return &MockDigestItem{
i: i,
}
}

// String ...
func (d *MockDigestItem) String() string {
return ""
}

// Type ...
func (d *MockDigestItem) Type() byte {
return byte(d.i)
}

// Encode ...
func (d *MockDigestItem) Encode() ([]byte, error) {
return []byte{byte(d.i)}, nil
}

// Decode ...
func (d *MockDigestItem) Decode(_ io.Reader) error {
return nil
}

0 comments on commit 737945e

Please sign in to comment.