Skip to content

Commit

Permalink
Merge branch 'main' into wip-websocket-client
Browse files Browse the repository at this point in the history
  • Loading branch information
JCrawsh committed Aug 16, 2023
2 parents 76cecc4 + 82ab9e6 commit d400d51
Show file tree
Hide file tree
Showing 127 changed files with 4,143 additions and 383 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/golangci/golangci-lint
rev: v1.46.2
rev: v1.52.2
hooks:
- id: golangci-lint
- repo: https://github.com/dnephin/pre-commit-golang
Expand All @@ -16,7 +16,7 @@ repos:
- id: go-unit-tests
- id: go-mod-tidy
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v8.0.0
rev: v9.5.0
hooks:
- id: commitlint
stages: [commit-msg]
Expand Down
68 changes: 34 additions & 34 deletions address-codec/address_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"testing"

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

func TestEncode(t *testing.T) {
Expand All @@ -29,7 +29,7 @@ func TestEncode(t *testing.T) {
for _, tc := range tt {
t.Run(tc.description, func(t *testing.T) {

assert.Equal(t, tc.expectedOutput, Encode(tc.input, tc.inputPrefix, tc.inputLength))
require.Equal(t, tc.expectedOutput, Encode(tc.input, tc.inputPrefix, tc.inputLength))

})
}
Expand All @@ -56,7 +56,7 @@ func TestDecode(t *testing.T) {
t.Run(tc.description, func(t *testing.T) {

res, _ := Decode(tc.input, tc.inputPrefix)
assert.Equal(t, tc.expectedOutput, res)
require.Equal(t, tc.expectedOutput, res)
})
}
}
Expand Down Expand Up @@ -106,11 +106,11 @@ func TestEncodeClassicAddressFromPublicKeyHex(t *testing.T) {
got, err := EncodeClassicAddressFromPublicKeyHex(tc.input)

if tc.expectedErr != nil {
assert.EqualError(t, err, tc.expectedErr.Error())
require.EqualError(t, err, tc.expectedErr.Error())
} else {
assert.NoError(t, err)
assert.NoError(t, err)
assert.Equal(t, tc.expectedOutput, got)
require.NoError(t, err)
require.NoError(t, err)
require.Equal(t, tc.expectedOutput, got)
}
})
}
Expand Down Expand Up @@ -180,9 +180,9 @@ func TestEncodeSeed(t *testing.T) {
got, err := EncodeSeed(tc.input, tc.inputEncodingType)

if tc.expectedErr != nil {
assert.EqualError(t, err, tc.expectedErr.Error())
require.EqualError(t, err, tc.expectedErr.Error())
} else {
assert.Equal(t, tc.expectedOutput, got)
require.Equal(t, tc.expectedOutput, got)
}
})
}
Expand Down Expand Up @@ -239,12 +239,12 @@ func TestDecodeSeed(t *testing.T) {
got, algorithm, err := DecodeSeed(tc.input)

if tc.expectedErr != nil {
assert.EqualError(t, err, tc.expectedErr.Error())
assert.Nil(t, tc.expectedOutput)
require.EqualError(t, err, tc.expectedErr.Error())
require.Nil(t, tc.expectedOutput)
} else {
assert.NoError(t, err)
assert.Equal(t, tc.expectedOutput, got)
assert.Equal(t, tc.expectedAlgorithm, algorithm)
require.NoError(t, err)
require.Equal(t, tc.expectedOutput, got)
require.Equal(t, tc.expectedAlgorithm, algorithm)
}
})
}
Expand Down Expand Up @@ -294,13 +294,13 @@ func TestDecodeAddressToAccountID(t *testing.T) {
typePrefix, accountID, err := DecodeClassicAddressToAccountID(tc.input)

if tc.expectedErr != nil {
assert.EqualError(t, err, tc.expectedErr.Error())
assert.Nil(t, tc.expectedPrefix, typePrefix)
assert.Nil(t, tc.expectedAccountID, accountID)
require.EqualError(t, err, tc.expectedErr.Error())
require.Nil(t, tc.expectedPrefix, typePrefix)
require.Nil(t, tc.expectedAccountID, accountID)
} else {
assert.NoError(t, err)
assert.Equal(t, tc.expectedPrefix, typePrefix)
assert.Equal(t, tc.expectedAccountID, accountID)
require.NoError(t, err)
require.Equal(t, tc.expectedPrefix, typePrefix)
require.Equal(t, tc.expectedAccountID, accountID)
}
})
}
Expand All @@ -327,9 +327,9 @@ func TestIsValidClassicAddress(t *testing.T) {
for _, tc := range tt {
t.Run(tc.description, func(t *testing.T) {
if tc.expected != true {
assert.False(t, IsValidClassicAddress(tc.input))
require.False(t, IsValidClassicAddress(tc.input))
} else {
assert.True(t, IsValidClassicAddress(tc.input))
require.True(t, IsValidClassicAddress(tc.input))
}
})
}
Expand Down Expand Up @@ -361,10 +361,10 @@ func TestEncodeNodePublicKey(t *testing.T) {
res, err := EncodeNodePublicKey(tc.input)

if tc.expectedErr != nil {
assert.EqualError(t, err, tc.expectedErr.Error())
require.EqualError(t, err, tc.expectedErr.Error())
} else {
assert.NoError(t, err)
assert.Equal(t, tc.expectedOutput, res)
require.NoError(t, err)
require.Equal(t, tc.expectedOutput, res)
}
})
}
Expand Down Expand Up @@ -396,10 +396,10 @@ func TestDecodeNodePublicKey(t *testing.T) {
res, err := DecodeNodePublicKey(tc.input)

if tc.expectedErr != nil {
assert.EqualError(t, err, tc.expectedErr.Error())
require.EqualError(t, err, tc.expectedErr.Error())
} else {
assert.NoError(t, err)
assert.Equal(t, tc.expectedOutput, res)
require.NoError(t, err)
require.Equal(t, tc.expectedOutput, res)
}
})
}
Expand Down Expand Up @@ -431,10 +431,10 @@ func TestEncodeAccountPublicKey(t *testing.T) {
res, err := EncodeAccountPublicKey(tc.input)

if tc.expectedErr != nil {
assert.EqualError(t, err, tc.expectedErr.Error())
require.EqualError(t, err, tc.expectedErr.Error())
} else {
assert.NoError(t, err)
assert.Equal(t, tc.expectedOutput, res)
require.NoError(t, err)
require.Equal(t, tc.expectedOutput, res)
}
})
}
Expand Down Expand Up @@ -466,10 +466,10 @@ func TestDecodeAccountPublicKey(t *testing.T) {
res, err := DecodeAccountPublicKey(tc.input)

if tc.expectedErr != nil {
assert.EqualError(t, err, tc.expectedErr.Error())
require.EqualError(t, err, tc.expectedErr.Error())
} else {
assert.NoError(t, err)
assert.Equal(t, tc.output, res)
require.NoError(t, err)
require.Equal(t, tc.output, res)
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions address-codec/base58_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package addresscodec
import (
"testing"

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

func TestEncodeBase58(t *testing.T) {
Expand Down Expand Up @@ -34,7 +34,7 @@ func TestEncodeBase58(t *testing.T) {

for _, tc := range tt {
t.Run(tc.description, func(t *testing.T) {
assert.Equal(t, tc.expectedOutput, EncodeBase58(tc.input))
require.Equal(t, tc.expectedOutput, EncodeBase58(tc.input))
})
}
}
Expand Down Expand Up @@ -64,7 +64,7 @@ func TestDecodeBase58(t *testing.T) {

for _, tc := range tt {
t.Run(tc.description, func(t *testing.T) {
assert.Equal(t, tc.expectedOutput, DecodeBase58(tc.input))
require.Equal(t, tc.expectedOutput, DecodeBase58(tc.input))
})
}
}
42 changes: 21 additions & 21 deletions binary-codec/definitions/definitions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@ package definitions
import (
"testing"

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

func TestLoadDefinitions(t *testing.T) {

err := loadDefinitions()
assert.NoError(t, err)
assert.Equal(t, int32(-1), definitions.Types["Done"])
assert.Equal(t, int32(4), definitions.Types["Hash128"])
assert.Equal(t, int32(-3), definitions.LedgerEntryTypes["Any"])
assert.Equal(t, int32(-399), definitions.TransactionResults["telLOCAL_ERROR"])
assert.Equal(t, int32(1), definitions.TransactionTypes["EscrowCreate"])
assert.Equal(t, &fieldInfo{Nth: 0, IsVLEncoded: false, IsSerialized: false, IsSigningField: false, Type: "Unknown"}, definitions.Fields["Generic"].fieldInfo)
assert.Equal(t, &fieldInfo{Nth: 28, IsVLEncoded: false, IsSerialized: true, IsSigningField: true, Type: "Hash256"}, definitions.Fields["NFTokenBuyOffer"].fieldInfo)
assert.Equal(t, &fieldInfo{Nth: 16, IsVLEncoded: false, IsSerialized: true, IsSigningField: true, Type: "UInt8"}, definitions.Fields["TickSize"].fieldInfo)
assert.Equal(t, &FieldHeader{TypeCode: 2, FieldCode: 4}, definitions.Fields["Sequence"].FieldHeader)
assert.Equal(t, &FieldHeader{TypeCode: 18, FieldCode: 1}, definitions.Fields["Paths"].FieldHeader)
assert.Equal(t, &FieldHeader{TypeCode: 2, FieldCode: 33}, definitions.Fields["SetFlag"].FieldHeader)
assert.Equal(t, &FieldHeader{TypeCode: 16, FieldCode: 16}, definitions.Fields["TickSize"].FieldHeader)
assert.Equal(t, "UInt32", definitions.Fields["TransferRate"].Type)
assert.Equal(t, "Sequence", definitions.FieldIdNameMap[FieldHeader{TypeCode: 2, FieldCode: 4}])
assert.Equal(t, "OfferSequence", definitions.FieldIdNameMap[FieldHeader{TypeCode: 2, FieldCode: 25}])
assert.Equal(t, "NFTokenSellOffer", definitions.FieldIdNameMap[FieldHeader{TypeCode: 5, FieldCode: 29}])
assert.Equal(t, int32(131076), definitions.Fields["Sequence"].Ordinal)
assert.Equal(t, int32(131097), definitions.Fields["OfferSequence"].Ordinal)
require.NoError(t, err)
require.Equal(t, int32(-1), definitions.Types["Done"])
require.Equal(t, int32(4), definitions.Types["Hash128"])
require.Equal(t, int32(-3), definitions.LedgerEntryTypes["Any"])
require.Equal(t, int32(-399), definitions.TransactionResults["telLOCAL_ERROR"])
require.Equal(t, int32(1), definitions.TransactionTypes["EscrowCreate"])
require.Equal(t, &fieldInfo{Nth: 0, IsVLEncoded: false, IsSerialized: false, IsSigningField: false, Type: "Unknown"}, definitions.Fields["Generic"].fieldInfo)
require.Equal(t, &fieldInfo{Nth: 28, IsVLEncoded: false, IsSerialized: true, IsSigningField: true, Type: "Hash256"}, definitions.Fields["NFTokenBuyOffer"].fieldInfo)
require.Equal(t, &fieldInfo{Nth: 16, IsVLEncoded: false, IsSerialized: true, IsSigningField: true, Type: "UInt8"}, definitions.Fields["TickSize"].fieldInfo)
require.Equal(t, &FieldHeader{TypeCode: 2, FieldCode: 4}, definitions.Fields["Sequence"].FieldHeader)
require.Equal(t, &FieldHeader{TypeCode: 18, FieldCode: 1}, definitions.Fields["Paths"].FieldHeader)
require.Equal(t, &FieldHeader{TypeCode: 2, FieldCode: 33}, definitions.Fields["SetFlag"].FieldHeader)
require.Equal(t, &FieldHeader{TypeCode: 16, FieldCode: 16}, definitions.Fields["TickSize"].FieldHeader)
require.Equal(t, "UInt32", definitions.Fields["TransferRate"].Type)
require.Equal(t, "Sequence", definitions.FieldIdNameMap[FieldHeader{TypeCode: 2, FieldCode: 4}])
require.Equal(t, "OfferSequence", definitions.FieldIdNameMap[FieldHeader{TypeCode: 2, FieldCode: 25}])
require.Equal(t, "NFTokenSellOffer", definitions.FieldIdNameMap[FieldHeader{TypeCode: 5, FieldCode: 29}])
require.Equal(t, int32(131076), definitions.Fields["Sequence"].Ordinal)
require.Equal(t, int32(131097), definitions.Fields["OfferSequence"].Ordinal)
}

// Helper functions to create and test ordinals.
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestConvertIntToBytes(t *testing.T) {

for _, tc := range tt {
t.Run(tc.description, func(t *testing.T) {
assert.Equal(t, tc.expected, convertIntToBytes(tc.input))
require.Equal(t, tc.expected, convertIntToBytes(tc.input))
})
}
}
Loading

0 comments on commit d400d51

Please sign in to comment.