Skip to content
Snippets Groups Projects
Select Git revision
  • f4e22b7d1fed61b0bbfd20fa7c0de5763107c934
  • release default protected
  • master protected
  • NationalTreasure/NotificationUpgrade
  • XX-4441
  • xx-4417/gw-poll-earliest-client-round
  • tls-websockets
  • hotfix/drain
  • hotfix/matcher
  • projects/crust_RELEASE
  • XX-4055/ChannelIdentityTracking
  • XX-4066/CrustUpgrade_MASTER
  • Ace/Huawei
  • hotfix/accumulate-notifs
  • XX-3564/TlsCipherSuite
  • hotfix/groupNotification
  • Anne/License-Update
  • hotfix/trustoldgatewaysonly
  • hotfix/notifications
  • notls
  • url-repo-rename
  • v0.0.4
  • v0.0.3
  • v0.0.2
  • v0.0.1
25 results

roundData_test.go

  • roundData_test.go 2.94 KiB
    ///////////////////////////////////////////////////////////////////////////////
    // Copyright © 2020 xx network SEZC                                          //
    //                                                                           //
    // Use of this source code is governed by a license that can be found in the //
    // LICENSE file                                                              //
    ///////////////////////////////////////////////////////////////////////////////
    
    package dataStructures
    
    import (
    	"gitlab.com/elixxir/comms/mixmessages"
    	"gitlab.com/elixxir/comms/testutils"
    	"reflect"
    	"testing"
    )
    
    func TestData_UpsertRound(t *testing.T) {
    	d := NewData()
    
    	// Construct a mock round object
    	ri := &mixmessages.RoundInfo{
    		ID:       0,
    		UpdateID: 0,
    	}
    
    	pubKey, err := testutils.LoadPublicKeyTesting(t)
    	if err != nil {
    		t.Errorf("Failed to load public key: %v", err)
    		t.FailNow()
    	}
    	rnd := NewRound(ri, pubKey, nil)
    	err = d.UpsertRound(rnd)
    	if err != nil {
    		t.Errorf("Failed to upsert round: %+v", err)
    	}
    }
    
    func TestData_GetRound(t *testing.T) {
    	d := NewData()
    
    	// Construct a mock round object
    	ri := &mixmessages.RoundInfo{
    		ID:       0,
    		UpdateID: 0,
    	}
    	testutils.SignRoundInfoRsa(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, nil)
    
    	_ = d.UpsertRound(rnd)
    	_, err = d.GetRound(0)
    	if err != nil {
    		t.Errorf("Failed to get roundinfo with proper id")
    	}
    }
    
    func TestData_GetWrappedRound(t *testing.T) {
    	d := NewData()
    
    	// Construct a mock round object
    	ri := &mixmessages.RoundInfo{
    		ID:       0,
    		UpdateID: 0,
    	}
    	testutils.SignRoundInfoRsa(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, nil)
    
    	_ = 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()
    
    	// Construct a mock round object
    	roundInfoOne := &mixmessages.RoundInfo{
    		ID:       2,
    		UpdateID: 3,
    	}
    	testutils.SignRoundInfoRsa(roundInfoOne, t)
    
    	pubKey, err := testutils.LoadPublicKeyTesting(t)
    	if err != nil {
    		t.Errorf("Failed to load public key: %v", err)
    		t.FailNow()
    	}
    	roundOne := NewRound(roundInfoOne, pubKey, nil)
    	_ = d.UpsertRound(roundOne)
    
    	// Construct a mock round object
    	roundInfoTwo := &mixmessages.RoundInfo{
    		ID:       2,
    		UpdateID: 4,
    	}
    	testutils.SignRoundInfoRsa(roundInfoTwo, t)
    
    	roundTwo := NewRound(roundInfoTwo, pubKey, nil)
    	_ = d.UpsertRound(roundTwo)
    	r, err := d.GetRound(2)
    	if err != nil {
    		t.Errorf("Failed to get round: %+v", err)
    	}
    	if r.UpdateID != 4 {
    		t.Error("Round did not properly upsert")
    	}
    }