Skip to content
Snippets Groups Projects
Commit 3d0720e3 authored by Tigran Avakyan's avatar Tigran Avakyan
Browse files

Made changes to pass in group as JSON

parent 77f8112b
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,7 @@ import (
"gitlab.com/elixxir/client/user"
"gitlab.com/elixxir/crypto/certs"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/large"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/elixxir/primitives/id"
"gitlab.com/elixxir/primitives/switchboard"
......@@ -146,12 +147,19 @@ func InitClient(storage Storage, loc string) error {
// “Jono”
// OIF3OJ5I
func Register(registrationCode string, gwAddr string, numNodes int,
mint bool, grp *cyclic.Group) ([]byte, error) {
mint bool, grpJSON string) ([]byte, error) {
if numNodes < 1 {
return id.ZeroID[:], errors.New("invalid number of nodes")
}
// Unmarshal group JSON
grp := cyclic.NewGroup(large.NewMaxInt(), large.NewMaxInt(), large.NewMaxInt())
err := grp.UnmarshalJSON([]byte(grpJSON))
if err != nil {
return id.ZeroID[:], err
}
UID, err := api.Register(registrationCode, gwAddr, uint(numNodes), mint, grp)
if err != nil {
......
......@@ -147,8 +147,12 @@ func TestRegister(t *testing.T) {
g := large.NewInt(2)
q := large.NewInt(3)
grp := cyclic.NewGroup(p, g, q)
grpJSON, err := grp.MarshalJSON()
if err != nil {
t.Errorf("Failed to marshal group JSON: %s", err)
}
regRes, err := Register(registrationCode, gwAddress, 1, false, grp)
regRes, err := Register(registrationCode, gwAddress, 1, false, string(grpJSON))
if err != nil {
t.Errorf("Registration failed: %s", err.Error())
}
......@@ -170,8 +174,12 @@ func TestRegisterBadNumNodes(t *testing.T) {
g := large.NewInt(int64(2))
q := large.NewInt(int64(3))
grp := cyclic.NewGroup(p, g, q)
grpJSON, err := grp.MarshalJSON()
if err != nil {
t.Errorf("Failed to marshal group JSON: %s", err)
}
_, err = Register(registrationCode, gwAddress, 0, false, grp)
_, err = Register(registrationCode, gwAddress, 0, false, string(grpJSON))
if err == nil {
t.Errorf("Registration worked with bad numnodes! %s", err.Error())
}
......@@ -202,8 +210,12 @@ func TestLoginLogout(t *testing.T) {
g := large.NewInt(2)
q := large.NewInt(3)
grp := cyclic.NewGroup(p, g, q)
grpJSON, err := grp.MarshalJSON()
if err != nil {
t.Errorf("Failed to marshal group JSON: %s", err)
}
regRes, err := Register(registrationCode, gwAddress, 1, false, grp)
regRes, err := Register(registrationCode, gwAddress, 1, false, string(grpJSON))
loginRes, err2 := Login(regRes, gwAddress, "")
if err2 != nil {
t.Errorf("Login failed: %s", err.Error())
......@@ -216,6 +228,7 @@ func TestLoginLogout(t *testing.T) {
if err3 != nil {
t.Errorf("Logoutfailed: %s", err.Error())
}
globals.LocalStorage = nil
}
......
......@@ -22,7 +22,6 @@ import (
"gitlab.com/elixxir/client/parse"
"gitlab.com/elixxir/client/user"
"gitlab.com/elixxir/comms/connect"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/elixxir/primitives/id"
"gitlab.com/elixxir/primitives/switchboard"
......@@ -122,16 +121,10 @@ func sessionInitialization() {
// FIXME Use a different encoding for the user ID command line argument,
// to allow testing with IDs that are long enough to exercise more than
// 64 bits
grp := cyclic.Group{}
grpBuff := []byte(viper.GetString("group"))
err := grp.UnmarshalJSON(grpBuff)
if err != nil {
fmt.Printf("Could Not Decode group from JSON: %s\n", err.Error())
return
}
grpJSON := viper.GetString("group")
regCode := new(id.User).SetUints(&[4]uint64{0, 0, 0, userId}).RegistrationCode()
_, err = bindings.Register(regCode, gwAddr, int(numNodes), mint, &grp)
_, err = bindings.Register(regCode, gwAddr, int(numNodes), mint, grpJSON)
if err != nil {
fmt.Printf("Could Not Register User: %s\n", err.Error())
return
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment