Example #1
0
    def test_settleRollbackOutgoing(self):
        "Test settleRollbackOutgoing"

        self.assertRaises(
            Exception, self.payerLink.settleRollbackOutgoing,
            messages.SettleRollback(
                transactionID=self.payerLink.transactionID))

        self.payerLink.state = payerlink.PayerLink.states.locked

        ret = self.payerLink.settleRollbackOutgoing(
            messages.SettleRollback(
                transactionID=self.payerLink.transactionID))

        self.assertEqual(self.payerLink.state,
                         payerlink.PayerLink.states.cancelled)

        self.assertEqual(len(ret), 3)

        msg = ret[0]
        self.assertTrue(isinstance(msg, messages.FilterTimeouts))
        function = msg.function
        self.assertFalse(function(messages.PayerTimeout()))
        self.assertTrue(function(messages.NodeStateTimeout_Route()))
        msg = ret[1]
        self.assertTrue(isinstance(msg, messages.OutboundMessage))
        self.assertEqual(msg.localID, messages.payerLocalID)
        msg = msg.message
        self.assertTrue(isinstance(msg, messages.Cancel))
        msg = ret[2]
        self.assertTrue(isinstance(msg, messages.SetEvent))
        self.assertEqual(msg.event, messages.SetEvent.events.paymentFinished)
Example #2
0
    def test_msg_cancel(self):
        "Test msg_cancel"

        self.payerLink.transactionID = 'txID'

        for s in (payerlink.PayerLink.states.confirmed,
                  payerlink.PayerLink.states.hasPayerRoute):
            self.payerLink.state = s

            ret = self.payerLink.msg_cancel(None)

            self.assertEqual(self.payerLink.state,
                             payerlink.PayerLink.states.cancelled)

            self.assertEqual(len(ret), 3)
            msg = ret[0]
            self.assertTrue(isinstance(msg, messages.FilterTimeouts))
            function = msg.function
            self.assertFalse(function(messages.PayerTimeout()))
            self.assertTrue(function(messages.NodeStateTimeout_Route()))
            msg = ret[1]
            self.assertTrue(isinstance(msg, messages.CancelRoute))
            self.assertTrue(msg.transactionID, 'txID')
            self.assertTrue(msg.isPayerSide, True)
            msg = ret[2]
            self.assertTrue(isinstance(msg, messages.SetEvent))
            self.assertEqual(msg.event,
                             messages.SetEvent.events.paymentFinished)

        self.payerLink.state = payerlink.PayerLink.states.locked
        self.assertRaises(Exception, self.payerLink.msg_cancel, None)
        self.assertEqual(self.payerLink.state,
                         payerlink.PayerLink.states.locked)
Example #3
0
    def test_msg_timeout_initial(self):
        "Test msg_timeout (state: initial)"

        ret = self.payerLink.handleMessage(
            messages.PayerTimeout(state=payerlink.PayerLink.states.initial))

        self.assertEqual(self.payerLink.state,
                         payerlink.PayerLink.states.cancelled)

        self.assertEqual(len(ret), 2)

        msg = ret[0]
        self.assertTrue(isinstance(msg, messages.FilterTimeouts))
        function = msg.function
        self.assertFalse(function(messages.PayerTimeout()))
        self.assertTrue(function(messages.NodeStateTimeout_Route()))
        msg = ret[1]
        self.assertTrue(isinstance(msg, messages.SetEvent))
        self.assertEqual(msg.event, messages.SetEvent.events.receiptReceived)
