def setUp(self) -> None: self._account_model = BdnAccountModelBase( account_id="", logical_account_name="", certificate="", expire_date=utils_constants.DEFAULT_EXPIRATION_DATE.isoformat(), cloud_api=BdnServiceModelConfigBase( msg_quota=None, permit=BdnServiceModelBase(service_type=BdnServiceType.PERMIT), expire_date=utils_constants.DEFAULT_EXPIRATION_DATE.isoformat( ), ), blockchain_protocol="Ethereum", blockchain_network="Mainnet", ) self.rpc_port = helpers.get_free_port() opts = gateway_helpers.get_gateway_opts( 8000, rpc_port=self.rpc_port, account_model=self._account_model, blockchain_protocol="Ethereum", ) self.node = MockGatewayNode(opts) self.node.eth_ws_proxy_publisher = MockEthWsProxyPublisher( None, None, None, self.node) self.node.eth_ws_proxy_publisher.call_rpc = AsyncMock( return_value=JsonRpcResponse(request_id=1)) self.sut = EthOnBlockFeed(self.node)
def get_gateway_opts(self) -> GatewayOpts: self._account_model = BdnAccountModelBase( account_id="", logical_account_name="", certificate="", expire_date=utils_constants.DEFAULT_EXPIRATION_DATE.isoformat(), cloud_api=BdnServiceModelConfigBase( msg_quota=None, permit=BdnServiceModelBase(service_type=BdnServiceType.PERMIT), expire_date=utils_constants.DEFAULT_EXPIRATION_DATE.isoformat( )), blockchain_protocol="Ethereum", blockchain_network="Mainnet", )
def test_old_account_model_to_new(self): old_account_model = BdnOldAccountModelBase( "fake_id", "fake_name", "fake_cert", tx_paid=BdnServiceModelConfigBase( expire_date=str(date.today() + timedelta(days=100)), msg_quota=BdnServiceModelBase(limit=100)), new_transaction_streaming=BdnServiceModelConfigBase( expire_date=str(date.today() + timedelta(days=100)), permit=BdnServiceModelBase()), cloud_api=BdnServiceModelConfigBase( expire_date=str(date.today() + timedelta(days=100)), permit=BdnServiceModelBase())) old_account_model_json = json_encoder.to_json(old_account_model) new_account_model = model_loader.load_model_from_json( BdnAccountModelBase, old_account_model_json) self.assertEqual( old_account_model.tx_paid.is_service_valid(), new_account_model.tx_paid.is_service_valid(), ) self.assertEqual( old_account_model.tx_paid.msg_quota.limit, new_account_model.tx_paid.msg_quota.limit, ) self.assertEqual( old_account_model.cloud_api.is_service_valid(), new_account_model.cloud_api.is_service_valid(), ) self.assertEqual( old_account_model.new_transaction_streaming.is_service_valid(), new_account_model.new_transaction_streaming.is_service_valid(), ) # new account settings are not being set to default values, the SDN most verify that the payload is valid self.assertIsNone(new_account_model.new_transaction_streaming.feed)
def test_quota_account_setting(self): new_account_model = BdnAccountModelBase( "fake_id", "fake_name", "fake_cert", tx_paid=BdnQuotaServiceModelConfigBase( expire_date=str(date.today() + timedelta(days=100)), msg_quota=BdnServiceModelBase(limit=100)), block_paid=BdnQuotaServiceModelConfigBase(), cloud_api=BdnFeedServiceModelConfigBase(), new_transaction_streaming=BdnFeedServiceModelConfigBase()) new_account_model_json = json_encoder.to_json(new_account_model) old_account_model = model_loader.load_model_from_json( BdnOldAccountModelBase, new_account_model_json) self.assertTrue(new_account_model.tx_paid.is_service_valid()) self.assertTrue(old_account_model.tx_paid.is_service_valid()) self.assertEqual(old_account_model.tx_paid.msg_quota.limit, new_account_model.tx_paid.msg_quota.limit)
def get_gateway_opts(self) -> GatewayOpts: feed_service_model = FeedServiceModelBase(allow_filtering=True, available_fields=["all"]) base_feed_service_model = BdnFeedServiceModelConfigBase( expire_date="2999-01-01", feed=feed_service_model) self._account_model = BdnAccountModelBase( account_id="", logical_account_name="", certificate="", expire_date=utils_constants.DEFAULT_EXPIRATION_DATE.isoformat(), cloud_api=BdnServiceModelConfigBase( msg_quota=None, permit=BdnServiceModelBase(service_type=BdnServiceType.PERMIT), expire_date=utils_constants.DEFAULT_EXPIRATION_DATE.isoformat( )), new_transaction_streaming=base_feed_service_model, new_pending_transaction_streaming=base_feed_service_model, on_block_feed=base_feed_service_model, new_block_streaming=base_feed_service_model, transaction_state_feed=base_feed_service_model, blockchain_protocol="Ethereum", blockchain_network="Mainnet", )