diff options
author | Joey Zhou <josephyzhou@gmail.com> | 2014-02-18 07:46:16 +0800 |
---|---|---|
committer | Joey Zhou <josephyzhou@gmail.com> | 2014-02-18 07:46:16 +0800 |
commit | e72a782bf0e0a0059e8dff83fa5fc80cc6f678e5 (patch) | |
tree | 11b47c8a5c481b87acc18e1fa2250106bf07b992 /ethutil/encoding_test.go | |
parent | e5b97fe03e8789bf4e113946a1935c0ba270ad2b (diff) | |
download | dexon-e72a782bf0e0a0059e8dff83fa5fc80cc6f678e5.tar dexon-e72a782bf0e0a0059e8dff83fa5fc80cc6f678e5.tar.gz dexon-e72a782bf0e0a0059e8dff83fa5fc80cc6f678e5.tar.bz2 dexon-e72a782bf0e0a0059e8dff83fa5fc80cc6f678e5.tar.lz dexon-e72a782bf0e0a0059e8dff83fa5fc80cc6f678e5.tar.xz dexon-e72a782bf0e0a0059e8dff83fa5fc80cc6f678e5.tar.zst dexon-e72a782bf0e0a0059e8dff83fa5fc80cc6f678e5.zip |
adding compact decode tests
Diffstat (limited to 'ethutil/encoding_test.go')
-rw-r--r-- | ethutil/encoding_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/ethutil/encoding_test.go b/ethutil/encoding_test.go index bcabab0b1..cbfbc0eaf 100644 --- a/ethutil/encoding_test.go +++ b/ethutil/encoding_test.go @@ -35,3 +35,33 @@ func TestCompactHexDecode(t *testing.T) { t.Error("Error compact hex decode. Expected", exp, "got", res) } } + +func TestCompactDecode(t *testing.T) { + exp := []int{1, 2, 3, 4, 5} + res := CompactDecode("\x11\x23\x45") + + if !CompareIntSlice(res, exp) { + t.Error("odd compact decode. Expected", exp, "got", res) + } + + exp = []int{0, 1, 2, 3, 4, 5} + res = CompactDecode("\x00\x01\x23\x45") + + if !CompareIntSlice(res, exp) { + t.Error("even compact decode. Expected", exp, "got", res) + } + + exp = []int{0, 15, 1, 12, 11, 8 /*term*/, 16} + res = CompactDecode("\x20\x0f\x1c\xb8") + + if !CompareIntSlice(res, exp) { + t.Error("even terminated compact decode. Expected", exp, "got", res) + } + + exp = []int{15, 1, 12, 11, 8 /*term*/, 16} + res = CompactDecode("\x3f\x1c\xb8") + + if !CompareIntSlice(res, exp) { + t.Error("even terminated compact decode. Expected", exp, "got", res) + } +}
\ No newline at end of file |