Example #4
0
    def test_msg_confirm(self):
        "Test msg_confirm"
        self.assertRaises(Exception, self.payerLink.handleMessage,
                          messages.PayerLink_Confirm(agreement=True))

        self.payerLink.state = payerlink.PayerLink.states.hasReceipt

        ret = self.payerLink.handleMessage(
            messages.PayerLink_Confirm(agreement=True))

        self.assertEqual(self.payerLink.state,
                         payerlink.PayerLink.states.confirmed)

        self.assertEqual(len(ret), 2)
        msg = ret[0]
        self.assertTrue(isinstance(msg, messages.OutboundMessage))
        self.assertEqual(msg.localID, messages.payerLocalID)
        msg = msg.message
        self.assertTrue(isinstance(msg, messages.Confirm))
        self.assertEqual(msg.ID, None)
        self.assertEqual(msg.meetingPointID, self.payerLink.meetingPointID)
        msg = ret[1]
        self.assertTrue(isinstance(msg, messages.MakeRoute))
        self.assertEqual(msg.amount, self.payerLink.amount)
        self.assertEqual(msg.transactionID, self.payerLink.transactionID)
        #self.assertEqual(msg.startTime, None) #TODO
        #self.assertEqual(msg.endTime, None) #TODO
        self.assertEqual(msg.meetingPointID, self.payerLink.meetingPointID)
        self.assertEqual(msg.ID, messages.payerLocalID)
        self.assertEqual(msg.isPayerSide, True)

        self.payerLink.state = payerlink.PayerLink.states.hasReceipt

        ret = self.payerLink.handleMessage(
            messages.PayerLink_Confirm(agreement=False))

        self.assertEqual(self.payerLink.state,
                         payerlink.PayerLink.states.cancelled)

        self.assertEqual(len(ret), 3)
        msg = ret[0]
        self.assertTrue(isinstance(msg, messages.FilterTimeouts))
        function = msg.function
        self.assertFalse(function(messages.PayerTimeout()))
        self.assertTrue(function(messages.NodeStateTimeout_Route()))
        msg = ret[1]
        self.assertTrue(isinstance(msg, messages.OutboundMessage))
        self.assertEqual(msg.localID, messages.payerLocalID)
        msg = msg.message
        self.assertTrue(isinstance(msg, messages.Cancel))
        self.assertEqual(msg.ID, None)
        msg = ret[2]
        self.assertTrue(isinstance(msg, messages.SetEvent))
        self.assertEqual(msg.event, messages.SetEvent.events.paymentFinished)
Example #5
0
    def test_msg_timeout_other(self):
        "Test msg_timeout (state: other)"

        ret = self.payerLink.handleMessage(
            messages.PayerTimeout(
                state=payerlink.PayerLink.states.receivedRequestCommit))

        self.assertEqual(self.payerLink.state,
                         payerlink.PayerLink.states.initial)

        self.assertEqual(len(ret), 0)
Example #6
0
    def test_msg_timeout_receivedRequestCommit(self):
        "Test msg_timeout (state: receivedRequestCommit)"

        self.payerLink.state = payerlink.PayerLink.states.receivedRequestCommit

        ret = self.payerLink.handleMessage(
            messages.PayerTimeout(
                state=payerlink.PayerLink.states.receivedRequestCommit))

        self.assertEqual(self.payerLink.state,
                         payerlink.PayerLink.states.committed)

        self.assertEqual(len(ret), 2)

        msg = ret[0]
        self.assertTrue(isinstance(msg, messages.FilterTimeouts))
        function = msg.function
        self.assertFalse(function(messages.PayerTimeout()))
        self.assertTrue(function(messages.NodeStateTimeout_Route()))
        msg = ret[1]
        self.assertTrue(isinstance(msg, messages.SetEvent))
        self.assertEqual(msg.event, messages.SetEvent.events.paymentFinished)
Example #7
0
    def test_settleCommitIncoming(self):
        "Test settleCommitIncoming"

        ret = self.payerLink.settleCommitIncoming(
            messages.SettleCommit(token="bar"))

        self.assertEqual(self.payerLink.state,
                         payerlink.PayerLink.states.committed)

        self.assertEqual(len(ret), 2)

        msg = ret[0]
        self.assertTrue(isinstance(msg, messages.FilterTimeouts))
        function = msg.function
        self.assertFalse(function(messages.PayerTimeout()))
        self.assertTrue(function(messages.NodeStateTimeout_Route()))
        msg = ret[1]
        self.assertTrue(isinstance(msg, messages.SetEvent))
        self.assertEqual(msg.event, messages.SetEvent.events.paymentFinished)
Example #8
0
    def test_haveNoRouteOutgoing(self):
        "Test haveNoRouteOutgoing"

        ret = self.payerLink.haveNoRouteOutgoing(None, None)

        self.assertEqual(self.payerLink.state,
                         payerlink.PayerLink.states.cancelled)

        self.assertEqual(len(ret), 3)
        msg = ret[0]
        self.assertTrue(isinstance(msg, messages.FilterTimeouts))
        function = msg.function
        self.assertFalse(function(messages.PayerTimeout()))
        self.assertTrue(function(messages.NodeStateTimeout_Route()))
        msg = ret[1]
        self.assertTrue(isinstance(msg, messages.OutboundMessage))
        self.assertEqual(msg.localID, messages.payerLocalID)
        msg = msg.message
        self.assertTrue(isinstance(msg, messages.Cancel))
        msg = ret[2]
        self.assertTrue(isinstance(msg, messages.SetEvent))
        self.assertEqual(msg.event, messages.SetEvent.events.paymentFinished)