Skip to content
Snippets Groups Projects
Commit 5b8f3a3a authored by Josh Brooks's avatar Josh Brooks
Browse files

Add tests for new functionality

parent 36e23d01
Branches
Tags
1 merge request!58Revert "Modify waiting lock"
...@@ -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\tExpected: %v"+
"\n\tReceived: %v", rnd, retrieved)
}
}
func TestData_ComparisonFunc(t *testing.T) { func TestData_ComparisonFunc(t *testing.T) {
d := NewData() d := NewData()
......
...@@ -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\tExpected round info: %v"+
"\n\tReceived round info: %v"+
"\n\tExpected public key: %v"+
"\n\tReceived public key: %v"+
"\n\tExpected needsValidation: %v"+
"\n\tReceived 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)
......
...@@ -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\tExpected: %v"+
"\n\tReceived: %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(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment