Skip to content

Commit

Permalink
update linter version, add lint exceptions for gosec, update change log
Browse files Browse the repository at this point in the history
  • Loading branch information
rohenaz committed Sep 17, 2024
1 parent 86e755e commit 265b342
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ on:
- "master"

env:
GO_VERSION: '1.22' # Use the version you need
GOLANGCI_LINT_VERSION: v1.59 # Latest version as of my last update
GO_VERSION: '1.22'
GOLANGCI_LINT_VERSION: v1.60.1

jobs:
detect-modules:
Expand Down
9 changes: 7 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ linters-settings:
checks:
# the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
argument,case,condition,operation,return,assign

govet:
# report about shadowed variables
shadow: true
Expand Down Expand Up @@ -336,7 +336,7 @@ linters:
- dogsled
# - revive
- prealloc
- exportloopref
- copyloopvar
- exhaustive
- sqlclosecheck
- nolintlint
Expand Down Expand Up @@ -398,6 +398,11 @@ issues:
- staticcheck
text: "SA1019:"

# Exclude some gosec messages
- linters:
- gosec
text: "G115:"

# Exclude lll issues for long lines with go:generate
- linters:
- lll
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file. The format
## Table of Contents

- [Unreleased](#unreleased)
- [1.1.8 - 2024-09-17](#118---2024-09-17)
- [1.1.7 - 2024-09-10](#117---2024-09-10)
- [1.1.6 - 2024-09-09](#116---2024-09-09)
- [1.1.5 - 2024-09-06](#115---2024-09-06)
Expand All @@ -16,6 +17,17 @@ All notable changes to this project will be documented in this file. The format
- [1.0.0 - 2024-06-06](#100---2024-06-06)


## [1.1.8] - 2024-09-17
### Changed
- Restore Transaction `Clone` to its previous state, and add `ShallowClone` as a more efficient alternative
- Fix the version number bytes in `message`
- Rename `merkleproof.ToHex()` to `Hex()`
- Update golangci-lint version and rules

### Added
- `transaction.ShallowClone`
- `transaction.Hex`

## [1.1.7] - 2024-09-10
- Rework `tx.Clone()` to be more efficient
- Introduce SignUnsigned to sign only inputs that have not already been signed
Expand Down
4 changes: 2 additions & 2 deletions primitives/hash/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"crypto/sha256"
"crypto/sha512"

"golang.org/x/crypto/ripemd160"
"golang.org/x/crypto/ripemd160" //nolint:gosec // required
)

// Sha256 calculates hash(b) and returns the resulting bytes.
Expand Down Expand Up @@ -42,7 +42,7 @@ func Sha512HMAC(b, key []byte) []byte {

// Ripemd160 hashes with RIPEMD160
func Ripemd160(b []byte) []byte {
ripe := ripemd160.New()
ripe := ripemd160.New() //nolint:gosec // required
_, _ = ripe.Write(b[:])
return ripe.Sum(nil)
}
Expand Down
6 changes: 3 additions & 3 deletions script/interpreter/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"hash"
"math/big"

"golang.org/x/crypto/ripemd160"
"golang.org/x/crypto/ripemd160" //nolint:gosec // required

ec "github.com/bitcoin-sv/go-sdk/primitives/ec"
crypto "github.com/bitcoin-sv/go-sdk/primitives/hash"
Expand Down Expand Up @@ -1869,7 +1869,7 @@ func opcodeRipemd160(op *ParsedOpcode, t *thread) error {
return err
}

t.dstack.PushByteArray(calcHash(buf, ripemd160.New()))
t.dstack.PushByteArray(calcHash(buf, ripemd160.New())) //nolint:gosec // required
return nil
}

Expand Down Expand Up @@ -1914,7 +1914,7 @@ func opcodeHash160(op *ParsedOpcode, t *thread) error {
}

hash := sha256.Sum256(buf)
t.dstack.PushByteArray(calcHash(hash[:], ripemd160.New()))
t.dstack.PushByteArray(calcHash(hash[:], ripemd160.New())) //nolint:gosec // required
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions transaction/merklepath.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ func (mp *MerklePath) Bytes() []byte {
return bytes
}

// ToHex converts the MerklePath to a hexadecimal string representation
func (mp *MerklePath) ToHex() string {
// Hex converts the MerklePath to a hexadecimal string representation
func (mp *MerklePath) Hex() string {
return hex.EncodeToString(mp.Bytes())
}

Expand Down
12 changes: 6 additions & 6 deletions transaction/merklepath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,30 @@ var BRC74JSON = MerklePath{

var BRC74JSONTrimmed = `{"blockHeight":813706,"path":[[{"offset":3048,"hash":"304e737fdfcb017a1a322e78b067ecebb5e07b44f0a36ed1f01264d2014f7711"},{"offset":3049,"hash":"d888711d588021e588984e8278a2decf927298173a06737066e43f3e75534e00","txid":true},{"offset":3050,"hash":"98c9c5dd79a18f40837061d5e0395ffb52e700a2689e641d19f053fc9619445e","txid":true},{"offset":3051,"duplicate":true}],[],[{"offset":763,"duplicate":true}],[{"offset":380,"hash":"858e41febe934b4cbc1cb80a1dc8e254cb1e69acff8e4f91ecdd779bcaefb393"}],[{"offset":191,"duplicate":true}],[{"offset":94,"hash":"f80263e813c644cd71bcc88126d0463df070e28f11023a00543c97b66e828158"}],[{"offset":46,"hash":"f36f792fa2b42acfadfa043a946d4d7b6e5e1e2e0266f2cface575bbb82b7ae0"}],[{"offset":22,"hash":"7d5051f0d4ceb7d2e27a49e448aedca2b3865283ceffe0b00b9c3017faca2081"}],[{"offset":10,"hash":"43aeeb9b6a9e94a5a787fbf04380645e6fd955f8bf0630c24365f492ac592e50"}],[{"offset":4,"hash":"45be5d16ac41430e3589a579ad780e5e42cf515381cc309b48d0f4648f9fcd1c"}],[{"offset":3,"duplicate":true}],[{"offset":0,"hash":"d40cb31af3ef53dd910f5ce15e9a1c20875c009a22d25eab32c11c7ece6487af"}]]}`

func TestMerklePath_ParseHex(t *testing.T) {
func TestMerklePathParseHex(t *testing.T) {
t.Parallel()

t.Run("parses from hex", func(t *testing.T) {
mp, err := NewMerklePathFromHex(BRC74Hex)
require.NoError(t, err)
require.Equal(t, BRC74Hex, mp.ToHex())
require.Equal(t, BRC74Hex, mp.Hex())
})
}

func TestMerklePath_ToHex(t *testing.T) {
func TestMerklePathToHex(t *testing.T) {
// t.Parallel()

t.Run("serializes to hex", func(t *testing.T) {
path := MerklePath{
BlockHeight: BRC74JSON.BlockHeight,
Path: BRC74JSON.Path,
}
hex := path.ToHex()
hex := path.Hex()
require.Equal(t, BRC74Hex, hex)
})
}

func TestMerklePath_ComputeRootHex(t *testing.T) {
func TestMerklePathComputeRootHex(t *testing.T) {
t.Parallel()

t.Run("computes a root", func(t *testing.T) {
Expand Down Expand Up @@ -120,7 +120,7 @@ func TestMerklePath_Verify(t *testing.T) {

}

func TestMerklePath_Combine(t *testing.T) {
func TestMerklePathCombine(t *testing.T) {
t.Parallel()

t.Run("combines two paths", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion transaction/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,6 @@ func TestSignUnsignedNew(t *testing.T) {
require.NoError(t, err)

for _, input := range tx.Inputs {
require.Positive(t, len(input.UnlockingScript.Bytes()))
require.NotEmpty(t, input.UnlockingScript.Bytes())
}
}
1 change: 0 additions & 1 deletion util/bytemanipulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func TestLittleEndianBytes(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
result := util.LittleEndianBytes(tc.input, tc.length)
Expand Down

0 comments on commit 265b342

Please sign in to comment.