def test_txn(self): """Test receipt of a Transaction. """ self.node.receive_transaction = MagicMock() txn = Transaction(0, 'command1', 1) s = txn.serialize() self.proto.stringReceived(s) self.assertTrue(self.node.receive_transaction.called) obj = self.node.receive_transaction.call_args[0][0] self.assertEqual(type(obj), Transaction) self.assertEqual(obj, txn)
def scenario1(node): """Start the paxos algorithm by bringing a Transaction in circulation. A node sends it directly to the single quick node. This scenario assumes a healthy state i.e one quick node and the others are slow. Args: node (Node): Node calling this method """ logging.debug('start test scenario 1') if node.id == 2: # create a Transaction and send it to node with id == 0 (the quick node) txn = Transaction(2, 'command1', 1) connection = node.peers_connection.get('0') if connection is not None: logging.debug('txn send to node 0') connection.sendString(txn.serialize())