Beispiel #1
0
    def test_basic(self):
        model = MockModel()
        ewctrl = EWalletController(model, None)
        config = {"offer_expiry_interval": 30, "ep_expiry_interval": 30}
        comm = MockComm()
        agent = EAgent(ewctrl, config, comm)

        # At this point the agent should not have an active proposal
        self.assertFalse(agent.has_active_ep())
        # no messages should have been sent to the network
        self.assertEqual(len(comm.get_messages()), 0)

        color_spec = "obc:03524a4d6492e8d43cb6f3906a99be5a1bcd93916241f759812828b301f25a6c:0:153267"

        cv0 = {'color_spec': "", 'value': 100}
        cv1 = {'color_spec': color_spec, 'value': 200}

        my_offer = MyEOffer(None, cv0, cv1)

        their_offer = EOffer('abcdef', cv1, cv0)

        agent.register_my_offer(my_offer)
        agent.register_their_offer(their_offer)
        agent.update()

        # Agent should have an active exchange proposal
        self.assertTrue(agent.has_active_ep())
        # Exchange proposal should have been sent over comm
        # it should be the only message, as we should not resend our offer
        # if their is an active proposal to match it
        self.assertTrue(len(comm.get_messages()), 1)
        [proposal] = comm.get_messages()
        # The offer data should be in the proposal
        their_offer_data = their_offer.get_data()
        self.assertEquals(their_offer_data, proposal["offer"])
 def test_get_data_etx_data(self):
   ewctrl = MockEWalletController()
   a = EOffer(1, "A", "B")
   b = EOffer(1, "B", "A")
   src = MyEProposal(ewctrl, a, b)
   src.etx_data = "etx_data"
   result = src.get_data()
   expected = {'pid':src.pid, 'offer':a.get_data(), 'etx_data': "etx_data"}
   self.assertEqual(result, expected)
   self.assertEqual(result.get('etx_spec'), None)
 def test_get_data_etx_data(self):
     ewctrl = MockEWalletController()
     a = EOffer(1, "A", "B")
     b = EOffer(1, "B", "A")
     src = MyEProposal(ewctrl, a, b)
     src.etx_data = "etx_data"
     result = src.get_data()
     expected = {
         'pid': src.pid,
         'offer': a.get_data(),
         'etx_data': "etx_data"
     }
     self.assertEqual(result, expected)
     self.assertEqual(result.get('etx_spec'), None)
Beispiel #4
0
    def test_basic(self):
        model = MockModel()
        ewctrl = EWalletController(model, None)
        config = {"offer_expiry_interval": 30,
                  "ep_expiry_interval": 30}
        comm = MockComm()
        agent = EAgent(ewctrl, config, comm)

        # At this point the agent should not have an active proposal
        self.assertFalse(agent.has_active_ep())
        # no messages should have been sent to the network
        self.assertEqual(len(comm.get_messages()), 0)

        color_spec = "obc:03524a4d6492e8d43cb6f3906a99be5a1bcd93916241f759812828b301f25a6c:0:153267"

        cv0 = { 'color_spec' : "", 'value' : 100 }
        cv1 = { 'color_spec' : color_spec, 'value' : 200 }

        my_offer = MyEOffer(None, cv0, cv1)

        their_offer = EOffer('abcdef', cv1, cv0)

        agent.register_my_offer(my_offer)
        agent.register_their_offer(their_offer)
        agent.update()

        # Agent should have an active exchange proposal
        self.assertTrue(agent.has_active_ep())
        # Exchange proposal should have been sent over comm
        # it should be the only message, as we should not resend our offer
        # if their is an active proposal to match it
        self.assertTrue(len(comm.get_messages()), 1)
        [proposal] = comm.get_messages()
        # The offer data should be in the proposal
        their_offer_data = their_offer.get_data()
        self.assertEquals(their_offer_data, proposal["offer"])
 def test_unexpired(self):
   eo = EOffer(0, None, None)
   eo.refresh(42)
   self.assertFalse(eo.expired())
 def test_matches_ignores_id(self):
     eo = EOffer(1, "A", "B")
     self.assertTrue(eo.matches(EOffer(2, "B", "A")))
 def test_matches_equality_table(self):
     eo = EOffer(1, "A", "B")
     self.assertTrue(eo.matches(EOffer(1, "B", "A")))
     self.assertFalse(eo.matches(EOffer(1, "B", "X")))
     self.assertFalse(eo.matches(EOffer(1, "X", "A")))
     self.assertFalse(eo.matches(EOffer(1, "X", "X")))
 def test_convert_to_data(self):
     src = EOffer(1, "A", "B")
     result = src.get_data()
     expected = {'oid': 1, 'A': "A", 'B': "B"}
     self.assertEqual(result, expected)
 def test_is_same_ignores_expired(self):
     eo = EOffer(1, "A", "B")
     x = EOffer(1, "A", "B")
     x.refresh(42)
     self.assertTrue(eo.is_same_as_mine(x))
 def test_expired(self):
     eo = EOffer(0, None, None)
     eo.refresh(-1)
     self.assertTrue(eo.expired())
 def test_unexpired_shift(self):
     eo = EOffer(0, None, None)
     eo.refresh(0)
     self.assertTrue(eo.expired_shift(42))
     self.assertFalse(eo.expired_shift(-42))
