def test_calc_consensus_chain_multiple_nodes(setup): node_0 = MagicMock() node_0.execute_rpc.side_effect = [ 'hash1', 'hash2', JSONRPCError({ 'code': -1, 'message': 'error' }) ] node_1 = MagicMock() node_1.execute_rpc.side_effect = [ 'hash1', 'hash2', JSONRPCError({ 'code': -1, 'message': 'error' }) ] setup.context.first_block_height = 10 setup.context.nodes = {'0': node_0, '1': node_1} chain = setup.cli_stats._calc_consensus_chain() assert len(chain) == 2 assert chain[0] == 'hash1' assert chain[1] == 'hash2'
def test_execute_cmd_with_exception(): context = MagicMock() node = MagicMock() node.generate_tx.side_effect = JSONRPCError( {'code': -1, 'message': 'test_message'}) context.nodes = {'node-1': node} e = Event(context) e._execute_cmd('tx node-1')
def test_calc_consensus_chain_first_node_no_block(setup): node_0 = MagicMock() node_0.execute_rpc.side_effect = JSONRPCError({ 'code': -1, 'message': 'error' }) setup.context.first_block_height = 10 setup.context.nodes = {'0': node_0} chain = setup.cli_stats._calc_consensus_chain() assert len(chain) == 0
def test_calc_consensus_chain_one_node(self): node_0 = MagicMock() node_0.execute_rpc.side_effect = [ 'hash', JSONRPCError({ 'code': -1, 'message': 'error' }) ] self.context.first_block_height = 10 self.context.nodes = {'0': node_0} chain = self.cli_stats._calc_consensus_chain() self.assertEqual(len(chain), 1) self.assertEqual(chain[0], 'hash')