-
Notifications
You must be signed in to change notification settings - Fork 204
/
requiredDataPool_test.go
115 lines (93 loc) · 2.58 KB
/
requiredDataPool_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package process_test
import (
"strconv"
"testing"
"github.com/multiversx/mx-chain-go/process"
"github.com/stretchr/testify/assert"
)
func TestRequiredDataPool_ExpectedData(t *testing.T) {
hashes := [][]byte{
[]byte("first_data"),
[]byte("second_data"),
}
rd := process.RequiredDataPool{}
rd.SetHashes(hashes)
assert.Equal(t, hashes, rd.ExpectedData())
}
func TestRequiredDataPool_SetHashesNilListResets(t *testing.T) {
hashes := [][]byte{
[]byte("first_data"),
[]byte("second_data"),
}
rd := process.RequiredDataPool{}
rd.SetHashes(hashes)
rd.SetHashes(nil)
assert.Nil(t, rd.ExpectedData())
}
func TestRequiredDataPool_SetHashesEmptyListResets(t *testing.T) {
hashes := [][]byte{
[]byte("first_data"),
[]byte("second_data"),
}
rd := process.RequiredDataPool{}
rd.SetHashes(hashes)
rd.SetHashes(make([][]byte, 0))
assert.Nil(t, rd.ExpectedData())
}
func TestRequiredDataPool_SetReceivedHashSettingAllWorks(t *testing.T) {
hashes := [][]byte{
[]byte("first_data"),
[]byte("second_data"),
}
rd := process.RequiredDataPool{}
rd.SetHashes(hashes)
rd.SetReceivedHash([]byte("first_data"))
rd.SetReceivedHash([]byte("second_data"))
assert.True(t, rd.ReceivedAll())
}
func TestRequiredDataPool_SetReceivedHashSettingIncompleteWorks(t *testing.T) {
hashes := [][]byte{
[]byte("first_data"),
[]byte("second_data"),
}
rd := process.RequiredDataPool{}
rd.SetHashes(hashes)
rd.SetReceivedHash([]byte("first_data"))
assert.False(t, rd.ReceivedAll())
}
func TestRequiredDataPool_SetReceivedHashSettingWrongHashWorks(t *testing.T) {
hashes := [][]byte{
[]byte("first_data"),
[]byte("second_data"),
}
rd := process.RequiredDataPool{}
rd.SetHashes(hashes)
rd.SetReceivedHash([]byte("first_data"))
rd.SetReceivedHash([]byte("third_data"))
assert.False(t, rd.ReceivedAll())
}
func TestRequiredDataPool_SetReceivedHashSettingWrongHashThenCorrectWorks(t *testing.T) {
hashes := [][]byte{
[]byte("first_data"),
[]byte("second_data"),
}
rd := process.RequiredDataPool{}
rd.SetHashes(hashes)
rd.SetReceivedHash([]byte("first_data"))
rd.SetReceivedHash([]byte("third_data"))
rd.SetReceivedHash([]byte("second_data"))
assert.True(t, rd.ReceivedAll())
}
func TestRequiredDataPool_SetReceivedHashMultipleSettingAllWorks(t *testing.T) {
maxHashes := 8
hashes := make([][]byte, maxHashes)
for idx := 0; idx < maxHashes; idx++ {
hashes[idx] = []byte("hash " + strconv.Itoa(idx))
}
rd := process.RequiredDataPool{}
rd.SetHashes(hashes)
for idx := 0; idx < maxHashes; idx++ {
rd.SetReceivedHash([]byte("hash " + strconv.Itoa(idx)))
}
assert.True(t, rd.ReceivedAll())
}