Skip to content
Snippets Groups Projects
Select Git revision
  • b35c5f632b801efce7486aea534cb600059eb478
  • 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

addFact_test.go

Blame
  • addFact_test.go 1.73 KiB
    package ud
    
    import (
    	jww "github.com/spf13/jwalterweatherman"
    	"gitlab.com/elixxir/comms/client"
    	pb "gitlab.com/elixxir/comms/mixmessages"
    	"gitlab.com/elixxir/primitives/fact"
    	"gitlab.com/xx_network/comms/connect"
    	"gitlab.com/xx_network/crypto/csprng"
    	"gitlab.com/xx_network/crypto/signature/rsa"
    	"gitlab.com/xx_network/primitives/id"
    	"os"
    	"testing"
    )
    
    func TestMain(m *testing.M) {
    	jww.SetStdoutThreshold(jww.LevelTrace)
    	connect.TestingOnlyDisableTLS = true
    	os.Exit(m.Run())
    }
    
    type testAFC struct{}
    
    // Dummy implementation of SendRegisterFact so that we don't need to run our own
    // UDB server.
    func (rFC *testAFC) SendRegisterFact(*connect.Host, *pb.FactRegisterRequest) (
    	*pb.FactRegisterResponse, error) {
    	return &pb.FactRegisterResponse{}, nil
    }
    
    // Test that the addFact function completes successfully
    func TestAddFact(t *testing.T) {
    	isReg := uint32(1)
    
    	// Create a new Private Key to use for signing the Fact
    	rng := csprng.NewSystemRNG()
    	cpk, err := rsa.GenerateKey(rng, 2048)
    	if err != nil {
    		t.Fatal(err)
    	}
    
    	comms, err := client.NewClientComms(nil, nil, nil, nil)
    	if err != nil {
    		t.Errorf("Failed to start client comms: %+v", err)
    	}
    
    	// Create our Manager object
    	m := Manager{
    		comms:      comms,
    		net:        newTestNetworkManager(t),
    		privKey:    cpk,
    		registered: &isReg,
    	}
    
    	// Create our test fact
    	USCountryCode := "US"
    	USNumber := "6502530000"
    	f := fact.Fact{
    		Fact: USNumber + USCountryCode,
    		T:    2,
    	}
    
    	// Set up a dummy comms that implements SendRegisterFact
    	// This way we don't need to run UDB just to check that this
    	// function works.
    	tAFC := testAFC{}
    	uid := &id.ID{}
    	// Run addFact and see if it returns without an error!
    	_, err = m.addFact(f, uid, &tAFC)
    	if err != nil {
    		t.Fatal(err)
    	}
    }