Skip to content

Commit

Permalink
feat: add attachments handler to the sidecar (#1107)
Browse files Browse the repository at this point in the history
* add attachments handler

* add tests
  • Loading branch information
Jiloc authored Dec 12, 2024
1 parent 8fe9a46 commit 57c30e4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions emily_sidecar/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,13 @@ def handle_new_block():
return jsonify({}), 200


# stacks-node will seldomly send a POST request to /attachments/new
# if the request is not handled, the node will loop and keep retrying
# https://github.com/stacks-network/stacks-core/issues/5558
@app.route("/attachments/new", methods=["POST"])
def handle_attachments():
return jsonify({}), 200


if __name__ == "__main__":
app.run(host="127.0.0.1", port=5000)
21 changes: 21 additions & 0 deletions emily_sidecar/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,26 @@ def test_new_block_post_request_failure(self, mock_post):
self.assertIn("Failed to send chainstate", response.get_json()["error"])


class AttachmentsTestCase(unittest.TestCase):
def setUp(self):
self.app = app.test_client()
self.app.testing = True

def test_handle_attachments_with_any_json(self):
test_json = {"key": "value"}
response = self.app.post('/attachments/new', json=test_json)
self.assertEqual(response.status_code, 200)
self.assertEqual({}, response.get_json())

def test_handle_attachments_with_empty_json(self):
response = self.app.post('/attachments/new', json={})
self.assertEqual(response.status_code, 200)
self.assertEqual({}, response.get_json())

def test_handle_attachments_with_no_json(self):
response = self.app.post('/attachments/new')
self.assertEqual(response.status_code, 200)
self.assertEqual({}, response.get_json())

if __name__ == '__main__':
unittest.main()

0 comments on commit 57c30e4

Please sign in to comment.