Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
DisSys Inc.
bsc-shamir
Commits
90121b90
Commit
90121b90
authored
Jun 04, 2020
by
Anders Jensen Løvig
Browse files
Fix agreement test
parent
b9914b0c
Changes
2
Hide whitespace changes
Inline
Side-by-side
election/agreement.go
View file @
90121b90
package
election
import
(
"errors"
"fmt"
"log"
"sync"
...
...
@@ -53,6 +54,9 @@ func (a *Agreement) TallyList() ([]uuid.UUID, error) {
// Find the maximum subset
hashes
:=
MaxSubset
(
a
.
required
,
bls
)
if
len
(
hashes
)
==
0
{
return
nil
,
errors
.
New
(
"cannot agree on ballots"
)
}
// We know create a list of ballots we have in the subset.
list
:=
make
([]
uuid
.
UUID
,
0
,
len
(
a
.
ourList
))
...
...
election/election_test.go
View file @
90121b90
...
...
@@ -257,10 +257,15 @@ func TestCloseAgreement(t *testing.T) {
_
=
testElection
(
t
,
PhaseTallying
,
func
(
e
*
Election
)
<-
chan
time
.
Time
{
e
.
Status
.
Phase
=
PhaseCollect
ballots
:=
CreateBallots
(
3
,
createXS
(
1
),
big
.
NewInt
(
1
))
ballots
:=
CreateBallots
(
3
,
createXS
(
3
),
big
.
NewInt
(
1
))
e
.
handleBallot
(
UniqueID
(
strconv
.
Itoa
(
1
)),
ballots
[
"1"
])
e
.
handleClosing
(
"2"
)
b
:=
ballots
[
"2"
]
_
=
e
.
Agreement
.
AddList
(
"2"
,
map
[
string
]
uuid
.
UUID
{
b
.
Hash
()
:
b
.
ID
,
})
e
.
handleClosing
(
"3"
)
return
time
.
After
(
100
*
time
.
Millisecond
)
...
...
@@ -285,12 +290,16 @@ func TestTallyDeadline(t *testing.T) {
e
.
Deadline
=
time
.
Now
()
.
Add
(
1
*
time
.
Second
)
_
=
e
.
Start
()
ballots
:=
CreateBallots
(
3
,
createXS
(
1
),
big
.
NewInt
(
1
))
ballots
:=
CreateBallots
(
3
,
createXS
(
3
),
big
.
NewInt
(
1
))
e
.
handleBallot
(
UniqueID
(
strconv
.
Itoa
(
1
)),
ballots
[
"1"
])
// By closing another server, we should go directly to tallying when
// deadline is reached
e
.
handleClosing
(
"2"
)
b
:=
ballots
[
"2"
]
_
=
e
.
Agreement
.
AddList
(
"2"
,
map
[
string
]
uuid
.
UUID
{
b
.
Hash
()
:
b
.
ID
,
})
return
time
.
After
(
1200
*
time
.
Millisecond
)
})
...
...
@@ -319,9 +328,13 @@ func TestTallyAfterClose(t *testing.T) {
e
.
Deadline
=
time
.
Now
()
.
Add
(
1000
*
time
.
Millisecond
)
_
=
e
.
Start
()
ballots
:=
CreateBallots
(
3
,
createXS
(
1
),
big
.
NewInt
(
1
))
ballots
:=
CreateBallots
(
3
,
createXS
(
3
),
big
.
NewInt
(
1
))
e
.
handleBallot
(
UniqueID
(
strconv
.
Itoa
(
1
)),
ballots
[
"1"
])
b
:=
ballots
[
"2"
]
_
=
e
.
Agreement
.
AddList
(
"2"
,
map
[
string
]
uuid
.
UUID
{
b
.
Hash
()
:
b
.
ID
,
})
e
.
handleClosing
(
"2"
)
return
time
.
After
(
1200
*
time
.
Millisecond
)
...
...
@@ -354,6 +367,9 @@ func TestHandleTally(t *testing.T) {
Share
:
ballots
[
"4"
]
.
Share
,
Commits
:
ballots
[
"4"
]
.
Commits
,
}
ballotList
:=
map
[
string
]
uuid
.
UUID
{
ballots
[
"1"
]
.
Hash
()
:
ballots
[
"1"
]
.
ID
,
}
_
=
testElection
(
t
,
PhaseResult
,
func
(
e
*
Election
)
<-
chan
time
.
Time
{
e
.
Status
.
Phase
=
PhaseCollect
...
...
@@ -363,7 +379,9 @@ func TestHandleTally(t *testing.T) {
if
e
.
tallyBox
.
Size
()
!=
0
{
t
.
Errorf
(
"Expected 0 tally, got %d"
,
e
.
tallyBox
.
Size
())
}
e
.
handleClosing
(
"2"
)
_
=
e
.
Agreement
.
AddList
(
"2"
,
ballotList
)
e
.
handleTally
(
"2"
,
tally1
)
e
.
handleTally
(
"2"
,
tally1
)
...
...
@@ -372,6 +390,7 @@ func TestHandleTally(t *testing.T) {
}
e
.
handleClosing
(
"3"
)
_
=
e
.
Agreement
.
AddList
(
"3"
,
ballotList
)
e
.
handleTally
(
"3"
,
tally2
)
return
time
.
After
(
500
*
time
.
Millisecond
)
...
...
@@ -399,9 +418,11 @@ func TestCloseTimeoutTally(t *testing.T) {
e
.
Status
.
Phase
=
PhaseCollect
e
.
Config
.
CloseSleep
=
1
*
time
.
Second
ballots
:=
CreateBallots
(
3
,
createXS
(
1
),
big
.
NewInt
(
1
))
ballots
:=
CreateBallots
(
3
,
createXS
(
3
),
big
.
NewInt
(
1
))
e
.
handleBallot
(
UniqueID
(
strconv
.
Itoa
(
1
)),
ballots
[
"1"
])
e
.
handleClosing
(
"3"
)
_
=
e
.
Agreement
.
AddList
(
"2"
,
map
[
string
]
uuid
.
UUID
{
ballots
[
"2"
]
.
Hash
()
:
ballots
[
"2"
]
.
ID
})
e
.
handleClosing
(
"2"
)
// This should start a go-routine waiting for late ballots
e
.
nextPhase
(
ReasonAgreement
)
...
...
@@ -409,7 +430,8 @@ func TestCloseTimeoutTally(t *testing.T) {
// This prevent us from wait for ballot lists
e
.
Config
.
CloseSleep
=
0
e
.
handleClosing
(
"4"
)
_
=
e
.
Agreement
.
AddList
(
"3"
,
map
[
string
]
uuid
.
UUID
{
ballots
[
"3"
]
.
Hash
()
:
ballots
[
"3"
]
.
ID
})
e
.
handleClosing
(
"3"
)
if
e
.
Status
.
Phase
!=
PhaseCloseWait
{
t
.
Errorf
(
"Not waiting for late ballots"
)
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment