From c213df42e3d9580760a43cd796cb53f5a7473578 Mon Sep 17 00:00:00 2001
From: Sydney Anne Erickson <sydney@elixxir.io>
Date: Wed, 18 Nov 2020 11:53:23 -0800
Subject: [PATCH] Comments and fix TestAddFact

---
 ud/addFact.go      |  2 +-
 ud/addFact_test.go | 34 +++++++++++++++++++---------------
 2 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/ud/addFact.go b/ud/addFact.go
index 70bf0f4d5..28bf676b2 100644
--- a/ud/addFact.go
+++ b/ud/addFact.go
@@ -25,11 +25,11 @@ func (m *Manager) addFact(fact fact.Fact, aFC addFactComms) (*pb.FactRegisterRes
 		FactType: uint32(fact.T),
 	}
 
+	// Sign our fact for putting into the request
 	fsig, err := rsa.Sign(rand.Reader, m.privKey, hash.CMixHash, mmFact.Digest(), nil)
 	if err != nil {
 		return &pb.FactRegisterResponse{}, err
 	}
-	//signature.Sign(mmFact, m.privKey)
 
 	// Create our Fact Removal Request message data
 	remFactMsg := pb.FactRegisterRequest{
diff --git a/ud/addFact_test.go b/ud/addFact_test.go
index 8284215b5..dd9269c34 100644
--- a/ud/addFact_test.go
+++ b/ud/addFact_test.go
@@ -1,55 +1,59 @@
 package ud
 
 import (
-"gitlab.com/elixxir/client/interfaces/contact"
-"gitlab.com/elixxir/comms/client"
 	pb "gitlab.com/elixxir/comms/mixmessages"
-"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"
-"testing"
+	"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"
+	"testing"
 )
 
 type testAFC struct{}
 
+// Dummy implementation of SendRegisterFact so we don't need
+// to run our own UDB server
 func (rFC *testAFC) SendRegisterFact(host *connect.Host, message *pb.FactRegisterRequest) (*pb.FactRegisterResponse, error) {
 	return &pb.FactRegisterResponse{}, nil
 }
 
+// Test that the addFact function completes successfully
 func TestAddFact(t *testing.T) {
-	c, err := client.NewClientComms(&id.DummyUser, nil, nil, nil)
-	if err != nil {
-		t.Fatal(err)
-	}
-
+	// Add our host, addFact uses it to get the ID of the user
 	h, err := connect.NewHost(&id.DummyUser, "address", nil, connect.GetDefaultHostParams())
 	if err != nil {
 		t.Fatal(err)
 	}
 
+	// 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)
 	}
 
+	// Create our Manager object
 	m := Manager{
-		comms:   c,
+		comms:   nil,
 		host:    h,
 		privKey: cpk,
 	}
 
-	f := contact.Fact{
+	// Create our test fact
+	f := fact.Fact{
 		Fact: "testing",
 		T:    2,
 	}
 
+	// Setup a dummy comms that implements SendRegisterFact
+	// This way we don't need to run UDB just to check that this
+	// function works.
 	tafc := testAFC{}
 
+	// Run addFact and see if it returns without an error!
 	_, err = m.addFact(f, &tafc)
 	if err != nil {
 		t.Fatal(err)
 	}
 }
-
-- 
GitLab