Skip to content

Commit

Permalink
use require instead of assert in tests, use require.Positive instead …
Browse files Browse the repository at this point in the history
…of Greater than 0
  • Loading branch information
rohenaz committed Sep 3, 2024
1 parent 5a52c21 commit c7ba917
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion util/big_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestNewRandomBigInt(t *testing.T) {
b := util.NewRandomBigInt(tc.byteLen)
require.NotNil(t, b)
require.LessOrEqual(t, len(b.Bytes()), tc.byteLen)
require.Greater(t, b.BitLen(), 0)
require.Positive(t, b.BitLen())
})
}
}
Expand Down
11 changes: 5 additions & 6 deletions util/bytemanipulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"

crypto "github.com/bitcoin-sv/go-sdk/primitives/hash"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/bitcoin-sv/go-sdk/util"
Expand Down Expand Up @@ -63,7 +62,7 @@ func TestLittleEndianBytes(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
result := util.LittleEndianBytes(tc.input, tc.length)
assert.Equal(t, tc.expected, result)
require.Equal(t, tc.expected, result)
})
}
}
Expand All @@ -74,27 +73,27 @@ func TestReverseBytes(t *testing.T) {
t.Run("Empty slice", func(t *testing.T) {
input := []byte{}
result := util.ReverseBytes(input)
assert.Equal(t, input, result)
require.Equal(t, input, result)
})

t.Run("Single byte", func(t *testing.T) {
input := []byte{0x01}
result := util.ReverseBytes(input)
assert.Equal(t, input, result)
require.Equal(t, input, result)
})

t.Run("Multiple bytes", func(t *testing.T) {
input := []byte{0x01, 0x02, 0x03, 0x04}
expected := []byte{0x04, 0x03, 0x02, 0x01}
result := util.ReverseBytes(input)
assert.Equal(t, expected, result)
require.Equal(t, expected, result)
})

t.Run("Odd number of bytes", func(t *testing.T) {
input := []byte{0x01, 0x02, 0x03, 0x04, 0x05}
expected := []byte{0x05, 0x04, 0x03, 0x02, 0x01}
result := util.ReverseBytes(input)
assert.Equal(t, expected, result)
require.Equal(t, expected, result)
})

t.Run("genesis hash", func(t *testing.T) {
Expand Down
21 changes: 10 additions & 11 deletions util/bytestring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/bitcoin-sv/go-sdk/util"
Expand Down Expand Up @@ -33,7 +32,7 @@ func TestNewByteStringFromHex(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := util.NewByteStringFromHex(tt.input)
assert.Equal(t, tt.expected, result)
require.Equal(t, tt.expected, result)
})
}
}
Expand All @@ -52,7 +51,7 @@ func TestByteStringMarshalJSON(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
result, err := json.Marshal(tt.input)
require.NoError(t, err)
assert.Equal(t, tt.expected, string(result))
require.Equal(t, tt.expected, string(result))
})
}
}
Expand All @@ -75,10 +74,10 @@ func TestByteStringUnmarshalJSON(t *testing.T) {
var bs util.ByteString
err := json.Unmarshal([]byte(tt.input), &bs)
if tt.wantErr {
assert.Error(t, err)
require.Error(t, err)
} else {
assert.NoError(t, err)
assert.Equal(t, tt.expected, bs)
require.NoError(t, err)
require.Equal(t, tt.expected, bs)
}
})
}
Expand All @@ -97,7 +96,7 @@ func TestByteStringString(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := tt.input.String()
assert.Equal(t, tt.expected, result)
require.Equal(t, tt.expected, result)
})
}
}
Expand All @@ -116,7 +115,7 @@ func TestByteStringValue(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
result, err := tt.input.Value()
require.NoError(t, err)
assert.Equal(t, tt.expected, result)
require.Equal(t, tt.expected, result)
})
}
}
Expand All @@ -137,10 +136,10 @@ func TestByteStringScan(t *testing.T) {
var bs util.ByteString
err := bs.Scan(tt.input)
if tt.wantErr {
assert.Error(t, err)
require.Error(t, err)
} else {
assert.NoError(t, err)
assert.Equal(t, tt.expected, bs)
require.NoError(t, err)
require.Equal(t, tt.expected, bs)
}
})
}
Expand Down

0 comments on commit c7ba917

Please sign in to comment.