Skip to content

Commit

Permalink
github: bump golangci-lint and fix linter issues (cosmos#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgrinaker committed Nov 6, 2020
1 parent 69dd35b commit a41e36b
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: golangci/golangci-lint-action@v2.1.0
- uses: golangci/golangci-lint-action@v2.3.0
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.30
version: v1.32
args: --timeout 10m
github-token: ${{ secrets.github_token }}
4 changes: 2 additions & 2 deletions basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestUnit(t *testing.T) {
tree.root = origNode
}

//////// Test Set cases:
// Test Set cases:

// Case 1:
t1 := T(N(4, 20))
Expand All @@ -172,7 +172,7 @@ func TestUnit(t *testing.T) {
expectSet(t4, 8, "(((1 2) (5 6)) ((7 8) 9))", 5)
expectSet(t4, 10, "(((1 2) (5 6)) (7 (9 10)))", 5)

//////// Test Remove cases:
// Test Remove cases:

t10 := T(N(N(1, 2), 3))

Expand Down
2 changes: 1 addition & 1 deletion common/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (bz HexBytes) MarshalJSON() ([]byte, error) {
s := strings.ToUpper(hex.EncodeToString(bz))
jbz := make([]byte, len(s)+2)
jbz[0] = '"'
copy(jbz[1:], []byte(s))
copy(jbz[1:], s)
jbz[len(jbz)-1] = '"'
return jbz, nil
}
Expand Down
2 changes: 1 addition & 1 deletion nodedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ func (ndb *nodeDB) decrVersionReaders(version int64) {
}
}

////////////////// Utility and test functions /////////////////////////////////
// Utility and test functions

func (ndb *nodeDB) leafNodes() []*Node {
leaves := []*Node{}
Expand Down
60 changes: 59 additions & 1 deletion proof_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,65 @@ func (proof *RangeProof) _computeRootHash() (rootHash []byte, treeEnd bool, err
return rootHash, treeEnd, nil
}

///////////////////////////////////////////////////////////////////////////////
// toProto converts the proof to a Protobuf representation, for use in ValueOp and AbsenceOp.
func (proof *RangeProof) ToProto() *iavlproto.RangeProof {
pb := &iavlproto.RangeProof{
LeftPath: make([]*iavlproto.ProofInnerNode, 0, len(proof.LeftPath)),
InnerNodes: make([]*iavlproto.PathToLeaf, 0, len(proof.InnerNodes)),
Leaves: make([]*iavlproto.ProofLeafNode, 0, len(proof.Leaves)),
}
for _, inner := range proof.LeftPath {
pb.LeftPath = append(pb.LeftPath, inner.toProto())
}
for _, path := range proof.InnerNodes {
pbPath := make([]*iavlproto.ProofInnerNode, 0, len(path))
for _, inner := range path {
pbPath = append(pbPath, inner.toProto())
}
pb.InnerNodes = append(pb.InnerNodes, &iavlproto.PathToLeaf{Inners: pbPath})
}
for _, leaf := range proof.Leaves {
pb.Leaves = append(pb.Leaves, leaf.toProto())
}

return pb
}

// rangeProofFromProto generates a RangeProof from a Protobuf RangeProof.
func RangeProofFromProto(pbProof *iavlproto.RangeProof) (RangeProof, error) {
proof := RangeProof{}

for _, pbInner := range pbProof.LeftPath {
inner, err := proofInnerNodeFromProto(pbInner)
if err != nil {
return proof, err
}
proof.LeftPath = append(proof.LeftPath, inner)
}

for _, pbPath := range pbProof.InnerNodes {
var path PathToLeaf // leave as nil unless populated, for Amino compatibility
if pbPath != nil {
for _, pbInner := range pbPath.Inners {
inner, err := proofInnerNodeFromProto(pbInner)
if err != nil {
return proof, err
}
path = append(path, inner)
}
}
proof.InnerNodes = append(proof.InnerNodes, path)
}

for _, pbLeaf := range pbProof.Leaves {
leaf, err := proofLeafNodeFromProto(pbLeaf)
if err != nil {
return proof, err
}
proof.Leaves = append(proof.Leaves, leaf)
}
return proof, nil
}

// keyStart is inclusive and keyEnd is exclusive.
// If keyStart or keyEnd don't exist, the leaf before keyStart
Expand Down
12 changes: 6 additions & 6 deletions tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1077,9 +1077,9 @@ func TestVersionedTreeProofs(t *testing.T) {
}

func TestOrphans(t *testing.T) {
//If you create a sequence of saved versions
//Then randomly delete versions other than the first and last until only those two remain
//Any remaining orphan nodes should either have fromVersion == firstVersion || toVersion == lastVersion
// If you create a sequence of saved versions
// Then randomly delete versions other than the first and last until only those two remain
// Any remaining orphan nodes should either have fromVersion == firstVersion || toVersion == lastVersion
require := require.New(t)
tree, err := NewMutableTree(db.NewMemDB(), 100)
require.NoError(err)
Expand Down Expand Up @@ -1324,14 +1324,14 @@ func TestLoadVersionForOverwriting(t *testing.T) {
_, _, err = tree.SaveVersion()
require.NoError(err, "SaveVersion should not fail, write the same value")

//The tree version now is 52 which is equal to latest version.
//Now any key value can be written into the tree
// The tree version now is 52 which is equal to latest version.
// Now any key value can be written into the tree
tree.Set([]byte("key any value"), []byte("value any value"))
_, _, err = tree.SaveVersion()
require.NoError(err, "SaveVersion should not fail.")
}

//////////////////////////// BENCHMARKS ///////////////////////////////////////
// BENCHMARKS

func BenchmarkTreeLoadAndDelete(b *testing.B) {
numVersions := 5000
Expand Down

0 comments on commit a41e36b

Please sign in to comment.