-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add /peers route to get the validator peers
Signed-off-by: Andrea Gunderson <[email protected]>
- Loading branch information
Showing
10 changed files
with
206 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2017 Intel Corporation | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ----------------------------------------------------------------------------- | ||
|
||
syntax = "proto3"; | ||
|
||
option java_multiple_files = true; | ||
option java_package = "sawtooth.sdk.protobuf"; | ||
option go_package = "client_peer"; | ||
|
||
message ClientPeersGetRequest{ | ||
} | ||
|
||
message ClientPeersGetResponse { | ||
enum Status { | ||
STATUS_UNSET = 0; | ||
OK = 1; | ||
ERROR = 2; | ||
} | ||
Status status = 1; | ||
repeated string peers = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright 2017 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ------------------------------------------------------------------------------ | ||
|
||
import json | ||
from aiohttp.test_utils import unittest_run_loop | ||
from components import Mocks, BaseApiTest | ||
from sawtooth_rest_api.protobuf.validator_pb2 import Message | ||
from sawtooth_rest_api.protobuf import client_peers_pb2 | ||
|
||
|
||
class PeersGetRequestTests(BaseApiTest): | ||
|
||
async def get_application(self, loop): | ||
self.set_status_and_connection( | ||
Message.CLIENT_PEERS_GET_REQUEST, | ||
client_peers_pb2.ClientPeersGetRequest, | ||
client_peers_pb2.ClientPeersGetResponse) | ||
|
||
handlers = self.build_handlers(loop, self.connection) | ||
return self.build_app(loop, '/peers', handlers.fetch_peers) | ||
|
||
@unittest_run_loop | ||
async def test_peers_request(self): | ||
"""Verifies a GET /peers works proberly. | ||
It will receive a Protobuf response with: | ||
- list of peer endoints | ||
It should send an empty Protobuf request. | ||
It should send back a JSON response with: | ||
- a response status of 200 | ||
- a link property that ends in '/peers' | ||
- a data property matching the peers | ||
""" | ||
self.connection.preset_response( | ||
peers=["Peer1", "Peer2"], | ||
status=self.status.OK) | ||
|
||
response = await self.get_assert_200('/peers') | ||
self.connection.assert_valid_request_sent() | ||
|
||
self.assert_has_valid_link(response, '/peers') | ||
self.assertEquals(["Peer1", "Peer2"], response['data']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
validator/tests/test_client_request_handlers/test_peer_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Copyright 2017 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ------------------------------------------------------------------------------ | ||
|
||
import sawtooth_validator.state.client_handlers as handlers | ||
from sawtooth_validator.protobuf import client_peers_pb2 | ||
from test_client_request_handlers.base_case import ClientHandlerTestCase | ||
from test_client_request_handlers.mocks import MockGossip | ||
|
||
|
||
class TestPeerRequests(ClientHandlerTestCase): | ||
def setUp(self): | ||
gossip = MockGossip() | ||
self.initialize( | ||
handlers.PeersGetRequest(gossip), | ||
client_peers_pb2.ClientPeersGetRequest, | ||
client_peers_pb2.ClientPeersGetResponse, | ||
) | ||
|
||
def test_peer_request(self): | ||
"""Verifies requests for peers work properly. | ||
Queries the default mock gossip for peers. Expecting "Peer1" | ||
Expects to find: | ||
- a status of OK | ||
- a head_id of 'B-2' (the latest) | ||
- the default paging response, showing all 3 resources returned | ||
- a list of blocks with 3 items | ||
- the items are instances of Block | ||
- The first item has a header_signature of 'B-2' | ||
""" | ||
response = self.make_request() | ||
|
||
self.assertEqual(self.status.OK, response.status) | ||
self.assertEqual(["Peer1"], response.peers) |