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_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_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_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_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)