Пример #1
0
def app(hexed_client_id):

    bp = flask.Blueprint("test_views", __name__)

    @bp.route("/test-create", methods=["POST"])
    def create_token():
        TokenCreateSchema().validate_and_deserialize(flask.request.form)
        return "ok"

    @bp.route("/test-mint", methods=["POST"])
    def mint_token():
        ContractTransactSchema().validate_and_deserialize(flask.request.form)
        return "ok"

    registry = RPCRegistry()
    registry.dict[hexed_client_id] = mock.MagicMock(spec=RPCClient,
                                                    client_id=hexed_client_id)

    app = flask.Flask(__name__)
    app.config["TESTING"] = True
    app.config["rpc-client"] = registry

    app.register_blueprint(bp)

    return app
Пример #2
0
    def test_class_behaves_like_immutable_dict(self, transaction_service_client):
        registry = RPCRegistry()
        with pytest.raises(TypeError):
            registry["hello"] = "goodbye"

        with pytest.raises(TypeError):
            del registry["something"]
Пример #3
0
def app(hexed_client_id):
    rpc_client = MagicMock(spec=RPCClient, client_id=hexed_client_id)
    rpc_client.deploy_single_contract.return_value = (MockTokenProxy(), {
        "blockNumber": 100
    })

    registry = RPCRegistry()
    registry.dict[hexed_client_id] = rpc_client

    app = flask.Flask(__name__)
    app.config["TESTING"] = True
    app.config["rpc-client"] = registry

    app.register_blueprint(tokens_blueprint)

    return app
Пример #4
0
def transaction_service_app(rpc_client_id):
    app = construct_flask_app()
    app.config["TESTING"] = True
    app.config["rpc-client"] = RPCRegistry()
    app.config["rpc-client"].dict = {
        rpc_client_id:
        mock.Mock(**{"send_transaction.return_value": b"my_tx_hash"})
    }
    return app
Пример #5
0
    def test_getitem_with_valid_tuple_creates_stores_and_returns_rpc_instance(
            self, mock_rpc_client, valid_tuple):

        registry = RPCRegistry()
        chain_url, privkey, *strategy = valid_tuple
        expected_id = generate_hash_key(chain_url, privkey)
        # Assert the registry does not have the instance.
        with pytest.raises(werkzeug.exceptions.NotFound):
            registry[expected_id]

        instance, actual_id = registry[valid_tuple]
        mock_rpc_client.assert_called_once()
        assert actual_id == expected_id
        assert isinstance(instance, JSONRPCClient)
        assert registry[actual_id] == (instance, actual_id)
Пример #6
0
    def test_getitem_with_valid_tuple_creates_stores_and_returns_rpc_instance(
            self, mock_parent, valid_tuple):
        registry = RPCRegistry()
        chain_url, privkey, strategy = (
            "https://test.net",
            b"12345678909876543211234567890098",
            GAS_STRATEGIES["FAST"],
        )
        expected_id = generate_hash_key(chain_url, privkey, strategy)
        # Assert the registry does not have the instance.
        with pytest.raises(KeyError):
            registry[expected_id]

        instance = registry[valid_tuple]
        assert instance.client_id == expected_id
        assert isinstance(instance, RPCClient)
        assert registry[instance.client_id] == instance
Пример #7
0
 def test_getitem_raises_keyerror(self, invalid_key):
     with pytest.raises(KeyError):
         RPCRegistry()[invalid_key]
Пример #8
0
 def test_class_implements_pop_method(self, transaction_service_client):
     assert RPCRegistry().pop("Something") is None
Пример #9
0
 def test_getitem_raises_keyerror(self, invalid_key):
     with pytest.raises(werkzeug.exceptions.NotFound):
         RPCRegistry()[invalid_key]
Пример #10
0
def register_blueprints(app):
    app.config["rpc-client"] = RPCRegistry()
    for bp in (transactions_blueprint, instances_blueprint, tokens_blueprint):
        app.register_blueprint(bp)