Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
comms
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
comms
Commits
5b8f3a3a
Commit
5b8f3a3a
authored
4 years ago
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for new functionality
parent
36e23d01
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!58
Revert "Modify waiting lock"
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
network/dataStructures/roundData_test.go
+31
-0
31 additions, 0 deletions
network/dataStructures/roundData_test.go
network/dataStructures/round_test.go
+21
-0
21 additions, 0 deletions
network/dataStructures/round_test.go
network/instance_test.go
+29
-0
29 additions, 0 deletions
network/instance_test.go
with
81 additions
and
0 deletions
network/dataStructures/roundData_test.go
+
31
−
0
View file @
5b8f3a3a
...
@@ -10,6 +10,7 @@ package dataStructures
...
@@ -10,6 +10,7 @@ package dataStructures
import
(
import
(
"gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/comms/testutils"
"gitlab.com/elixxir/comms/testutils"
"reflect"
"testing"
"testing"
)
)
...
@@ -58,6 +59,36 @@ func TestData_GetRound(t *testing.T) {
...
@@ -58,6 +59,36 @@ func TestData_GetRound(t *testing.T) {
}
}
}
}
func
TestData_GetWrappedRound
(
t
*
testing
.
T
)
{
d
:=
NewData
()
// Construct a mock round object
ri
:=
&
mixmessages
.
RoundInfo
{
ID
:
0
,
UpdateID
:
0
,
}
testutils
.
SignRoundInfo
(
ri
,
t
)
pubKey
,
err
:=
testutils
.
LoadPublicKeyTesting
(
t
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to load public key: %v"
,
err
)
t
.
FailNow
()
}
rnd
:=
NewRound
(
ri
,
pubKey
)
_
=
d
.
UpsertRound
(
rnd
)
retrieved
,
err
:=
d
.
GetWrappedRound
(
0
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to get roundinfo with proper id"
)
}
if
!
reflect
.
DeepEqual
(
rnd
,
retrieved
)
{
t
.
Errorf
(
"Retrieved value did not match expected!"
+
"
\n\t
Expected: %v"
+
"
\n\t
Received: %v"
,
rnd
,
retrieved
)
}
}
func
TestData_ComparisonFunc
(
t
*
testing
.
T
)
{
func
TestData_ComparisonFunc
(
t
*
testing
.
T
)
{
d
:=
NewData
()
d
:=
NewData
()
...
...
This diff is collapsed.
Click to expand it.
network/dataStructures/round_test.go
+
21
−
0
View file @
5b8f3a3a
...
@@ -32,6 +32,27 @@ func TestNewRound(t *testing.T) {
...
@@ -32,6 +32,27 @@ func TestNewRound(t *testing.T) {
}
}
// Smoke test for other constructor
func
TestNewVerifiedRound
(
t
*
testing
.
T
)
{
pubKey
,
_
:=
testutils
.
LoadPublicKeyTesting
(
t
)
ri
:=
&
mixmessages
.
RoundInfo
{
ID
:
uint64
(
1
),
UpdateID
:
uint64
(
1
)}
rnd
:=
NewVerifiedRound
(
ri
,
pubKey
)
// Check that values in object match inputted values
if
rnd
.
info
!=
ri
||
rnd
.
pubkey
!=
pubKey
||
*
rnd
.
needsValidation
!=
1
{
t
.
Errorf
(
"Initial round values from constructor are not expected."
+
"
\n\t
Expected round info: %v"
+
"
\n\t
Received round info: %v"
+
"
\n\t
Expected public key: %v"
+
"
\n\t
Received public key: %v"
+
"
\n\t
Expected needsValidation: %v"
+
"
\n\t
Received needsValidation: %v"
,
ri
,
rnd
.
info
,
pubKey
,
rnd
.
pubkey
,
rnd
.
needsValidation
,
1
)
}
}
// Unit test of Get()
// Unit test of Get()
func
TestNewRound_Get
(
t
*
testing
.
T
)
{
func
TestNewRound_Get
(
t
*
testing
.
T
)
{
pubKey
,
_
:=
testutils
.
LoadPublicKeyTesting
(
t
)
pubKey
,
_
:=
testutils
.
LoadPublicKeyTesting
(
t
)
...
...
This diff is collapsed.
Click to expand it.
network/instance_test.go
+
29
−
0
View file @
5b8f3a3a
...
@@ -171,6 +171,35 @@ func TestInstance_GetRound(t *testing.T) {
...
@@ -171,6 +171,35 @@ func TestInstance_GetRound(t *testing.T) {
}
}
}
}
func
TestInstance_GetWrappedRound
(
t
*
testing
.
T
)
{
i
:=
Instance
{
roundData
:
ds
.
NewData
(),
}
// Construct a mock round object
ri
:=
&
mixmessages
.
RoundInfo
{
ID
:
uint64
(
1
)}
testutils
.
SignRoundInfo
(
ri
,
t
)
pubKey
,
err
:=
testutils
.
LoadPublicKeyTesting
(
t
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to load public key: %v"
,
err
)
t
.
FailNow
()
}
rnd
:=
ds
.
NewRound
(
ri
,
pubKey
)
_
=
i
.
roundData
.
UpsertRound
(
rnd
)
retrieved
,
err
:=
i
.
GetWrappedRound
(
id
.
Round
(
1
))
if
err
!=
nil
||
retrieved
==
nil
{
t
.
Errorf
(
"Failed to retrieve round: %+v"
,
err
)
}
if
!
reflect
.
DeepEqual
(
rnd
,
retrieved
)
{
t
.
Errorf
(
"Retrieved value did not match expected!"
+
"
\n\t
Expected: %v"
+
"
\n\t
Received: %v"
,
rnd
,
retrieved
)
}
}
func
TestInstance_GetRoundUpdate
(
t
*
testing
.
T
)
{
func
TestInstance_GetRoundUpdate
(
t
*
testing
.
T
)
{
i
:=
Instance
{
i
:=
Instance
{
roundUpdates
:
ds
.
NewUpdates
(),
roundUpdates
:
ds
.
NewUpdates
(),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment