Skip to content
Snippets Groups Projects
Select Git revision
  • 10b59333432de304c73a908d11cdbf7f0867a626
  • release default
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • master protected
  • XX-4688/DbEncoding
  • hotfix/update
  • @XX-4682/Files
  • hotfix/XX-4655
  • dev protected
  • project/HavenNotifications
  • XX-4602/SilentMessageType
  • jono/npmTest
  • wasmTest2
  • XX-4461/FileUpload
  • XX-4505/blockuser
  • XX-4441
  • Jakub/Emoji-CI-Test
  • testing/websockets
  • fastReg
  • fast-registration
  • NewHostPool
  • v0.3.22
  • v0.3.21
  • v0.3.20
  • v0.3.18
  • v0.3.17
  • v0.3.16
  • v0.3.15
  • v0.3.14
  • v0.3.13
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • 812b395df518ce096d01d5292596ca26f8fe92d9c4487ddfa515e190a51aa1a1
  • 76ba08e2dfa1798412a265404fa271840b52c035869111fce8e8cdb23a036a5a
41 results

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