def test_build_response_fails_on_bad_data_type(): """Test internal build_response functions for data type check.""" dispatcher = ContractApiRequestDispatcher(MagicMock()) with patch.object( dispatcher, "dispatch_request", lambda x, x1, x2, fn: fn(data=b"some_data", dialogue=MagicMock()), ), pytest.raises( ValueError, match=r"Invalid state type, got=<class '.+'>, expected=typing.Dict" ): dispatcher.get_state(MagicMock(), MagicMock(), MagicMock()) with patch.object( dispatcher, "dispatch_request", lambda x, x1, x2, fn: fn(rm=12, dialogue=MagicMock()), ), pytest.raises(ValueError, match=r"Invalid message type"): dispatcher.get_raw_message(MagicMock(), MagicMock(), MagicMock()) with patch.object( dispatcher, "dispatch_request", lambda x, x1, x2, fn: fn(tx=b"some_data", dialogue=MagicMock()), ): with pytest.raises( ValueError, match=r"Invalid transaction type, got=<class '.+'>, expected=typing.Dict", ): dispatcher.get_deploy_transaction(MagicMock(), MagicMock(), MagicMock()) with pytest.raises( ValueError, match=r"Invalid transaction type, got=<class '.+'>, expected=typing.Dict", ): dispatcher.get_raw_transaction(MagicMock(), MagicMock(), MagicMock())
async def connect(self) -> None: """Set up the connection.""" self._ledger_dispatcher = LedgerApiRequestDispatcher( self.connection_status, loop=self.loop, api_configs=self.api_configs) self._contract_dispatcher = ContractApiRequestDispatcher( self.connection_status, loop=self.loop, api_configs=self.api_configs) self._event_new_receiving_task = asyncio.Event(loop=self.loop) self.connection_status.is_connected = True
async def connect(self) -> None: """Set up the connection.""" if self.is_connected: # pragma: nocover return self._state.set(ConnectionStates.connecting) self._ledger_dispatcher = LedgerApiRequestDispatcher( self._state, loop=self.loop, api_configs=self.api_configs, logger=self.logger, ) self._contract_dispatcher = ContractApiRequestDispatcher( self._state, loop=self.loop, api_configs=self.api_configs, logger=self.logger, ) self._event_new_receiving_task = asyncio.Event(loop=self.loop) self._state.set(ConnectionStates.connected)
async def test_get_handler(): """Test failed to get handler.""" with pytest.raises(Exception, match="Performative not recognized."): ContractApiRequestDispatcher(ConnectionStatus()).get_handler( ContractApiMessage.Performative.ERROR )