diff --git a/ud/addFact.go b/ud/addFact.go index 1d7372eac09958a9ae24486188fd9dcb0436736f..32c9ad650890ac81f21d5e7f0589a903e067917e 100644 --- a/ud/addFact.go +++ b/ud/addFact.go @@ -2,6 +2,7 @@ package ud import ( "crypto/rand" + "github.com/pkg/errors" pb "gitlab.com/elixxir/comms/mixmessages" "gitlab.com/elixxir/crypto/factID" "gitlab.com/elixxir/crypto/hash" @@ -19,6 +20,11 @@ func (m *Manager) SendRegisterFact(fact fact.Fact) (*pb.FactRegisterResponse, er } func (m *Manager) addFact(inFact fact.Fact, aFC addFactComms) (*pb.FactRegisterResponse, error) { + if !m.IsRegistered(){ + return nil, errors.New("Failed to add fact: " + + "client is not registered") + } + // Create a primitives Fact so we can hash it f, err := fact.NewFact(inFact.T, inFact.Fact) if err != nil { diff --git a/ud/addFact_test.go b/ud/addFact_test.go index 312591a6fe7f686a4dc8d43cd755ce40fb255cdd..22f2fd09a79b2234d808a8093ffcac9170b5a3c6 100644 --- a/ud/addFact_test.go +++ b/ud/addFact_test.go @@ -20,6 +20,7 @@ func (rFC *testAFC) SendRegisterFact(host *connect.Host, message *pb.FactRegiste // Test that the addFact function completes successfully func TestAddFact(t *testing.T) { + isReg := uint32(1) // 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 { @@ -37,6 +38,7 @@ func TestAddFact(t *testing.T) { m := Manager{ host: h, privKey: cpk, + registered:&isReg, } // Create our test fact