Skip to content
Snippets Groups Projects
Select Git revision
  • afaee6e99a4a7738ec77eb83f756b30b9972e5ae
  • release default protected
  • master protected
  • hotfix/GrpcParameters
  • XX-4441
  • tls-websockets
  • hotfix/allow-web-creds
  • hotfix/nilCert
  • XX-3566_const_time_token_compare
  • AceVentura/AccountBackup
  • dev
  • waitingRoundsRewrite
  • fullRateLimit
  • XX-3564/TlsCipherSuite
  • XX-3563/DisableTlsCheck
  • notls
  • url-repo-rename
  • perftuning
  • Anne/CI2
  • AddedGossipLogging
  • hotfix/connectionReduction
  • v0.0.6
  • v0.0.4
  • v0.0.5
  • v0.0.3
  • v0.0.2
  • v0.0.1
27 results

metrics.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)
    	}
    }