cwtch_peer_test.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package peer
  2. import (
  3. "testing"
  4. )
  5. // TODO: Rewrite these tests (and others) using the news event bus interface.
  6. func TestCwtchPeerGenerate(t *testing.T) {
  7. /**
  8. alice := NewCwtchPeer("alice")
  9. groupID, _, _ := alice.StartGroup("test.server")
  10. exportedGroup, _ := alice.ExportGroup(groupID)
  11. t.Logf("Exported Group: %v from %v", exportedGroup, alice.GetProfile().Onion)
  12. importedGroupID, err := alice.ImportGroup(exportedGroup)
  13. group := alice.GetGroup(importedGroupID)
  14. t.Logf("Imported Group: %v, err := %v %v", group, err, importedGroupID)
  15. */
  16. }
  17. func TestTrustPeer(t *testing.T) {
  18. /**
  19. groupName := "2c3kmoobnyghj2zw6pwv7d57yzld753auo3ugauezzpvfak3ahc4bdyd"
  20. alice := NewCwtchPeer("alice")
  21. aem := new(event.Manager)
  22. aem.Initialize()
  23. alice.Init(connectivity.LocalProvider(),aem)
  24. defer alice.Shutdown()
  25. bob := NewCwtchPeer("bob")
  26. bem := new(event.Manager)
  27. bem.Initialize()
  28. bob.Init(connectivity.LocalProvider(), bem)
  29. defer bob.Shutdown()
  30. bobOnion := bob.GetProfile().Onion
  31. aliceOnion := alice.GetProfile().Onion
  32. groupID, _, err := alice.StartGroup(groupName)
  33. if err != nil {
  34. t.Error(err)
  35. }
  36. groupAlice := alice.GetGroup(groupID)
  37. if groupAlice.GroupID != groupID {
  38. t.Errorf("Alice should be part of group %v, got %v instead", groupID, groupAlice)
  39. }
  40. exportedGroup, err := alice.ExportGroup(groupID)
  41. if err != nil {
  42. t.Error(err)
  43. }
  44. err = alice.InviteOnionToGroup(bobOnion, groupID)
  45. if err == nil {
  46. t.Errorf("onion invitation should fail since alice does no trust bob")
  47. }
  48. err = alice.TrustPeer(bobOnion)
  49. if err == nil {
  50. t.Errorf("trust peer should fail since alice does not know about bob")
  51. }
  52. // bob adds alice contact by importing serialized group created by alice
  53. _, err = bob.ImportGroup(exportedGroup)
  54. if err != nil {
  55. t.Error(err)
  56. }
  57. err = bob.TrustPeer(aliceOnion)
  58. if err != nil {
  59. t.Errorf("bob must be able to trust alice, got %v", err)
  60. }
  61. err = bob.InviteOnionToGroup(aliceOnion, groupID)
  62. if err == nil {
  63. t.Errorf("bob trusts alice but peer connection is not ready yet. should not be able to invite her to group, instead got: %v", err)
  64. }
  65. */
  66. }