def test_single_mock_block_processing(self, mock_get_info_head_block,
                                          mock_get_block):  #put get_info first
        """
        Tests block processing on a mocked block
        """
        mock_get_info_head_block.return_value = {'head_block_num': 99999999999}
        # get_block returns fake_block1
        mock_get_block.return_value = fake_block1
        # mock callback functions
        mock_start_block = Mock()
        mock_action = Mock()
        mock_commit_block = Mock()

        # register the mock callback functions
        d = Demux(start_block_fn=mock_start_block,
                  commit_block_fn=mock_commit_block)
        d.register_action(mock_action)
        # process the mock block fake_block1
        d.process_block(100)

        # assertions
        mock_get_block.assert_called_once()
        mock_get_block.assert_called_with(100)
        mock_start_block.assert_called_once()
        assert mock_action.call_count == 1
        mock_commit_block.assert_called_once()
Exemplo n.º 2
0
 def test_register_multiple_action_functions(self, mock_get_info_head_block,
                                             mock_get_block):
     """
     Tests that multiple action functions are registered to a specific account and name, including actions with no account or name specified
     """
     mock_get_info_head_block.return_value = {'head_block_num': 99999999999}
     mock_get_block.return_value = fake_block2
     # mock callback functions
     mock_start_block = Mock()
     mock_action1 = Mock()
     mock_action2 = Mock()
     mock_action3 = Mock()
     mock_commit_block = Mock()
     # parent mock for checking call order
     m = Mock()
     m.mock_action1, m.mock_action2, m.mock_action3 = mock_action1, mock_action2, mock_action3
     m.mock_calls
     # register the mock callback functions
     d = Demux(start_block_fn=mock_start_block,
               commit_block_fn=mock_commit_block)
     d.register_action(mock_action1, "account21", "name21")
     d.register_action(mock_action2, "account22", "name22")
     d.register_action(mock_action3)
     # process the mock fake block 2
     d.process_block(200)
     # assertions
     assert mock_get_block.call_count == 1
     assert mock_start_block.call_count == 1
     assert mock_action1.call_count == 1
     assert mock_action2.call_count == 1
     assert mock_action3.call_count == 2
     assert mock_commit_block.call_count == 1
     # action_dict assertions
     assert d._action_dict[('account21', 'name21',
                            'updates')] == [mock_action1]
     assert d._action_dict[('account22', 'name22',
                            'updates')] == [mock_action2]
     assert d._action_dict[(None, None, 'updates')] == [mock_action3]
     # action functions call order assertions
     m.assert_has_calls([
         call.mock_action3(fake_block2.get('transactions')[0]['trx']
                           ['transaction'].get('actions')[0],
                           block=fake_block2,
                           transaction=fake_block2.get('transactions')[0]),
         call.mock_action1(fake_block2.get('transactions')[0]['trx']
                           ['transaction'].get('actions')[0],
                           block=fake_block2,
                           transaction=fake_block2.get('transactions')[0]),
         call.mock_action3(fake_block2.get('transactions')[0]['trx']
                           ['transaction'].get('actions')[1],
                           block=fake_block2,
                           transaction=fake_block2.get('transactions')[0]),
         call.mock_action2(fake_block2.get('transactions')[0]['trx']
                           ['transaction'].get('actions')[1],
                           block=fake_block2,
                           transaction=fake_block2.get('transactions')[0])
     ])
Exemplo n.º 3
0
    def test_no_commit_block_function(self, mock_get_info_head_block,
                                      mock_get_block):
        """
        When users do not want to use the commit_block function
        """
        mock_get_info_head_block.return_value = {'head_block_num': 99999999999}
        mock_get_block.return_value = fake_block1
        # mock callback functions
        mock_start_block = Mock()
        mock_action = Mock()
        mock_commit_block = Mock()

        d = Demux(start_block_fn=mock_start_block)
        d.register_action(mock_action)
        d.process_block(9999)

        mock_start_block.assert_called_once()
        mock_action.assert_called()
        mock_commit_block.assert_not_called()
Exemplo n.º 4
0
    def test_start_and_commit_callback_functions_called(
            self, mock_get_info_head_block, mock_get_block):
        """
        Ensure the start_block and commit_block functions are called when processing a block
        """
        mock_get_info_head_block.return_value = {'head_block_num': 99999999999}
        mock_get_block.return_value = fake_block1
        # mock callback functions
        mock_start_block = Mock()
        mock_action = Mock()
        mock_commit_block = Mock()

        d = Demux(start_block_fn=mock_start_block,
                  commit_block_fn=mock_commit_block)
        d.register_action(mock_action)
        d.process_block(9999)
        mock_start_block.assert_called_once()
        mock_action.assert_called()
        mock_commit_block.assert_called_once()
 def test_block_with_no_transactions(self, mock_get_info_head_block,
                                     mock_get_block):
     """
     Ensure we can process a block with no transactions251
     """
     mock_get_info_head_block.return_value = {'head_block_num': 99999999999}
     # get_block returns manual block_1
     mock_get_block.return_value = block_1
     # mock callback functions
     mock_start_block = Mock()
     mock_action = Mock()
     mock_commit_block = Mock()
     # register the mock callback functions
     d = Demux(start_block_fn=mock_start_block,
               commit_block_fn=mock_commit_block)
     d.register_action(mock_action)
     # process the mock block_1
     d.process_block(1)
     # assertions
     mock_get_block.assert_called_once()
     mock_get_block.assert_called_with(1)
     mock_start_block.assert_called_once()
     assert mock_action.call_count == 0
     mock_commit_block.assert_called_once()