diff --git a/storage/cmix/key_test.go b/storage/cmix/key_test.go new file mode 100644 index 0000000000000000000000000000000000000000..2dac7c4c9c406286006129f7575d63eee545d812 --- /dev/null +++ b/storage/cmix/key_test.go @@ -0,0 +1,7 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright © 2020 Privategrity Corporation / +// / +// All rights reserved. / +//////////////////////////////////////////////////////////////////////////////// + +package cmix diff --git a/storage/cmix/store.go b/storage/cmix/store.go index 3ff308f25033883455870a5e40e4cc8bdea3c41e..9a3b4c96b71d4abd0ad5b5005a5d619338860d42 100644 --- a/storage/cmix/store.go +++ b/storage/cmix/store.go @@ -1,3 +1,9 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright © 2020 Privategrity Corporation / +// / +// All rights reserved. / +//////////////////////////////////////////////////////////////////////////////// + package cmix import ( @@ -39,7 +45,7 @@ func NewStore(grp *cyclic.Group, kv *versioned.KV, priv *cyclic.Int) (*Store, er s := &Store{ nodes: make(map[id.ID]*key), dhPrivateKey: priv, - dhPublicKey: priv, + dhPublicKey: pub, grp: grp, kv: kv, } @@ -188,7 +194,7 @@ func (s *Store) marshal() ([]byte, error) { nodes := make([]id.ID, len(s.nodes)) index := 0 - for nid, _ := range s.nodes { + for nid := range s.nodes { nodes[index] = nid } @@ -231,4 +237,4 @@ func (s *Store) unmarshal(b []byte) error { } return nil -} \ No newline at end of file +} diff --git a/storage/cmix/store_test.go b/storage/cmix/store_test.go new file mode 100644 index 0000000000000000000000000000000000000000..e630e049235fdb6eb481f59f324b4f9550ac601b --- /dev/null +++ b/storage/cmix/store_test.go @@ -0,0 +1,48 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright © 2020 Privategrity Corporation / +// / +// All rights reserved. / +//////////////////////////////////////////////////////////////////////////////// + +package cmix + +import ( + "gitlab.com/elixxir/client/storage/versioned" + "gitlab.com/elixxir/crypto/cyclic" + "gitlab.com/elixxir/crypto/diffieHellman" + "gitlab.com/elixxir/crypto/large" + "gitlab.com/elixxir/ekv" + "testing" +) + +// Happy path +func TestNewStore(t *testing.T) { + kv := make(ekv.Memstore) + vkv := versioned.NewKV(kv) + + grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(2)) + priv := grp.NewInt(2) + pub := diffieHellman.GeneratePublicKey(priv, grp) + + store, err := NewStore(grp, vkv, priv) + if err != nil { + t.Errorf(err.Error()) + return + } + + if store.nodes == nil { + t.Errorf("Failed to initialize nodes") + } + if store.dhPrivateKey == nil || store.dhPrivateKey.Cmp(priv) != 0 { + t.Errorf("Failed to set store.dhPrivateKey correctly") + } + if store.dhPublicKey == nil || store.dhPublicKey.Cmp(pub) != 0 { + t.Errorf("Failed to set store.dhPublicKey correctly") + } + if store.grp == nil { + t.Errorf("Failed to set store.grp") + } + if store.kv == nil { + t.Errorf("Failed to set store.kv") + } +}