Skip to content
Snippets Groups Projects
Select Git revision
  • 19c02b66d55d4bf6a999c13522474930a29a2c72
  • release default protected
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • hotfix/TestHostPool_UpdateNdf_AddFilter
  • XX-4719/announcementChannels
  • xx-4717/logLevel
  • jonah/noob-channel
  • master protected
  • XX-4707/tagDiskJson
  • xx-4698/notification-retry
  • hotfix/notifylockup
  • syncNodes
  • hotfix/localCB
  • XX-4677/NewChanManagerMobile
  • XX-4689/DmSync
  • duplicatePrefix
  • XX-4601/HavenInvites
  • finalizedUICallbacks
  • XX-4673/AdminKeySync
  • debugNotifID
  • anne/test
  • v4.7.5
  • v4.7.4
  • v4.7.3
  • v4.7.2
  • v4.7.1
  • v4.6.3
  • v4.6.1
  • v4.5.0
  • v4.4.4
  • v4.3.11
  • v4.3.8
  • v4.3.7
  • v4.3.6
  • v4.3.5
  • v4.2.0
  • v4.3.0
  • v4.3.4
  • v4.3.3
  • v4.3.2
  • v4.3.1
41 results

transmitMessage.go

Blame
  • ndf_test.go 1.83 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"
    	"testing"
    )
    
    func setup() *Ndf {
    	msg := &mixmessages.NDF{
    		Ndf: testutils.ExampleNDF,
    	}
    	ndf := &Ndf{}
    
    	_ = ndf.Update(msg)
    	return ndf
    }
    
    func TestNdf_Get(t *testing.T) {
    	ndf := setup()
    
    	if ndf.Get() == nil {
    		t.Error("Should have returned ndf.f")
    	}
    }
    
    func TestNdf_Update(t *testing.T) {
    	msg := &mixmessages.NDF{
    		Ndf: testutils.ExampleNDF,
    	}
    	badMsg := &mixmessages.NDF{
    		Ndf: []byte("lasagna"),
    	}
    	ndf := Ndf{}
    
    	err := ndf.Update(badMsg)
    	if err == nil {
    		t.Error("Should have returned error when unable to decode ndf")
    	}
    
    	err = ndf.Update(msg)
    	if err != nil {
    		t.Errorf("Failed to update ndf: %+v", err)
    	}
    
    	if ndf.f == nil || ndf.hash == nil || ndf.pb == nil {
    		t.Error("Failed to properly set contents of ndf object")
    	}
    }
    
    func TestNdf_GetHash(t *testing.T) {
    	ndf := setup()
    
    	if ndf.GetHash() == nil {
    		t.Error("Hash not properly returned")
    	}
    }
    
    func TestNdf_GetPb(t *testing.T) {
    	ndf := setup()
    
    	if ndf.GetPb() == nil {
    		t.Error("Pb not properly set")
    	}
    }
    
    func TestNdf_CompareHash(t *testing.T) {
    	ndf := &Ndf{}
    
    	ndf = setup()
    	b := ndf.CompareHash(ndf.hash)
    	if !b {
    		t.Error("Should return true when hashes are the same")
    	}
    
    	b = ndf.CompareHash([]byte("test"))
    	if b {
    		t.Error("Should return false when hashes are different")
    	}
    }