def instantiate_blockchain_handlers(app_config, file_mode=True): issuing_address = app_config.issuing_address chain = app_config.chain secret_manager = initialize_signer(app_config) if file_mode: certificate_batch_handler = CertificateBatchHandler( secret_manager=secret_manager, certificate_handler=CertificateV2Handler(), merkle_tree=MerkleTreeGenerator()) else: certificate_batch_handler = CertificateBatchWebHandler( secret_manager=secret_manager, certificate_handler=CertificateWebV2Handler(), merkle_tree=MerkleTreeGenerator()) if chain == Chain.mockchain: transaction_handler = MockTransactionHandler() else: cost_constants = BitcoinTransactionCostConstants( app_config.tx_fee, app_config.dust_threshold, app_config.satoshi_per_byte) connector = BitcoinServiceProviderConnector(chain, app_config.bitcoind) transaction_handler = BitcoinTransactionHandler( connector, cost_constants, secret_manager, issuing_address=issuing_address) return certificate_batch_handler, transaction_handler, connector
def instantiate_blockchain_handlers(app_config): issuing_address = app_config.issuing_address chain = app_config.chain secret_manager = initialize_signer(app_config) certificate_batch_handler = CertificateBatchHandler(secret_manager=secret_manager, certificate_handler=CertificateV2Handler(), merkle_tree=MerkleTreeGenerator()) if chain == Chain.mockchain: transaction_handler = MockTransactionHandler() # ethereum chains elif chain == Chain.ethereum_mainnet or chain == Chain.ethereum_ropsten: cost_constants = EthereumTransactionCostConstants(app_config.gas_price, app_config.gas_limit) connector = EthereumServiceProviderConnector(chain, app_config.api_token) transaction_handler = EthereumTransactionHandler(connector, cost_constants, secret_manager, issuing_address=issuing_address) return certificate_batch_handler, transaction_handler, connector
def test_add_proof(self,mock_open): handler = CertificateV2Handler() cert_to_issue = {'kek':'kek'} proof = {'a': 'merkel'} file_call = 'call().__enter__().write(\'{"kek": "kek", "signature": {"a": "merkel"}}\')' chain = mock.Mock() metadata = mock.Mock() metadata.blockchain_cert_file_name = 'file_path.nfo' with patch.object( CertificateV2Handler, '_get_certificate_to_issue', return_value=cert_to_issue) as mock_method: handler.add_proof(metadata, proof) mock_open.assert_any_call('file_path.nfo','w') calls = mock_open.mock_calls call_strings = map(str, calls) assert file_call in call_strings