diff --git a/network/dataStructures/roundData_test.go b/network/dataStructures/roundData_test.go index 948080394966e7e5285d38c093f1e6441bc26ef4..faeaa7f0548957919a7e692474a6e1f7e2ba17f9 100644 --- a/network/dataStructures/roundData_test.go +++ b/network/dataStructures/roundData_test.go @@ -10,6 +10,7 @@ package dataStructures import ( "gitlab.com/elixxir/comms/mixmessages" "gitlab.com/elixxir/comms/testutils" + "reflect" "testing" ) @@ -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) { d := NewData() diff --git a/network/dataStructures/round_test.go b/network/dataStructures/round_test.go index 0fcf6802db954dbbfb9e879cc301d77dcd2f81fd..f251c26759eff4239a3ec7a363dbdded0fdbb207 100644 --- a/network/dataStructures/round_test.go +++ b/network/dataStructures/round_test.go @@ -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() func TestNewRound_Get(t *testing.T) { pubKey, _ := testutils.LoadPublicKeyTesting(t) diff --git a/network/instance_test.go b/network/instance_test.go index 8840bfcd89b57b5f69b7cc96b29661b6a599a913..845f205d34678017f554ae67197e6ca6f59b29c0 100644 --- a/network/instance_test.go +++ b/network/instance_test.go @@ -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) { i := Instance{ roundUpdates: ds.NewUpdates(),