forked from cobinhood/moneroutil
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblock_test.go
47 lines (37 loc) · 3.49 KB
/
block_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package moneroutil
import (
"bytes"
"encoding/hex"
"io/ioutil"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetBlockHash(t *testing.T) {
cases := []struct {
hash string
block string
}{
{"112a7fcec1e9589a8ccc202a0c4876055b9da6dd3a15528407d17366fb195a2a", "0707bda4eddd0522d7aafd4565c58981f351acbf7136329ac0b31ff6da91d0d205869c7ad4bf00daa50200028bb96601ffcfb86601a0d89880896e028a680671ad851b974dcec00f05a4e462c958ee3a50aac15b457eaaf380279f1e2b010bd859cfc2f26469f87ecfef17ead881998357effa1c939ed9796c029b3a630402080000017f1d0800000001f141f89a8097f8786605e570a0f7d06e5407d584d559637af2c0e1c0acf09ebb"},
{"ae1d3baac7fc972dccb888d54d40d930e1b651c9a7e2ca74ca3d9a9e5869bd86", "0707d3a4eddd05112a7fcec1e9589a8ccc202a0c4876055b9da6dd3a15528407d17366fb195a2aa0604444028cb96601ffd0b86601869182fbd16d02c85879f3c0256301bedb5f172a26ee0b03f0b2704d801fb43906d83168d8b9312b011083c976e0b4b057066a29336855683f24d3d7afe605f5ded5693a667ea800d9020800001f9ede6dee000000"},
{"5e3087e85cdfc631ba738a8bf3cb96fde3438b6a11fec909b05141a665975532", "0707d8a8eddd05ae1d3baac7fc972dccb888d54d40d930e1b651c9a7e2ca74ca3d9a9e5869bd8649995600028db96601ffd1b86601809796d89c70029633146661e0fe0bae6d691ac3f5f84d931b2a3fcdfbaea2087a71037de9cbd32b01207da2ff9660721ec0d4b32538f2f5b5fb91ad5454b49b0e6165429fe686206b020804a1d9e152fdfc000016ddf990067c02af983eb8986ce95aa28c8a5b2f7e213d522a64d4768cdef24b04e9a2dd6f0f853fccaaab96a49ce7e51568a130a27043acac52320bbbd0273f6d2a1a6fd01b12fca73aae33662022ddeba49fbbad7714475ed294b148095c3c31fa2891195930f9e0cf27c10aba9042cc6fb104948a5a326f14eea4e4a7227fa3184096f0aaea738fa5a07dfb6da7c3d9f030929d9344891d2b11b43865c860876d9e56d3b88007c82c48cc352b6fb4fd381d5f994bf7922bcc2bc9d75a781ee4b3d11ff28aa473644e67b8ba352e4f54fe79327371e373e0195f1e5608d9284ba49be21e5df9e13341822191a44a627691d510ea5eab29b37e0fddc8016e4a6897e01a0013be35355e61fbb41a88fe56b6e0070bf52454e12847beae49f1e9c09b330696a70ea5e8676b1530b06d977685b052b8b89313a38633cd0bf9e5c3c78baeb1a1063b95c7da4587b2abff62ddac1617e270207a392fff302783a4ced2be74bd879c3d787c3d8897c0b467d353bf73b5557e9f363e81edccde3bf030bfc001769ccd21a9f57f12472f4dde4b7d9a268021e559bfa346ca7f10382e9f37acd8b7e730a2c20575cc427939828ccc039af0a7e821ca3715efcca88e9303b027ca97a1c56c980b68995746487d75dd437cc5d57e2f2b4349f2f527c503d39ee5684c16d855a7c9289c7e9d0f09a5bfd3d3100ea4d12beb239ee8d37325faadf2ab13cd08944e0e1f48fd5f439a6a112f05a5ab4e8a31ff19b2bc5a8f6e82f73dfee3ba463c6d2376c5195900a87e38b39a8aef190ec217041645f8d32a5b59e0fd02ae7c48a14c2c2f0555f155e61b64a3f91d4304a438fe767f988b659a8f19fbe13660518f497727aa1db9184d40e240140fa6f1e22c2ae19002e50e55d9422c10ff696b9e6554acc13f9768bba362175c5943af767a9e7227eedbd5c84123c45b5c5e2f614e3ff1af14f67075f24aecfe9f06db6c3641d91e8740064dd2"},
}
for _, test := range cases {
expected, _ := HexToHash(test.hash)
serializedBlock, _ := hex.DecodeString(test.block)
reader := bytes.NewReader(serializedBlock)
block, err := ParseBlock(reader)
assert.Nil(t, err)
assert.Equal(t, expected, block.GetHash())
}
}
func TestExceptionalBlockHash(t *testing.T) {
blockHex, err := ioutil.ReadFile("block-202612-test.txt")
assert.Nil(t, err)
binaryBlock, err := hex.DecodeString(string(blockHex))
assert.Nil(t, err)
reader := bytes.NewReader(binaryBlock)
block, err := ParseBlock(reader)
assert.Nil(t, err)
expected := Hash{0xbb, 0xd6, 0x04, 0xd2, 0xba, 0x11, 0xba, 0x27, 0x93, 0x5e, 0x00, 0x6e, 0xd3, 0x9c, 0x9b, 0xfd, 0xd9, 0x9b, 0x76, 0xbf, 0x4a, 0x50, 0x65, 0x4b, 0xc1, 0xe1, 0xe6, 0x12, 0x17, 0x96, 0x26, 0x98}
assert.Equal(t, expected, block.GetHash())
}