Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crc16: add tests #3924

Merged
merged 7 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions crc16/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package crc16

import (
"testing"

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

func TestChecksum(t *testing.T) {
result := Checksum([]byte{0x12, 0x34, 0x56, 0x78, 0x90})
assert.Equal(t, []byte{0xe6, 0x48}, result)
}

func TestValidate(t *testing.T) {
err := Validate([]byte{0x12, 0x34, 0x56, 0x78, 0x90}, []byte{0xe6, 0x48})
assert.NoError(t, err)

err = Validate([]byte{0x12, 0x34, 0x56, 0x78, 0x90}, []byte{0xe7, 0x48})
assert.ErrorIs(t, err, ErrInvalidChecksum)
}
4 changes: 2 additions & 2 deletions go.list
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ github.com/spf13/viper v0.0.0-20150621231900-db7ff930a189
github.com/stellar/go
github.com/stellar/go-xdr v0.0.0-20201028102745-f80a23dac78a
github.com/stellar/throttled v2.2.3-0.20190823235211-89d75816f59d+incompatible
github.com/stretchr/objx v0.1.1
github.com/stretchr/testify v1.6.1
github.com/stretchr/objx v0.3.0
github.com/stretchr/testify v1.7.0
github.com/tyler-smith/go-bip39 v0.0.0-20180618194314-52158e4697b8
github.com/valyala/bytebufferpool v1.0.0
github.com/valyala/fasthttp v0.0.0-20170109085056-0a7f0a797cd6
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ require (
github.com/spf13/viper v0.0.0-20150621231900-db7ff930a189
github.com/stellar/go-xdr v0.0.0-20201028102745-f80a23dac78a
github.com/stellar/throttled v2.2.3-0.20190823235211-89d75816f59d+incompatible
github.com/stretchr/testify v1.6.1
github.com/stretchr/objx v0.3.0 // indirect
github.com/stretchr/testify v1.7.0
github.com/tyler-smith/go-bip39 v0.0.0-20180618194314-52158e4697b8
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v0.0.0-20170109085056-0a7f0a797cd6 // indirect
Expand Down
7 changes: 5 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,16 @@ github.com/stellar/go-xdr v0.0.0-20201028102745-f80a23dac78a/go.mod h1:yoxyU/M8n
github.com/stellar/throttled v2.2.3-0.20190823235211-89d75816f59d+incompatible h1:jMXXAcz6xTarGDQ4VtVbtERogcmDQw4RaE85Cr9CgoQ=
github.com/stellar/throttled v2.2.3-0.20190823235211-89d75816f59d+incompatible/go.mod h1:7CJ23pXirXBJq45DqvO6clzTEGM/l1SfKrgrzLry8b4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As=
github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tyler-smith/go-bip39 v0.0.0-20180618194314-52158e4697b8 h1:g3yQGZK+G6dfF/mw/SOwsTMzUVkpT4hB8pHxpbTXkKw=
github.com/tyler-smith/go-bip39 v0.0.0-20180618194314-52158e4697b8/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
Expand Down