Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
client
Commits
fd77e190
Commit
fd77e190
authored
2 years ago
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for checking store/load Identity.ProcessNext
parent
36530a48
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!510
Release
,
!433
Add tests for checking store/load Identity.ProcessNext
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cmix/identity/receptionID/identity_test.go
+107
-0
107 additions, 0 deletions
cmix/identity/receptionID/identity_test.go
with
107 additions
and
0 deletions
cmix/identity/receptionID/identity_test.go
+
107
−
0
View file @
fd77e190
...
...
@@ -14,6 +14,7 @@ import (
"gitlab.com/xx_network/primitives/id/ephemeral"
"gitlab.com/xx_network/primitives/netTime"
"math/rand"
"reflect"
"testing"
"time"
)
...
...
@@ -109,3 +110,109 @@ func TestIdentity_Equal(t *testing.T) {
"
\n
a: %s
\n
c: %s"
,
a
,
c
)
}
}
// TestIdentity_store_loadProcessNext tests that when an Identity is stored,
// Identity.ProcessNext is loaded. This test is exhaustive by making a reasonably
// long Identity.ProcessNext linked list, and checking if all Identity's are loaded.
func
TestIdentity_store_loadProcessNext
(
t
*
testing
.
T
)
{
kv
:=
versioned
.
NewKV
(
ekv
.
MakeMemstore
())
const
numTests
=
10
// Construct the first identity, which will be stored
ephId
:=
ephemeral
.
Id
{}
copy
(
ephId
[
:
],
[]
byte
{
0
})
first
:=
&
Identity
{
EphemeralIdentity
:
EphemeralIdentity
{
EphId
:
ephId
,
Source
:
&
id
.
Permissioning
,
},
AddressSize
:
0
,
End
:
netTime
.
Now
()
.
Round
(
0
),
ExtraChecks
:
0
,
StartValid
:
netTime
.
Now
()
.
Round
(
0
),
EndValid
:
netTime
.
Now
()
.
Round
(
0
),
Ephemeral
:
false
,
}
// Build the linked list with unique identities. Use temp as a temporary
// head, such that the previous node in the linked list can have its next
// set with the next identity, and then set temp to the next identity for
// the next iteration
temp
:=
first
for
i
:=
1
;
i
<
numTests
;
i
++
{
// Ensure uniqueness of every identity by having the ephemeral ID
// contain the number of the iteration (ie the value of i)
ephId
=
ephemeral
.
Id
{}
copy
(
ephId
[
:
],
[]
byte
{
byte
(
i
)})
next
:=
&
Identity
{
EphemeralIdentity
:
EphemeralIdentity
{
EphId
:
ephId
,
Source
:
&
id
.
Permissioning
,
},
AddressSize
:
25
,
End
:
netTime
.
Now
()
.
Round
(
0
),
ExtraChecks
:
16
,
StartValid
:
netTime
.
Now
()
.
Round
(
0
),
EndValid
:
netTime
.
Now
()
.
Round
(
0
),
Ephemeral
:
false
,
}
temp
.
ProcessNext
=
next
temp
=
next
}
// Save the first identity. This should be the head of
// the created linked list, and thus all nodes (Identity's) should be saved.
err
:=
first
.
store
(
kv
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to store: %s"
,
err
)
}
// Load the identity
loadedIdentity
,
err
:=
loadIdentity
(
kv
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to load: %+v"
,
err
)
}
// Smoke test: Check that there is a next element in the linked list
if
loadedIdentity
.
ProcessNext
==
nil
{
t
.
Fatalf
(
"Failed to load processNext for identity!"
)
}
// Serialize the linked list, such that we can iterate over
// it to check for expected values later
temp
=
&
loadedIdentity
serializedList
:=
make
([]
*
Identity
,
0
)
for
temp
!=
nil
{
serializedList
=
append
(
serializedList
,
temp
)
temp
=
temp
.
ProcessNext
}
// Smoke test: Check that the number of loaded identities is of the
// expected quantity
if
len
(
serializedList
)
!=
numTests
{
t
.
Fatalf
(
"Bad number of identities from Identity.ProcessNext."
+
"
\n
Expected: %d"
+
"
\n
Received: %d"
,
numTests
,
len
(
serializedList
))
}
// Go through every identity to make sure it has the expected value
for
i
:=
0
;
i
<
len
(
serializedList
);
i
++
{
// The loaded identity should have an ephemeral ID
// contain the number of the iteration (ie the value of i)
ephId
=
ephemeral
.
Id
{}
copy
(
ephId
[
:
],
[]
byte
{
byte
(
i
)})
received
:=
serializedList
[
i
]
if
!
reflect
.
DeepEqual
(
ephId
,
received
.
EphId
)
{
t
.
Errorf
(
"Identity #%d loaded is not expected."
+
"
\n
Expected: %+v"
+
"
\n
Received: %+v"
,
i
,
ephId
,
received
.
EphId
)
}
}
}
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