Beispiel #12
0
 def test_is_same_equality_table(self):
   eo = EOffer(1, "A", "B")
   self.assertTrue(eo.is_same_as_mine(EOffer(1, "A", "B")))
   self.assertFalse(eo.is_same_as_mine(EOffer(1, "X", "B")))
   self.assertFalse(eo.is_same_as_mine(EOffer(1, "A", "X")))
   self.assertFalse(eo.is_same_as_mine(EOffer(1, "X", "X")))
Beispiel #13
0
 def test_matches_ignores_id(self):
   eo = EOffer(1, "A", "B")
   self.assertTrue(eo.matches(EOffer(2, "B", "A")))
Beispiel #14
0
 def test_is_same_ignores_id(self):
   eo = EOffer(1, "A", "B")
   self.assertTrue(eo.is_same_as_mine(EOffer(2, "A", "B")))
Beispiel #15
0
 def test_is_same_ignores_expired(self):
   eo = EOffer(1, "A", "B")
   x = EOffer(1, "A", "B")
   x.refresh(42)
   self.assertTrue(eo.is_same_as_mine(x))
Beispiel #16
0
 def test_convert_to_data(self):
   src = EOffer(1, "A", "B")
   result = src.get_data()
   expected = {'oid': 1, 'A':"A", 'B':"B"}
   self.assertEqual(result, expected)
Beispiel #17
0
 def test_convert_from_data(self):
   data = {'oid': 1, 'A':"A", 'B':"B"}
   result = EOffer.from_data(data)
   expected = EOffer(1, "A", "B")
   self.assertEqual(result, expected)
Beispiel #18
0
 def test_unexpired_shift(self):
   eo = EOffer(0, None, None)
   eo.refresh(0)
   self.assertTrue(eo.expired_shift(42))
   self.assertFalse(eo.expired_shift(-42))
 def test_random_default_id(self):
     a = EOffer(0, None, None)
     b = EOffer(1, None, None)
     self.assertNotEqual(a.oid, 0)
     self.assertEqual(b.oid, 1)
Beispiel #20
0
 def test_matches_ignores_expired(self):
   eo = EOffer(1, "A", "B")
   x = EOffer(1, "B", "A")
   x.refresh(42)
   self.assertTrue(eo.matches(x))
 def test_unrefreshed_expired(self):
     eo = EOffer(0, None, None)
     self.assertTrue(eo.expired())
Beispiel #22
0
 def test_matches_equality_table(self):
   eo = EOffer(1, "A", "B")
   self.assertTrue(eo.matches(EOffer(1, "B", "A")))
   self.assertFalse(eo.matches(EOffer(1, "B", "X")))
   self.assertFalse(eo.matches(EOffer(1, "X", "A")))
   self.assertFalse(eo.matches(EOffer(1, "X", "X")))
 def test_unexpired(self):
     eo = EOffer(0, None, None)
     eo.refresh(42)
     self.assertFalse(eo.expired())
 def test_compatibility(self):
     meo = MyEOffer(1, "A", "B")
     eo = EOffer(1, "A", "B")
     self.assertTrue(meo.is_same_as_mine(eo))
 def test_convert_from_data(self):
     data = {'oid': 1, 'A': "A", 'B': "B"}
     result = EOffer.from_data(data)
     expected = EOffer(1, "A", "B")
     self.assertEqual(result, expected)
 def test_convert_to_data(self):
     eo = EOffer(1, "A", "B")
     src = EProposal("pid", "ewctrl", eo)
     result = src.get_data()
     expected = {'pid': "pid", 'offer': eo.get_data()}
     self.assertEqual(result, expected)
 def test_is_same_ignores_id(self):
     eo = EOffer(1, "A", "B")
     self.assertTrue(eo.is_same_as_mine(EOffer(2, "A", "B")))
Beispiel #28
0
 def test_convert_to_data(self):
   eo = EOffer(1, "A", "B")
   src = EProposal("pid", "ewctrl", eo)
   result = src.get_data()
   expected = {'pid':"pid", 'offer':eo.get_data()}
   self.assertEqual(result, expected)
 def test_is_same_equality_table(self):
     eo = EOffer(1, "A", "B")
     self.assertTrue(eo.is_same_as_mine(EOffer(1, "A", "B")))
     self.assertFalse(eo.is_same_as_mine(EOffer(1, "X", "B")))
     self.assertFalse(eo.is_same_as_mine(EOffer(1, "A", "X")))
     self.assertFalse(eo.is_same_as_mine(EOffer(1, "X", "X")))
 def test_unmatching_offers(self):
     ewctrl = MockEWalletController()
     a = EOffer(1, "A", "B")
     b = EOffer(2, "X", "Y")
     self.assertRaises(Exception, MyEProposal, ewctrl, a, b)
 def test_matches_ignores_expired(self):
     eo = EOffer(1, "A", "B")
     x = EOffer(1, "B", "A")
     x.refresh(42)
     self.assertTrue(eo.matches(x))
Beispiel #32
0
 def test_unrefreshed_expired(self):
   eo = EOffer(0, None, None)
   self.assertTrue(eo.expired())
 def test_construction(self):
     ewctrl = MockEWalletController()
     a = EOffer(1, "A", "B")
     b = EOffer(1, "B", "A")
     mep = MyEProposal(ewctrl, a, b)
     self.assertEqual(mep.my_offer, b)
Beispiel #34
0
 def test_expired(self):
   eo = EOffer(0, None, None)
   eo.refresh(-1)
   self.assertTrue(eo.expired())